Assigning data to subscript elements

Use this forum to post Vensim related questions.
Post Reply
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Assigning data to subscript elements

Post by nikvyas »

Hello all.

I'm struggling to come up with a neat algorithm that does the following:

I have a subscript with 20 elements (call them 20 planes).

I have a flying programme made up of a series of pulses. The heights of the pulses are multiples of 1. 1 is the length of each flight, so if there is a pulse of 4, it means that there are to be 4 flights at that time.

Now, it is necessary to see which of the 20 elements (i.e., 20 planes) are free to fly at that time. If the element as at value 0, it means it is available, but a 1 means that it is already undergoing a flight, so is not available.

What I want is for each element to be looked at in turn to see if it is free and if so, is there a flight left for it to do.

For instance, we have a pulse of 3, meaning 3 flights. Element1 is interrogated and is determined to be free (value of 0), so it will take 1 of the flights, leaving 2. Elements 2, 3, 4, 5 are busy (value of 1). Element 6 is free so is able to take a flight leaving one. Element 7 is busy, but element 8 is free to take the final flight.

Note that the pulse height is variable and the busyness or otherwise of the elements is dependant upon the flying programme (i.e., pulses) before the pulse in question.

Any help greatly appreciated.

Thanks

Nik
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Assigning data to subscript elements

Post by Administrator »

How about something like

FLIGHT ID[FLIGHT] = INITIAL(FLIGHT)

FIRST FLIGHT ID AVAILABLE = VMIN ( if then else ( flight slot free[FLIGHT!] = 0 , FLIGHT ID[FLIGHT!] , 9999999 ) )

If there are no flight slots available it will return 9999999, if there is one, it will return the ID number of the subscript.
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
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Assigning data to subscript elements

Post by tomfid »

The allocation functions are good for this. See attached. I used ALLOCATE BY PRIORITY which is the simplest variant. It's not strictly constrained to preserve integer planes, but if you manage the priority and width parameters it will do so.

Tom
Attachments
flight.mdl
(3.42 KiB) Downloaded 244 times
Lee Jones

Re: Assigning data to subscript elements

Post by Lee Jones »

I've done something like this before.

You could try using the function VECTOR_RANK to rank the aircraft by availability then allocate n aircraft to the current pulse so long as their rank is <= number of flights in that pulse. I've used this approach to manage batch processing in pharmaceuticals, it's simply and seem to work fine. The input to VECTOR RANK could be the availability indicator (i.e. not on a flight) but it could also incorporate flying hours available, maintenance required, whatever.
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

Thaks very much guys. Much appreciated. However - I'm obviously doing something silly, because my model doesn't run. You couldn't have a look could you please? "Mission Starts" is probably the culprit.

Nik
Last edited by nikvyas on Thu Jan 20, 2011 1:35 pm, edited 1 time in total.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Assigning data to subscript elements

Post by Administrator »

Why is everything in the model subscripted with the "P1" element? This is the problem in the model.

Tony.

PS. You really should put dimensions in this model.
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
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

The attached model is a part view of a much larger model. The p1 is a legacy subcript and I should have removed it. I'll remove and see if it clears the errors.
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

No, still doesn't work for some reason. Irrespective of whether or not the dimensions are set (and I admit that they should be, but the model is by no means in its finished state yet), I don't understand why the "Mission Starts" function doesn't work. Any help more than gratefully recieved.
Attachments
NACtest1.mdl
(10.86 KiB) Downloaded 244 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Assigning data to subscript elements

Post by tomfid »

I think mission starts actually do work. The problem is that Flying Programme is always 0. I'm not sure what the pulse trains in MSW and SSW are doing, but if I do a synthesim override on Flying Programme, setting it to 1, I get mission starts cycling through the last few (~v46-50) planes, based on their availability.

I think Lee's approach is cleverer than mine, as long as you don't care about which exact plane is in a given stage. As long as you only care about the number of planes in a given state, you don't need the subscripting to track individuals. For one example, see the carRental model that I posted about 2/3 of the way down this thread http://www.ventanasystems.co.uk/forum/v ... &hilit=car (on April 15).

If your model is big and you have 100k+ time steps, you're likely to want a savelist to limit the amount of disk storage needed. Also, you might consider setting the saveper to a longer interval, like 8 or 24 hrs (though that makes debugging harder, so probably best to hold off until things are in a reasonably finished state).

Tom
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

Thanks Tom - unfortunately I need to track individual aircraft (and their progress through maintenance). Your model would be perfect - if I could get my version to work :?

The Flying Programme does have pulses - but they are a long time in the future! For instance, there are pulses at 12381, 12386, 12391 etc. Unfortuantely Mission Starts doesn't seem to recognise them - and I can't seem to work out why. If Mission Starts worked, the rest of the model would flow exactly as intended.

The model I'm building is part of an intense, fairly urgent, exercise so any help as always is hugely appreciated.

Nik
Lee Jones

Re: Assigning data to subscript elements

Post by Lee Jones »

I've just downloaded the latest version and it seems to work for me, well, the last few vehicles record a "1" at the right time, i.e. each time there is a pulse at "flying programme".
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

Apologies Lee and Tom.

Yes - you're right............it does work :lol:

I made the mistake of looking at the graphs rather than looking at the tables.

Thanks again.

Nik
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

The allocation is done highest to lowest subscript. Is it possible to do it lowest to highest instead, so that subscript 1 gets allocated first as opposed to subscript 50 (assuming 50 subscripts)?

Thanks
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Assigning data to subscript elements

Post by tomfid »

The function's ordering is fixed, but you can always remap your model variables, i.e.

input x[b,c,a] = x[a,b,c]

do the allocation, then reverse the process to get back to your original ordering.

Tom
nikvyas
Senior Member
Posts: 112
Joined: Mon Apr 24, 2006 3:17 pm

Re: Assigning data to subscript elements

Post by nikvyas »

Thanks very much tom.
Post Reply