C# 如何应对微软Sover基金会现有的活跃模式?

C# 如何应对微软Sover基金会现有的活跃模式?,c#,ms-solver-foundation,C#,Ms Solver Foundation,我使用这个库来解直线方程,它可以从这个库中创建一个类对象,但是当我想重新创建对象时,它会把我扔掉: System.InvalidOperationException:上下文中已存在活动模型。 位于Microsoft.SolverFoundation.Services.SolverContext.CreateModel() 问题是,在计算第一个示例之后,我想更改数据并单击按钮,然后获得另一个示例的结果 class LinearResolve { public string[] Zmienn

我使用这个库来解直线方程,它可以从这个库中创建一个类对象,但是当我想重新创建对象时,它会把我扔掉:

System.InvalidOperationException:上下文中已存在活动模型。 位于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;
    }
}}
先打电话:

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