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

**URL:** <https://discuss.ampl.com/t/re-ampl-24662-declaring-variables-in-diferent-ways-leads-to-diferent-results/559>\
**Category:** Google Group Mirror\
**Created:** [May 16, 2023, 10:33pm UTC](https://discuss.ampl.com/t/re-ampl-24662-declaring-variables-in-diferent-ways-leads-to-diferent-results/559 "2023-05-16T22:33:03Z")\
**Posts on this page:** 2\
**Page:** 1

<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 16, 2023, 10:33pm UTC](https://discuss.ampl.com/t/re-ampl-24662-declaring-variables-in-diferent-ways-leads-to-diferent-results/559/1 "2023-05-16T22:33:03Z")

</div>

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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![leosmi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/leosmi/32/278_2.png) [@leosmi](https://discuss.ampl.com/u/leosmi)\
**Post date:** [November 30, 2023, 12:32pm UTC](https://discuss.ampl.com/t/re-ampl-24662-declaring-variables-in-diferent-ways-leads-to-diferent-results/559/2 "2023-11-30T12:32:34Z")

</div>

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:

```auto
# 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";

```
