Strange behaviour of a model

Use this forum to post Vensim related questions.
Post Reply
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Strange behaviour of a model

Post by LAUJJL »

Hi

I am presently trying to find something that must be wrong in a model, and I have already spent two days trying to fix it.
I have simplified the problem into a smaller model to make it understandable. The model has three subscripts and seems to have an instantaneous loop but it has not. Vector elm maps seem to be going out of bounds, but only in the first two periods of time! The error is occuring only in the first two periods and then the model is working all right, while there is no link between the periods, as there are no levels!
I use for the var4 variable, a vector elm map instead of a safer mapping, because in the bigger model I use more than one subscript, and it is not possible to map a set of subscripts like a single subscript.
Thanks to anybody solving that problem.
The model is joined.
Best regards.
JJ
Attachments
strange mapping.mdl
(3.57 KiB) Downloaded 370 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Hmm ... seems like a problem with equation ordering, but I'm not quite sure what it is. My first instinct was to separate the SUM() operations from the VECTOR ELM MAP, as follows:

var3[sub]=
if then else (option2 = 1,sum ( var3 in[sub,tub!,gub!] ), sum (var2[sub,tub
!,gub!]) )

**************************************************************
var3 in[sub,tub,gub]=
vector elm map(var2[s1,t1,g1],
((ident sub[sub] - 1) * elm tub * elm gub) +
((ident tub[tub] - 1) * elm gub) + ident gub[gub] - 1)


However, that didn't help.

You could probably accomplish the mapping using VECTOR SELECT rather than VECTOR ELM MAP - I think it may result in more robust equation ordering.

Tom
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom

Thank you for your answer.

I suspected too a problem of ordering.
I have found the problem. I will explain it tomorrow.
To find where the problem lies, I have first made a completey unmapped and ordered model that works, and I have progessively modified the model that works, until it is equivalent to the model that does not. It looks obviously like an inconsistency in equation ordering. In fact one must force Vensim to order it in a certain way, and the way it orders it is depending sometimes on the order you write a single equation even if the order has no effect on the result of the equation. I will too experience the vector select, although it does not look as powerful as the vector elm map, hoping it works more consistenly.
I just saw that Bob is back to the forum. He must certainly have some ideas on the problem. It would be better if he could find the reason of the inconsistency. Otherwise I will be obliged, if I cannot build something to force the way Vensim orders the equations in my model, to reconstruct it using eventually the vector select or something else.
Regards.
JJ

[Edited on 13-4-2010 by LAUJJL]
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom and everybody.
I built first a model without any mapping where the equations can be ordered by the modeler joined called strange_mapping_ordered with three options with value 0 or 1, making it possible to map or not map the three variables var2, var3 and var4. The objective was to detect which variable was causing the problem by simulating the 8 combinations of the options values.
I first verified that with value 1 for all the options, which means all variables are ordered, the results were correct. It was correct. Then I put the values of the options to 0 where all values are mapped and not forced into an order specified by the modeler, to verify that the wrong results where the same as the strange_mapping model. To my surprise the results were correct and equal to the correct ordered model. The calculations were the same as the strange_mapping model but the results were different. I then tried to modify step by step the strange_mapping_odered model to reduce progressively the differences between the two models.
I built the strange_mapping_ordered_2 model that does not order the var3 variable that makes it possible to simplify the model, suppressing the options from ordering or not the var3. The results are still correct.
Then I built the strange_mapping_ordered_3 model that suppresses the possibility to order the var2 variable, which simplifies greatly the model. I still get correct results whether the variable var4 is ordered or mapped.
The last model is the strange_mapping_ordered_4 model where all the variables are mapped like the strange_mapping_ordered model. The results are now wrong. Then the problem lies between the model 3 and the model 4. It seems now evident that even when the var4 ordered is not need, Vensim calculates it and this forces a different ordering. Now and this is rather strange, when one changes the strange_mapping_ordered_3 model into the strange_mapping_ordered_3_wrong model that is strictly equivalent but where the equation
if then else (option var4 ordered = 1,var4 ordered[subsui] ,var4 mapped[subsui])
is modified into its equivalent:
if then else (option var4 ordered = 0,var4 mapped[subsui],var4 ordered[subsui])
the results become incorrect!
The problem is that it looks like Vensim does not order the equations in the same way even with equivalent models where different presentations of the equations exist!
But I may be wrong somewhere and I would like somebody to tell me where if so.
joined the zip models.
Best regards.
JJ
Attachments
strange.zip
(7.95 KiB) Downloaded 350 times
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Hi JJ,

I did look at this. Unfortunately, the correct behavior for Vensim is to issue an error message and indicate a simultaneous equation. Normally an equation in the form

var[s2] = var[s1]

causes Vensim to expand all subscripts and then attempt to compute variable element by element. Using the VECTOR ELM MAP function confounds this computation because any subscript element can end up being used depending on the value of the offset.

I will fix it so that Vensim does issue the error message. Unfortunately, I don't think that will solve the problem that got you started on this.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange

Post by LAUJJL »

Hi Bob

