Esempio n. 1
0
        public override string MakeTransform(SimplexTable inputTable, out SimplexTable outputTable, out bool success)
        {
            var result  = "<h3>Let's ignore integer constrain:</h3><br>";
            var simplex = new SimplexMethod();

            result += simplex.MakeTransform(inputTable, out outputTable, out success);

            int counter = 1;

            while (success && !IsDone(outputTable))
            {
                result += $"<br><br><h4>Step {counter++}:</h4><br>";
                result += "BVector has fractional components. Let's add another constrain.<br>";

                result += AddConstrain(outputTable, out outputTable, out success);
                if (!success)
                {
                    break;
                }

                result += "So new Table looks like this:<br>";

                ReevaluateBasisAndDeltas(outputTable);
                result += PrintTableToHTML(outputTable, curBasis, curDelta);

                result += "<br><br>Using dual Simplex method:<br>";
                var dualSimplex = new DualSimplexMethod();
                result += dualSimplex.MakeTransform(outputTable, out outputTable, out success);
            }

            if (success)
            {
                result += "That's it. Now we have integer solution.<br>";
            }

            return(result);
        }
Esempio n. 2
0
        private List <int?> GetValidNuVector(SimplexTable inputTable, out SimplexTable outputTable, out string result)
        {
            outputTable = inputTable;
            result      = "";

            List <int?> nuVector    = null;
            bool        foundAllNus = false;

            while (!foundAllNus)
            {
                ReevaluateBasisAndDeltas(outputTable);
                nuVector = FormNuVector(outputTable, curBasis, out foundAllNus);
                if (!foundAllNus)
                {
                    var tarJ = curBasis[nuVector.IndexOf(-1)];
                    result += $"{outputTable.cLables[tarJ].Value} became bigger than any element of its set.<br>";
                    var maxElem = outputTable.discreteSet[tarJ].Max();
                    result += $"So, let's add constrain '{outputTable.cLables[tarJ].Value}' < {maxElem.ToString()} and run MMethod.<br>";

                    outputTable = new SimplexTable(outputTable);
                    outputTable.NumOfConstrains += 1;
                    outputTable.NumOfVariables  += 1;
                    outputTable.aMatrix[outputTable.NumOfConstrains - 1][tarJ].value = BigRational.One;
                    outputTable.aMatrix[outputTable.NumOfConstrains - 1][outputTable.NumOfVariables - 1].value = BigRational.One;
                    outputTable.bVector[outputTable.NumOfConstrains - 1].value = maxElem.value;

                    var simplexMethod = new SimplexMethod();
                    result += simplexMethod.MakeTransform(outputTable, out outputTable, out bool success);
                    if (!success)
                    {
                        return(null);
                    }
                }
            }

            return(nuVector);
        }