我正在处理的求解器项目(C#)需要测试是否存在解决方案(无论质量如何),还是不存在某些输入属于某些内容的问题预定义的实数范围。关于使用Microsoft Solver Foundation中的实数范围
我将以下示例放在一起,其中包含一个约束,表示值(参数类型)与由两个变量(决策类型)组成的方程之间的简单相等性测试。
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)。
将解算器指令更改为本地搜索(HybridLocalSearchDirective类)似乎也没有太大的差别。它包含各种属性,例如进行的“预解决”程度。它还使人们能够在解决过程中指定超时 - 但这似乎是一个相当不确定的方法。 – 2012-04-26 07:53:07