Page 1 of 1
Lookup Tables and Variables
Posted: Fri Nov 30, 2007 8:35 am
by nikvyas
Good morning all.
I was wondering if it's possible to have the elements of a lookup table as variables? i.e., rather than have defined, constant elements like:
[(0,0)-(10,10)],(1,4),(2,8),(3,9),(4,10)
have instead:
[(0,0)-(10,10)],(1,var1),(2,var2),(3,var3),(4,var4)
Thanks in advance.
Posted: Fri Nov 30, 2007 12:10 pm
by bob@vensim.com
You can use the function VECTOR LOOKUP available in Pro/DSS and introduced in version 5.6c.
Posted: Thu Dec 06, 2007 9:52 am
by nikvyas
Thanks Bob.
I've downloaded the latest version (5.7) and can see the Vector Lookup function. However, the instructions for its use are somewhat confusing.
I'd be very grateful if you could spend a couple of minutes in helping me out of my little problem. What I want to do is as follows:
I have ten repair schemes, each of which has a probability of occuring together with an associated repair time - for instance:
Repair1 - Prob 0.05; Repair time 3 hours
Repair2 - Prob 0.20; Repair time 1 hour
Repair3 - Prob 0.10; Repair time 1.5 hours etc etc
The probabilities and the repair times are variables. What I want to do is create a lookup table of average repair time versus arisings - so that the higher the number of arisings, the higher is the repair time.
I have a devised a function that generates the average repair time, so what I need to do now is to generate a lookup table of arisings versus average repair time.
One other thing I need to do (and haven't quite worked out how to, without using lots of IFTHENELSE statements) is sort the repair schemes in terms of repair time (low to high), so that in the above example where I've only shown three repair schemes, the sorting gives the following:
Repair2 - Prob 0.20; Repair time 1 hour
Repair3 - Prob 0.10; Repair time 1.5 hours
Repair1 - Prob 0.05; Repair time 3 hours
TIA for any help.
Posted: Thu Dec 06, 2007 12:19 pm
by bob@vensim.com
What you have described here does not really make sense to me. If there are 10 probability/repair time pairs than all you can get from that is an average repair time which is just
average repair time = SUM(probability of failure type[Ftype!]*repair time failure type[Ftype!])
or if you are tracking the count of failure events by type then it is
average repair time = SUM(failures[FType!]*repair time failure type[FType!])/sum(failures[FType!])
I can see no reason why there would be a relationship between the number of failures and the repair time from what you ahve said.
As far as sorting - VECTOR SORT ORDER combined with VECTOR REORDER should work for that.
Posted: Thu Dec 06, 2007 12:55 pm
by nikvyas
Hi Bob.
Maybe I explained it wrongly.
When an a/c lands, it has a number of arisings and it is the arising that takes the longest time to fix that determines the downtime of the a/c - so the greater the number of arisings, the higher is the probability that one of the arisings will take a long time to fix.
The equation is:
prob(r hour repair) =(q1+q2+...+qr)(power n) - (q1+q2+...+q(r-1))(power n)
where n is the number of arisings and q1, q2 and qr are the probabilities of the repair routes.
The average repair time is then simply:
Sum(Prob(r hour repair) * r length)
where r length is the length of a repair route.
The equation is mathematically sound (it has been derived from the binomial or multinomial function).
So what I now need to do is create a lookup table of arising versus average repair time - all of which are variables.
Thanks
Nik
[Edited on 12-6-2007 by nikvyas]
Posted: Thu Dec 06, 2007 2:03 pm
by nikvyas
But actually my main problem at the moment is in the sorting. I'm not sure that VECTOR SORT will do the trick.
As the equation above shows, I need to sort the repair schemes in order of repair length. But I also need to conserve the relationship between the repair length and its associated probability of occuring. i.e.,
Repair1=1 Probability1=0.2
Repair2=1.5 Probability2=0.1
Repair3=0.5 Probability3=0.25
Repair4=2.0 Probability4=0.40
Repair5=1 Probability5=0.05
Therefore, we have 10 individual variables. After sorting, I need:
Repair1S=2.0 Probability1S=0.40
Repair2S=1.5 Probability2S=0.1
Repair3S=1.0 Probability3S=0.2
Repair4S=1.0 Probability4S=0.05
Repair5S=0.5 Probability5=0.25
For the life of me, I have no idea how I do this in an elegant fashion. Bear in mind that I actuall have ten repair schemes, not the five demonstrated here. Like I said, it is more important that I sort out this little problem than the lookup table, so I'd be very, very grateful if I could get some help here.
Thanks
Nik
[Edited on 12-6-2007 by nikvyas]
Posted: Thu Dec 06, 2007 2:21 pm
by bob@vensim.com
Since you have an analytic expression for repair time I suspect you may not even want a lookup table for it.
For the sorting this is simple from your description:
ftype: (f1-f10)
sort order[ftype]=VECTOR SORT ORDER(repair time[Ftype],-1)
sorted repair time[ftype] = vector reorder(repair type[Ftype],sort order[ftype])
sorted failure prob[ftype] = vector reorder(failure prob[Ftype],sort order[ftype])
of course the sorted value for f1 is not reapply applying to f1 anymore.
Posted: Thu Dec 06, 2007 2:30 pm
by nikvyas
Thanks Bob - however the problem (as i see it) is that arrays (or subscripts) cannot contain variables. As far as I was aware, you had to explicitly define the elements; i.e:
array1[ftype]=1,2,3,4,5,6,7,8,9,10
But all of the elements in my array will be variables. i.e.,
array1[ftype]=repair_length1, repair_length2,repair_length3,repair_length4 etc etc
Maybe I'm missing something?
[Edited on 12-6-2007 by nikvyas]
lookup table
Posted: Thu Dec 06, 2007 4:37 pm
by LAUJJL
Hi Nick
you can always give the values of variables to a subscripted variable but you must use multiple equations.
joined a simplistic example.
Regards.
JJ
Posted: Fri Dec 07, 2007 10:00 am
by nikvyas
Hi JJ.
Thanks very much for your reply. I've tried your suggestion, but it doesn't seem to work unfortunately. I'd be grateful if you (or Bob) could have a look at the attached (very simple) model and let me know what I'm doing wrong.
I also have another, hopefully simple, question - I promise it'll be the last
Is it possible to have equations that work on individual subscripts within the subscript range (as opposed to the whole whole subscript range). For instance, from the attached model, is it possible to have:
test=sorted repair time[f1]*sorted failure prob[f1](power3) + sorted repair time[f2]*sorted failure prob[f2](power2)
To be honest, I have tried to avoid subscripts up to this point, but I'm at a point now where I HAVE to use them. So my knowledge of them is a bit shakey at the moment I'm afraid. Please bear with me.
Thanks
Nik
[Edited on 12-7-2007 by nikvyas]
[Edited on 12-7-2007 by nikvyas]
Posted: Fri Dec 07, 2007 12:58 pm
by bob@vensim.com
The answer to your qestionis of course you can use subscript elements in equations, though the equation you have would not work unless sorted failure prob was itself a Lookup function.
This is also the reason your model does not work. The equations should be
failure prob[f1]=p1 ~~|
failure prob[f2]=p2 ~~|
and so on - you need to select and replace the generic ftype on the left hand side that the equation editor puts in place.
Posted: Fri Dec 07, 2007 1:48 pm
by nikvyas
Thanks a lot Bob and JJ - I've got exactly what I needed.
After using Vensim for almost two years................I've finally been converted to the beauty of subscripts!