Re: [AMPL 24662] Declaring variables in diferent ways leads to diferent results

These formulations do appear to be the same, except that in the constraint you should say “if m in {10,11,12,1,2,3,4}”. But I think you could express the model even more clearly like this:

set MESES;
set MESES_A_SJ_P within MESES;

var AREA_SOJA {MESES};
var A_SJ_P >= 0;

s.t. SOJA_PLANTADA {m in MESES}:
   AREA_SOJA[m] = if m in MESES_A_SJ_P then A_SJ_P else 0;

Then in a data file for this model, you could specify the members of the two sets with the following statements:

set MESES := OUT NOV DEZ JAN FEV MAR ABR MAI JUN JUL AGO SET ;
set MESES_A_SJ_P := OUT NOV DEZ JAN FEV MAR ABR ;

I am not sure why you need to have the set JANEIRO. Is there some other constraint in the model where you need the months to be given by numbers?

Hi, thank you so much for your fast answer. Gmail threw my email in another folder and here I’m 5 months later haha.

I did something in compact mode to print the results:

# SAÍDAS
set ROTULOS := {
# MÊS
"MES",
# ATIVIDADES EXTRAS
"AREA_SOJA",
"AREA_TRIGO",
# ALIMENTOS
"AREA_PAST_Q",
"AREA_PAST_F",
"AREA_SILAGEM",
"RAÇÃO",
# ANIMAIS
"VACAS_LEITEIRAS",
"VACAS_SECAS",
"NOVILHAS",
"TERNEIRAS"
};

printf "\n";

# ARMAZENAR A SAÍDA EM ARQUIVO CSV
printf {rot in ROTULOS} "%s;", rot >> "resultados_V4.csv";
printf {m in MESES}
"\n%s;%.6f;%.6f;%.6f;%.6f;%.6f;%.6f;%.6f;%.6f;%.6f;%.6f;",
# MÊS
m,
# ATIVIDADES EXTRAS
AREA_SOJA_[m], # DEMANDA DE ÁREA PELA SOJA
AREA_TRIGO_[m], # DEMANDA DE ÁREA PELO TRIGO
# ALIMENTOS
AREA_PAST_Q_[m], # DEMANDA DE ÁREA DA PASTAGEM QUENTE
AREA_PAST_F_[m], # DEMANDA DE ÁREA DA PASTAGEM FRIA
AREA_SILAGEM_[m], # DEMANDA DE ÁREA PELA SILAGEM
RACAO_[m], # DEMANDA DE RAÇÃO
# ANIMAIS
VACAS_LACTACAO_[m], # QUANTIDADE DE VACAS EM LACTAÇÃO
VACAS_SECAS_[m], # QUANTIDADE DE VACAS SECAS/DESCARTE
NOVILHAS_[m], # QUANTIDADE DE NOVILHAS
TERNEIRAS_[m] # QUANTIDADE DE TERNEIRAS
>> "resultados_V4.csv";