示例#1
0
        public static Tableau NextTableau(Tableau t, Variable pHead, Variable pRow)
        {
            var pIndex = t.IndexOf(pRow);
            var pEq    = t[pRow].Switch(pHead);

            var equations = new Equation[t.Equations.Length];

            for (int i = 0; i < equations.Length; i++)
            {
                if (i == pIndex)
                {
                    equations[i] = pEq;
                }
                else
                {
                    equations[i] = t[i].Resolve(pEq);
                }
            }

            return(new Tableau(equations));
        }
示例#2
0
        public Solver(StreamReader reader)
        {
            var cells = ReadAllLines(reader).Select(l => l.Split(';')).ToArray();

            var vCnt = int.Parse(cells[0][0]);
            var cCnt = int.Parse(cells[0][1]);

            var pVars = new Variable[vCnt];
            var sVars = new Variable[cCnt];

            for (var i = 0; i < pVars.Length; i++)
            {
                pVars[i] = Variable.Problem(i + 1);
            }

            var eqs = new List <Equation>();

            for (var i = 0; i < cCnt; i++)
            {
                var op     = cells[i + 3][0];
                var fCells = cells[i + 3].Skip(1).ToArray();

                if (op == "<=" || op == "=")
                {
                    eqs.Add(new Equation(Variable.Slack(i + 1), GetFactorsByLine(pVars, fCells, true), double.Parse(cells[i + 3][vCnt + 1])));
                }

                if (op == ">=" || op == "=")
                {
                    eqs.Add(new Equation(Variable.Slack(i + 1), GetFactorsByLine(pVars, fCells, false), double.Parse(cells[i + 3][vCnt + 1])));
                }
            }

            //target function
            var tFactors = new VariableFactor[vCnt];
            var minimize = cells[1][0].Contains("min");

            for (var i = 0; i < tFactors.Length; i++)
            {
                var val = double.Parse(cells[1][i + 1]);

                if (minimize)
                {
                    val = -val;
                }

                tFactors[i] = new VariableFactor(pVars[i], val);
            }
            var targetVal = double.Parse(cells[1][vCnt + 1]);

            if (minimize)
            {
                targetVal = -targetVal;
            }

            var target = new Equation(Variable.Target(), tFactors, targetVal);

            eqs.Add(target);

            _equations = eqs.ToArray();
        }
示例#3
0
 public bool Equals(Equation other) => this == other;