Esempio n. 1
0
        /// <summary>
        /// Returns sorted PossibleExtensions
        /// </summary>
        /// <param name="omega"></param>
        /// <returns> </returns>
        public static List <PossibleExtension> FindPossibleExtensions(List <int> omega)
        {
            D Darray = new D();
            List <PossibleExtension> S = new List <PossibleExtension>();

            if (omega.Count == 1)
            {
                return(S);
            }
            Darray = Matrix.FindD(omega);
            for (int i = 0; i < Darray.Index.Count; i++)
            {
                if (omega.Contains(Darray.i[i]) && omega.Contains(Darray.j[i]))
                {
                    //весовой коэф
                    #region
                    int currentWeight = 0;
                    for (int j = 0; j < Darray.Index[i].Count; j++)
                    {
                        foreach (WeightCoefficient weight in Program.weights)
                        {
                            if (weight.index == Darray.Index[i][j])
                            {
                                currentWeight += weight.weight;
                            }
                        }
                    }
                    #endregion
                    PossibleExtension s = new PossibleExtension(Darray.i[i], Darray.j[i], currentWeight, Darray.Index[i]);
                    S.Add(s);
                }
            }
            //sorting
            PossibleExtensionComparer sc = new PossibleExtensionComparer();
            S.Sort(sc);
            return(S);
        }
Esempio n. 2
0
        private static void FourthStepA1a()//FourthStepA1a here
        {
            PossibleExtension possibleKnot = PossibleExtension.FindKnot(new List <PossibleExtension>(quantityOfSecondPossibleExtension[indexOfSecondPlunk].Except(helpfullMultitudeQ[indexOfSecondPlunk])));

            if (centralSecondElement[indexOfSecondPlunk].Last().weight > possibleKnot.weight)//неравенство 2.3.4
            {
                FourthStepA1c();
            }
            else
            {//неравенство 2.3.5
             //левая часть
                #region
                int newWeight = 0;
                newWeight += firstOrderedMultitude.weight;             //первое слагаемое
                for (int i = 0; i < helpfullMultitudeQ.Count - 1; i++) //3 слагаемое
                {
                    if (helpfullMultitudeQ[i].Any())
                    {
                        foreach (WeightCoefficient weight in weights)
                        {
                            if (helpfullMultitudeQ[i].Last().i == weight.index || helpfullMultitudeQ[i].Last().j == weight.index)
                            {
                                newWeight += weight.weight;
                            }
                        }
                    }
                }

                /*foreach (List<PossibleExtension> element in helpfullMultitudeQ)//3 слагаемое
                 * {
                 *  if (element.Any())
                 *  {
                 *      foreach (WeightCoefficient weight in weights)
                 *      {
                 *          if (element.Last().i == weight.index || element.Last().j == weight.index)
                 *          {
                 *              newWeight += weight.weight;
                 *          }
                 *      }
                 *  }
                 * }*/
                newWeight += possibleKnot.weight;//сумма слагаемых
                #endregion
                if (newWeight > firstRecord.weight + secondRecord.weight)
                {
                    helpfullMultitudeQ[indexOfSecondPlunk].Add(possibleKnot);
                    //формируем новое множество омега
                    List <int> usedIndexes = new List <int>();
                    usedIndexes.Add(possibleKnot.i);
                    usedIndexes.Add(possibleKnot.j);

                    secondOmega.Add(new List <int>());
                    centralSecondElement.Add(new List <CentralElement>());
                    helpfullMultitudeQ.Add(new List <PossibleExtension>());
                    quantityOfSecondPossibleExtension.Add(new List <PossibleExtension>());
                    indexOfSecondPlunk++;

                    secondOmega[indexOfSecondPlunk] = new List <int>(possibleKnot.elements.Except(usedIndexes));
                    FourthStep();
                }
                else
                {
                    FourthStepA1b();
                }
            }
        }
