Instantiating IntVar with maximum possible domain

635 views
Skip to first unread message

cjolinla

unread,
Mar 15, 2022, 3:57:26 PM3/15/22
to or-tools-discuss
Using CP-SAT

I wish to instantiate a new IntVar to be used as an indicator variable. I do not know at this point the possible values it may take, so I want to instantiate it with the largest domain possible. 

long myUpperBound = long.MaxValue - 1;
long myLowerBound = long.MinValue + 2;
IntVar myVar= CPmodel.NewIntVar(myLowerBound, myUpperBound, "var_name");

I get the following error:

Invalid model: var #3 has a domain that is too large, i.e. |UB - LB| overflow an int64_t: name: "var_name" domain: -9223372036854775806 domain: 9223372036854775806

Any suggestions?

Laurent Perron

unread,
Mar 15, 2022, 4:21:00 PM3/15/22
to or-tools-discuss
The solver rejects potential overflows. 

You will need to reduce the bounds. 

Int_max / 4?

--
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/74684fe3-d7f2-4936-aa0c-73f54ee034b1n%40googlegroups.com.

Matt Weeden

unread,
Mar 16, 2022, 7:10:03 AM3/16/22
to or-tools-discuss
If you know which vars are being observed, and what operations are being done on them, you could try to use the upper & lower bounds of the observed vars.  In Python, using CP-SAT I can access variable domains using "model._CpModel__model.variables[somevariable.Index()].domain".  With ".domain[0]" being lower bound and ".domain[1]" being upper bound.

cjolinla

unread,
Mar 16, 2022, 11:57:09 AM3/16/22
to or-tools-discuss
1- @LaurentPerron Thanks, this is how I currently get around it works fine so I will maintain this structure. In reality I have never had a model with a variable's domains or an Integer Expression fall outside Int.MaxValue, so I was just being greedy trying to use Long.

                    int myUpperBound = int.MaxValue;
                    int myLowerBound = int.MinValue;

2- @mweeden Yes I thought about cycling through the variables or expressions for which the indicator variable would be assigned but I was lazy and wanted the easiest way to capture all possible domains, i.e. the maximum value of an int_64. Thanks for the comments.

Reply all
Reply to author
Forward
0 new messages