Esempio n. 1
0
 public void GetResultForSimplex()
 {
     if (!TaskForMax)
     {
         simplexTable.ChangTargetFunction();
     }
     SelectBasis();
     CalculateD();
     while (FindGuideColumnForSimplex())
     {
         Console.WriteLine(simplexTable.ToString());
         Console.WriteLine("D:");
         for (int j = 0; j < simplexTable.nColumns; j++)
         {
             Console.Write(d[j] + "\t");
         }
         Console.WriteLine();
         FindGuideRowForSimplex();
         RecalculateTable();
         basis[guideRow] = guideColumn;
         //CalculateD();
     }
     if (!TaskForMax)
     {
         simplexTable.ChangTargetFunction();
     }
     GetResult();
 }
Esempio n. 2
0
        private SimplexAlgorithm GetResult(SimplexTable simplexTable, int startRowForTransform)
        {
            SimplexTable simplexT = (SimplexTable)simplexTable.Clone();

            CanonicalTransformation.TransformForSimplex(simplexT, startRowForTransform);
            Console.WriteLine(simplexT.ToString());
            SimplexAlgorithm smpAlg = new SimplexAlgorithm(simplexT, true);

            smpAlg.GetResultForSimplex();
            if (smpAlg.Result == null)
            {
                return(smpAlg);
            }
            int nOfDouble = IsDouble(smpAlg.Result);

            if (nOfDouble == -1)
            {
                return(smpAlg);
            }
            Console.WriteLine("double result({0})={1}", nOfDouble, smpAlg.Result[nOfDouble]);
            //Branch 1
            Console.WriteLine("start branch 1");
            SimplexTable simplexT1 = (SimplexTable)simplexT.Clone();

            AddLimitation(simplexT1, nOfDouble, smpAlg.Result[nOfDouble], "<=");
            SimplexAlgorithm smpAlg1;

            smpAlg1 = GetResult(simplexT1, simplexT1.nRows - 1);

            //Brackh 2
            Console.WriteLine("start branch 2");
            SimplexTable simplexT2 = (SimplexTable)simplexT.Clone();

            AddLimitation(simplexT2, nOfDouble, smpAlg.Result[nOfDouble], ">=");
            SimplexAlgorithm smpAlg2;

            smpAlg2 = GetResult(simplexT2, simplexT2.nRows - 1);
            if (smpAlg1.Result == null)
            {
                return(smpAlg2);
            }
            if (smpAlg2.Result == null)
            {
                return(smpAlg1);
            }
            if (smpAlg1.FunctionValue > smpAlg2.FunctionValue)
            {
                return(smpAlg1);
            }
            else
            {
                return(smpAlg2);
            }
        }