Re: [AMPL 15971] Problem: J already defined

64 views
Skip to first unread message
Message has been deleted

AMPL Google Group

unread,
Mar 23, 2018, 12:33:20 PM3/23/18
to am...@googlegroups.com
I didn't get the error message you mentioned. However, you have defined 'c' and 'd' as the param and also use the same entities in the indexing expression as sum{c in C}. There is no need to define the entities used in the indexing expression. You should use something like sum {ci in C} and 'ci' should not be defined as param or var.

--
Paras Tiwari
am...@googlegroups.com
{#HS:546768168-3440#}
On Thu, Mar 22, 2018 at 11:02 PM UTC, <am...@googlegroups.com> wrote:
what is happning when this message appears?

ampl: model C:\Users\Heyrton\Desktop\tcc\TCCv4.mod

C:\Users\Heyrton\Desktop\tcc\TCCv4.mod, line 2 (offset 20):
j is already defined
context: param >>> j <<< integer >= 0; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.

im tryiing others ways to declared all these parameters but is not working.

help me please


# PARÂMETROS
param j integer >= 0; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.
param c integer >= 0; # número de motoristas
param d integer >= 0; # número de dias no horizonte planejado
param dom integer >= 0; # número de domingos dentro do horizonte de planejamento
param dp integer >= 0; # número de jornadas do tipo dupla pegada
param noturno integer > 0; # número de jornadas do tipo noturno*/

# CONJUNTOS DE ÍNDICES
set Jor := {1..j}; # jornadas
set C := {1..c}; # motoristas
set D := {1..d}; # dias do horizonte planejado
set D0 := {2..d}; # dias para uso em jornadas ociosas (Jornadas0)
set Dom := {1..dom}; # domingos
set Dp := {1..dp}; # dupla-pegada
set Not := {1..noturno}; # jornadas noturnas

# Conjunto de jornadas do dia j, sendo j um dia útil, sábado ou domingo
param Kj {D}; # total de jornadas no dia j

# Conjunto de jornadas que não podem ser realizadas no dia j
# por qualquer tripulação que executou a jornada k no dia (j-1)

param Kj0 {D, Jor, D, Jor} binary;

# PARÂMETROS PARA A OTIMIZAÇÃO DE CUSTOS
param Tsi {Jor}; # Horário de início da jornada i em minutos
param Tei {Jor}; # Horário de término da jornada i em minutos
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) - 400).

# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j

### PRIMEIRO MODELO

# FUNÇÃO-OBJETIVO
maximize Ociosidade:
sum {c in C}
Yi[c];
#RESTRIÇÕES

s.t. Ocioso {c in C, d in D}: #Xij0 = 1 e adiciona o valor a Yi (add value 1 to Xij0 into value Yi)
Yi[c] >= Xij0[c,d];

s.t. Jornadas0 {c in C, d in D0, k1 in Kj[d-1]}: #Jornadas que tem restrição de serem executadas por uma suposta anterior
Xijk[c,d-1,k1] + sum{k2 in Kj[d]} Kj0[d-1,k1,d,k2] <= 1; #check Jorneys restrictions only exec for the pilot
s.t. 6diassemfolga {c in C, d in D}: #garante o 6/1
sum {f in 0..6} Xij0[c,d+f] >= 1; #garantee the jorney 6/1 (6 days in and 1 day out for the pilot)

solve;

data;

param j := 10;

param c := 10;

param d := 10;

param dom := 1;

param dp := 1;

param noturno := 1;

param Kj :=
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1;

param Kj0 :=
1 1 2 1 0
2 1 3 1 1
3 1 4 1 0
4 1 5 1 0
5 1 6 1 0
6 1 7 1 0
7 1 8 1 0
8 1 9 1 0
9 1 10 1 0;
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Eduardo Bessa

unread,
Mar 28, 2018, 3:36:45 PM3/28/18
to AMPL Modeling Language
Thank your, Paras. 

I tried to change all the repetitives entities and it works, But other error appears lol

param j integer >= 0; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.
param c integer >= 0; # número de motoristas
param d integer >= 0; # número de dias no horizonte planejado
param dom integer >= 0; # número de domingos dentro do horizonte de planejamento
param dp integer >= 0; # número de jornadas do tipo dupla pegada
param noturno integer > 0; # número de jornadas do tipo noturno*/

