Hello to everybody,--my name is Gianpaolo and I am pretty new of AMPL and the OPTI toolbox, so sorry for trivial mistakes.Basically, I am trying out the AMPL interface of the OPTI toolbox and I am in this section: http://www.i2c2.aut.ac.nz/Wiki/OPTI/index.php/File/AMPL.The point is that I would like to try this line: ampl -ogdiet MODELS\diet.mod MODELS\diet.datdiet.mod is the following file:set NUTR;
set FOOD;
param cost {FOOD} > 0;
param f_min {FOOD} >= 0;
param f_max {j in FOOD} >= f_min[j];
param n_min {NUTR} >= 0;
param n_max {i in NUTR} >= n_min[i];
param amt {NUTR,FOOD} >= 0;
var Buy {j in FOOD} >= f_min[j], <= f_max[j];
minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j];
subject to Diet {i in NUTR}:
n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];diet.dat is the following file:set NUTR := A B1 B2 C ;
set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ;
param: cost f_min f_max :=
BEEF 3.19 0 100
CHK 2.59 0 100
FISH 2.29 0 100
HAM 2.89 0 100
MCH 1.89 0 100
MTL 1.99 0 100
SPG 1.99 0 100
TUR 2.49 0 100 ;
param: n_min n_max :=
A 700 10000
C 700 10000
B1 700 10000
B2 700 10000 ;
param amt (tr):
A C B1 B2 :=
BEEF 60 20 10 15
CHK 8 0 20 20
FISH 8 10 15 10
HAM 40 40 35 10
MCH 15 35 15 15
MTL 70 30 15 15
SPG 25 50 25 15
TUR 60 20 15 10 ;everything works when I run :ampl: model diet.mod;
ampl: data diet.dat;
ampl: solve;
MINOS 5.5: optimal solution found.
6 iterations, objective 88.2
ampl: display Buy;
Buy [*] :=
BEEF 0
CHK 0
FISH 0
HAM 0
MCH 46.6667
MTL -1.07823e-16
SPG -1.32893e-16
TUR 0
;If I want to create a .nl file starting from the diet.mod and the diet.dat files, then I type :
ampl -ogdiet MODELS\diet.mod MODELS\diet.dat
D:\xxx\MovementPlanning\test.dat, line 1 (offset 4):
NUTR is already defined
context: set >>> NUTR <<< := A B1 B2 C ;
D:\xxx\MovementPlanning\test.dat, line 2 (offset 28):
FOOD is already defined
context: set >>> FOOD <<< := BEEF CHK FISH HAM MCH MTL SPG TUR ;
D:\xxx\MovementPlanning\test.dat, line 3 (offset 72):
syntax error
context: >>> param: <<< cost f_min f_max :=Could you please help me?Thank you in advance.Gianpaolo.
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 http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/groups/opt_out.
You will need to put the command
data;
at the beginning of your data file. This statement causes AMPL to read statements like
set NUTR := A B1 B2 C ;
in data mode; without it, AMPL interprets all your data statements as model definitions, which is why you get "NUTR is already defined" and other error messages. (This is not a problem when running interactively, because you type "data diet.dat" which puts AMPL into data mode.)
Bob Fourer
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of gianpaol...@gmail.com
Sent: Monday, February 17, 2014 2:50 PM
To: am...@googlegroups.com
Subject: [AMPL 8044] AMPL and generation of .nl files
Ok,I think I understood the problem.In this case how should I write the data file in order to avoid this problem? I mean I need to separate data end model, but at the same time I need to use this particular command.Is there a way to do that?Thank you.
>> You will need to put the command
>> data;
>> at the beginning of your data file.
data;
set NUTR := A B1 B2 C ;
ampl -ogdiet MODELS\diet.mod MODELS\diet.dat
Great! It works.
I am sorry, but probably it was a stupid question, but it is my first experience with AMPL.
Thank you very much to everybody!
--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/T4S22h6zNzM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.