有谁知道任何可以解决线性约束数学模型的简单求解器?示例简单模型:
a + b + c = 100;
a/b/c = 2/3/4;
a > d
我正在使用MS Solver基础,这是我的C#代码,但它会抛出UnsolvableModelException:
SolverContext solverContext = SolverContext.GetContext();
Model model = solverContext.CreateModel();
Decision a = new Decision(Domain.Real, "a");
Decision b = new Decision(Domain.Real, "b");
model.AddDecisions(a, b);
model.AddConstraint("fator", a / b == 4);
model.AddConstraint("sum", a + b == 5);
Solution solution = solverContext.Solve(new ConstraintProgrammingDirective());
Report report = solution.GetReport();
Console.WriteLine("a = {0} ; b = {1}", a, b);
感谢您的帮助
修改
因为int CSP(约束满意度编程)问题,在解决它时不应使用任何指令。 代码应该是:
SolverContext solverContext = SolverContext.GetContext();
Model model = solverContext.CreateModel();
Decision a = new Decision(Domain.Real, "a");
Decision b = new Decision(Domain.Real, "b");
model.AddDecisions(a, b);
model.AddConstraint("fator", a / b == 4);
model.AddConstraint("sum", a + b == 5);
Solution solution = solverContext.Solve();
Report report = solution.GetReport();
Console.WriteLine("a = {0} ; b = {1}", a, b);
然而,我不知道为什么我跑得很慢我只需要解决方案集中的第一个解决方案。
答案 0 :(得分:1)
根据您的需要,Wolfram Alpha可能很有用(至少用于验证)。我怀疑你能解决复杂的问题,因为输入是长度有限的。但是对于简单的问题作为你的例子,没关系。