Hi,

I am using amplpy and having an issue when I try to use a list of strings as a parameter value, since param only takes scalar values (per my understanding).

I essentially have the following:

set S = {‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’} ;

param O {S};

I would like O to be: { ‘Mon’:[‘Sat’, ‘Sun’], ‘Tue’:[‘Sun’, ‘Mon’], … ‘Sun’:[‘Fri’, ‘Sat’] }

The intent is to use O to exclude certain values when using sum, so that I can sum for 5 days of the week instead of all 7.

AMPL gives me an error message when I set O to be a dictionary like the above.

The workaround constraints I have used are shown in the following:

ampl.eval (‘’’

reset;

set S;

param demand {S} ;

var x {S} >= 0 integer;

minimize workers_objective : sum {j in S} x[j] ;

subject to

mon_constraint : sum {i in S} x[i] - x[‘Tue’] - x[‘Wed’] >= demand[‘Mon’] ;

tue_constraint : sum {i in S} x[i] - x[‘Wed’] - x[‘Thu’] >= demand[‘Tue’] ;

wed_constraint : sum {i in S} x[i] - x[‘Thu’] - x[‘Fri’] >= demand[‘Wed’] ;

thu_constraint : sum {i in S} x[i] - x[‘Fri’] - x[‘Sat’] >= demand[‘Thu’] ;

fri_constraint : sum {i in S} x[i] - x[‘Sat’] - x[‘Sun’] >= demand[‘Fri’] ;

sat_constraint : sum {i in S} x[i] - x[‘Sun’] - x[‘Mon’] >= demand[‘Sat’] ;

sun_constraint : sum {i in S} x[i] - x[‘Mon’] - x[‘Tue’] >= demand[‘Sun’] ;

‘’')

S = [‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’]

demand = {‘Mon’: 17, ‘Tue’: 13, ‘Wed’: 15, ‘Thu’: 19, ‘Fri’: 14, ‘Sat’: 16, ‘Sun’: 11}

ampl.getSet(‘S’).setValues(S)

ampl.getParameter(‘demand’).setValues(demand)

My preference would be to have a single constraint which utilizes the values of param O to subtract appropriately for each day of the week. Hope the above is clear.

In the pyomo version, I’m able to achieve this with the following python code:

for i in S:

model.demand_constraint.add(

sum(model.x[j] for j in S if i not in O[j]) >= demand[i])

Would appreciate any guidance. I’m happy to provide more information as needed.

Thanks

Atma