Thank you for the answer.
I will try to build a fake equation in my model that forces Vensim to order the calculations in a certain way.
I do not see how you may generate a simultaneous error, as in this case, one never asks the software to make a simultaneous calculation. The same calculus can be made without any mapping, which prooves that there is in fact no simultaneous equation, unless Vensim calculates values not in the same order which is from the last subscript up to the first one or at least I thought that was the rule.
Besides, if there was a simultaneous equation somewhere, the software could not calculate correctly as soon as the period is more or equal to 2.
Thanks again and best regards.
JJ

[Edited on 14-4-2010 by LAUJJL]
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Hi JJ,

The VECTOR ELM MAP function takes as its second argument a variable. Vensim does not make any assumptions about this variable (its range or whether it is constant over time) when ordering equations. Thus while the equation

var[s2] = VECTOR ELM MAP(var[s1],0)

is computable, it looks no different to Vensim than

var[s2] = VECTOR ELM MAP(var[s1],1)

which is not computable. Generally, of course, these equations appear as

var[s2] = VECTOR ELM MAP(var[s1],some other var)

and the assumption is that some other var could be anything. Actual range checking is done at run time, but for equation ordering all of var[sub] must already be computed which is clearly not the case.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

JJ - What is this model trying to accomplish, conceptually? Perhaps there's another path to implementation. - Tom
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour

Post by LAUJJL »

Hi Bob and Tom

I have found an evident solution to the problem.
One has to define the subrange subsui = (s2-s4) and
presui = (s1-s3) and map the subranges with
pre = presui->subsui.
It works very well.
Joined the model strange_mapping_ordered_5.mdl.
I did not thought possible to use that sort of mapping using multiple subscritps. I have made the correction in my model and it works too.
Tom, I am making a model that generates events a bit like Dudley's rainfalls. Logically I should use a time step = one day / 64, and simulate an event occuring or not during that time step. The problem is that the model will expand on 30 days, and work on 2500 - 50 possible travels between 50 towns. Making optimization with stochastic exogenous data, I need to build about 100 parallel simulations adding a sim = (s1-s100) subscript to most of the variables. I had to find a way to avoid using a too small time step. I have found the way to use a day time step, and still generate stochastics data for the day that I store in arrays. The problem is that each event influences the next event. A matter of car availability in the town the car is traveling from.
This will reduce considerably the optimization time that I fear may take at least one night, eventually much more.
I did not find another way to optimize with stochastic data than running parallel simulations and optimizing an average pay off. Do you know any?
Regards.
JJ

[Edited on 14-4-2010 by LAUJJL]

[Edited on 14-4-2010 by LAUJJL]
Attachments
strange mapping_ordered_5.mdl
(2.28 KiB) Downloaded 351 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Clever solution.

I can think of some alternatives to adding a dimension for the parallel sims, but none are easy to implement (all involve programming with the .dll or using a tool I built to run a model within a model, neither of which I can really support at the moment). Hopefully this capability will be available before too long.

Tom
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom

That would be a great advantage.
But there are rarely advantages without drawbacks.
For instance in my model, having replaced a small time step with a larger one has made the model very tricky and unelegant which makes it error prone and difficult to understand.
Do you mean a built in implementation in Vensim? What is 'not too long' for you?
One year, three years?
Regards.
JJ
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

I don't know exactly what "not too long" means. Order of magnitude a year, not a month, though it might be possible to accelerate with a funded project.

The 1/64 day time step for 30 days actually seems pretty reasonable, if the dimensionality of the problem could be kept manageable so that things run quickly. A wild guess: you have stocks of cars at each city, and customers arriving by some random process, taking a car (if available), and possibly going somewhere else, arriving after some random duration - hence the 50x50 trip matrix.

If the trip matrix were sparse, VECTOR SELECT might speed things up quite a bit. One way to make it sparse would be to restrict transitions to an adjacency network among cities, so that a Marseille-Toulouse trip always passes through Montpelier. That might be harder to calibrate though.

Just thinking out loud ...

Tom
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom

I appreciate your knowledge of french geography!
I have looked at my model, and right now I do not see how I could use the vector select.
I dot represent the intercity travel by an intercity grid with plenty of 0, but by a vector with the departure and arrival town.
The problem comes from somewhere else. It comes from the fact that there is a price grid for each intercities travel and too the estimated price of the competition, the problem being to set a price grid that maximizes the margin. Presently half of the demand is not satisfied because of the difficulty to control intercities flows. An adequate pricing would regulate the flow and diminish the non availability. But I will have to limit the number of prices to optimize using a pareto low, because Vensim will not stand 2500 - 50 parameters to optimize. Whatever solution found a one day step will decrease the simulation time. I have not yet tried optimization and I presently work with 3 agencies, being in the process of finding eventual bugs in the model with mass balances check and a full set of reality checks, the equations being particularly tricky.
There are other problems about the possibility to correct the stochastic nature of the demand by specific actions (special prices or Web promotion). Another problem is at what time is it possible to accept a demand in advance. Not to mention problems to come. I generally start with a highly simplified problem that I try to understand fully with plenty of reality checks and try to use it practically before attempting to add some new material. I have experienced too many complex models that I have never been able to use.
I prefer a simple model that I can use than a complex one not practicable.
Regards.
JJ
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Hi -

