Search code examples
indexingconstraintsampl

AMPL: Defining constraints on specific indices of a set


I have a little question regarding defining a constraint on specific indices of a set:

I defined set GAS := G1,G2,G3,G4; With decision variable Y = amount of gas sold per week.

After having implemented a complete model with correct constraints, the solver fails when fullfilling the next one: The production capacity for gasolines of type A (G1 and G2) in total is limited to 50,000 barrels per week, while the capacity for gasolines of type B (G3 and G4)in total is limited to 45,000 barrels per week.

I tried many different things, and the closest I got is:

Is there any way to make it possible to define these constraints in the correct way?

max_productionA{i in GAS, j in GAS: i == 1 and j == 2}:
(Y[i] + Y[j]) <= 50000;

max_productionB{i in GAS, j in GAS: i == 3 and j == 4}:
(Y[i] + Y[j]) <= 45000;

Solution

  • You need to begin each constraint with a "s.t." or "subject to" before the name of the constraint.

    If that doesn't fix your problem, can you please post more information about the error message?