# CONJUNTOS DE ÍNDICES
set Jor := {1..j}; # jornadas
set C := {1..c}; # motoristas
set D := {1..d}; # dias do horizonte planejado
set D0 := {2..d}; # dias para uso em jornadas ociosas (Jornadas0)
set Dom := {1..dom}; # domingos
set Dp := {1..dp}; # dupla-pegada
set Not := {1..noturno}; # jornadas noturnas

# Conjunto de jornadas do dia j, sendo j um dia útil, sábado ou domingo
param Kj {D}; # total de jornadas no dia j

# Conjunto de jornadas que não podem ser realizadas no dia j 
# por qualquer tripulação que executou a jornada k no dia (j-1)

param Kj0 {D, Jor, D, Jor} binary;

# PARÂMETROS PARA A OTIMIZAÇÃO DE CUSTOS
param Tsi {Jor}; # Horário de início da jornada i em minutos
param Tei {Jor}; # Horário de término da jornada i em minutos
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) – 400).

# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j

### PRIMEIRO MODELO

# FUNÇÃO-OBJETIVO
maximize Ociosidade:
sum {cj in C} Yi[cj];
#RESTRIÇÕES

s.t. Ocioso {ca in C, da in D}: #Xij0 = 1 e adiciona o valor a Yi (add value 1 to Xij0 into value Yi)
Yi[ca] >= Xij0[ca,da];

/*s.t. Jornadas0 {cb in C, db in D0, k1 in Kj[db-1]}: #Jornadas que tem restrição de serem executadas por uma suposta anterior
Xijk[cb,db-1,k1] + sum{k2 in Kj[db]} Kj0[d-1,k1,db,k2] <= 1; #check Jorneys restrictions only exec for the pilot
*/
s.t. 6diassemfolga {cc in C, dc in D}: #garante o 6/1
sum {f in 0..5} Xij0[cc,dc+f] >= 1; #garantee the jorney 6/1 (6 days in and 1 day out for the pilot)

/*s.t. dpdom {ce in C}: # Quem faz dupla pegada na semana, folga domingo (get 2 journeys on the day, out on sunday)
sum{de in Dom} xij0[ce,ji] >= 1;*/

/*s.t. motoristanoturno {cf in C, df in D}: # Motorista noturno só faz viagem noturna (night pilot can only do the night journeys)
sum{no in Not} xijk[cf,df,no] = sum{no in Not} x[cf,df+1,no];
s.t. motoristadp {cg in C, dg in D}: # Motorista só faz dupla pegada, se não tiver feito no dia anterior. (pilot only can do
sum{dpa in DP} Xijk[cg,dg,dpa] = sum{dpa in DP} Xijk[cg,dg+1,dpa];
s.t. quemjafolgoutrabalha {hc in C, dh in D}: #Quem ja folgou, trabalha todos os outros dias da semana.
Xij0[ch,dh] + sum{Kj[D] in Jor} Xijk[ch,dh,kjd] >= 1;
s.t. todomundotrabalha {ci in C, di in D, ji in Jor}: #todo mundo realiza alguma jornada
sum{o in c} Xijk[o,di,ji] >= 1;*/
 solve;

In this one,I tried to omit all the restrictions that is not running for synthax error but this kind one appear.
"Error at _cmdno 1 executing "solve" command
(file C:\Users\Heyrton\Desktop\tcc\TCCv6.mod, line 105, offset 3323):
error processing constraint 6diassemfolga[1,6]:
invalid subscript Xij0[1,11]"

Can u help me? 

AMPL Google Group

unread,
Mar 28, 2018, 4:30:11 PM3/28/18
to am...@googlegroups.com
In your constraint 6diassemfolga, you tried to access Xij0[cc,dc+f], where dc is defined over D. You can't add f in dc as you defined Xij0 over the set D. So the correct way to access Xij0 is Xij0[cc,dc].


--
Paras Tiwari
am...@googlegroups.com
{#HS:546768168-3440#}
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) - 400).

# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j

### PRIMEIRO MODELO

# FUNÇÃO-OBJETIVO
maximize Ociosidade:

Eduardo Bessa