I got curious about the computational challenge. It seems like the 50x50 city approach works with a 1/32 day time interval, at least in a little test model (attached). Does other combinatorial explosion make the approach impractical?

The interesting experiment with this model is to lower the fleet until it becomes a constraint (at around 10,000 cars).

It would also be interesting to reformulate this as a continuous model, to see whether the integer constraint on cars matters, and to try different delay distributions on the transit process.

Tom
Attachments
carRental.mdl
(11.15 KiB) Downloaded 356 times
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

I must admit, I had to look at a map to pick suitable cities. I've only been to Paris, Calais, and Dijon.

OK, I think I understand your problem much better now. The vector of origin-destination pairs makes a lot of sense.

To paraphrase your framing, it sounds like the goal is to maximize profit, which in turn is partly a matter of price, and partly ensuring that cars are available where needed, not piling up somewhere else.

A first step toward reducing dimensionality would be to forget about origin-destination pricing, and just have
price[fromCity,toCity] = a + b[fromCity] + c[toCity]
then you'd have only 101 parameters (one a, 50 b's and c's). That's still a lot though. The interpretation of b and c might be as origination and dropoff charges, designed to maintain balance.

Instead, I'd suggest creating some kind of feedback rule, that generates prices on the basis of local conditions in each city. Some of those would presumably be operating costs, and others would reflect demand-supply balance or the opportunity cost of not using a car elsewhere. Thus you might have
price[fromCity,toCity] = cost[fromCity]*(1+markup) + f(inventory[city]/desired inventory[city])
desired inventory[city] = SMOOTH( rentals[city], tau )*desired inventory coverage
Then you'd only have a few parameters to seek - desired inventory coverage, markup, and one to three to describe the shape of f(). Even adding other factors to the decision, it should be possible to keep the dimensionality reasonable.

Tom
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom

Thank you for your model.
It has interesting ideas and I will study it and see if I can incorporate some of them in my model.
Thanks again and best regards.
JJ
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour of a model

Post by LAUJJL »

Hi Tom

Here is joined a discreet version of the traffic model between towns.
It is unfortunately in French, but should not be too difficult to understand.
The three variables to optimize are the number of vehicules, the price of each intercity travel, and at what time from the beginning of the travel one decides to accept the offer of the customer. Otherwise the company returns the payment of the customer for non availability. The variable to optimize is not in the model, but should be the margin with the turnover and the fixed and variable costs of the vehicle, but might be something else like the capacity utilization.
It has a mass balance and some reality checks that verify mainly that the subscripts dimensions are correct and that every time, the number of vehicles rented or reserved plus the number of vehicles not rented or not reserved in the present or future is equal to the total number of vehicles.
there should some more reality checks, but I stopped developing the model.
It has too a day time step, while allowing to register many demands within one day, which increases the speed.
It works well, but already slowly with only three towns and not the 100 parallel simulations needed to cope with the stochastic inputs. If one introduces 50 towns, by modifying the subscripts, it will become awfully slow, and it will be impossible to optimize. It my take several years to find the optimum for the 1245 possible prices. One sees clearly the limit of introducing stockastic discreet events and the advantage of continuous modeling. I have stopped developping that model, because the option of buying that business is not valid for some other reasons.
I have observed that discreet modeling has most of the time more disadvantages than continuous one. It is closer to the reality and it is tempting to follow that path but with a lot of drawbacks with it.
For some reasons, the model rent12.mdl when run shows a simultaneous error with new versions of Vensim, and must be replaced with the rent14.mdl where the formulation is different and has no more the simultaneous error.
Regards.
JJ

[Edited on 1-5-2010 by LAUJJL]
Attachments
rent14.mdl
(40.74 KiB) Downloaded 299 times
rent12.mdl
(41.55 KiB) Downloaded 310 times
Last edited by LAUJJL on Thu Jan 20, 2011 10:00 pm, edited 1 time in total.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Post by tomfid »

Nice. I'll have a look.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

strange behaviour

Post by LAUJJL »

Hi Tom

I joined a version of the model, where I have changed some parameters to make it more realistic and the size of the subscripts too. There is a box which has a shape color in red.
Th equations must be changed if the subscript 'affaires' size is modified. It is better to run the reality checks if one modifies the parameters to verify that the subcripts have been modified accordingly. I have added too the capacity utilisation within the horizon and the instant capacity utilization called 'rotation sur horizon' and 'rotation courante'.
I have too modified the arrows that represent flows into the level 'disponibilité des agences' into full lines instead of dotted lines. I use Coyle's diagramming conventions.
The variables with a green back ground color are the policy changeable constants.
The model rent12_bis must be replaced by the model rent14.mdl that works with the new Vensim version.

Regards.
JJ

[Edited on 5-5-2010 by LAUJJL]
Attachments
rent14.mdl
(40.74 KiB) Downloaded 296 times
rent12_bis.mdl
(44 KiB) Downloaded 272 times
Post Reply