6
$\begingroup$

I'm new to AMPL and am trying to model the following constraints.

\begin{align}y_{ij3}&\le\sum_\ell X_{j\ell2}\quad(m=2,k=3)\\y_{ijk}&\le\sum_\ell\sum_mx_{j\ell m},\quad\forall i\in I,\forall j\in J,k=1,2.\end{align}

I'm not sure if I am on the right track. This is what I have so far:

subject to C1 {i in DEMAND, j in FACILITY}: Y[i,j,"CO"] <= sum{l in SIZE} X[j,l,"TRI"] ;

subject to C2_1 {i in DEMAND, j in FACILITY}: Y[i,j,"EL"] <= sum{l in SIZE,m in TECH} X[j,l,m] ;

subject to C2_2 {i in DEMAND, j in FACILITY}: Y[i,j,"TH"] <= sum{l in SIZE, m in TECH} X[j,l,m] ;

I modelled the second constraint in two parts. The relevant sets are as follows:

set ENERGY:= EL CO TH; #k

set TECH := COG TRI; #m
$\endgroup$
  • $\begingroup$ Welcome to OR.SE. Your code looks more or less OK -- but what exactly is your question? Did you try the code, and did you get any errors? $\endgroup$ – LarrySnyder610 Nov 14 '19 at 2:51
4
$\begingroup$
model;

set energy:= el co th;
set tech  := cog tri;
subject to cons1 {i in demand, j in facility}: y[i,j,'th'] <= sum{i in size} x[j,l,'tri'];
subject to cons2 {i in demand, j in facility, k in energy}: y[i,j,k] <= sum{j in facility, l in size, m in tech} x[j,l,m];

The only thing that you need to change is in your first constraint 'CO' to 'TH'. A good resource for the constraints declaration can be found here.

$\endgroup$
  • $\begingroup$ thank you, I can now see that I interchanged "CO" and "TH". However, for your second constraint, since the constraint is indexed over only $k=1,2$. Would it be appropriate to model it the way you did? My thinking is that way there will be double counting on the index $k=3$ which is already captured in constraint $1$. $\endgroup$ – george Nov 14 '19 at 17:50
  • $\begingroup$ You have control over the index in ampl, so you can choose which indices should be considered in the constraints. $\endgroup$ – Oguz Toragay Nov 14 '19 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.