gpt4 book ai didi

c# - 如何处理 Microsoft Solver Foundation 中已经存在的事件模型?

转载 作者:太空狗 更新时间:2023-10-30 01:29:43 31 4
gpt4 key购买 nike

我用这个库来求解线方程,它适用于从这个库创建一个类对象,但是当我想重新创建这个对象时,它让我失望了:

System.InvalidOperationException: There is already an active model in the context. At Microsoft.SolverFoundation.Services.SolverContext.CreateModel ()

问题是,在计算完第一个例子之后,我想更改数据并单击按钮并获取另一个例子的结果。

class LinearResolve
{
public string[] Zmienne = new string[3];

public LinearResolve(string[] table)
{
Zmienne = table;
}

public string Solver()
{
SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();
Decision a = new Decision(Domain.Real, "a");
Decision b = new Decision(Domain.Real, "b");
Decision c = new Decision(Domain.Real, "c");
model.AddDecisions(a, b, c);
model.AddConstraint("eqA", Zmienne[0]);
model.AddConstraint("eqB", Zmienne[1]);
model.AddConstraint("eqC", Zmienne[2]);
Solution solution = context.Solve();
string results = solution.GetReport().ToString();
return results;
}
}}

最佳答案

调用ClearModel第一:

SolverContext context = SolverContext.GetContext();
context.ClearModel();
Model model = context.CreateModel();

关于c# - 如何处理 Microsoft Solver Foundation 中已经存在的事件模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50241746/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com