假设我具有以下设置和参数:
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是家庭指数,每个家庭中人的N指数。对于每个家庭,我都需要进行一些计算,并使用以下数据进行解释: 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;
在第一个家庭中,我想添加来自G的第一人称数据,并将其与来自第一个家庭中其他2个成员的3 *数据相加。即:
3+3*(2+8)
same for another family.
我该如何编码?
答案 0 :(得分:1)
这样的事情怎么样?
G[1,1] + 3 * sum {i in N: (1,i) in E and i <> 1} H[1,i];
或者,假设您要对通用家庭fam
和个人ind
(不仅是家庭1和个人1)执行此操作:
G[fam,ind] + 3 * sum {i in N: (fam,i) in E and i <> ind} H[fam,i];