Multi-input Lookup

Use this forum to post Vensim related questions.
Post Reply
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Multi-input Lookup

Post by geo_curious »

Hi,

I am been struggling with this super simple lookup that should work with subscripts. As usual, I cannot make heads or tails of the subscript instructions in the manual for my intended use case. I know, it's just me :roll:. Here is the problem:

Inputs: Pressure number [PN16, PN10, PN6, PN4, PN2], outside pipe diameter
Output: Inside pipe diameter
Screenshot 2024-01-01 164150.png
Screenshot 2024-01-01 164150.png (47.65 KiB) Viewed 30640 times
Screenshot 2024-01-01 164330.png
Screenshot 2024-01-01 164330.png (179.03 KiB) Viewed 30640 times
I "hard coded" a temporary fix and decided I would have to manually select the pressure number because subscripts are incoherent to work with beyond simple integer outputs for a single variable input. Right now, my model will only take in one pressure number which I have to manually select. This will never be useful for an application, which is my intended goal. Is there any way that I can assign the pressure numbers as the subscripts that will be selected then also input the desired outside diameter number? I tried this as a "selected pressure number" then called the outside diameter (shown) as a LOOKUP EXTRAPOLATE, but that did not work using IF THEN ELSE, subscripts in a variable with lookups as graph, etc.. I should say I tried this for 4 days and it did not work.

At the moment, all the Pressure Number variables are lookups. Each of them have unique values of inside diameter for every input of selected outside diameter.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Multi-input Lookup

Post by Administrator »

I'm struggling to follow at what you are doing here.

Subscripts are usually used to turn one variable into an array. So you could have a variable called "sales" and this could be subscripted by "region".

I've had a go at building something simple that I think might be what you are trying to do.

First, I created a subscript range "Pressure number" with elements PN16, PN10, PN6, PN4, PN2.
"selected outside diameter distribution" is now subscripted by "pressure number", and each "pressure number" has a different value.
I've created a lookup that takes "Pressure number" as an input, and returns the diameter needed.
"inside diameter distribution system" now "looks up" the "selected outside diameter distribution" from the "lookup pressure number to inside diameter" lookup.

I hope this makes sense. "selected outside diameter distribution" and "inside diameter distribution system" are now arrayed, each has a different value for each pressure number.
Attachments
pressure_number_demo.mdl
(1.89 KiB) Downloaded 273 times
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
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

Thank you for the response. What I am seeing in this example model does not have a selection of the outside diameter. This example is only taking one input and giving one output. I need two inputs, and one output from a lookup table.

Again, there are two "selections" that must be made:
1. outside diameter (mm) [X]
2. pressure number (bar) [Y]

The output should be a lookup of the array. Each combination of [X,Y] outputs from a lookup table, the inside diameter.

In a function form this could be:
lookup inside diameter([X, Y])

That is the easy part to understand. Writing this as subscripts does not make sense to me. Am I allowed to have a subscript of [X,Y]?
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

Here is the non-ideal workaround I came up with, not knowing how to do the two-dimensional lookup. I add X+Y=Z, then Z=index for lookup, then LOOKUP EXTRAPOLATE(lookup inside diameter, X+Y ). So the lookup appears as:
Screenshot 2024-01-04 104403.png
Screenshot 2024-01-04 104403.png (43.98 KiB) Viewed 30607 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Multi-input Lookup

Post by Administrator »

