Пример #1
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();
                }
            }
        }
Пример #2
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();
                        }
                    }
                }
            }
        }