Parameter indexing

11 views
Skip to first unread message

Abdulrahman Aldeek

unread,
Nov 30, 2022, 10:55:04 AM11/30/22
to AMPL Modeling Language
Hello everyone

I have a problem in regard to parameter indexing. I have defined a set ol and the parameters G{ol} and B{ol}. The issue is that I want to utilize G and B for indices i,j and j,i without introducing a new set. For example, I would like to be able to use G[i,j] and G[j,i] without introducing a new set. Something like that:

subject to active_power_balance {i in ob, d in od}:  
      sum{(i,j) in ol}((RR[i,j,d]*G[i,j]) - (II[i,j,d]*B[i,j])) -  sum{(j,i) in ol}((RR[j,i,d]*G[j,i]) - (-II[j,i,d]*B[j,i])) = 0; 

Note that RR and II are decision variables that were defined using the set ol.

How can I do this?

AMPL Google Group

unread,
Nov 30, 2022, 3:13:53 PM11/30/22
to AMPL Modeling Language
I would write it like this:

set ob;
set od;
set ol within {ob,ob};

param G {ol};
param B {ol};

var RR {ol,od};
var II {ol,od};

subject to active_power_balance {i in ob, d in od}:
  sum{(i,j) in ol}((RR[i,j,d]*G[i,j]) - (II[i,j,d]*B[i,j])) - 
  sum{(j,i) in ol}((RR[j,i,d]*G[j,i]) - (-II[j,i,d]*B[j,i])) = 0;

Since you index the constraint over "i in ob", the sums are interpreted in different ways:
  • sum{(i,j) in ol} is the sum over all j such that (i,j) is in ol.
  • sum{(j,i) in ol} is the sum over all j such that (j,i) is in ol.
The members of the set ol (a set of pairs) must be given in the data for the model. But if you have a formula for this set, then you can instead write "set ol =" followed by the formula.


--
Robert Fourer
am...@googlegroups.com
{#HS:2083461520-113040#}
Reply all
Reply to author
Forward
0 new messages