Re: [or-tools-discuss] CP-SAT: questions about constraints & strategies

146 views
Skip to first unread message
Message has been deleted

Laurent Perron

unread,
Mar 8, 2021, 10:13:59 AM3/8/21
to or-tools-discuss
The unsupported message comes from the symmetry detection.
It is harmless and we will remove it asap.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Le lun. 8 mars 2021 à 15:51, Peter Meter <all.of.the.offe...@gmail.com> a écrit :
Hello!

I was trying to find answers to my questions here, but no success. If I missed something please point me to the right correspondence. 
I am using CP-SAT with python (can switch to c++ if it easier to get what I want with c++). 

I have these questions:

1. Is there a way to filter list of variables? Lets say I have a list X of 10 boolean vars. I know that only 4 going to be true. How do I know the indices of these 4 x[i]'s? 

2. I have a list of boolean variables X[i_1, j, k]. Is there a way to say to the solver that if it already tried the assignment x[i_1, j, 1] then no need to try x[i_1, j 2], or any other x[i_1,j, k] for that matter? How do I introduce new heuristic, and how do I define it? 

3. How to use strategies? I cannot find any guide on it. 

4. Is it possible to make a new variable with domain based on some other variable? (I guess the answer is "no", but maybe there is workaround with some sort of 2 step model)?  

5. Why solver spits out:
Unsupported constraint type kIntProd

Thank you, 
Pete

--
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/e356d6a1-1552-4db1-a242-08e06b8a5a81n%40googlegroups.com.
Message has been deleted

Laurent Perron

unread,
Mar 8, 2021, 11:39:47 AM3/8/21
to or-tools-discuss
q1: scan and check solution values.
q2: the solver is learning that. But you can always add a clause to the model that is the no-good of the assignment you want to forbid.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Le lun. 8 mars 2021 à 16:16, Peter Meter <all.of.the.offe...@gmail.com> a écrit :
Thank you Laurent! This message is very confusing to be honest. 

Do you have any advice on Q1 or Q2? 

Best wishes,
Pete

Message has been deleted

Laurent Perron

unread,
Mar 8, 2021, 12:01:47 PM3/8/21
to or-tools-discuss
you cannot write:

if x[i] > 0:

x[i] is a variable. any imperative code will not work as the value is assigned at a leaf of the search tree.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Le lun. 8 mars 2021 à 17:47, Peter Meter <all.of.the.offe...@gmail.com> a écrit :
Re Q1. I am not sure I follow. How would you scan? The True/False are assigned during the solving phase. As far as I understand the CP, I should provide a constraint that "picks" only the 4 x[i]'s which are true. 
For example, I can compute the weighted sum of x[i]'s via model.Add(SUM_OF_Xs == sum( w[i]*x[i] for i in range(..) ) ). In this case the "false" x[i]'s wont contribute and the sum is always good. But what if I need to add extra layer of 4 weights only to those x[i]s which are true? i.e.:
k = 0 
for i in range(...):
    if x[i] > 0:
         # multiply with some weight W[k]
         k +=1
How do I achieve it? 


Re Q2. I will try that, thank you!
Reply all
Reply to author
Forward
Message has been deleted
0 new messages