Topic
• 6 replies
• Latest Post - ‏2018-06-20T08:58:24Z by Tunemelo
Tunemelo
9 Posts

# Pinned topic Alternative modes with alternative resources

‏2018-06-13T14:10:19Z |

Hello everybody,

I have the following problem:

There are different products with 3 main production steps (1,2(a,b),3) and alternative resources at each production step. The number of production steps depends on the resource used at one specific production step (= variable). Meaning that, if resource x at production step 2a is used, then production step 2b becomes necessary.

I was thinking to assume that there are always 4 production steps and to include the problem by defining two modes.

Mode 1 declares the alternative resources for production steps 1,2(a,b),3 if the resource at production step 2a makes production step 2b on an extra resource necessary. And Mode 2 declares the alternative resources for production steps 1,2,3 if the production step 2b is already included in 2a and therefore 2b does not need to be carried out anymore (then there is a dummy resource for 2b with a duration of 0). The alternative resources for production step 1 and 3 are the same in both modes, only the resources for production step 2a and 2b differ.

In the first place it should be decided if Mode 1 or Mode 2 is taken. And in the second place it should be decided which alternative resources in each process step should be chosen.

Is it possible "to define an alternative in an alternative"? Or is there a better way of expressing this problem in CP?

Thanks a lot:)

• PhilippeLaborie
184 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-14T11:39:13Z

Hello,

First, there is absolutely no problem in defining alternative of alternative in CP Optimizer. Constraint alternative(x,[y1,...,yn]) is a constraint like any other so it can be defined between any interval variable x and any set of interval variables yi.

Now, for your problem, in your description is seems that there is no constraints between the resources allocated to steps 1 and 3 from one side and the resources allocated to steps 2a (and 2b).

In this case, you could focus on the complex step 2 only (and have 'usual' alternative for the steps 1 and 3).

If I understand well, this step2 can be executed in different modes, some of them require 1 interval (let's call these intervals a_i for a mode i in 1..n), some of them 2 intervals (let's call them b_j -> c_j for a mode j in 1..m). You could define the step2 as being the alternative of n+m intervals, for modes i in 1..n, these are directly the a_i intervals, for modes j in 1..m, these intervals are a set of m additional intervals s_j that span [b_j,c_j] and have the same presence status (presenceOf(s_j)==presenceOf(b_j), presenceOf(s_j)==presenceOf(c_j)).

Another option is indeed to use alternative of alternatives: you say that you have 2 main modes for step 2: either using 1 interval 'a' or 2 intervals (by introducing a new interval s spanning 'b->c') and you say that 'a' is the alternative of the 'a_i', 'b' is the alternative of the 'b_j' and 'c' is the alternative of the 'c_j'.

Philippe

• PhilippeLaborie
184 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-14T11:39:13Z

Hello,

First, there is absolutely no problem in defining alternative of alternative in CP Optimizer. Constraint alternative(x,[y1,...,yn]) is a constraint like any other so it can be defined between any interval variable x and any set of interval variables yi.

Now, for your problem, in your description is seems that there is no constraints between the resources allocated to steps 1 and 3 from one side and the resources allocated to steps 2a (and 2b).

In this case, you could focus on the complex step 2 only (and have 'usual' alternative for the steps 1 and 3).

If I understand well, this step2 can be executed in different modes, some of them require 1 interval (let's call these intervals a_i for a mode i in 1..n), some of them 2 intervals (let's call them b_j -> c_j for a mode j in 1..m). You could define the step2 as being the alternative of n+m intervals, for modes i in 1..n, these are directly the a_i intervals, for modes j in 1..m, these intervals are a set of m additional intervals s_j that span [b_j,c_j] and have the same presence status (presenceOf(s_j)==presenceOf(b_j), presenceOf(s_j)==presenceOf(c_j)).

Another option is indeed to use alternative of alternatives: you say that you have 2 main modes for step 2: either using 1 interval 'a' or 2 intervals (by introducing a new interval s spanning 'b->c') and you say that 'a' is the alternative of the 'a_i', 'b' is the alternative of the 'b_j' and 'c' is the alternative of the 'c_j'.

Philippe

• Tunemelo
9 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-14T20:45:16Z

Hello,

First, there is absolutely no problem in defining alternative of alternative in CP Optimizer. Constraint alternative(x,[y1,...,yn]) is a constraint like any other so it can be defined between any interval variable x and any set of interval variables yi.

Now, for your problem, in your description is seems that there is no constraints between the resources allocated to steps 1 and 3 from one side and the resources allocated to steps 2a (and 2b).

In this case, you could focus on the complex step 2 only (and have 'usual' alternative for the steps 1 and 3).

If I understand well, this step2 can be executed in different modes, some of them require 1 interval (let's call these intervals a_i for a mode i in 1..n), some of them 2 intervals (let's call them b_j -> c_j for a mode j in 1..m). You could define the step2 as being the alternative of n+m intervals, for modes i in 1..n, these are directly the a_i intervals, for modes j in 1..m, these intervals are a set of m additional intervals s_j that span [b_j,c_j] and have the same presence status (presenceOf(s_j)==presenceOf(b_j), presenceOf(s_j)==presenceOf(c_j)).

Another option is indeed to use alternative of alternatives: you say that you have 2 main modes for step 2: either using 1 interval 'a' or 2 intervals (by introducing a new interval s spanning 'b->c') and you say that 'a' is the alternative of the 'a_i', 'b' is the alternative of the 'b_j' and 'c' is the alternative of the 'c_j'.

Philippe

Hi Philippe,

// Step 2 Variable
dvar interval Step_2 [p in Products];

