Error using subranges in Allocate Available
Error using subranges in Allocate Available
Tom/Bob,
I was wrestling with a "bad ptype" error I was getting when using subranges subscript (i.e. a group within a subscripted variable) with the Allocate Available function. I finally figured out it's the subrange that it doesn't like, since when I pull the subrange out as it's own subscript it works!
Is this a bug...and if so, is there a fix? It can get pretty messy when you're dealing with 100 subscripts to have them all at one level.
Thanks in advance,
Lou
I was wrestling with a "bad ptype" error I was getting when using subranges subscript (i.e. a group within a subscripted variable) with the Allocate Available function. I finally figured out it's the subrange that it doesn't like, since when I pull the subrange out as it's own subscript it works!
Is this a bug...and if so, is there a fix? It can get pretty messy when you're dealing with 100 subscripts to have them all at one level.
Thanks in advance,
Lou
-
- Super Administrator
- Posts: 4600
- Joined: Wed Mar 05, 2003 3:10 am
Re: Error using subranges in Allocate Available
I'll have to double check, but I'd only use full ranges with allocate available. It's a "vector" function, so runs on a whole subscript range, using sub-ranges can confuse things.
I'd create a temporary variable that you pass to the allocate available function.
I'd create a temporary variable that you pass to the allocate available function.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
-
- Super Administrator
- Posts: 4600
- Joined: Wed Mar 05, 2003 3:10 am
Re: Error using subranges in Allocate Available
If you can post the model you are using, I can modify the call to allocate available so it works on the full range.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Error using subranges in Allocate Available
Actually, I had a similar "unsolveable" problem with Find Market Price...different error ("subscript range error in demand quantity") but with the same solution.
I can't post a model where I am right now...but I will ASAP.
Thanks again!
I can't post a model where I am right now...but I will ASAP.
Thanks again!
Re: Error using subranges in Allocate Available
Actually, based on your suggestion...I was able to do a mapping (at the subrange level) to a generic continuous subscript to be used by the allocation functions and that worked. Thank you very much!
However, I have a related question. I'm trying to disallow one demander to be supplied by one supplier (e.g. d3 to s4). I know that I can just set the priority for s4 = 0 (since the priorities work in reverse for the supply side), but that would disallow anyone else to be supplied by s4. I know these are supposed to be commodity functions and this is best handled by an IP, but I've been trying to avoid going that route. Put another way, is there someway to use a binary array with the functions to tell them "who" is allowed to supply "who"? I suspect that this can be accomplished with a second subscript, but I only know how to use that to represent different products.
Thanks (again) in advance!
Lou
However, I have a related question. I'm trying to disallow one demander to be supplied by one supplier (e.g. d3 to s4). I know that I can just set the priority for s4 = 0 (since the priorities work in reverse for the supply side), but that would disallow anyone else to be supplied by s4. I know these are supposed to be commodity functions and this is best handled by an IP, but I've been trying to avoid going that route. Put another way, is there someway to use a binary array with the functions to tell them "who" is allowed to supply "who"? I suspect that this can be accomplished with a second subscript, but I only know how to use that to represent different products.
Thanks (again) in advance!
Lou
-
- Super Administrator
- Posts: 4600
- Joined: Wed Mar 05, 2003 3:10 am
Re: Error using subranges in Allocate Available
It will be easier to advise if you can upload the part of the model you are working on. Can you do that?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Error using subranges in Allocate Available
OK, here's a version of the model that I posted a while ago, which Tom helped me with. It's a lot further along now, but the basics with the allocation are still the same. I made two variables (Assignment PtoC, Assignment CtoR) that have the binary "restrictions". The Two-Way Allocation module is the one I'm using...you can ignore all the rest.
Thanks for the help!
Lou
Thanks for the help!
Lou
- Attachments
-
- Allocation Chain 27Jun12 Sanitized.mdl
- (39.85 KiB) Downloaded 363 times
-
- Super Administrator
- Posts: 4600
- Joined: Wed Mar 05, 2003 3:10 am
Re: Error using subranges in Allocate Available
I've had a quick look. I'm struggling with the terminology you've used, but have you tried subscripting the relay priority vector by supplier/demander and making the relevant entry there zero?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Error using subranges in Allocate Available
Actually, I tried that a while ago and got nowhere with it. I tried it again here...but wasn't sure about the order of the subscripts. In any case, neither way is working. If I make the subscripts (Supplier, Demander), I get an error. If I make them (Demander, Supplier) it runs, but the answers are non-sensical. Both are attached.
- Attachments
-
- Allocation Chain 28Jun12 Sanitized DS.mdl
- (38.51 KiB) Downloaded 369 times
-
- Allocation Chain 28Jun12 Sanitized SD.mdl
- (38.63 KiB) Downloaded 335 times
Re: Error using subranges in Allocate Available
Actually, I'll ask a related question. Is this kind of allocation possible with a multi-dimensional FIND ZERO with constraints? For example, I want to minimize the difference between total demand and total supply, with the restrictions that
Sum(Allocated[Demander!,Supplier]) <= Available Supply[Supplier]
Sum(Allocated[Demander,Supplier!]) <= Required Demand[Demander]
Or in Vensim terms,
X[Supplier] = MIN(Sum(Allocated[Demander!,Supplier]), Available Supply[Supplier])
Y[Demander] = MIN(Sum(Allocated[Demander,Supplier!]), Required Demand[Demander])
Excess Demand[Demander,Supplier] = Y[Demander] - X[Supplier]
So, the FIND ZERO function might be:
Allocated[Demander,Supplier] = FIND ZERO(Ones[Demander, Supplier], Excess Demand[Demander, Supplier], Ones [Demander, Supplier], Ones [Demander, Supplier], ELMCOUNT(Demander)*ELMCOUNT(Supplier), 0, .01, 100, 0)
I remember trying this once, but just got errors: “Singular Jacobian”, “Illegal Bounds on Vector Argument”. Any ideas…or examples?
Lou
Sum(Allocated[Demander!,Supplier]) <= Available Supply[Supplier]
Sum(Allocated[Demander,Supplier!]) <= Required Demand[Demander]
Or in Vensim terms,
X[Supplier] = MIN(Sum(Allocated[Demander!,Supplier]), Available Supply[Supplier])
Y[Demander] = MIN(Sum(Allocated[Demander,Supplier!]), Required Demand[Demander])
Excess Demand[Demander,Supplier] = Y[Demander] - X[Supplier]
So, the FIND ZERO function might be:
Allocated[Demander,Supplier] = FIND ZERO(Ones[Demander, Supplier], Excess Demand[Demander, Supplier], Ones [Demander, Supplier], Ones [Demander, Supplier], ELMCOUNT(Demander)*ELMCOUNT(Supplier), 0, .01, 100, 0)
I remember trying this once, but just got errors: “Singular Jacobian”, “Illegal Bounds on Vector Argument”. Any ideas…or examples?
Lou
Re: Error using subranges in Allocate Available
Generally, what you're trying to do should be possible. You might check the FIND ZERO example model linked in the help system. I can ponder the details a bit and make further suggestions, I think.
Possibly the singular matrix problems arise because the inequality framing admits a multitude of solutions. Allocation[s,d] = 0 would be a valid solution to your first two equations, for example, even though other positive allocations would be more desirable.
Tom
Possibly the singular matrix problems arise because the inequality framing admits a multitude of solutions. Allocation[s,d] = 0 would be a valid solution to your first two equations, for example, even though other positive allocations would be more desirable.
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Error using subranges in Allocate Available
Just wanted to circle back around on this and ask if there's any way to do a many-to-many allocation but restrict what gets allocated to what (example models were posted back in Mar). The help makes mention that you can use multiple dimensional subscripts in the FIND MARKET PRICE construct (i.e. demand[product, demander], supply[product, supplier]) but doesn't give examples. Are there any examples of this kind of thing? I found one other post where someone was trying to do this...but no models were uploaded.
I've been struggling with how to do this and even did a model that sets up an allocation using the optimizer, but would prefer to use the allocation algorithms (or FIND ZERO) if possible.
Thanks,
Lou
I've been struggling with how to do this and even did a model that sets up an allocation using the optimizer, but would prefer to use the allocation algorithms (or FIND ZERO) if possible.
Thanks,
Lou
-
- Super Administrator
- Posts: 4600
- Joined: Wed Mar 05, 2003 3:10 am
Re: Error using subranges in Allocate Available
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Error using subranges in Allocate Available
You can use FIND MARKET PRICE to allocate between suppliers and demanders. You can add a product or other dimensions (ensuring that supplier and demander are the last subscripts) as long as there are no interactions among products, so that it's OK to handle each product as a separate allocation. If you add a product subscript to the example in the help system, it should work fine. The function also treats the quantity allocated as a commodity - i.e. it's equally attractive to all suppliers and demanders. Any more complex use will probably require FIND ZERO.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Error using subranges in Allocate Available
Thanks, but the example doesn't help because it doesn't make a many-to-many alloc (i.e. even if I use multiple products, they're still all commodities)...nor can I restrict the assignment (i.e. supplier 1 cannot supply to demander 2, etc.)...using, for instance, the :EXCEPT: function.
Tom...I'm attaching a simple model that uses FIND ZERO function to do what I want to do (along with a spreadsheet equivalent), but it's not zeroing for some reason. Is there something I'm doing wrong? I've tried with the #elements set to 2 and 4 (it's a 2x2 matrix, so should be 4, but I remember a case where it only worked with one dimension specified).
Any help would be greatly appreciated. I would consider this something that would be a breakthrough, since an allocation optimization across time (with changing demand/supply) would be incredibly useful in so many applications! I used to do this kind of thing for the CPG industry years ago...and they paid $M's for the software that did it! It used CPLEX as the solver...and essentially cranked out a schedule for ordering, production, packaging, shipping, etc.
Thanks again and have a great weekend.
Tom...I'm attaching a simple model that uses FIND ZERO function to do what I want to do (along with a spreadsheet equivalent), but it's not zeroing for some reason. Is there something I'm doing wrong? I've tried with the #elements set to 2 and 4 (it's a 2x2 matrix, so should be 4, but I remember a case where it only worked with one dimension specified).
Any help would be greatly appreciated. I would consider this something that would be a breakthrough, since an allocation optimization across time (with changing demand/supply) would be incredibly useful in so many applications! I used to do this kind of thing for the CPG industry years ago...and they paid $M's for the software that did it! It used CPLEX as the solver...and essentially cranked out a schedule for ordering, production, packaging, shipping, etc.
Thanks again and have a great weekend.
- Attachments
-
- Alloc.xlsx
- (10.56 KiB) Downloaded 359 times
-
- Generic Allocation Stage 1.mdl
- (3.92 KiB) Downloaded 355 times
Re: Error using subranges in Allocate Available
I'll take a look ...
FIND ZERO operates on a one-dimensional vector, so if you have a 2x2 matrix, you'll have to map it to a single 4-element vector first.
FIND ZERO operates on a one-dimensional vector, so if you have a 2x2 matrix, you'll have to map it to a single 4-element vector first.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Error using subranges in Allocate Available
I think what you REALLY want here is something like a linear program. I've been pondering creating a function for that, but haven't worked out the details.
FIND ZERO can handle a lot of cases though. Here's a version that treats the supply/demand balance like a market - the "price" could be interpreted more broadly as a priority. You could shut down some elements of the shipment matrix (where supplier A can't serve demander B) by setting that element of the shipping cost to a high value (or reworking the share equation a bit).
FIND ZERO can handle a lot of cases though. Here's a version that treats the supply/demand balance like a market - the "price" could be interpreted more broadly as a priority. You could shut down some elements of the shipment matrix (where supplier A can't serve demander B) by setting that element of the shipping cost to a high value (or reworking the share equation a bit).
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Error using subranges in Allocate Available
Tom,
Many thanks! I think I can use that construct in my model. In my other example, I tried mapping the Demander (D1, D2) and Supplier (S1, S2) variables to a single vector Alloc (A1-A4) as you suggested, but it still doesn't zero (reposted). However, I was actually successful at using a different construct to drive the constraints to zero using penalties for overages and weights to prefer one demander or another...but I wanted to stay away from that as it takes too long and I wanted the allocation to be "built-in" while using the optimizer for other things.
If you implement a linear program into Vensim, please let us know! I know there's a "hot link" way to do it with a spreadsheet, but I'm not really a coder.
Kind regards,
Lou
Many thanks! I think I can use that construct in my model. In my other example, I tried mapping the Demander (D1, D2) and Supplier (S1, S2) variables to a single vector Alloc (A1-A4) as you suggested, but it still doesn't zero (reposted). However, I was actually successful at using a different construct to drive the constraints to zero using penalties for overages and weights to prefer one demander or another...but I wanted to stay away from that as it takes too long and I wanted the allocation to be "built-in" while using the optimizer for other things.
If you implement a linear program into Vensim, please let us know! I know there's a "hot link" way to do it with a spreadsheet, but I'm not really a coder.
Kind regards,
Lou
- Attachments
-
- Generic Allocation 16Aug12.mdl
- (3.17 KiB) Downloaded 347 times
Re: Error using subranges in Allocate Available
I think the problem here is that the quantity to zero ('difference') has dimension 1, while the output vector has dimension 4. You could modify 'difference' to combine the differences between constraints/desires and actual allocations, yielding a 4D input. But that would still have problems, because there will be times when meeting all constraints is infeasible. That's why the version I posted has the additional logic for prioritization and utilization.
I'll post here if an experimental LP becomes available.
I'll post here if an experimental LP becomes available.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/