No variable declared error

16 views
Skip to first unread message

Meredith Price

unread,
Sep 20, 2021, 10:43:43 AM9/20/21
to am...@googlegroups.com
Hello,

Can you explain why I'm getting the error message no variable declared?

# Set and Parameters
set cities:= New York, Los Angeles, Chicago, Atlanta;
set region:= Region 1 ,Region 2, Region 3;
set LINKS :=
(New York, Region 1) (New York, Region 2) (New York, Region 3)
(Los Angeles, Region 1) (Los Angeles, Region 2) (Los Angeles, Region 3)
(Chicago, Region 1) (Chicago, Region 2) (Chicago, Region 3)
(Atlanta, Region 1) (Atlanta, Region 2) (Atlanta, Region 3);
param Supply:=
New York 100 Los Angeles 100 Chicago 100 Atlanta 100;
param Demand:=
Region 1 80 Region 2 70 Region 3 40;
param fixed:=
New York 400 Los Angeles 500 Chicago 300 Atlanta 150;
param cost:=
New York Region 1 20
New York Region 2 40
New York Region 3 50
Los Angeles Region 1 48
Los Angeles Region 2 15
Los Angeles Region 3 26
Chicago Region 1 26
Chicago Region 2 35
Chicago Region 3 10
Atlanta Region 1 24
Atlanta Region 2 50
Atlanta Region 3 35;
# Set and Parameters
set cities;
set region;
set LINKS within (cities, cross region);
param Supply {cities} >=0;
param Demand {region} >=0;
param fixed {cities} >=0;
#Decision Variables
var x{(i,j) in LINKS} >=0;
var y{i in cities} binary;
#Objective Funtion
minimize Z:sum{i in cities} fixed[i]*y[i]+sum{(i,j) in LINKS} cost[i,j]*x[i,j];
#Constraints
subject to c1 {i in cities}:sum{(i,j)in LINKS}x[i,j]<=Supply[i];
subject to c2 {j in region}:sum{(i,j)in LINKS}x[i,j]>=Demand[j];
subject to c3 {i in cities}:sum{(i,j)in LINKS}y[i]<=2;
subject to c4 {i in cities}:sum{(i,j)in LINKS}y[i]>=0;
subject to c5 {i in cities}:{in LINKS}y[i] = 4;
subject to c5 {i in cities}:{in LINKS}y[i] = 3;

Thanks,

Meredith

Davi Doro

unread,
Sep 20, 2021, 11:29:46 AM9/20/21
to AMPL Modeling Language
Hi Meredith,

I don't know which method you are using to solve your model with AMPL, but whatever the case may be you need to distinguish between data and model. This can be done either by using the model; and data; statements or creating a model file and a data file, and read each as such. Aside from that, you also need to use quotes around literal strings that have spaces, such as "New York". Below you can see your model without syntax errors. There are still formulation errors, but that you will have to fix yourself, as I don't know what you are trying to do.

Reply all
Reply to author
Forward
0 new messages