Page 1 of 1

Assigning data to subscript elements

Posted: Wed Jan 19, 2011 4:30 pm
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

Re: Assigning data to subscript elements

Posted: Wed Jan 19, 2011 6:07 pm
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.

Re: Assigning data to subscript elements

Posted: Wed Jan 19, 2011 6:10 pm
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

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 10:12 am
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.

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 10:18 am
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

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 12:59 pm
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.

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 1:24 pm
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.

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 1:45 pm
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.

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 2:49 pm
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

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 3:21 pm
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

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 4:12 pm
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".

Re: Assigning data to subscript elements

Posted: Thu Jan 20, 2011 4:29 pm
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

Re: Assigning data to subscript elements

Posted: Mon Jan 24, 2011 9:59 am
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

Re: Assigning data to subscript elements

Posted: Mon Jan 24, 2011 2:48 pm
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

Re: Assigning data to subscript elements

Posted: Mon Jan 24, 2011 2:54 pm
by nikvyas
Thanks very much tom.