Esempio n. 3
0
        private static void SecondStepA1()
        {
            //формируем список F
            #region
            List <int> newMultitudeF = new List <int>();
            foreach (CentralElement element in supportingMultitudeF[indexOfFirstPlunk])
            {
                newMultitudeF.Add(element.index);
            }
            #endregion
            if (omega[indexOfFirstPlunk].Except(newMultitudeF).Count() == 0)
            {
                SecondStepA1b();
            }
            else
            {
                //формируем список F
                #region
                newMultitudeF = new List <int>();
                foreach (CentralElement element in supportingMultitudeF[indexOfFirstPlunk])
                {
                    newMultitudeF.Add(element.index);
                }
                #endregion
                centralElement = CentralElement.FindCentral(new List <int>(omega[indexOfFirstPlunk].Except(newMultitudeF)));
                if (IsEqual(quantityOfPossibleExtension[indexOfFirstPlunk], supportingMultitudeQ[indexOfFirstPlunk]))
                {
                    SecondStepA1c();
                }
                else if (new List <PossibleExtension>(quantityOfPossibleExtension[indexOfFirstPlunk].Except(supportingMultitudeQ[indexOfFirstPlunk])).Count != 0)
                {
                    knotElement = PossibleExtension.FindKnot(new List <PossibleExtension>(quantityOfPossibleExtension[indexOfFirstPlunk].Except(supportingMultitudeQ[indexOfFirstPlunk])));
                    //сравниваем веса претендентов на роль узлового и центрального эл-тов
                    if (knotElement.weight < centralElement.weight)//неравенство 2.3.1
                    {
                        SecondStepA1c();
                    }
                    else//неравенство 2.3.2
                    {
                        //левая часть
                        #region
                        int newWeight = 0;
                        for (int i = 0; i < supportingMultitudeQ.Count - 1; i++)//1 слагаемое
                        {
                            if (supportingMultitudeQ[i].Any())
                            {
                                foreach (WeightCoefficient weight in weights)
                                {
                                    if (supportingMultitudeQ[i].Last().i == weight.index || supportingMultitudeQ[i].Last().j == weight.index)
                                    {
                                        newWeight += weight.weight;
                                    }
                                }
                            }
                        }

                        /*foreach (List<PossibleExtension> element in supportingMultitudeQ)
                         * {
                         *  if (element.Any())
                         *  {
                         *      foreach (WeightCoefficient weight in weights)
                         *      {
                         *          if (element.Last().i == weight.index || element.Last().j == weight.index)
                         *          {
                         *              newWeight += weight.weight;//первое слагаемое
                         *          }
                         *      }
                         *  }
                         *
                         * }*/

                        newWeight += knotElement.weight;//сумма слагаемых
                        #endregion
                        if (newWeight > (firstRecord.weight + secondRecord.weight) / 2)
                        {
                            supportingMultitudeQ[indexOfFirstPlunk].Add(knotElement);
                            //формируем новое множество омега
                            List <int> usedIndexes = new List <int>();
                            usedIndexes.Add(knotElement.i);
                            usedIndexes.Add(knotElement.j);

                            omega.Add(new List <int>());
                            supportingMultitudeF.Add(new List <CentralElement>());
                            supportingMultitudeQ.Add(new List <PossibleExtension>());
                            quantityOfPossibleExtension.Add(new List <PossibleExtension>());
                            indexOfFirstPlunk++;

                            omega[indexOfFirstPlunk] = new List <int>(knotElement.elements.Except(usedIndexes));
                            SecondStep();
                        }
                        else
                        {
                            SecondStepA1b();
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 private static void FourthStepA()
 {
     quantityOfSecondPossibleExtension[indexOfSecondPlunk] = PossibleExtension.FindPossibleExtensions(secondOmega[indexOfSecondPlunk]);
     centralSecondElement[indexOfSecondPlunk].Add(CentralElement.FindCentral(secondOmega[indexOfSecondPlunk]));
     FourthStepA0();
 }
Esempio n. 5
0
 private static void SecondStepA()
 {
     quantityOfPossibleExtension[indexOfFirstPlunk] = PossibleExtension.FindPossibleExtensions(omega[indexOfFirstPlunk]);
     SecondStepA1();
 }