protected string FormAnswer(SimplexTable table, List <int> basis)
        {
            var result = "";

            for (int j = 0; j < table.NumOfVariables; j++)
            {
                if (basis.Contains(j))
                {
                    result += $"{table.cLables[j].Value} = {table.bVector[basis.IndexOf(j)].ToString()}";
                }
                else
                {
                    result += $"{table.cLables[j].Value} = 0";
                }

                if (j + 1 < table.NumOfVariables)
                {
                    result += ", ";
                }
            }

            var costValue = new SimplexCoef();

            ReevaluateBasisAndDeltas(table);
            for (int i = 0; i < table.NumOfConstrains; i++)
            {
                costValue += table.cVector[basis[i]] * table.bVector[i];
            }

            costValue += table.constantValue;
            result    += $"<br>L = {((table.costFIsInverted) ? (-costValue).ToString() : costValue.ToString())}<br>";

            return(result);
        }
        protected List <SimplexCoef> EvaluateDeltas(List <SimplexCoef> basisC, SimplexTable table)
        {
            var simplexDeltes = new List <SimplexCoef>();

            for (int j = 0; j < table.NumOfVariables; j++)
            {
                var dotProd = new SimplexCoef();
                for (int i = 0; i < table.NumOfConstrains; i++)
                {
                    dotProd += basisC[i] * table.aMatrix[i][j];
                }
                simplexDeltes.Add(table.cVector[j] - dotProd);
            }

            return(simplexDeltes);
        }
        private List <SimplexCoef> FormBFractVector(SimplexTable table)
        {
            var bFracts = new List <SimplexCoef>();

            foreach (var b in table.bVector)
            {
                var curBFract = b.value.Fract();
                if (curBFract == 0)
                {
                    bFracts.Add(null);
                }
                else
                {
                    var nwCoef = new SimplexCoef(b);
                    nwCoef.value = -curBFract;
                    bFracts.Add(nwCoef);
                }
            }
            return(bFracts);
        }
        protected int FindIndexOfMin(List <SimplexCoef> delta)
        {
            int         resIndex = 0;
            SimplexCoef minCoef  = delta[0];

            for (int i = 0; i < delta.Count; i++)
            {
                if (delta[i] == null)
                {
                    continue;
                }
                if (minCoef == null || delta[i] < minCoef)
                {
                    resIndex = i;
                    minCoef  = delta[i];
                }
            }

            return(resIndex);
        }
Exemple #5
0
        private List <SimplexCoef> FormBFractVector(SimplexTable table)
        {
            var bFracts = new List <SimplexCoef>();

            for (int i = 0; i < table.NumOfConstrains; i++)
            {
                var curBFract = table.bVector[i].value.Fract();

                if (curBFract == 0 || !table.cLables[curBasis[i]].IsSelected)
                {
                    bFracts.Add(null);
                }
                else
                {
                    var nwCoef = new SimplexCoef(table.bVector[i]);
                    nwCoef.value = -curBFract;
                    bFracts.Add(nwCoef);
                }
            }
            return(bFracts);
        }