有谁知道任何可以解决线性约束数学模型的简单求解器?示例一个简单的模型:
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(constraint sstisfaction programming) 问题,解决它时不应该使用任何指令。代码应该是:
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);
但是,我不知道为什么我跑得很慢我只需要解决方案集中的第一个解决方案。