Example #1
0
        public LPModel(string name, LPGoal goal, IEnumerable<LPConstraint> constraints)
        {
            Name = name;
            Objective = goal.Goal;
            GoalKind = goal.GoalType;

            _constraint = new List<LPConstraint>(constraints);
        }
Example #2
0
        private static LPGoal ParseGoal(ParseTreeNode lpGoalNode)
        {
            var rGoal = new LPGoal();
            if (lpGoalNode.ChildNodes[0].ToString() == "min (Keyword)")
                rGoal.GoalType = LPGoalType.Minimize;
            else if (lpGoalNode.ChildNodes[0].ToString() == "max (Keyword)")
                rGoal.GoalType = LPGoalType.Maximize;

            rGoal.Goal = ParsePolynomial(lpGoalNode.ChildNodes[1]);

            return rGoal;
        }
Example #3
0
        public static LPModel ConvertParseTreeToModel(ParseTree tree)
        {
            string modelName = "";
            var lpGoal = new LPGoal();
            var lpConstraints = new List<LPConstraint>();

            if (tree.Root.ToString() == "lpApp")
            {
                foreach (ParseTreeNode node in tree.Root.ChildNodes)
                {
                    switch (node.ToString())
                    {
                        case "lpAppName":
                            modelName = ParseModelName(node);
                            break;
                        case "lpModel":
                            foreach (ParseTreeNode subNodes in node.ChildNodes)
                            {
                                switch (subNodes.ToString())
                                {
                                    case "lpGoal":
                                        lpGoal = ParseGoal(subNodes);
                                        break;
                                    case "lpConstraints":
                                        lpConstraints = ParseConstraints(subNodes);
                                        break;
                                }
                            }
                            break;
                    }
                }
            }
            else
            {
                throw new Exception("The Root element is not Correct");
            }

            return new LPModel(modelName.Replace("(appIdentifier)", "").Replace(" ", ""), lpGoal, lpConstraints);
        }