I am trying to use Microsoft Solver Foundation SatSolver to solve a simple CNF problem through Visual Studio (C# or VB). Can anyone post a simple example explaining how this can be done?
Here is a short example:
ConstraintSystem s1 = ConstraintSystem.CreateSolver();
CspTerm t1 = s1.CreateBoolean("v1");
CspTerm t2 = s1.CreateBoolean("v2");
CspTerm t3 = s1.CreateBoolean("v3");
CspTerm t4 = s1.CreateBoolean("v4");
CspTerm tOr12 = s1.Or(s1.Neg(t1), s1.Neg(t2));
CspTerm tOr13 = s1.Or(s1.Neg(t1), s1.Neg(t3));
CspTerm tOr14 = s1.Or(s1.Neg(t1), s1.Neg(t4));
CspTerm tOr23 = s1.Or(s1.Neg(t2), s1.Neg(t3));
CspTerm tOr24 = s1.Or(s1.Neg(t2), s1.Neg(t4));
CspTerm tOr34 = s1.Or(s1.Neg(t3), s1.Neg(t4));
CspTerm tOr = s1.Or(t1, t2, t3, t4);
s1.AddConstraints(tOr12);
s1.AddConstraints(tOr13);
s1.AddConstraints(tOr14);
s1.AddConstraints(tOr23);
s1.AddConstraints(tOr24);
s1.AddConstraints(tOr34);
s1.AddConstraints(tOr);
ConstraintSolverSolution solution1 = s1.Solve();
Console.WriteLine(solution1[t1]);
Console.WriteLine(solution1[t2]);
Console.WriteLine(solution1[t3]);
Console.WriteLine(solution1[t4]);
The result should have only one variable with a value of 1, and the rest should have 0, but the solution is 1,1,1,0.
Thanks Guy
您应该使用s1.Not(t1)
而不是s1.Neg(t1)
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.