簡體   English   中英

如何處理Microsoft Solver Foundation中已有的活動模型?

[英]How to deal with an active model already present in Microsoft Solver Foundation?

我使用庫來解決線方程,它適用於從這個庫創建一個類對象,但是當我想重新創建對象時,它會拋棄我:

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;
    }
}}

首先調用ClearModel

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM