0

I have a set of Data in this format

# Input Data for items in the format (i,l,w,h) 
i for item, l for length , w for width, h for height
set itemData :=
271440  290 214 361
1504858 394 194 114
4003733 400 200 287
4012512 396 277 250
4013886 273 221 166; 

I am trying to get the lengths of each item, using the following code

set IL = setof  {i in items, (i,l,w,h) in itemData} (i,l); #length of item i

This method only does not allow me to access the individual item length. What i am trying to do is to have

display IL[271440] = 290;

how can i go about doing this?

SunRay
  • 200
  • 14

1 Answers1

0

Careful with terminology. In AMPL terms, that table isn't a "set". You have a table of parameters. Your sets are the row and column indices for that table: {"l","w","h"} for the columns, and item ID numbers for the rows.

In AMPL it would be handled something like this:

(.mod part)
set items;
set attributes := {"l","w","h"};
param itemData{items, attributes};
(.dat part)

set items := 
271440
1504858
4003733
4012512
4013886
;

param itemData: l w h :=
271440  290 214 361
1504858 394 194 114
4003733 400 200 287
4012512 396 277 250
4013886 273 221 166
;

You can then do:

ampl: display itemData[271440,"l"];
itemData[271440,'l'] = 290

I think it's possible to define set "items" at the same time as itemData and avoid the need to duplicate the ID numbers. Section 9.2 of the AMPL Book shows how to do this for a parameter that has a single index set, but I'm not sure of the syntax for doing this when you have two index sets as above. (If anybody does know, please add it!)