AMPL No variables declared error

Hi, I have just started my first exercise with AMPL as part of an on-line course but I keep receiving the no variables declared error and I am not sure how to solve it. I put the following data in my file called “capstone”.

var x >=0;
var y >=0;

maximize 25x+30y;

subject to x<= 6000;
subject to y<= 4000;
subject to x1/200+y1/140 <=40

then in the console I write:
ampl: model capstone.mod;
ampl: option solver cplex;
ampl: solve;

but it keeps giving me “no variables declared”. I have no idea where the error is and I need to finish this project.

Any help would be more than appreciated!

Thank you
Simona

Hi Simona,

Aren’t you getting any errors when you run model capstone.mod; like the following?

ampl: model capstone.mod;

capstone.mod, line 4 (offset 32):
	syntax error
context:  maximize  >>> 25x+ <<< 30y;
  • In the objective maximize 25x+30y; you need to specify a name for the objective and have “*” between the coefficients and the variables as follows: maximize objective: 25 * x+30 * y;
  • In the constraints like subject to x<= 6000; you also need to specify a name: subject to c1: x<= 6000;
  • In the last constraint x1 and x2 were not declared.
1 Like