2015-10-25 46 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解算器也可能有用。 –

相關問題