AMPL says all my parameters are already defined?

8,972 views
Skip to first unread message

Gustav Danell

unread,
May 8, 2014, 10:02:58 AM5/8/14
to am...@googlegroups.com
Hello!

Ive gotten the problem described in the topic, i.e. that all my parameters get the error that it is already defined. Ive tried to confer with google and the manuals but I have not yet seen anything that solves this issue. From google I learned that I must be careful to use the .dat file in the data statement in the .run file, but that I already do. I think I follow the manual regarding defining. 

For instance I get that p is already defined in my .dat file statement:

param p:        1 2:=
1 0 2
2 3 0;

set I := 1,2;
set J := 1,2;

where I'm in my .mod file has defined p as:

param p{I,J};
set I;
set J;

Thanks in advance
Cenderze

fbahr

unread,
May 8, 2014, 11:48:40 AM5/8/14
to am...@googlegroups.com
Do you load your .mod and .dat files into AMPL's interactive shell, i.e.

ampl: model my_model.mod;
ampl: data my_model.dat;


or do you pass .mod, .dat, and .run files from shell as command line parameters to AMPL, i.e.

$ ampl -o0 my_model.mod my_model.dat my_model.run

?

In the latter case, does you .dat file include the data; "preample" (= keyword in the first line of the .dat file)?

--fbahr

Gustav Danell

unread,
May 9, 2014, 4:45:00 AM5/9/14
to am...@googlegroups.com
Thanks for replying fbahr!

I'm using AMPL's own compiler (?) found in the amplcml  folder. It is simply called AMPL. 

I have a .run file. This is my whole .run file:

reset;
model C:\Users\Guda\Documents\exjobb.mod;
data C:\Users\Guda\Documents\exjobb.dat;

option solver gurobi;

solve;
printf('Total route: %i', sum {t in T, v in V, i in I, j in J} c[i,j,v] * x[i,j,v,t]);

Robert Fourer

unread,
May 9, 2014, 1:54:06 PM5/9/14
to am...@googlegroups.com
This .run file looks OK. Most likely you have some command in the .dat file that is putting AMPL back into "model mode" -- any non-data command such as "let" or "display" will do that. In that case you should add "data;" each time you switch from non-data commands to data statements in your .dat file.

If you still have a problem then you could try posting your files exjobb.mod and exjobb.dat.

Bob Fourer
am...@googlegroups.com

=======

Gustav Danell

unread,
May 19, 2014, 3:11:52 PM5/19/14
to am...@googlegroups.com, 4...@ampl.com
Thanks! That was the cause! I found a "let" statement in the .dat file which removed the problems when I erased it.

wangyi...@gmail.com

unread,
Mar 23, 2016, 1:31:40 AM3/23/16
to AMPL Modeling Language, 4...@ampl.com
Hi,

I met the same problem. I have a .run .mod, two .dat documents, and some variables are defined in .run, some in others. I run them in linux. They work.

But when I run them in windows, i typed ampl: include **.run, it says a lot params have been defined.

You said shoud add “data”, what does it mean?

在 2014年5月9日星期五 UTC-5下午12:54:06,AMPL Optimization写道:

Victor Zverovich

unread,
Mar 23, 2016, 12:15:09 PM3/23/16
to am...@googlegroups.com, 4...@ampl.com
It means adding the statement

  data;

which should normally be at the beginning of a .dat file or before any data statements. Please see Chapter 9. Specifying Data of the AMPL book for more details.

HTH,
Victor

--
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.

aurora...@gmail.com

unread,
Jan 2, 2017, 1:27:12 PM1/2/17
to AMPL Modeling Language
hello ! 
I'm trying to solve one problem in ampl but I made this error and I do not know how to solve it.. Would you mind help me please?



set servizi;
set estetiste; 

param orelavoroperestetista{j in servizi, i in estetiste};

param ricavo{j in servizi};  

param costoorario{i in estetiste}; 

param numeromassimoore{i in estetiste}; 

param domandaminimaperservizio{j in servizi}; 

var X{j in servizi, i in estetiste} integer >=0; 

maximize profitto_totale: sum{j in servizi, i in estetiste} X[j, i]*( ricavo[j] - costoorario[i]*numeromassimoore[i]); 

subject to vicolodisponbilitàoraria{j in servizi, i in estetiste}: orelavoroperestetista[j, i]*X[j,i]= numeromassimoore[i]; 

subject to vicolodomanda{j in servizi}: sum{i in estetiste} X[j, i] >=domandaminimaperservizio[j]; 




 ############ DATA STARTS HERE ############ 

set servizi := massaggi depilazione manicure; 
set estetiste :=  adriana michela; 

param orelavoroperestetista: massaggi depilazione manicure := 
                  adriana      1          0.5         0.5 
                  michela      1.5        0.5           1; 

param  ricavo := massaggi     30  
                 depilazione  20 
                 manicure     25; 

param numeromassimoore := adriana 8  
                          michela 8; 

param costoorario := adriana 10
                     michela 8.5; 

param domandaminimaperservizio :=
massaggi    2 
depilazione   2 
manicure       2; 



this is the problem.,
and that's the error :



Tmp/tin19412, line 28 (offset 747):
servizi is already defined
context:  set  >>> servizi  <<< := massaggi depilazione manicure;
== 3 ==========================



Thank you for your help

Robert Fourer

unread,
Jan 3, 2017, 10:32:38 AM1/3/17
to am...@googlegroups.com
If you are putting all of these statements in one file, you need to put the statement "data;" before the data part, so AMPL knows it is starting to read data statements rather than model statements. If you forget "data;" then AMPL reads "set servizi := massaggi depilazione manicure;" as a model statement and reports that servizi is already defined.

If the data statements are in a separate file, then you could still be reading that file in "model mode" -- though I can't tell why from the information provided. As a quick fix you can add "data;" at the beginning of your data file.

Bob Fourer
am...@googlegroups.com

=======

Indrajit Sen Gupta

unread,
Jan 3, 2017, 11:17:43 AM1/3/17
to AMPL Modeling Language
Your parameter "orelavoroperestetista" is defined over "servizi" and "estetiste" in that order. Hence while providing data for orelavoroperestetista "servizi" should be along the rows and not the columns. Can you try transposing and see?

Regards,
Indrajit

Reply all
Reply to author
Forward
0 new messages