// Mode 1 - no breakdown of Step 2
// Ressource 1 for Step 2

dvar interval Step2 [p in Products] optional size Duration2[p];

// Ressource 2 for Step 2

...

// Mode 2 - breakdown of Step 2

dvar interval Step2ab [p in Products] optional;

// Mode 2 - Step 2a and Step 2b
// Ressource 1 for Step 2a
dvar interval Step2a [p in Products] optional size Duration2a[p];

// Ressource 2 for Step 2a

...

// Ressource 1 for Step 2b
dvar interval Step2b [p in Products] optional size Duration2b[p];

// Mode 1 or Mode 2 as alternatives for Step 2
forall (p in Products)

alternative (Step_2[p], all (p in Products) [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)

span (Step2ab[p], all(p in Products) [Step2a[p],Step2a[p]));

// Step 2a before Step 2b
forall (p in Products)

endBeforeStart(Step2a[p],Step2b[p]);

forall (p in Products)

{

presenceOf(Step2ab[p])== presenceOf(Step2a[p]);

presenceOf(Step2ab[p])== presenceOf(Step2b[p]);

};

The alternative and the span constraints are not working like this as I tried to include both variables. Obviously that's not correct how I did it. Do I need to include an additional interval variable for this (to cumulate Step2 and Step2ab first)?

Did I understood you correct that you suggest to establish one interval variable for each resource in each mode (Mode 1: Step2, Mode 2: Step2a --> Step2b)? (There are completely different alternative resources for Step2, Step2a and Step2b= 10 in total)

• PhilippeLaborie
184 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-15T06:58:56Z
• Tunemelo
• ‏2018-06-14T20:45:16Z

Hi Philippe,

// Step 2 Variable
dvar interval Step_2 [p in Products];

// Mode 1 - no breakdown of Step 2
// Ressource 1 for Step 2

dvar interval Step2 [p in Products] optional size Duration2[p];

// Ressource 2 for Step 2

...

// Mode 2 - breakdown of Step 2

dvar interval Step2ab [p in Products] optional;

// Mode 2 - Step 2a and Step 2b
// Ressource 1 for Step 2a
dvar interval Step2a [p in Products] optional size Duration2a[p];

// Ressource 2 for Step 2a

...

// Ressource 1 for Step 2b
dvar interval Step2b [p in Products] optional size Duration2b[p];

// Mode 1 or Mode 2 as alternatives for Step 2
forall (p in Products)

alternative (Step_2[p], all (p in Products) [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)

span (Step2ab[p], all(p in Products) [Step2a[p],Step2a[p]));

// Step 2a before Step 2b
forall (p in Products)

endBeforeStart(Step2a[p],Step2b[p]);

forall (p in Products)

{

presenceOf(Step2ab[p])== presenceOf(Step2a[p]);

presenceOf(Step2ab[p])== presenceOf(Step2b[p]);

};

The alternative and the span constraints are not working like this as I tried to include both variables. Obviously that's not correct how I did it. Do I need to include an additional interval variable for this (to cumulate Step2 and Step2ab first)?

Did I understood you correct that you suggest to establish one interval variable for each resource in each mode (Mode 1: Step2, Mode 2: Step2a --> Step2b)? (There are completely different alternative resources for Step2, Step2a and Step2b= 10 in total)

I think that you are doing something wrong here:

```// Mode 1 or Mode 2 as alternatives for Step 2
forall (p in Products)
alternative (Step_2[p], all (p in Products) [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)
span (Step2ab[p], all(p in Products) [Step2a[p],Step2a[p]));
```

Why do you need to iterate over the products inside the alternative constraints?

I think it should rather be:

```forall (p in Products)
alternative (Step_2[p], [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)
span (Step2ab[p], [Step2a[p],Step2a[p]));
```

• Tunemelo
9 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-15T10:58:28Z

I think that you are doing something wrong here:

<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">// Mode 1 or Mode 2 as alternatives for Step 2 forall (p in Products) alternative (Step_2[p], all (p in Products) [Step2[p],Step2ab[p]]); // Span 2ab over 2a and 2b forall (p in Products) span (Step2ab[p], all(p in Products) [Step2a[p],Step2a[p])); </pre>

Why do you need to iterate over the products inside the alternative constraints?

I think it should rather be:

<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">forall (p in Products) alternative (Step_2[p], [Step2[p],Step2ab[p]]); // Span 2ab over 2a and 2b forall (p in Products) span (Step2ab[p], [Step2a[p],Step2a[p])); </pre>

I see. But it is still not working like this. It's telling me that the add-on syntax is not supported when I try to run the model with these both constraints...

forall (p in Products)

alternative (Step_2[p], [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)

span (Step2ab[p], [Step2a[p],Step2a[p]]);

• PhilippeLaborie
184 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-15T11:29:10Z
• Tunemelo
• ‏2018-06-15T10:58:28Z

I see. But it is still not working like this. It's telling me that the add-on syntax is not supported when I try to run the model with these both constraints...

forall (p in Products)

alternative (Step_2[p], [Step2[p],Step2ab[p]]);

// Span 2ab over 2a and 2b
forall (p in Products)

span (Step2ab[p], [Step2a[p],Step2a[p]]);

Right. In OPL the syntax is rather: alternative(Step_2[p], append(Step2[p],Step2ab[p]));

• Tunemelo
9 Posts

#### Re: Alternative modes with alternative resources

‏2018-06-20T08:58:24Z

Right. In OPL the syntax is rather: alternative(Step_2[p], append(Step2[p],Step2ab[p]));

Thanks, that works!:)