Hi ,all

I want to create a constraint in OPL.I don't know how to ?

tuple  JUP
   string p;
   string u;   
} ;

{JUP} jup=...;

dvar interval TT[o in jup];

I want to create a constraint

forall(o in jup:o.p==p1) 
  the number of 'startOf(TT[o])<=5'  will be less than 10

Could you help me?

Thanks all.

This question is marked "community wiki".

asked 12 Mar '14, 21:45

spzcwg's gravatar image

accept rate: 0%

edited 13 Mar '14, 07:25

fbahr's gravatar image

fbahr ♦


You may also use a constraint on a cumulative function, such as in the following example. We have for each interval a function that is 1 from the start of the interval to the infinity of time. Summing these functions over the interval will give you a cumul function that represents ay any time points the number of intervals that starts before this time point. What you have to enforce is that at any time points 0 to 6 (6 excluded), this function cannot take values higher than 10. This is done through the function alwaysIn

using CP;

 range R = 1 .. 30;
 range horizon = 0 .. 10;
 int wall = 5;
 int threshold = 10;

 dvar interval itv[R] in horizon size 3;

 cumulFunction f = sum(r in R) stepAtStart(itv[r],1);


answered 21 Mar '14, 11:18

David's gravatar image

accept rate: 12%

I'm sorry,I never use this function, Could you tell me how to use this funciton to my problem? thank you!

(24 Mar '14, 21:14) spzcwg

I advise you to read the documentation concerning interval scheduling and cumulative functions. These concepts are high level abstractions, very powerful to model complex constraints.

These global expressions and constraints usually propagate better with intervals (it would be interesting for you to compare number of fails and branches with both implementations)

(25 Mar '14, 07:45) David

And they are more efficient than explicitely stating the constraint with logical expressions as in fbahr response.

(26 Mar '14, 05:01) jfpuget

Thanks all,I have solved this problem with cumulFunction function. Yes,I find it is powerful! Thans a lot!

(03 Apr '14, 03:04) spzcwg

Your constraint can easily be formulated using the logical implication operator (=>) [and some aux. variable(s) z].

using CP;

tuple JUP { string p; string u; };
{JUP} jup = ...;
dvar interval TT[o in jup];

string p1 = ...;
{JUP} jup_p1 = { o | o in jup: o.p == p1 };
dvar int+ z[jup_p1] in 0..1;

subject to {
  forall (o in jup_p1) (startOf(TT[o]) <= 5) => (z[o] == 1);

  sum (o in jup_p1) z[o] <= 10;

However: while, IINM, logical implications are also allowed in CPLEX OPL models, the interval datatype (and, hence, startOf) can only be used in combination with the CP solver.


answered 13 Mar '14, 07:15

fbahr's gravatar image

fbahr ♦
accept rate: 13%

edited 13 Mar '14, 07:16

Thanks for your help,It works well.

(17 Mar '14, 03:48) spzcwg

The cumulative function proposed by David does what fbahr proposes, albeit in a more efficient way.

(26 Mar '14, 04:59) jfpuget
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 12 Mar '14, 21:45

Seen: 17,515 times

Last updated: 03 Apr '14, 03:04

OR-Exchange! Your site for questions, answers, and announcements about operations research.