Page 1 of 1

Potential bug in constant elasticity priority profile

Posted: Wed Jun 29, 2022 8:38 am
by eneko
Hi Vensim developers and users,

I may have found a bug in the implementation of constant elasticity priority profile functions in Vensim.

I have been working with the ALLOCATE AVAILABLE function. I have seen that when the priority profile is a constant elasticity function (numeric value 5), there could be some discontinuities. The example below:

Code: Select all

allocation[branch]= 
	ALLOCATE AVAILABLE(demand[branch], priority[branch,ptype], available) 
	~	 
	~		| 

available= 
	20*Time 
	~	 
	~		| 

branch: 
	Boston, Dayton, Fresno 
	~	 
	~		| 

demand[branch]= 
	500, 300, 750 
	~	 
	~		| 

pprofile: 
	ptype, ppriority, pwidth, pextra 
	~	 
	~		| 

priority[branch,pprofile]= 
	5,5,2,1; 
	5,7,4,2; 
	5,3,4,3; 
	~	 
	~		| 


Produces the following output:
allocation
allocation
c_e1.png (18.83 KiB) Viewed 792 times
This happens also when the constant elasticity function is mixed with other profiles:

Code: Select all

allocation 0[branch]= 
	ALLOCATE AVAILABLE(demand[branch], priority 0[branch,ptype], available) 
	~	 	
	~		| 

priority 0[branch,pprofile]= 
	3,5,1,0; 
	3,7,2,0; 
	5,3,2,3; 
	~	 
	~		| 
allocation 0
allocation 0
c_e2.png (18.17 KiB) Viewed 792 times
I suppose that this happens because the image of this profile function, against the others, is not totally contained in the range [0, request] when pwidth != ppriority (i.e. image(priority_func(x)) != [0, request]);
q(x) = q0 * (x/ppriority)^(-pextra) if x > pwidth
q(x) = q0 * (pwidth/ppriority)^(-pextra)if x <= pwidth


This could easily be solved with a transposition for x and a redefinition for the second equation:
q(x) = q0 * ((x-pwidth+ppriority)/ppriority)^(-pextra) if x > pwidth
q(x) = q0 if x <= pwidth
See some examples for both definitions below:
Constant elasticity functions
Constant elasticity functions
cons_elas.png (43.3 KiB) Viewed 792 times


I suppose that a similar problem may happen with the constant elasticity supply function when using the many-to-many allocation.

I hope my explanation was clear.

Cheers,
Eneko

Re: Potential bug in constant elasticity priority profile

Posted: Wed Jun 29, 2022 9:05 am
by eneko
I forgot to say that I am using Vensim DSS 9.2.4 x64 in Windows.

Re: Potential bug in constant elasticity priority profile

Posted: Thu Jul 14, 2022 5:17 pm
by tomfid
Can you post your sample model?

Re: Potential bug in constant elasticity priority profile

Posted: Fri Jul 15, 2022 7:42 am
by eneko
Yes. Please, find the sample model below:
test_allocate_available.mdl
(2.7 KiB) Downloaded 95 times

Re: Potential bug in constant elasticity priority profile

Posted: Mon Jul 18, 2022 5:45 pm
by tomfid
It took me a while to get into this, but I think you've identified a bug in the behavior for large allocations. I haven't found the particular line of code, but I think the algorithm is limiting the range of priorities considered in some cases, and that leads to the discontinuity.

I don't think we want to change the definition of the curves however. The range consideration you identify indicates that there's an unstated constraint on the pwidth priority, which is that pwidth should be >= ppriority in order to realize sensible behavior where q0 is a possible output. Instead we'll note this in the documentation.

The bug will obviously be fixed though.