Sorry for the slow reply (I'm unwell at the moment). I still just don't understand this at all.

Can you try and simplify things please? Let me know what info you have, then what you need to get from it?

If you have an array of lookups, it's easy to pick out a specific one which could be the 2nd lookup argument. This is done via a fake loop in Vensim.

some value = sum ( if then else ( array index id[array!] = input to get, some lookup[array!] , 0 ) )

The SUM function loops over the array, and is zero for all values other than the "input to get". If you have an array of pressure number lookups, it could be something like

some value = sum ( if then else ( pressure subscript id[pressure number!] = distribution index, some lookup[pressure number!] , 0 ) )

Hope this helps. It's the best I can guess at for now.
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
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

Sorry to hear you are under the weather. I will try to explain this again.
This is the order of operations:
1. Pressure number is selected
2. Pressure number limits the pipe diameters.
3. Outside pipe diameter is selected.
4. Based on the selected pressure number and the selected outside diameter the inside diameter is looked up.

Here is the table. Headers are the Pressure Number. The left-hand row are the Outside Diameters.
diameters.png
diameters.png (78.21 KiB) Viewed 30582 times
As far as I can tell, there is nothing obscure about the problem. If I can clarify anything, please let me know.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Multi-input Lookup

Post by LAUJJL »

Hi

I may be wrong but this looks like a two dimensionnal lookup. it is possible to build a two dim lookup with the vector lookup function. Look at the examples of Vensim model functions in users/public/vensim directory. joined.

JJ
Attachments
VECTOR LOOKUP.mdl
(4.11 KiB) Downloaded 266 times
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

Hi JJ,

The VECTOR LOOKUP makes sense, sort of. Unfortunately, it does not work either. I am going to layout my attempt at making the VECTOR LOOKUP function work. From the example "VECTOR_LOOKPU.mdl" above.
XDim[x1, x2, x3], YDim[y1,y2,y3,y4,y5]
2-dim.png
2-dim.png (10.33 KiB) Viewed 30553 times
So I set my test problem up as ODDim[ OD20, OD25 ] and PNDim[ PN2, PN4, PN6, PN10, PN16 ]
od min = 20; od max = 25; od distribution = 20; pn min = 2; pn max = 16; pn distribution = 6
2-dim-pipe.png
2-dim-pipe.png (169.3 KiB) Viewed 30553 times
The vector is:
vector.png
vector.png (57.06 KiB) Viewed 30551 times
od slice is: VECTOR LOOKUP(lookup inside diameter HDPE[ODDim, PN2],pn distribution,pn min,pn max,0)

inside diameter distribution system is: VECTOR LOOKUP( od slice[PN2] , od distribution , od min , od max , 0 )

Errors are -
SUBSCRIPTS: Th Subscript Constant -PN2- also has a defining equation.
" " for PN4 - PN16
SUBSCRIPTS: Subscript 1 of variable -od slice- is a member of the -PNDim-


So, yeah. The examples are not helpful in describing 2-dim lookup.
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

I found one problem in the model. The previously defined variables PN2 - PN16 had lookup tables that were throwing some errors. I deleted those variables and redeclared them as subscripts.

Now the model runs. However, the output from lookup is erroneous and appears extrapolated? Not sure. How would I make the vector lookup explicit for discrete values, rather than interpolated/extrapolated?

In the current version, as from the inputs above, the output is 3. No where in the lookup does 3 appear.
vector.png
vector.png (57.06 KiB) Viewed 30548 times
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

This just does not make any sense. According to the example file for the VECTOR LOOKUP, the x, y, values are input to a standardized distribution range of x-min to x-max and y-min to y-max. I, however, input a value of x = 6 and y = 25 which should be "21" in the lookup, but I get 3. This is incoherent.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Multi-input Lookup

Post by LAUJJL »

Hi

To really help, I need further explanation about your problem which is not clear in my mind.

What are you trying to do? What is the purpose of the model.

There is a pressure: is it continuous or discreet? Can you describe it? Is is constant through the time, is it choosen at the start of the simulation. What is its effect on the objective of the model.

Same for the internal and external pipe diameter. What is this pipe doing? is the thickness of the pipe equal to the external - internal pipe diameter?

It is very difficult to help without having a complete written description of the whole problem and not only one of its part.

Regards.

JJ
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

I am trying to extract a constant, as in the above table. I do not see how I can explain this very, very simple effort any more clearly.
1. There is a lookup table. It contains inside diameters.
2. There is a pressure number that must be selected because it dictates how thick the pipe needs to be.
3. There is an outside diameter that must be selected.
4. Based on the pressure number (Y), and the outside diameter (X), you get inside diameter.

Here is the dysfunctional model. Try running "pn distribution = 6" and "od distribution = 25". The expected result from the table is 21. Vensim finds 3. Now try "pn distribution = 16" and "od distribution = 25". The expected result from the table is 18. Vensim finds 18. The results are wholly inconsistent, so I have no idea what the VECTOR LOOKUP for 2-dimensions is doing. It does not make sense to me.
2-dim_lookup_fail.mdl
(4.86 KiB) Downloaded 272 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Multi-input Lookup

Post by Administrator »

Sorry again, I'm still under the weather.

I've attached a demo model that does this two different ways.

1. Reading the values in as data. This is my preferred way of doing things, read these in as a time series and use GET_DATA_AT_TIME ("time" being the outside diameter). But that might mean units checking gets very confused. So have a look and see if this works for you. This is my preferred way.

2. Reading things into a lookup.

Change "outside diameter selected" and "pressure number selected" to get the correct values into "looked up value" and "looked up value based on data).

How this works is as follows.
1. Create subscript range for pressure number (PN2, PN4 etc).
2. Create a subscripted constant "PRESSURE NUMBER VALUE FOR EACH SUBSCRIPT ELEMENT". This has the actual pressure numbers, 2, 4, 6, 10, 16, 20.
3. Create a subscripted constant called "PRESSURE NUMBER ID". This simply has the value 1,2,3 etc, it's essentially the index of the pressure number subscript. So for PN2, it's value is 1 (PN2 is the first subscript element), for PN20, the value is 6 (PN20 is the 6th element in the subscript range).
4. Take "PRESSURE NUMBER SELECTED" and work out which subscript range is the correct one to use. This is done via a loop, loop over all elements in the "pressure number" subscript range and find one that the "PRESSURE NUMBER SELECTED" matches.
5. Now we know the correct pressure number subscript range to target. Loop again to find the correct value in the lookup/data.

Steps 4 and 5 are only there to map the numeric index of the subscript range (1,2,3,4,5,6) onto the pressure numbers within the range (2,4,6,10,16,20).

I'll raise this as a future enhancement. It would be easier to have a dedicated function that looks up the x and y in the original 2d matrix.
Attachments
demo.mdl
(3.82 KiB) Downloaded 266 times
Book1.xlsx
(10.23 KiB) Downloaded 268 times
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
geo_curious
Member
Posts: 46
Joined: Tue Mar 14, 2023 2:05 am
Vensim version: DSS

Re: Multi-input Lookup

Post by geo_curious »

Spot on. This is perfect. Thank you for taking the time on this one.

If nothing else in this long discussion topic, I have become more familiar with subscripts in Vensim. I look forward to that enhancement!
Post Reply