0

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?

1
  • 1
    Explaining why exactly the answers provided in the question you linked would go a long way towards helping others provide the answer that you're looking for. Commented Apr 13, 2019 at 17:48

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This looks very promising but I'm a little confused - what exactly is IndexSetForAssign? Thank you for your help.
IndexSetForAssign is the index set you used when you defined Assign. Assuming you did dvar int Assign[I] this would just be I.
Ah, the problem is my simplification, as Assign is actually 4 dimensional. I now have that part working thanks to your assistance!
1

At https://www.ibm.com/developerworks/community/forums/html/topic?id=7bb1e7ff-ec3a-4e79-a8c4-c20050dfad0c&ps=25 I answered the same question and gave an example.

range r=1..5;

float value[r]=[2,3,4.5,1,0];
dvar int i in 1..5;
dexpr int j=6-i;

maximize sum(k in r) value[k]*(k==j);
subject to
{

}

execute
{
writeln("i=",i);
}

Comments

0

It seems you want to define an expression as the value of an array indexed by a variable. This is called the element constraint [1] and is only available in the context of Constraint Programming, as a Linear Programming solver can't cope with such constraints.

[1] https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_constraints_types_inCP.html#usropllangref.uss_langref_constraints.1073721__section1319017294580

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.