AMPL Syntax error - Greater than or equal to sign?

268 views
Skip to first unread message

Matthew Otis

unread,
Mar 23, 2016, 3:46:50 PM3/23/16
to AMPL Modeling Language
Hi there, I am modeling a sort of schedule optimization problem in AMPL and am using gurobi for the option solver.

In this problem, I have declared a set of schedules from 1 through 1000, and called this set "Schedules".
Each schedule sas a sort of layer (a parameter called "layer" has been created) with a value ranging from 1 to 4. This is a sort of preference or hirearchy of the days off that this particular schedule has. 

I want several constraints that determine how many schedules of each preference are available. For instance, I want at least 170 of the schedules to have a preference layer of 1. I wrote the following line to do so:

subject to Preference1: sum {j in Schedules: layer[j]=1} >= L1Demand;

However, when I go to include the model file in the ampl window, I get the following error:

syntax error 

context:
 
     subject to Preference1: sum {j in Schedules: layer[j]=1}  >>> >= <<<  L1Demand;

I don't understand why this is throwing out a syntax error. I may be missing something very basic or obvious, but can anyone tell me as to why this would be happening? Thank you very much.

Alessandro Oscar Gilardino Arias

unread,
Mar 23, 2016, 4:13:00 PM3/23/16
to am...@googlegroups.com

You should write something after the sum statement, in the way you are writing your constraint it is evaluating nothing.

As an example

subject to Preference1: sum {j in Schedules: layer[j]=1} variable_activated_schedule[j] >= L1Demand;

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

Matthew Otis

unread,
Mar 23, 2016, 8:09:01 PM3/23/16
to AMPL Modeling Language
I see. That seems to have fixed my problem, thank you.

I do have a question regarding this, though. I simply added a 1 at the end, so now it looks like: 
subject to Preference1: sum {j in Schedules: layer[j]=1} 1 >= L1Demand;

This made my program run, but when I type in 
"display Preference1;" I get "Preference1 = 0". 
This number should be 171 as I counted this number before running the program.

When I type 
"display sum {j in Schedules: layer[j]=1} 1"
 I do in fact get 171 (which  is the number that it should be). Why does displaying the constraint name give me 0 when it had to be over 170 to actually have run successfully? Thank you

Victor Zverovich

unread,
Mar 24, 2016, 2:14:21 PM3/24/16
to am...@googlegroups.com
Since Preference1 is a constraint, display Preference1 prints the current dual value. If you want to print the constraint itself in solver or AMPL form you should use expand or show command, for example

  expand Preference1;

Also note that if Preference1 doesn't contain any variables, it should probably be a check rather than constraint.

HTH,
Victor
Reply all
Reply to author
Forward
0 new messages