Page 1 of 1

Sort Order (for multivariable)

Posted: Mon Aug 10, 2020 2:38 am
by husnafezaahmad
Hello everyone :)

I have another problem with my model. Attached is my model. I want to combine all marginal cost and rank it from lower to highest value.
I tried vector sort order, but it can only sort 1 variable.

Is there any other solution?

Thanks in advance, team.

Re: Sort Order (for multivariable)

Posted: Mon Aug 10, 2020 2:03 pm
by tomfid
You'll have to combine the 4 subscripts into a single master subscript if you want to sort them in a single operation. Something like:

unit : coal unit, hydro unit, ...

Then writing equations just for a particular subset (coal unit for example) becomes somewhat clumsy because the equation editor will insert "unit" by default into equations. So, another option would be to create a dedicated dimension for the master sort, and use mapping to assign the match for coal unit, hydro unit, etc.

Sorting is a computationally expensive operation, so I would discourage it wherever possible. If the idea is to create a merit-order dispatch, you could achieve the same thing with the ALLOC functions or FIND ZERO.

Re: Sort Order (for multivariable)

Posted: Mon Aug 10, 2020 4:45 pm
by husnafezaahmad
tomfid wrote: Mon Aug 10, 2020 2:03 pm
Then writing equations just for a particular subset (coal unit for example) becomes somewhat clumsy because the equation editor will insert "unit" by default into equations. So, another option would be to create a dedicated dimension for the master sort, and use mapping to assign the match for coal unit, hydro unit, etc.
Sorry Tom, but i'm not clear with this. Done doing the master subscript, but i can't quite follow this part.
Can you please once again explain this part once again.

Thank you so much, Tom.

Re: Sort Order (for multivariable)

Posted: Mon Aug 10, 2020 5:10 pm
by tomfid
I think it makes sense to ask first, why are we doing this? If I knew, I could give a more useful answer.

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 2:55 am
by husnafezaahmad
OK the idea is like this.

I will calculate the marginal cost for each units from each technology. (technology = coal, RE, gas, hydro) (unit = coal 1, coal 2, etc).

After that, i want to rank the marginal cost, starting from the lowest value up to the highest value. This is because later on, i'll use this rank to calculate the average marginal cost. Hence, i really need to do this rank/sort model.

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 3:20 am
by tomfid
I'll ponder how exactly to do this.

However, averages are independent of order, so it seems unneccessary to sort. You could simply use something like SUM( marginal cost[unit!]*capacity[unit!] ) / SUM( capacity[unit!] ).

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 3:22 am
by tomfid
Similarly, if you want the cost of the marginal plant, you can use something like VMAX( IF THEN ELSE( utilization[plant!]>0, cost[plant!], 0 ) )

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 4:28 am
by husnafezaahmad
tomfid wrote: Tue Aug 11, 2020 3:20 am I'll ponder how exactly to do this.

However, averages are independent of order, so it seems unneccessary to sort. You could simply use something like SUM( marginal cost[unit!]*capacity[unit!] ) / SUM( capacity[unit!] ).
I think i need to rephrase my sentence. The average marginal cost i'm talking about is not that literal average.
I really need to sort it out in order for me to do the next calculation hence the rank.

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 4:41 am
by husnafezaahmad
This is the overview of what i'm trying to model. I put it into flowchart view so that u can get the idea of what i'm tyring to do.
IMG_2786 copy.jpg
IMG_2786 copy.jpg (968.01 KiB) Viewed 6543 times
The idea is like that.

Re: Sort Order (for multivariable)

Posted: Tue Aug 11, 2020 4:13 pm
by tomfid
I would do something like this:
e mkt clearing.mdl
(5.47 KiB) Downloaded 215 times

Re: Sort Order (for multivariable)

Posted: Thu Aug 13, 2020 2:02 pm
by husnafezaahmad
Hi Tom,

Sorry, i just get the time to read your reply. Thank you so much.
I will look over it and i'm sure u've been such a help, Tom :)

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 3:33 pm
by husnafezaahmad
tomfid wrote: Tue Aug 11, 2020 4:13 pm I would do something like this:
e mkt clearing.mdl

Hello Tom,

I'm so sorry that i keep on asking you on simple things. The model that you've shared with me is brilliant. That's what i've been having in my mind. Thanks so much for giving me the idea on how to do it.

But Tom, it has been almost a week, and i still cannot figure out on how you make the subrange from a subscript.

Screen Shot 2020-08-18 at 23.17.29.png
Screen Shot 2020-08-18 at 23.17.29.png (177.73 KiB) Viewed 6475 times


I tried to add re into unit type. But when i put re unit on the right hand side [coal,gas,hydro,re -> (unit:c unit,g unit,h unit,re unit)], it didn't work. It will end up having [coal,gas,hydro,re -> (unit:c unit,g unit,h unit)], instead without re unit.


