# \[AMPL 24638\] Flexible Job Shop model - Help

**URL:** <https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543>\
**Category:** Google Group Mirror\
**Created:** [May 8, 2023, 3:27pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543 "2023-05-08T15:27:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor\_salazar](https://avatars.discourse-cdn.com/v4/letter/v/c6cbf5/32.png) [@victor\_salazar](https://discuss.ampl.com/u/victor_salazar)\
**Post date:** [May 8, 2023, 3:27pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/1 "2023-05-08T15:27:02Z")

</div>

I need help with this model of Flexible Job Shop in AMPL please, i know that “oper” its a subset of “trab”, and his original index it’s [J\_i] and o it’s t\_i, but i don’t know how to model it.

this params are used in R4 and R5.

#.mod

param t; #numero total de trabajos  
param m; #numero total de maquinas  
param o; #numero total de operaciones  
param q; #numero total de posiciones

set trab := 1…t; #Conjunto de trabajos  
set oper := 1…o; #subconjunto de operaciones  
set maquin := 1…m; #Conjunto de Maquinas  
set pos := 1…q; #posicion

param a{maquin,trab,oper} binary; #1 si la operacion del trabajo se hace en k  
param p{trab,oper}; #tiempo de proceso de la operacion j del trabajo i  
param M \>= 0; #limitacion  
param d{trab}; # fecha de entrega

var x{i in trab, j in oper, k in maquin, l in pos} binary;#si la op del trab se hace en la maquin, en la posicion  
var v{i in trab, j in oper, k in maquin} binary; #1 si la op del trab se hace en la maquina  
var TM{k in maquin, l in pos} \>= 0;#tiempo de inicio de la maquina y la posicion  
var ti{i in trab, j in oper} \>= 0;#tiempo de inicio de la operacion en el trabajo  
var C{i in trab} \>= 0; #tiempo requerido para completar el trabajo  
var T{i in trab} \>=0; #tardanza del trabajo  
var U {i in trab} binary; #if c{i in trab} - d{i in trab} \> 0 then 1 else 0;

minimize z: sum{i in trab} U[i]; #funcion Objetivo

subj to r1{i in trab}: C[i] \>= sum{j in oper}(ti[i,j] + p[i,j]);  
subj to r2{i in trab}: T[i] \>= C[i] - d[i];  
subj to r3{i in trab}: T[i] \<= U[i] \* M;  
subj to r4{i in trab, j in 1…o-1}: ti[i,o] + p[i,j] \<= ti[i,j+1];

subj to r5{i in trab, j in oper, k in maquin, l in 1…q-1}: TM[k,l] + p[i,j] \* x[i,j,k,l] \<= TM[k,l+1];  
subj to r6{i in trab, j in oper, k in maquin, l in pos}: TM[k,l] \<= ti[i,j] + (1-x[i,j,k,l]) \* M;  
subj to r7{i in trab, j in oper, k in maquin, l in pos}: TM[k,l] + (1-x[i,j,k,l]) \* M \>= ti[i,j];  
subj to r8{i in trab, j in oper, k in maquin}: v[i,j,k] \<= a[k,i,j];

subj to r9{k in maquin, l in pos}: sum{i in trab, j in oper}x[i,j,k,l] = 1;  
subj to r10{i in trab, j in oper}: sum{k in maquin}v[i,j,k] = 1;  
subj to r11{i in trab, j in oper, k in maquin}: sum{l in pos}x[i,j,k,l] = v[i,j,k];

#.dat  
param t := 3;  
param m := 3;  
param o := 3;  
param q := 2;

param a :=

1 1 1 1  
1 1 2 0  
1 1 3 0  
1 2 1 0  
1 2 2 0  
1 2 3 0  
1 3 1 0  
1 3 2 0  
1 3 3 0  
2 1 1 1  
2 1 2 0  
2 1 3 0  
2 2 1 0  
2 2 2 0  
2 2 3 0  
2 3 1 0  
2 3 2 0  
2 3 3 0  
3 1 1 0  
3 1 2 0  
3 1 3 1  
3 2 1 0  
3 2 2 0  
3 2 3 0  
3 3 1 0  
3 3 2 0  
3 3 3 0  
;

param p:  
1 2 3 :=  
1 16 16 16  
2 40 20 36  
3 30 30 24  
;

param M := 100;

param d:=  
1 160  
2 240  
3 130  
;

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [May 8, 2023, 10:26pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/2 "2023-05-08T22:26:43Z")

</div>

There aren’t any syntax errors or other obvious mistakes in your model and data. Maybe you are not writing constraints r4 and r5 correctly, but your question does not have enough information for me to tell what the correct form might be. Do you have a mathematical formulation for these constraints – and also the sets, parameters, and variables that appear in tham?

---

<div class="post-metadata">

**Author:** ![victor\_salazar](https://avatars.discourse-cdn.com/v4/letter/v/c6cbf5/32.png) [@victor\_salazar](https://discuss.ampl.com/u/victor_salazar)\
**Post date:** [May 8, 2023, 10:37pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/3 "2023-05-08T22:37:44Z")

</div>

![FJS.png](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/aefb8d572a07db86075110a8ed327e37f8dc2a0c.png)

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [May 9, 2023, 2:36pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/4 "2023-05-09T14:36:08Z")

</div>

This formulation would be very helpful, but unfortunately the resolution of the picture is too low. I cannot clearly read the mathematical symbols – especially the subscripts. Can you provide a copy with higher resolution? If it’s in a file, you can try attaching the file.

---

<div class="post-metadata">

**Author:** ![victor\_salazar](https://avatars.discourse-cdn.com/v4/letter/v/c6cbf5/32.png) [@victor\_salazar](https://discuss.ampl.com/u/victor_salazar)\
**Post date:** [May 9, 2023, 3:42pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/5 "2023-05-09T15:42:23Z")

</div>

the model is taken from this paper, from what I understand “oper” should be something like “oper[j]”

(Attachment Dialnet-ModeloDeProgramacionLinealEnteraMixtaParaLaProgram-6046313 (2).pdf is missing)

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [May 10, 2023, 9:16pm UTC](https://discuss.ampl.com/t/ampl-24638-flexible-job-shop-model-help/543/6 "2023-05-10T21:16:37Z")

</div>

There seem to be some mistakes in the paper’s statement of the model, such as listing sk as a variable. The following is my best guess as to what the authors intended to write.

It appears that the oper set is supposed to be different for each member of trab. As far as I can tell, the paper is trying to express constraint r4 like:

```auto
param t;
param o {1..t};

set trab := 1..t;
set oper {i in trab} := 1..o[i];

param p {i in trab, oper[i]};
var ti {i in trab, oper[i]};

subj to r4 {i in trab, j in 1..o[i]-1}: ti[i,j] + p[i,j] <= ti[i,j+1];

```

Similarly, it appears that the pos set is supposed to be different for each member of maquin:

```auto
param m;
param q {1..m};

set maquin := 1..m;
set pos {k in maquin} := 1..q[k];

var TM {k in maquin, pos[k]};
var x {i in trab, oper[i], k in maquin, pos[k]};

subj to r5 {i in trab, j in oper[i], k in maquin, l in 1..q[k]-1}: 
   TM[k,l] + p[i,j] * x[i,j,k,l] <= TM[k,l+1];

```
