Hi,
Considering the table below, how can I find out the position (1st, 2nd element...) of the highest NPV for each Stand? (for Stand 6 it would return 3rd, for Stand 7 it would return 2nd). I tried the ord() function but it works only with one-dimensional sets, which is not the case since I am trying to return the value of a parameter.
In this case:
set
Stand /6, 7/
Age /40, 45, 50/
Both Diam and NPV are parameters
Stand Age Diam NPV
6 40 25 98
6 45 28 99
6 50 30 101
7 40 21 95
7 45 23 96
7 50 24 95
Thanks for your help
Position of an element in a table
Position of an element in a table
- Attachments
-
- image.png (10.04 KiB) Viewed 2013 times
Re: Position of an element in a table
I wonder if you really want to have the position - i.e. k'th age value in the stand is the highest NPV. It seems it would be more useful to have a set of tuples that indicate where the best NPV is to be found: in a GAMS model, this would be more useful than the position.
Something like this untested code should work for computing both:
-Steve
Something like this untested code should work for computing both:
Code: Select all
parameters
npv(stand,age)
position(stand)
mx(stand)
p
;
set bestNPV(stand,age);
* read values into npv
position(stand) = NA;
mx(stand) = -INF;
bestNPV(stand,age) = no;
loop{stand,
p = 1;
loop{age,
if {(npv(stand,age) > mx(stand),
position(stand) = p;
mx(stand) = npv(stand,age);
bestNPV(stand,a2) = no;
bestNPV(stand,age) = yes;
};
p = p + 1;
};
};
Re: Position of an element in a table
Hi,
Thanks for your reply.
Well, my initial idea was to find the position of the highest NPV and use this number to search for another parameter value correspondent to the same position, but in another table. However, the code you provided gave me an insight into another way of doing so, which is more straightforward. So yes, it worked to solve my problem. Thanks
Thanks for your reply.
Well, my initial idea was to find the position of the highest NPV and use this number to search for another parameter value correspondent to the same position, but in another table. However, the code you provided gave me an insight into another way of doing so, which is more straightforward. So yes, it worked to solve my problem. Thanks