![](/img/trans.png)
[英]Microsoft Solver Foundation UnsolvableModelException
[英]On working with ranges of real numbers in Microsoft Solver Foundation
我正在研究的求解器项目(C#)要求测试是否有解决方案,而不论其质量如何,或者是否要解决某些输入落在某些预定的实数范围内的问题。
我将以下示例放在一起,其中包含一个约束,表示一个值(参数类型)和由两个变量组成的方程(决策类型)之间的简单相等性测试。
const double DESIRED_OUTPUT_VALUE = -2.5;
SolverContext solver = SolverContext.GetContext();
Model model = solver.CreateModel();
//Defined a value to be tested against
Parameter output = new Parameter(Domain.Real, "output");
output.SetBinding(DESIRED_OUTPUT_VALUE);
//Defined a range between 1 & 10 for the input variables.
Domain inputDomain = Domain.RealRange(1, 10);
Decision inputA = new Decision(inputDomain, "inputA");
Decision inputB = new Decision(inputDomain, "inputB");
model.AddDecision(inputA);
model.AddDecision(inputB);
model.AddParameter(output);
//The constraint, which given the value of output currently is not solvable.
Constraint constraint = model.AddConstraint("result", output == inputA / inputB);
/*Expected that the solver would report back quickly that this is no feasable solution.
*However instead it just sits there with a blank screen...
*/
Solution solution = solver.Solve();
Report report = solution.GetReport();
Console.WriteLine(report);
Console.ReadLine();
我观察到的是,如果更改了约束条件以至于没有解,并且其中表示的方程是除法或乘法,则求解器似乎停滞了,未给出关于是否仍在求解的任何反馈。
我怀疑这种类似停滞的行为与求解器正在处理实数并且处于某些穷举搜索之中有关,但是,如果更改了约束以使存在已知的解决方案,则它会非常快速地工作。
遍历各种论坛后,我仍然不确定是什么引起了这种现象,或者鉴于这是我第一次使用Microsoft Solver Foundation,因此我的实施方法是否正确。
其他人是否遇到过此问题或确实有解决方案?
d。
Solver Foundation选择的求解器取决于许多因素。 一个重要因素是您如何在目标和约束中使用决策。 在这种情况下,您将划分两个决策,这意味着需要使用非常通用的求解器。
如果可以编写模型,使决策对象中的目标和约束线性化,那么您将获得更大的成功。 我意识到这并非总是可能的,但是在这种特定情况下,它可以:将输出== inputA / inputB更改为inputB * output == inputA。
我认为这应该有所帮助。 内特
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.