2015-10-25 47 views

回答

1

Model类将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(); 
} 

你可能知道,微软也不再积极推进微软求解基金会

+0

谢谢,你说“为了跟踪你的期限......”,你能否用一段代码解释更多,也许? – Masoud

+0

是的,我知道微软不再推动无国界医生的活动,你的建议是什么? – Masoud

+1

[Minizinc](http://www.minizinc.org/)和/或Gecode可能值得一看。另外,像Z3或Clasp这样的SMT解算器也可能有用。 –

相关问题