Originally posted by: ChrisBr
Hello,
Since the result of "count(...)" depends on decision variables, it is not possible to set it to an int as long as the values of the concerned decision variables are not known. But this is possible after the resolution when the decision variables are fixed.
You can set it to a "dexpr int" or define a "dvar int" and constrain it to be equal to the result of "count(...)".
To sum up, all the following statements are allowed:
dexpr int c1 = count(all(j in jup : j.p=="T") jupz[j], 1);
dvar int c2 in 0..card(jup);
subject to {
c2 == count(all(j in jup : j.p=="T") jupz[j], 1);
}
int c3 = count(all(j in jup : j.p=="T") jupz[j], 1);
About your second question: it is mentioned in documentation that
Conditions in if-else statements must be ground; that is, they must not contain decision variables.
So you cannot write:
if(count(all(j in jup : j.p=="T") jupz[j], 1)<=5) ...
But you can use implications of constraints instead, for example:
((count(all(j in jup : j.p=="T") jupz[j], 1)) <=5) => (...);
or conditional expression, for example:
k == (((count(all(j in jup : j.p=="T") jupz[j], 1)) <=5) ? 1000 : -1);
I hope this clarifies,
Chris.
#DecisionOptimization#OPLusingCPOptimizer