CODE WON'T RUN

118 views
Skip to first unread message

Eizee Mariano

unread,
Aug 19, 2022, 8:57:04 AM8/19/22
to AMPL Modeling Language
Hi encountered some problems as this code wont run. Asking for help please.
schedule1.dat
schedule1.mod

AMPL Google Group

unread,
Aug 19, 2022, 4:06:13 PM8/19/22
to AMPL Modeling Language
When you try to solve, you are seeing this error message:

error processing constraint night_morning[1,7,1]:
        invalid subscript assignment[7,1,1,3]

According to your definition in the model, constraint night_morning[1,7,1] should be this:

assignment[7,1,1,3] + assignment[7,2,1,1] <= 1

But the error message is telling you that the variable assignment[7,1,1,3] does not exist. To see why, observe that "var assignment" is defined as follows,

var assignment {i in I, j in J, k in K, l in L} binary;

The four indexing sets are given as follows by the data:

ampl: display I,J,K,L;
set I := 1 2 3 4 5 6;
set J := 1 2 3;
set K := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20;
set L := 1 2 3;

Thus assignment[7,1,1,3] does not exist because 7 is not in the set I. Maybe you meant to write "assignment[i,3,k,l] + assignment[i+1,1,k,l]".


--
Robert Fourer
am...@googlegroups.com
{#HS:1984344618-111507#}

Eizee Mariano

unread,
Aug 20, 2022, 9:25:53 AM8/20/22
to am...@googlegroups.com
image.png image.png
 
image.png

Hello Sir! Thank you for the response. I am now getting this error when running my code and data file. Please help. The first photo is my data file and the second photo is the mod file. The last photo is the mathematical code and constraints as our basis Sir. 


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1984344618-5888491673-1660939569-1157747738%40helpscout.net.

AMPL Google Group

unread,
Aug 21, 2022, 7:59:47 PM8/21/22
to AMPL Modeling Language
You define

param X {DAYS, MSHIFT, NURSES} > 0;

which says there must be a positive value X[i,j,k] for every combination of i in DAYS, j in MSHIFT, and k in NURSES. Your AMPL data does not give all these values. So AMPL gets to the end of the X data before all the values have been read, and as a result it gives the error message "expected ; . or number". There is a similar problem with Y and Z.

Really the problem is not with the data, however, but with the definition of the parameters. Instead of X, Y, and Z, you can simply define

param needed {DAYS, SHIFTS} > 0;

where needed[i,j] is the number of nurses needed in shift j on day i. The shifts are 1 (morning), 2 (afternoon), and 3 (night). Using this definition, the sets MSHIFT, ASHIFT, and NSHIFT aren't needed (and in fact you aren't using them for anything in your model). In constraint morning_shift, X[i,1,k] can be replaced by needed[i,1], and similarly for constraints afternoon_shift and night_shift. The data for param needed can be given in a common AMPL table formal:

param needed:   
       1   2   3 :=
   1   3   4   2
   2   3   4   5
   3   4   3   4
   4   4   3   3
   5   3   4   4
   6   3   3   2 ;


--
Robert Fourer
am...@googlegroups.com
{#HS:1984344618-111507#}
On Sat, Aug 20, 2022 at 1:26 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
image.pngimage.pngimage.png

Hello Sir! Thank you for the response. I am now getting this error when running my code and data file. Please help. The first photo is my data file and the second photo is the mod file. The last photo is the mathematical code and constraints as our basis Sir.

On Fri, Aug 19, 2022 at 8:05 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
When you try to solve, you are seeing this error message:

error processing constraint night_morning[1,7,1]:
        invalid subscript assignment[7,1,1,3]

According to your definition in the model, constraint night_morning[1,7,1] should be this:

assignment[7,1,1,3] + assignment[7,2,1,1] <= 1

But the error message is telling you that the variable assignment[7,1,1,3] does not exist. To see why, observe that "var assignment" is defined as follows,

var assignment {i in I, j in J, k in K, l in L} binary;

The four indexing sets are given as follows by the data:

ampl: display I,J,K,L;
set I := 1 2 3 4 5 6;
set J := 1 2 3;
set K := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20;
set L := 1 2 3;

Thus assignment[7,1,1,3] does not exist because 7 is not in the set I. Maybe you meant to write "assignment[i,3,k,l] + assignment[i+1,1,k,l]".


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages