# how to create such constraint in OPL of cplex

 1 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 11●2●2●5 accept rate: 0% fbahr ♦ 4.6k●7●17

 2 Hi 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); constraints{ alwaysIn(f,0,wall+1,0,threshold); }  answered 21 Mar '14, 11:18 David 306●1●6 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 1 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 1 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
 1 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 ♦ 4.6k●7●17 accept rate: 13% 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
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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

Tags:

×191
×37
×13