optimizationcplexoplilog

Indexing array "Assign" with type dexpr int not supported by this algorithm


My question is similar to one already asked, but there was not an answer (at least not one accepted nor suitable).

I am attempting to make a constraint, which I've simplified below:

dexpr int startingWeekChanges[p in People] = 7 * y + 1; 

...

for(p in People){
    Assign[startingWeekChanges[p]] == 1;
}

But I see this is not allowed (error message being "Indexing array "Assign" with type dexpr int not supported by this algorithm").

I can't change over to constraint programming. Is there an alternative strategy to get by this?


Solution

  • I think something like this might do the trick:

    forall (i in IndexSetForAssign)
       Assign[i] == (sum (p in People) (startingWeekChanges[p] == i) >= 1);
    

    It sets Assign[i] to 1 if at least one startingWeekChanges[p] has the value i. If not then it sets Assign[i] to 0.

    The expressions above exploit the fact that you can use the truth value (1 if true, 0 otherwise) of a constraint for modeling.