Screen Shot 2020-08-18 at 23.23.30.png
Screen Shot 2020-08-18 at 23.23.30.png (184.38 KiB) Viewed 6475 times



I tried to find it on the net, the SD books that i have (Sterman & Morecroft), but i still couldn't get the idea.

I hope you don't mind to share with me on how you do that because i want to alter the model you shared a little bit according to my objective.
Once again, i'm sorry to bother you with this kind of issue.

Hope to hear from you soon.

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:07 pm
by tomfid
I used subscript mapping: https://www.vensim.com/documentation/re ... apping.htm and subranges: https://www.vensim.com/documentation/22100.htm

You may find it helpful to switch to text view to see the raw subscript equations.

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:09 pm
by husnafezaahmad
tomfid wrote: Tue Aug 18, 2020 4:07 pm I used subscript mapping: https://www.vensim.com/documentation/re ... apping.htm and subranges: https://www.vensim.com/documentation/22100.htm

You may find it helpful to switch to text view to see the raw subscript equations.
Thank you so much for your respond, Tom. I've read that one. But i'll tried to read it again, thoroughly.

Thank you so much :D

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:09 pm
by tomfid
coal,gas,hydro,re -> (unit:c unit,g unit,h unit) won't work, because you can't map 4 elements to 3 elements. Perhaps "re unit" doesn't exist as a member of "unit"?

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:12 pm
by tomfid
There are at least two ways to create a subrange:

1. If you already have
unit : (u1-u9)
you can create
subunit : (u3-u6)
and it will automatically appear in the subrange list.

2. You can build them up hierarchically, by first defining
unit low : (u1-u4)
unit high : (u5-u9)
then merging those with:
unit : unit low, unit high

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:35 pm
by husnafezaahmad
tomfid wrote: Tue Aug 18, 2020 4:12 pm There are at least two ways to create a subrange:

1. If you already have
unit : (u1-u9)
you can create
subunit : (u3-u6)
and it will automatically appear in the subrange list.

2. You can build them up hierarchically, by first defining
unit low : (u1-u4)
unit high : (u5-u9)
then merging those with:
unit : unit low, unit high

And that seems much more clearer to me :) will try both and let you know if i success.
I can't thank you enough, Tom.

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 4:43 pm
by husnafezaahmad
tomfid wrote: Tue Aug 18, 2020 4:12 pm There are at least two ways to create a subrange:

1. If you already have
unit : (u1-u9)
you can create
subunit : (u3-u6)
and it will automatically appear in the subrange list.

2. You can build them up hierarchically, by first defining
unit low : (u1-u4)
unit high : (u5-u9)
then merging those with:
unit : unit low, unit high


Tom,

Thanks so much for your guidance. I have finally understand on how to do the mapping for subscript and the subranges. Like finally! Should have u earlier. :lol: once and for the nth time, Thank You so much!

Re: Sort Order (for multivariable)

Posted: Tue Aug 18, 2020 5:55 pm
by tomfid
Great! You're most welcome.

Re: Sort Order (for multivariable)

Posted: Mon Aug 24, 2020 12:01 pm
by husnafezaahmad
Hai Tom,

Here i am again, hoping that u can do me a favor.

I am still trying to understand the model that u have shared with me earlier.
But i couldn't get on how the model is doing. The output seems like it did what i want.

If you don't mind, can you please brief me a little bit especially on how "output" and "marginal cost" works.

Thanks in advance, Tom. Sorry to burden you.

Re: Sort Order (for multivariable)

Posted: Tue Aug 25, 2020 4:11 pm
by tomfid
The documentation for the allocation process is here: https://www.vensim.com/documentation/al ... erview.htm

The basic idea is that the unit costs are used to construct an aggregate supply curve. Then it computes the market-clearing costs, where demand intersects that curve. Any plant below that cost runs, and plants above are idle.

The width parameter controls how much diversity is assumed in cost - if the width is small utilization is essentially a strict sequence. If it is large, the cutoff is soft - plants with similar costs near the margin will operate simultaneously with partial utilization.

Re: Sort Order (for multivariable)

Posted: Fri Aug 28, 2020 4:46 pm
by husnafezaahmad
tomfid wrote: Tue Aug 25, 2020 4:11 pm The documentation for the allocation process is here: https://www.vensim.com/documentation/al ... erview.htm

The basic idea is that the unit costs are used to construct an aggregate supply curve. Then it computes the market-clearing costs, where demand intersects that curve. Any plant below that cost runs, and plants above are idle.

The width parameter controls how much diversity is assumed in cost - if the width is small utilization is essentially a strict sequence. If it is large, the cutoff is soft - plants with similar costs near the margin will operate simultaneously with partial utilization.
Thanks a lot, Tom!! :D