Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //new changes
            Stopwatch sw = new Stopwatch();

            sw.Start();
            SimplexTable st = MatrixReader.ReadSimplexTable("MatrixA.txt", "VectorB.txt", "VectorC.txt", "Signs.txt");
            //CanonicalTransformation.TransformForSimplex(st);
            //SimplexAlgorithm sa = new SimplexAlgorithm(st, true);
            //sa.GetResultForSimplex();
            BranchAndBoundAlgorithm bb = new BranchAndBoundAlgorithm();
            SimplexAlgorithm        sa = bb.GetResult(st, true);

            Console.Write("\nResult\n{\t");
            for (int i = 0; i < sa.Result.Length; i++)
            {
                Console.Write(sa.Result[i] + "\t");
            }
            Console.WriteLine("}");
            Console.Write("Function value {0} ", sa.FunctionValue);
            sw.Stop();
            Console.WriteLine("{0} ms", sw.ElapsedMilliseconds);
            Console.ReadLine();
        }