from ortools.sat.python import cp_model
model = cp_model.CpModel()
x = model.NewIntVar(0, 1000000, 'x')
model.Add(x > 100)
model.Add(x < 10000)
solver = cp_model.CpSolver()
solver.Solve(model)
#Get x domain? 101..9999
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/98e71d97-3321-4776-b425-8c1c6648ae91o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CABcmEebHx96JAdb55NcUN7eMEWOmqiGpwts-dEw0mKeAQ1%3D6Xg%40mail.gmail.com.
status: OPTIMAL
solution: 101
num_booleans: 1
num_branches: 1
num_integer_propagations: 1
wall_time: 0.000451
user_time: 0.000451
deterministic_time: 8e-08
tightened_variables {
name: "x"
domain: 101
domain: 9999
}
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CAA%3D%3D6MHWx8z9SXWwW7XnG1xJ5xouBPiJ%3DaAn_gYB7DiPuq5Vyw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/f9f77876-d558-4bb3-94ba-d79b2b839c9fo%40googlegroups.com.
from ortools.sat.python import cp_model
model = cp_model.CpModel()
v1 = model.NewIntVar(0, 1000000, "v1")
b1 = model.NewBoolVar("b1")
model.Add(v1 < 1000).OnlyEnforceIf(b1)
model.Add(v1 > 10000).OnlyEnforceIf(b1.Not())
solver = cp_model.CpSolver()
solver.Solve(model)
solver.parameters.fill_tightened_domains_in_response = True
solver.Solve(model)
print(solver.ResponseProto())
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/312107e2-2703-4d97-9620-03b5ac03ce55o%40googlegroups.com.
tightened_variables {
name: "v1"
domain: 0
domain: 999
domain: 10001
domain: 1000000
}
tightened_variables {
name: "b1"
domain: 0
domain: 1
}
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/ac6d8ff4-014a-4d83-af35-2db7e06d9e44o%40googlegroups.com.
using System;using Google.OrTools.Sat;
namespace GoogleSATSolverExperiments02{ class GoogleSatSolverExperiments02Main { static void Main(string[] args) { // Create the model Google.OrTools.Sat.CpModel model = new CpModel(); MyORModel myModel = new MyORModel(); myModel.initModel(model); IntVar[] decisionVariables = myModel.decisionVariables;
// Create a solver and solves the model. Console.WriteLine("Basic model:"); CpSolver solver = new CpSolver(); solver.StringParameters = "fill_tightened_domains_in_response:true"; Console.WriteLine(solver.StringParameters); MySolutionPrinter solutionPrinter = new MySolutionPrinter(decisionVariables); solver.SearchAllSolutions(model, solutionPrinter); Console.WriteLine(String.Format("Number of solutions found: {0}", solutionPrinter.SolutionCount())); foreach (IntegerVariableProto ivp in solver.Response.TightenedVariables) { Console.WriteLine(ivp.ToString()); }
// Try it again with only presolve Console.WriteLine("Basic model:"); solver.StringParameters = "fill_tightened_domains_in_response:true stop_after_presolve:true"; Console.WriteLine(solver.StringParameters); solutionPrinter.reset(); solver.SearchAllSolutions(model, solutionPrinter); Console.WriteLine(String.Format("Number of solutions found: {0}", solutionPrinter.SolutionCount())); foreach (IntegerVariableProto ivp in solver.Response.TightenedVariables) { Console.WriteLine(ivp.ToString()); }
// Restrict the model with a simulated user selection C == 0 Console.WriteLine("\nModel with additional restriction C == 0:"); model.Add(myModel.C == 0L); solver.StringParameters = "fill_tightened_domains_in_response:true"; Console.WriteLine(solver.StringParameters); solutionPrinter.reset(); solver.SearchAllSolutions(model, solutionPrinter); Console.WriteLine(String.Format("Number of solutions found: {0}", solutionPrinter.SolutionCount())); foreach (IntegerVariableProto ivp in solver.Response.TightenedVariables) { Console.WriteLine(ivp.ToString()); }
Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
class MyORModel { public IntVar A; public IntVar B; public IntVar C; public IntVar D;
public IntVar Atab; public IntVar Btab; public IntVar Ctab;
public Constraint tableConstraint; public Constraint valueAssignmentConstraint;
public IntVar tableCondition; public BoundedLinearExpression tableConditionExpression; public Constraint tableConditionConstraint; public BoundedLinearExpression tableConditionExpressionNegated; public Constraint tableConditionNegatedConstraint;
public IntVar[] decisionVariables { get { return new IntVar[] { A, B, C, D, tableCondition }; } }
public void initModel(CpModel model) { // The variables themselves A = model.NewIntVar(0L, 2L, "A"); B = model.NewIntVar(0L, 1L, "B"); C = model.NewIntVar(0L, 2L, "C"); D = model.NewIntVar(0L, 2L, "D");
// Tuple set for restriction table // Values for A, B, C may only be values listed on a line in this table, if D == 0. long[,] tableData = new long[2, 3] { { 0, 1, 0 }, { 1, 0, 0 }, };
// Tuple set header // Since OnlyEnforceIf() is not supported for AddAllowedAssignments constraint, // need to simulate this using local table variables and enforcing equality // with the original variables in case the enforcing condition is true. Atab = model.NewIntVarFromDomain(A.Domain, "Atab"); Btab = model.NewIntVarFromDomain(B.Domain, "Btab"); Ctab = model.NewIntVarFromDomain(C.Domain, "Ctab"); IntVar[] tupleSetHeader = new IntVar[] { Atab, Btab, Ctab }; // Table constraint tableConstraint = model.AddAllowedAssignments(tupleSetHeader, tableData);
// Table only applies when D == 0 // IntVar implements the ILiteral interface required as argument to OnlyEnforceIf tableCondition = model.NewBoolVar("tableCondition"); // Link the boolan variable to the expression D == 0 // This is basically copied from an example given in // and seems to be the only way to do it although it seems pretty awkward tableConditionExpression = (D == 0); tableConditionConstraint = model.Add(tableConditionExpression); tableConditionConstraint.OnlyEnforceIf(tableCondition);
tableConditionExpressionNegated = (D != 0); tableConditionNegatedConstraint = model.Add(tableConditionExpressionNegated); tableConditionNegatedConstraint.OnlyEnforceIf(tableCondition.Not());
// When the table is enforced, real variables and local table variables must be the same. Constraint Aequality = model.Add(A == Atab); Aequality.OnlyEnforceIf(tableCondition); Constraint Bequality = model.Add(B == Btab); Bequality.OnlyEnforceIf(tableCondition); Constraint Cequality = model.Add(C == Ctab); Cequality.OnlyEnforceIf(tableCondition);
// To avoid irrelevant multiple solutions, assign local table variables to the // first line of the table when it is not enforced Constraint AtabDefault = model.Add(Atab == tableData[0, 0]); AtabDefault.OnlyEnforceIf(tableCondition.Not()); Constraint BtabDefault = model.Add(Btab == tableData[0, 1]); BtabDefault.OnlyEnforceIf(tableCondition.Not()); Constraint CtabDefault = model.Add(Ctab == tableData[0, 2]); CtabDefault.OnlyEnforceIf(tableCondition.Not());
// Value assignment constraint // C may only take on the value 2 if the table is not enforced (i.e. D != 0). valueAssignmentConstraint = model.Add(C == 2L); valueAssignmentConstraint.OnlyEnforceIf(tableCondition.Not()); } }
public class MySolutionPrinter : CpSolverSolutionCallback { public MySolutionPrinter(IntVar[] variables) { variables_ = variables; } public override void OnSolutionCallback() { Console.Write("Solution #{0}: ", solution_count_); foreach (IntVar v in variables_) { Console.Write( String.Format(" {0}={1};", v.ShortString(), Value(v))); } solution_count_++; Console.WriteLine(); } public int SolutionCount() { return solution_count_; }
internal void reset() { solution_count_ = 0; }
private int solution_count_; private IntVar[] variables_; }}
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/6d58fcd6-0f55-4781-a0fc-cc5aa0d83451o%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/cabcfd57-b968-4d6c-96eb-e0d22158dad7o%40googlegroups.com.
I just pushed the fix.
Le mar. 16 juin 2020 à 12:04, Christopher Hamkins <christoph...@ksb.com> a écrit :
Thanks for the quick response and fix! I'll watch for the fix.--
Am Dienstag, 16. Juni 2020 11:55:39 UTC+2 schrieb Frederic Didier:Yeah sorry, I realized there was a bug after I replied to you, I submitted a fix internally but I am not sure yet when it will be pushed to the or-tool repository (hopefully soon).I think if you specify a time limit that is not too long, it is a decent work around until this work with stop_after_presolve:true.
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/c13d4191-f980-4d01-9c24-ce49de2cef89o%40googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/c13d4191-f980-4d01-9c24-ce49de2cef89o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/946f8da7-aeb7-4a2d-9def-7a38bad8426dn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CAA%3D%3D6MFPO-ha0Dc26g%3D_GiK-16c2kz2YLRWiMYXGwUcQd6_7aA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/f763bb7d-fc20-4ef7-8314-80f471d25a47n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/7ddbf0d8-1389-4c82-b0ea-2f62d362cbf7n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CAPyyUTuqVWrjVEvF3QtdJDyfTnsUL-96H0VLqcGAKQ7bQYY0XA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/CAA%3D%3D6MEB4bbm8cfvknVJnqRhgFnJjkp5VrOJBpxjfy6QYyU3kw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/f5f4035f-50a8-4337-9cdd-6a858429de32n%40googlegroups.com.