我在 Solver Foundation 模型中定义了多少 Terms/Variables/Constraints/Non-Zeroes?

How many Terms/Variables/Constraints/Non-Zeroes I defined in my Solver Foundation model?

我在我的程序中使用 Microsoft Solver Foundation Express 版本,根据 this link.

,Express 版本的模型大小受到限制

有什么方法可以找到多少:

我使用代码在我的模型中定义了吗?

Model class 维护 DecisionsConstraints 作为集合。您可以列举并计算它们。

要跟踪您的 Term 变量,您可以通过自己的构造方法创建和计算它们。

示例:

static Term NewTerm(Term t)
{
    noOfTerms++;   //  defined as class variable somewhere else
    return t;
}

static void Main(string[] args)
{
    var context = SolverContext.GetContext();
    var model = context.CreateModel();
    double sqrt2 = Math.Sqrt(2.0);

    var t = new Decision(Domain.RealRange(-sqrt2, +sqrt2), "t");
    var u = new Decision(Domain.RealRange(-2 * sqrt2, +2 * sqrt2), "u");

    model.AddDecisions(t, u);

    Term P = NewTerm(2 * t * t / (3 * t * t + u * u + 2 * t) - (u * u + t * t) / 18);

    model.AddGoal("objective", GoalKind.Maximize, P);

    Console.WriteLine("Constraints: " + model.Constraints.Count());
    Console.WriteLine("Decisions:   " + model.Decisions.Count());
    Console.WriteLine("Goals:       " + model.Goals.Count());
    Console.WriteLine("Terms:       " + noOfTerms);

    Solution sol = context.Solve();
    Report report = sol.GetReport();
    Console.WriteLine(report);
    Console.WriteLine();
}

您可能知道 Microsoft 不再积极推广 Microsoft Solver Foundation