Search code examples
linear-programmingamplglpk

how I can use 2 different indices for one set?


Suppose I have the following sets and parameter :

 param n; #number of individual
param f; #number of household
set N, default{1..n}; #set of individuals
 set F, default{1..f}; #set of family
 set E,  within F cross N;
 param H{E};
 param G{E};
 var O;

param L{E};

F is the index of family and N index of persons in each family. for each family I want do some calculation that I will explain it with the following data:

 set E:=
 1  1        # first family first person
 1  2        # first family second person
 1  3        # first family third person
 2  1        # second family first person
 2  2 ;      # second family second person


param G := 
 1  1   3
 1  2   4
 1  3   5
 2  1   6
 2  2   7;


 param H:=
  1  1   10 
  1  2   2
  1  3   8
  2  1   3
  2  2   9;

In the first family I want to add the data of first person from G and add it with 3* the data from 2 others member in first family. that is:

   3+3*(2+8) 
 same for another family.

how I can code this?


Solution

  • How about something like this?

    G[1,1] + 3 * sum {i in N: (1,i) in E and i <> 1} H[1,i];
    

    Or, assuming you're going to want to do this for a generic family fam and individual ind (not just family 1 and individual 1):

    G[fam,ind] + 3 * sum {i in N: (fam,i) in E and i <> ind} H[fam,i];