Reputation:
let s be a index of scenario and j index of Network Nodes.(s={1*200} , j={1*100}) d(s,j)= total impacts of contamination scenario s, if the contaminant is first detected by scenario at j. W(s)=the subset of Network Nodes which d(s,j)<>0. W'(s)= the subset of W(s) such that d(s,j)<>d(s,j') , for all j,j' belong to W'(s).
How can I make the subset W'(s)?
I got error with below code! My try:
Set
i /1*100/
s/1*200/
;
Alias (i,j);
set
Node(j)
Wp(Node)
same(Node)
U(Node)
;
Parameter d(s,j);
scalar t,posMin;
$call GDXXRW.exe data.xlsx par=d rng=sheet2!A1:X200
$GDXIN data.gdx
$LOAD d
$GDXIN
Loop(s,
Node(j)=(j.val);
while(Card(Node)<>0,
t=smin(Node$(d(s,Node)),d(s,Node));
same(Node)$(d(s,Node)=t)=yes;
posMin=smin(Node,same(Node));
display t,same, posMin;
Wp(Node)=Wp(Node)+( Node$(Node.val=posMin));
display Wp;
same(Node)$(Node.val=posMin)=no;
u(Node)=same(Node);
Node=Node-U;
);
);
Upvotes: 0
Views: 75
Reputation: 376
If I've understood your problem and type of data correctly, would something like this work?:
Given some data:
set s / 1*5 /,
j / 1*3 /;
alias(j,i);
table d(s,j)
1 2 3
1 0 20 20
2 0 0 20
3 10 20 30
4 0 0 0
5 0 20 30
;
Set W is a subset of s containing only non-zero rows:
set W(s);
W(s) = yes$sum(j, d(s,j));
display W;
Set Wp is a subset of W(s) containing the elements of W minus the non-zero repeated elements across j:
set Wp(s);
Wp(s) = yes$W(s);
loop((W(s),i,j),
if(((d(s,i) eq d(s,j)) and (d(s,i) ne 0) and (ord(i) ne ord(j))),
Wp(W) = no;
));
display Wp;
For me, this makes:
s={1,2,3,4,5}
W={1,2,3,5}
Wp={2,3,5}
Create a set Q. If your data is over two dimensions and you want your set to be defined over two dimensions, this will suffice:
set Q(s,j);
Q(s,j) = yes$d(s,j);
display Q;
Create parameter storing min values across j for each s (in Q):
parameter xp(s);
xp(s) = smin(j$Q(s,j), d(s,j));
display xp;
Create a copy of original data that only retains the min values across j:
parameter d_copy(s,j);
d_copy(s,j) = d(s,j)$(d(s,j) eq xp(s));
Remove any duplicates as j increases:
loop((s,i,j),
if((d_copy(s,j) eq d(s,i))$(ord(j) gt ord(i)),
d_copy(s,j) = 0;
);
);
display d_copy;
Create a subset of Q that corresponds to the min values:
set Qp(s,j);
Qp(Q) = yes$d_copy(Q);
display Qp;
Upvotes: 2