unread,
Apr 24, 2018, 8:50:13 PM4/24/18
to AMPL Modeling Language
Thank you for the answer! 

Do you know any way to check the loop without "f" ? The "f" is necessary to know if the pilot worked 6 days to stay out for once in the week.

Eduardo Bessa

unread,
Apr 25, 2018, 12:22:05 AM4/25/18
to AMPL Modeling Language
I wrote in this way and it works! Thank you, Tiwari!

s.t. 6diassemfolga {cc in C, dc in d..d-6}: #garante o 6/1
sum {f in 0..5} Xij0[cc,dc+f] >= 1;

collin...@gmail.com

unread,
May 9, 2018, 9:58:02 PM5/9/18
to AMPL Modeling Language
Could you help me?

AMPL Google Group

unread,
May 10, 2018, 2:04:09 PM5/10/18
to Ampl Modeling Language
Do you still have questions? It's not clear if you have figured out the solution and still have problems. If you have problem, please explain in detail.

--
Paras Tiwari
am...@googlegroups.com
{#HS:546768168-3440#}
On Thu, May 10, 2018 at 1:58 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Could you help me?



On Wed, Apr 25, 2018 at 4:22 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
I wrote in this way and it works! Thank you, Tiwari!

s.t. 6diassemfolga {cc in C, dc in d..d-6}: #garante o 6/1

sum {f in 0..5} Xij0[cc,dc+f] >= 1;

Em terça-feira, 24 de abril de 2018 21:50:13 UTC-3, Eduardo Bessa escreveu:



On Wed, Apr 25, 2018 at 12:50 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Thank you for the answer!

Do you know any way to check the loop without "f" ? The "f" is necessary to know if the pilot worked 6 days to stay out for once in the week.


Em quarta-feira, 28 de março de 2018 17:30:11 UTC-3, AMPL Google Group escreveu:

Eduardo Bessa

unread,
May 22, 2018, 8:16:38 PM5/22/18
to AMPL Modeling Language
Hi, Paras.

I am trying to run the model, but this message appears:
presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 6Noturna[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 5FolgaDomDp[1,1,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 7DuplaPegada[2,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 6Noturna[2,1]:
all variables eliminated, but lower bound = 1 > 0
21 presolve messages suppressed.

What this means? 

model: 

#TCC.mod

# PARÂMETROS
param j >= 0 integer; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.
param c >= 0 integer; # número de motoristas
param d >= 0 integer; # número de dias no horizonte planejado
param dom >= 0 integer; # número de domingos dentro do horizonte de planejamento
param dp >= 0 integer; # número de jornadas do tipo dupla pegada
param notu >= 0 integer; # número de jornadas do tipo noturno

# CONJUNTOS DE ÍNDICES
set Jor := {1..j}; # jornadas
set C := {1..c}; # motoristas
set D := {1..d}; # dias do horizonte planejado
set D0 := {2..d}; # dias para uso em jornadas ociosas (Jornadas0)
set Dom := {1..dom}; # domingos
set Dp := {1..dp}; # dupla-pegada
set Not := {1..notu}; # jornadas noturnas

# Conjunto de jornadas do dia j, sendo j um dia útil, sábado ou domingo
set Kj {D}; # total de jornadas no dia j

# Conjunto de jornadas que não podem ser realizadas no dia j 
# por qualquer tripulação que executou a jornada k no dia (j-1)
# binary, 1 se jornada do dia j não pode ser realizada

param Kj0 {D, Jor, D, Jor} binary;

# PARÂMETROS PARA A OTIMIZAÇÃO DE CUSTOS
param Tsi {Jor}; # Horário de início da jornada i em minutos
param Tei {Jor}; # Horário de término da jornada i em minutos
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) – 400).

# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j


########### PRIMEIRO MODELO ##############

# FUNÇÃO-OBJETIVO
maximize Ociosidade:
sum {c1 in C} Yi[c1];

# RESTRIÇÕES

s.t. 1Ocioso {c1 in C, d1 in D}:
Yi[c1] = Xij0[c1,d1];

s.t. 2Jornadas0 {c1 in C, d1 in D0, k in Kj[d1-1]}:
Xijk[c1,d1-1,k] + sum{k2 in Kj[d1]} Kj0 [d1-1,k,d1,k2] <= 1;
s.t. 3Folga {c1 in C, d1 in 1..d-6}: 
sum {d2 in 0..6} Xij0 [c1,d1+d2] >= 1;
s.t. 4FolgaDomingo {c1 in C}:
sum {dom1 in Dom} Xij0 [c1,dom1] >= 1; 

# Verificar normas, geralmente 01folga no domingo por mês
s.t. 5FolgaDomDp {c1 in C, dom1 in Dom, d1 in D}:
Xij0 [c1,dom1] >= sum {dp1 in Dp} Xijk[c1,d1,dp1];

s.t. 6Noturna {c1 in C, d1 in 1..d-3}:
sum {notu1 in Not} Xijk[c1,d1,notu1] = sum {notu1 in Not} Xijk[c1,d1+1,notu1];
s.t. 7DuplaPegada {c1 in C, d1 in 1..d-3}:
sum {dp1 in Dp} Xijk[c1,d1,dp1] = sum {dp1 in Dp} Xijk[c1,d1+1,dp1];
s.t. 8Apenas01JornadaDia {c1 in C, d1 in D}:
Xij0[c1,d1] + sum {j1 in Kj[d1]} Xijk[c1,d1,j1] <= 1;
s.t. 9TodasJornadasRealizadas {d1 in D, j1 in Kj[d1]}:
sum {c1 in C} Xijk[c1,d1,j1] = 1;
s.t. 10TodasJornadasDomingo {d1 in D, dp1 in Dp}:
sum {c1 in C} Xijk[c1,d1,dp1] = 1;
s.t. 11TodasJornadasNoturnas {d1 in D, notu1 in Not}:
sum {c1 in C} Xijk[c1,d1,notu1] = 1;

data; 

param j := 5;

param c := 5;

param d := 5;

param dom := 1;

param dp := 1;

param notu := 1;

set Kj[1] := 1;
set Kj[2] := 1 2;
set Kj[3] := 3 4;
set Kj[4] := 4;
set Kj[5] := 5;

param Kj0 :=
 1 1 2 1 1
 1 1 2 2 1
 2 1 3 1 1 
 2 1 3 3 1
 2 1 3 4 1
 2 2 3 3 1
 2 2 3 1 1
 2 2 3 4 1
 3 1 4 1 1
 3 3 4 4 1
 3 4 4 4 1
 4 1 5 1 1
 4 4 5 5 1;

 solve;
  

Em quinta-feira, 22 de março de 2018 20:02:42 UTC-3, Eduardo Bessa escreveu:
what is happning when this message appears? 

ampl: model C:\Users\Heyrton\Desktop\tcc\TCCv4.mod

C:\Users\Heyrton\Desktop\tcc\TCCv4.mod, line 2 (offset 20):
j is already defined
context:  param  >>> j  <<< integer >= 0; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.

im tryiing others ways to declared all these parameters but is not working.

help me please


# PARÂMETROS
param j integer >= 0; # número de jornadas, incluindo as dos dias úteis, sábado e domingo.
param c integer >= 0; # número de motoristas
param d integer >= 0; # número de dias no horizonte planejado
param dom integer >= 0; # número de domingos dentro do horizonte de planejamento
param dp integer >= 0; # número de jornadas do tipo dupla pegada
param noturno integer > 0; # número de jornadas do tipo noturno*/

# CONJUNTOS DE ÍNDICES
set Jor := {1..j}; # jornadas
set C := {1..c}; # motoristas
set D := {1..d}; # dias do horizonte planejado
set D0 := {2..d}; # dias para uso em jornadas ociosas (Jornadas0)
set Dom := {1..dom}; # domingos
set Dp := {1..dp}; # dupla-pegada
set Not := {1..noturno}; # jornadas noturnas

# Conjunto de jornadas do dia j, sendo j um dia útil, sábado ou domingo
param Kj {D}; # total de jornadas no dia j

# Conjunto de jornadas que não podem ser realizadas no dia j 
# por qualquer tripulação que executou a jornada k no dia (j-1)

param Kj0 {D, Jor, D, Jor} binary;

# PARÂMETROS PARA A OTIMIZAÇÃO DE CUSTOS
param Tsi {Jor}; # Horário de início da jornada i em minutos
param Tei {Jor}; # Horário de término da jornada i em minutos
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) – 400).

# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j

### PRIMEIRO MODELO

# FUNÇÃO-OBJETIVO
maximize Ociosidade:
sum {c in C} 
Yi[c];
#RESTRIÇÕES

s.t. Ocioso {c in C, d in D}: #Xij0 = 1 e adiciona o valor a Yi (add value 1 to Xij0 into value Yi)
Yi[c] >= Xij0[c,d];

s.t. Jornadas0 {c in C, d in D0, k1 in Kj[d-1]}: #Jornadas que tem restrição de serem executadas por uma suposta anterior
Xijk[c,d-1,k1] + sum{k2 in Kj[d]} Kj0[d-1,k1,d,k2] <= 1; #check Jorneys restrictions only exec for the pilot
s.t. 6diassemfolga {c in C, d in D}: #garante o 6/1
sum {f in 0..6} Xij0[c,d+f] >= 1; #garantee the jorney 6/1 (6 days in and 1 day out for the pilot)

solve;

Eduardo Bessa

unread,
May 22, 2018, 8:20:02 PM5/22/18
to AMPL Modeling Language

Hi Paras, 

I run the model but this message appears. What this means? And the solution is not okay either. It is like the restriction (s.t. 8Apenas01JornadaDia {c1 in C, d1 in D}:
Xij0[c1,d1] + sum {j1 in Kj[d1]} Xijk[c1,d1,j1] <= 1;) is not working.. Thank you

presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 6Noturna[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 5FolgaDomDp[1,1,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 7DuplaPegada[2,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 6Noturna[2,1]:
all variables eliminated, but lower bound = 1 > 0
21 presolve messages suppressed.



TCCv8.mod

AMPL Google Group

unread,
May 23, 2018, 12:05:52 AM5/23/18
to Ampl Modeling Language
As a start on checking the model, I suggest picking one of the error messages, say,



presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0

and expanding the constraint mentioned in the message:


ampl: expand 7DuplaPegada[1,1];


subject to 7DuplaPegada[1,1]:

Xijk[1,1,1] - Xijk[1,2,1] = 0;



Next I would check the bounds on the one variable in this constraint:


ampl: display Xijk[1,1,1].ub;
Xijk[1,1,1].ub = 1

ampl: display Xijk[1,2,1];
Xijk[1,2,1] = 0

Here I see that AMPL's presolve phase has determined that this variable must equal one. Thus the constraint becomes -1 = 0, which cannot possibly be satisfied. Now you will have to make a further examination of your model to figure out why this contradiction is occurring.

--
Dr. Paras Tiwari
am...@googlegroups.com
{#HS:546768168-3440#}
On Wed, May 23, 2018 at 12:20 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hi Paras,

I run the model but this message appears. What this means? And the solution is not okay either. It is like the restriction (s.t. 8Apenas01JornadaDia {c1 in C, d1 in D}:
Xij0[c1,d1] + sum {j1 in Kj[d1]} Xijk[c1,d1,j1] <= 1;) is not working.. Thank you


presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 6Noturna[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 5FolgaDomDp[1,1,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 7DuplaPegada[2,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 6Noturna[2,1]:
all variables eliminated, but lower bound = 1 > 0
21 presolve messages suppressed.




Em quinta-feira, 10 de maio de 2018 15:04:09 UTC-3, AMPL Google Group escreveu:



On Wed, May 23, 2018 at 12:16 AM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hi, Paras.

I am trying to run the model, but this message appears:
presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 6Noturna[1,1]:
all variables eliminated, but upper bound = -1 < 0
presolve, constraint 5FolgaDomDp[1,1,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 7DuplaPegada[2,1]:
all variables eliminated, but lower bound = 1 > 0
presolve, constraint 6Noturna[2,1]:
all variables eliminated, but lower bound = 1 > 0
21 presolve messages suppressed.

What this means?

model:

#TCC.mod

# PARÂMETROS
param j >= 0 integer; # número de jornadas, incluindo as dos dias úteis,
sábado e domingo.
param c >= 0 integer; # número de motoristas
param d >= 0 integer; # número de dias no horizonte planejado
param dom >= 0 integer; # número de domingos dentro do horizonte de
planejamento
param dp >= 0 integer; # número de jornadas do tipo dupla pegada
param notu >= 0 integer; # número de jornadas do tipo noturno


# CONJUNTOS DE ÍNDICES
set Jor := {1..j}; # jornadas
set C := {1..c}; # motoristas
set D := {1..d}; # dias do horizonte planejado
set D0 := {2..d}; # dias para uso em jornadas ociosas (Jornadas0)
set Dom := {1..dom}; # domingos
set Dp := {1..dp}; # dupla-pegada
set Not := {1..notu}; # jornadas noturnas


# Conjunto de jornadas do dia j, sendo j um dia útil, sábado ou domingo
set Kj {D}; # total de jornadas no dia j


# Conjunto de jornadas que não podem ser realizadas no dia j
# por qualquer tripulação que executou a jornada k no dia (j-1)
# binary, 1 se jornada do dia j não pode ser realizada

param Kj0 {D, Jor, D, Jor} binary;

# PARÂMETROS PARA A OTIMIZAÇÃO DE CUSTOS
param Tsi {Jor}; # Horário de início da jornada i em minutos
param Tei {Jor}; # Horário de término da jornada i em minutos
param Ci {Jor}; # Custo de cada jornada i dado por ((tej - tsi) – 400).


# VARIÁVEIS
var Xijk {C, D, Jor} binary; # 1 se motorista i, no dia j, realiza jornada k
var Yi {C} binary; # 1 se motorista i nao trabalha nenhum dia
var Xij0 {C, D} binary; # 1 se tripulaçao i não trabalha no dia j


########### PRIMEIRO MODELO ##############

# FUNÇÃO-OBJETIVO
maximize Ociosidade:

sum {c1 in C} Yi[c1];

# RESTRIÇÕES

s.t. 1Ocioso {c1 in C, d1 in D}:
Yi[c1] = Xij0[c1,d1];

s.t. 2Jornadas0 {c1 in C, d1 in D0, k in Kj[d1-1]}:
Xijk[c1,d1-1,k] + sum{k2 in Kj[d1]} Kj0 [d1-1,k,d1,k2] <= 1;
s.t. 3Folga {c1 in C, d1 in 1..d-6}:
sum {d2 in 0..6} Xij0 [c1,d1+d2] >= 1;
s.t. 4FolgaDomingo {c1 in C}:
sum {dom1 in Dom} Xij0 [c1,dom1] >= 1;

# Verificar normas, geralmente 01folga no domingo por mês
s.t. 5FolgaDomDp {c1 in C, dom1 in Dom, d1 in D}:
Xij0 [c1,dom1] >= sum {dp1 in Dp} Xijk[c1,d1,dp1];

s.t. 6Noturna {c1 in C, d1 in 1..d-3}:
sum {notu1 in Not} Xijk[c1,d1,notu1] = sum {notu1 in Not}
Xijk[c1,d1+1,notu1];
s.t. 7DuplaPegada {c1 in C, d1 in 1..d-3}:
sum {dp1 in Dp} Xijk[c1,d1,dp1] = sum {dp1 in Dp} Xijk[c1,d1+1,dp1];
s.t. 8Apenas01JornadaDia {c1 in C, d1 in D}:
Xij0[c1,d1] + sum {j1 in Kj[d1]} Xijk[c1,d1,j1] <= 1;
s.t. 9TodasJornadasRealizadas {d1 in D, j1 in Kj[d1]}:
sum {c1 in C} Xijk[c1,d1,j1] = 1;
s.t. 10TodasJornadasDomingo {d1 in D, dp1 in Dp}:
sum {c1 in C} Xijk[c1,d1,dp1] = 1;
s.t. 11TodasJornadasNoturnas {d1 in D, notu1 in Not}:
sum {c1 in C} Xijk[c1,d1,notu1] = 1;

data;

param j := 5;

param c := 5;

param d := 5;

param dom := 1;

param dp := 1;

param notu := 1;

set Kj[1] := 1;
set Kj[2] := 1 2;
set Kj[3] := 3 4;
set Kj[4] := 4;
set Kj[5] := 5;

param Kj0 :=

1 1 2 1 1
1 1 2 2 1
2 1 3 1 1
2 1 3 3 1
2 1 3 4 1
2 2 3 3 1
2 2 3 1 1
2 2 3 4 1
3 1 4 1 1
3 3 4 4 1
3 4 4 4 1
4 1 5 1 1
4 4 5 5 1;

solve;


Em quinta-feira, 22 de março de 2018 20:02:42 UTC-3, Eduardo Bessa escreveu:



On Thu, May 10, 2018 at 6:03 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Do you still have questions? It's not clear if you have figured out the solution and still have problems. If you have problem, please explain in detail.

--
Dr. Paras Tiwari
am...@googlegroups.com
Message has been deleted

Eduardo Bessa

unread,
May 23, 2018, 2:52:44 AM5/23/18
to AMPL Modeling Language
Thank you, Paras! I think the problem is my data because i changed the data tests and it worked! I made the changes and the new model is attached. My solution is not okay now.. Variable Xijk should be binary and appear that..Why is that happen? 


ampl: model TCCv8.mod;
ampl: solve;
MINOS 5.51: ignoring integrality of 380 variables
MINOS 5.51: optimal solution found.
55 iterations, objective 19
ampl: display Xijk;
Xijk [*,1,*]
:         1        2   3   4   5   6   7    :=
1    0.5           0   0   0   0   0   0
2    0             0   0   0   0   0   0
3    0             0   0   0   0   0   0
4    0             0   0   0   0   0   0
5    0             0   0   0   0   0   0
6    0             0   0   0   0   0   0
7    0             0   0   0   0   0   0
8    0             0   0   0   0   0   0
9    0             0   0   0   0   0   0
10   0             0   0   0   0   0   0
11   0             0   0   0   0   0   0
12   0             0   0   0   0   0   0
13   0             0   0   0   0   0   0
14   0             0   0   0   0   0   0
15   0             0   0   0   0   0   0
16   0             0   0   0   0   0   0
17   0             0   0   0   0   0   0
18   0.5           0   0   0   0   0   0
19   0             0   0   0   0   0   0
20   1.51745e-15   0   0   0   0   0   0
- mostrar texto das mensagens anteriores -
TCCv8.mod

AMPL Google Group

unread,
May 25, 2018, 11:58:19 AM5/25/18
to Ampl Modeling Language
You can see from the first solver message that the solver did not enforce the requirement for the variables to take integer values:


ampl: solve;
MINOS 5.51: ignoring integrality of 380 variables

The trouble here is that you did not specify a solver, and so AMPL by default used MINOS which cannot handle integer variables. Instead since you have a linear problem you should specify one of the linear solvers that recognizes integer variables, such as CPLEX, Gurobi, or Xpress; this is done by giving the command "option solver cplex;" or "option solver gurobi;" etc.

--
Robert Fourer
am...@googlegroups.com
{#HS:546768168-3440#}
Em quarta-feira, 23 de maio de 2018 01:05:52 UTC-3, AMPL Google Group escreveu:



On Wed, May 23, 2018 at 4:05 AM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
As a start on checking the model, I suggest picking one of the error messages, say,


presolve, constraint 7DuplaPegada[1,1]:
all variables eliminated, but upper bound = -1 < 0

and expanding the constraint mentioned in the message:


ampl: expand 7DuplaPegada[1,1];


subject to 7DuplaPegada[1,1]:

Xijk[1,1,1] - Xijk[1,2,1] = 0;



Next I would check the bounds on the one variable in this constraint:


ampl: display Xijk[1,1,1].ub;
Xijk[1,1,1].ub = 1

ampl: display Xijk[1,2,1];
Xijk[1,2,1] = 0

Here I see that AMPL's presolve phase has determined that this variable must equal one. Thus the constraint becomes -1 = 0, which cannot possibly be satisfied. Now you will have to make a further examination of your model to figure out why this contradiction is occurring.

--
Dr. Paras Tiwari
am...@googlegroups.com


Eduardo Bessa

unread,
Jun 3, 2018, 4:36:30 PM6/3/18
to AMPL Modeling Language
Thank You, Robert.

I changed the solver and it works. Now i will focus on the model! 

Thanks again

Eduardo Bessa

unread,
Sep 4, 2018, 11:52:40 AM9/4/18
to AMPL Modeling Language
Yes. How can I help you?
Reply all
Reply to author
Forward
0 new messages