Page 1 of 1

Combining Lookup Variables

Posted: Fri Nov 22, 2019 1:36 am
by bil
Hi,

I have two lookup variables I would like to combine into one. For example, given two lookup variables that represent an activity of a single individual in time as either engaged (1) or not (0): how can I combine "Work" and "Sleep" to have a third lookup variable "Busy". The input to the lookup variables is "Time".

Please find below some ideas I am exploring, but they are not straight forward. Ignore what is below if you have a straight forward suggestion.

I am able to combine (addition operator) the two lookup variables to have "Busy output" as an auxiliary variable that shows the expected output after simulation. However I am interested in a lookup variable so that I can find out what times are busy without running the entire simulation.

Another option I considered is to have two Vensim files. The first Vensim file creates the combined lookups for the duration of the simulation as an auxiliary variable "Busy output", then exports "Busy output" as an Excel file "Busy.xlsx". The second Vensim file then reads in "Busy.xlsx" as a lookup variable "Busy lookup" and proceeds. As you can imagine, this approach will be cumbersome, as well as error prone when scaling to multiple individuals. Also, this approach might require some mouse-clicking because I do not know how to export data automatically during, or after, a simulation without using mouse as illustrated in the help pages (http://www.vensim.com/documentation/data_export.htm).

Looking forward to your responses.

Regards

Re: Combining Lookup Variables

Posted: Fri Nov 22, 2019 2:15 am
by tomfid
How about something like:

working = work_lookup(time)
sleeping = sleep_lookup(time)
busy = IF THEN ELSE( working :OR: sleeping, 0, 1 )

?

Re: Combining Lookup Variables

Posted: Fri Nov 22, 2019 11:38 am
by bil
Thanks for the prompt reply.

Whilst this may be a neater solution, it don't think it will work well with all the cases I plan to use it for. There are 2 cases, which should be checked in the same equation (IF ELSE THEN equation).

The first case is to check if the individual is busy in the current simulation time. In this case, your suggestion works well by using current simulation time "Time" in the equations.

The second case is to check if the individual is busy in a future, or even past, time. For this scenario, I would want something like:

busy_at_future_time = busy_lookup(future_time)

Having a single combined lookup would allow for an equation like:

future_time1 = Time + duration_of_new_activity1
start_new_activity1 = IF THEN ELSE( busy_lookup(Time) = 0 :AND: busy_lookup(future_time1) = 0,
1, 0 )

However, using your suggestion, perhaps we could have something for each activity like:

future_time1 = Time + duration_of_new_activity1
busy_now = IF THEN ELSE( work_lookup(Time) :OR: sleep_lookup(Time), 1, 0 )
busy_at_end_activity1 = IF THEN ELSE( work_lookup(future_time1) :OR: sleep_lookup(future_time1), 1, 0 )
start_new_activity1 = IF THEN ELSE( busy_now = 0 :AND: busy_at_end_activity1 = 0,
1, 0 )

Using this last suggestion would lead to a messy stock and flow diagram because each activity (which there will be many of) will have to be linked to the all the lookup variables (which may be many as well). However, when using a single combined lookup like busy_lookup(), there should be much less links and variables as the model scales up.

Any further suggestions?
Thanks

Re: Combining Lookup Variables

Posted: Sat Nov 23, 2019 8:17 am
by Administrator
The only thing I can think of is VECTOR LOOKUP which is not available in PLE. You can use VECTOR LOOKUP to define a lookup based on an array of values. So it would be easy to add two arrays to give a 3rd array which would be your lookup.

Re: Combining Lookup Variables

Posted: Sat Nov 23, 2019 12:47 pm
by tomfid
If the point is to combine a bunch of conflicting schedule elements in a static way, which is what lookups would do, you could pre-combine the lookup tables in a spreadsheet and plug the result into the model.

If it's something else, I'd have to understand more about the dynamics to be represented in order to comment.

Re: Combining Lookup Variables

Posted: Sun Nov 24, 2019 11:51 pm
by bil
tomfid wrote: Sat Nov 23, 2019 12:47 pm If the point is to combine a bunch of conflicting schedule elements in a static way, which is what lookups would do, you could pre-combine the lookup tables in a spreadsheet and plug the result into the model.

If it's something else, I'd have to understand more about the dynamics to be represented in order to comment.
I have implemented this already because it is the option that provides me the combined schedule as a lookup variable which makes the diagram easier to read.
Administrator wrote: Sat Nov 23, 2019 8:17 am The only thing I can think of is VECTOR LOOKUP which is not available in PLE. You can use VECTOR LOOKUP to define a lookup based on an array of values. So it would be easy to add two arrays to give a 3rd array which would be your lookup.
I am running PLE+ and it also doesn't have VECTOR LOOKUP, but I am currently using a spreadsheet for the combination (explained above).


Thank you both