Reputation: 4080
This question is more theoretical then practical. My patches have variables timber_value
and harvest_cost
.
Please, is in NetLogo a way how to select a patch with maximum timber value and minimal harvest cost in one 'ask' i.e. at the same time?
I imagine that could be solved by adding variable difference
(difference = timber_value - harvest_cost
) and simply select the patch by ask max-one-of patches [difference]
.
However, I was wondering if there is another approach considering two variables (timber_value and harvest_cost) at the same time?
I can't really figure out better way then the one described...
Thank you for your shared knowledge and discussion !
Upvotes: 1
Views: 325
Reputation: 9610
In general the answer is no, but this has nothing to do with NetLogo. To see the problem, create ordered pairs of values for the two attributes. Suppose you get [2 1] and [1 2]. How do you want to compare them? That said, you can get the largest timber value patches and then of them the lowest harvest cost patches.
patches-own [x y]
to test
ca
ask patches [
set x random-float 1
set y random-float 1
]
show map [[list x y] of ?]
sublist
sort-by compare patches
0 10
end
to-report compare [#p1 #p2]
let _x1 [x] of #p1
let _x2 [x] of #p2
let _y1 [y] of #p1
let _y2 [y] of #p2
report (_x1 < _x2) or (_x1 = _x2 and _y1 < _y2)
end
On the other hand, it seems in this case that you would be better off sorting by total profit. Since this is just a real number, none of these sorting issues arise.
Upvotes: 2