示例#1
0
        public static LPPolynomial JoinPolys(LPPolynomial poly1, LPPolynomial poly2)
        {
            var rLPoly = new LPPolynomial(poly1);

            foreach (var polyn in poly2.GetPoly)
            {
                rLPoly.AddNewVariable(polyn.Item1, polyn.Item2);
            }

            rLPoly.Constant += poly2.Constant;

            return rLPoly;
        }
示例#2
0
        private static LPPolynomial ParseMonomial(ParseTreeNode node)
        {
            var lpPoly = new LPPolynomial();
            switch (node.ChildNodes.Count)
            {
                case 1:
                    lpPoly.AddNewVariable(node.ChildNodes[0].ToString().Replace("(variable)", "").Replace(" ", ""), 1f);
                    break;
                case 3:
                    double coefficient = 0;
                    switch (node.ChildNodes[0].ToString())
                    {
                        case "lpNumber":
                            coefficient = ParseLPNumber(node.ChildNodes[0]);
                            break;
                        case "number":
                            coefficient = ParseNumber(node.ChildNodes[0]);
                            break;
                        default:
                            throw new Exception("Invalid Model - Modeler Error At Monomial");
                    }

                    lpPoly.AddNewVariable(node.ChildNodes[2].ToString().Replace("(variable)", "").Replace(" ", ""),
                                          coefficient);
                    break;
            }

            return lpPoly;
        }