Topic
• 7 replies
• Latest Post - ‏2012-10-17T03:43:48Z by qtbgo
qtbgo
134 Posts

# Pinned topic How to constrain the distance between cumulFunction?

‏2012-10-13T03:46:57Z |
Hi, I have the following constraint
``````
cumulFunction resUsage[k in 1..q] =  sum(j in 1..n) pulse(qcTasks[k][j],l[j]);   forall(k in 1..q-1) resUsage[k+1] - resUsage[k] >=2;```
```

But this is not what I want. What I actually want is that when
``````
resUsage[k+1] > 0```
```
, I restrict
``````
resUsage[k+1] - resUsage[k] >=2;```
```

But the following have error
``````
forall(k in 1..q-1) resUsage[k+1] != 0 => resUsage[k+1] - resUsage[k] >=2;```
```

Can any one help me to achieve this?
Thanks
Updated on 2012-10-17T03:43:48Z at 2012-10-17T03:43:48Z by qtbgo
623 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-13T09:08:17Z
Hello.

Indeed, constraint on cumul function can be used only as top-level constraint, not inside an expression.
However I do not understand what exactly do you want to achieve. Could you please give us more details?

Note that constraining cumul function like this:
``````
resUsage[k+1] - resUsage[k] >=2;```
```

says that the function must be at least two everywhere on interval -maxint/2..maxint/2. It may be better to use alwaysIn constraint that allows to specify different interval than -maxint/2..maxint/2. Note that constraint alwaysIn cannot be used in an expression neither.

I do not understand the condition:
``````
resUsage[k+1] > 0```
```

Does it mean that resUsagek+1 must be bigger than 0 everywhere? Or that there is some point where resUsagek+1 is bigger than 0?

Also note that there is an implicit constraint that says that cumul function can never have a value lower than 0.

Best regards, Petr
• qtbgo
134 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-13T10:08:15Z
Hello.

Indeed, constraint on cumul function can be used only as top-level constraint, not inside an expression.
However I do not understand what exactly do you want to achieve. Could you please give us more details?

Note that constraining cumul function like this:
<pre class="jive-pre">``` resUsage[k+1] - resUsage[k] >=2;``` </pre>
says that the function must be at least two everywhere on interval -maxint/2..maxint/2. It may be better to use alwaysIn constraint that allows to specify different interval than -maxint/2..maxint/2. Note that constraint alwaysIn cannot be used in an expression neither.

I do not understand the condition:
<pre class="jive-pre">``` resUsage[k+1] > 0``` </pre>
Does it mean that resUsagek+1 must be bigger than 0 everywhere? Or that there is some point where resUsagek+1 is bigger than 0?

Also note that there is an implicit constraint that says that cumul function can never have a value lower than 0.

Best regards, Petr
Let me try to detail it.
``````
dvar interval qcTasks[k in 1..q][j in 1..n] optional in 10..H ;```
```

Which means that Quay crane k performs task j.

l[i] is always biger than 0.

The cumulative curve of
``````
resUsage[k+1]```
```
falls to 0 between two consecutive intervals. What I want is that when it isn't 0, it should be 2 away from resUsage[k].
• qtbgo
134 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-13T10:43:18Z
• qtbgo
• ‏2012-10-13T10:08:15Z
Let me try to detail it.
<pre class="jive-pre">``` dvar interval qcTasks[k in 1..q][j in 1..n] optional in 10..H ;``` </pre>
Which means that Quay crane k performs task j.

l[i] is always biger than 0.

The cumulative curve of <pre class="jive-pre">``` resUsage[k+1]``` </pre> falls to 0 between two consecutive intervals. What I want is that when it isn't 0, it should be 2 away from resUsage[k].
l[i] is the bay number of task(container) i.

In fact, what I actually want is that when there is overlap between two tasks by two adjacent quay cranes, I want there are at least 1 bays between the two quay cranes.
623 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-15T07:44:36Z
• qtbgo
• ‏2012-10-13T10:43:18Z
l[i] is the bay number of task(container) i.

In fact, what I actually want is that when there is overlap between two tasks by two adjacent quay cranes, I want there are at least 1 bays between the two quay cranes.
Finally I think I understand. Bay is a position of quay crane for a task. And there is some kind of minimum safety distance for adjacent cranes. Am I right?

I suggest to create a state function for every crane. It's value is the current position of the crane:
``````
stateFunction qCraneState[1..q]; ... subject to
{ ... forall (k in 1..q) forall (j in 1..n) alwaysEqual(qCraneState[k], qcTasks[k][j], l[j]); ...```
```

Note that this state function can also replace noOverlap for qcTasks[k]. I would suggest to try the performance with and without this noOverlap. State function also supports transition times if you need it.

Using alwaysIn constraint, it is possible to restrict position of adjacent crane like this:
``````

// Restrict position of quay crane k+1 to be in interval l[j]+1..1000000 while crane k performs task j: forall(k in 1..q-1) alwaysIn(qCraneState[k+1], qcTasks[k][j], l[j]+1, 1000000);
// Restrict position of quay crane k-1 to be in interval 0..l[j]-1 while crane k performs task j: forall(k in 2..q) alwaysIn(qCraneState[k-1], qcTasks[k][j], 0, l[j]-1);```
```

Note that when qcTasks[k][j] is absent then the alwaysIn constraint is ignored. Also note that alwaysIn constraint does not force the crane to stay in a certain position. The crane can move. Basically, alwaysIn and alwaysEqual can overlap only if they are compatible.

Best regards, Petr
623 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-15T07:46:21Z
Finally I think I understand. Bay is a position of quay crane for a task. And there is some kind of minimum safety distance for adjacent cranes. Am I right?

I suggest to create a state function for every crane. It's value is the current position of the crane:
<pre class="jive-pre">``` stateFunction qCraneState[1..q]; ... subject to { ... forall (k in 1..q) forall (j in 1..n) alwaysEqual(qCraneState[k], qcTasks[k][j], l[j]); ...``` </pre>
Note that this state function can also replace noOverlap for qcTasks[k]. I would suggest to try the performance with and without this noOverlap. State function also supports transition times if you need it.

Using alwaysIn constraint, it is possible to restrict position of adjacent crane like this:
<pre class="jive-pre">``` // Restrict position of quay crane k+1 to be in interval l[j]+1..1000000 while crane k performs task j: forall(k in 1..q-1) alwaysIn(qCraneState[k+1], qcTasks[k][j], l[j]+1, 1000000); // Restrict position of quay crane k-1 to be in interval 0..l[j]-1 while crane k performs task j: forall(k in 2..q) alwaysIn(qCraneState[k-1], qcTasks[k][j], 0, l[j]-1);``` </pre>
Note that when qcTasks[k][j] is absent then the alwaysIn constraint is ignored. Also note that alwaysIn constraint does not force the crane to stay in a certain position. The crane can move. Basically, alwaysIn and alwaysEqual can overlap only if they are compatible.

Best regards, Petr
A small correction. I think that the intervals for crane position should be l[j]+2..1000000 and 0..l[j]-2.

Petr
• qtbgo
134 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-17T03:42:02Z
Thank you very much for your help, Petr.
• qtbgo
134 Posts

#### Re: How to constrain the distance between cumulFunction?

‏2012-10-17T03:43:48Z
Thank you very much for your help, Petr.