From: "Lisa Wells" To: designCPN@daimi.au.dk Date: Mon, 18 Aug 2003 11:52:03 +0200 Subject: Re: (dCPN) Question concerning the use of a real (in a union colorset) Dear Martina Friedrich, As you have discovered, Design/CPN does not support real numbers in token values. However, you can use infinite integers (IntInf.int) to approximate the use of real numbers in token values. Your idea for working around the problem was right on target, but the syntax was slightly wrong. What you need instead is: color Real = IntInf; In other words, you only have to write IntInf (instead of IntInf.int). This is implicitly described at the top of the Design/CPN 4.x manual addendum, however, it is easy to overlook. Then you can define color Int_String_Real = union I:Int + S:String + R: Real; When you use the functions IntInfToReal and RealToIntInf, you need to state the desired precision of the real numbers -- this corresponds to the "p" in the description of the two functions. The precision determines how many digits there should be to the right of the decimal point of a real number. Here are a couple of examples. Suppose that you have the following declarations val pr = 3; val n = 98.12345; val x = RealToIntInf 3 n; val y = RealToIntInf pr n; val z = IntInfToReal pr x; val w = IntInfToReal 4 x; Then x and y are infinite integers (IntInf.int), and they have the same value: x = y = BI{digits=[98123], sign=POS} The "digits" value above corresponds to all of the digits to the left of the decimal point in n, followed by the first 3 digits to the right of the decimal point in n. The first 3 digits after the decimal point were included because the precision of the conversion was 3 (or pr, which is also equal to 3). On the other hand, z and w have the following real values: z = 98.123 w = 9.8123 Note the difference between z and w. z was obtained by converting x back to a real number with precision 3, while w was obtained by converting x back to a real number with precision 4. Care must be taken to use the same precision when converting a real number to an infinite integer and back to a real number. You will need to use the functions RealToIntInf and IntInfToReal when you want to convert to and from real numbers, and when you want to manipulate pseudo-real numbers. For example, you will have to use the RealToIntInf function to calculate an initial marking if you want to convert a real number to a (infinite integer) value that is a legal token value. Alternatively, you would also have to use the two functions, if you want to have an arc inscription where a real number is added to a pseudo-real number that is represented as an infinite integer. For example, suppose that r is a variable, where var r: Real, and Real is defined as above. If r is on an input arc to a transition and all of the tokens on the input place have precision pr, then an arc inscription for an output arc of the transition could look like this: RealToIntInf pr ((IntInfToReal pr r)+3.1415) I hope that this helps you. If not, please let us know. Best regards, Lisa ----- Original Message ----- From: "Martina Friedrich" To: Sent: Thursday, August 14, 2003 11:18 AM Subject: (dCPN) Question concerning the use of a real (in a union colorset) > Dear ladies and gentlemen, > I am a Civil Engineer student and I am working with Design/CPN in the course > of my diploma thesis. > > The following problem occured: > I have a problem concerning the use of a real number in a union colorset. > I would like to model a color that can either be an integer, a real or a > string. > For example: > color Int = int; > color String = string; > color Real = ???? > color Int_String_Real = union I:Int + S:String + R: Real; > > It works extremely well if I only use numbers, i.e. integers and strings. > However the application of real number is not accepted during the syntax check. > In the Design/CPN 4.x manual addendum it is said that the real type can no > longer be used as a color type. Unfortunately I am not in a position to > understand the explanations concerning the conversion functions, i.e. IntInfToReal > p i. Do these function need to be applied each time I would like to use a > real number, e.g. as part of an output arc of a transition? Or is it possible > to declare a color with type real which can be used during the whole > modelling? How does the declaration node needs to look like and what is the type of > the color that I would like to use as a real? > > I tried to model a color which should solve this problem by following the > explanation stated below > val IntInfToReal : int -> IntInf.int -> real > my version: > color Real = IntInf.int; > However, Design/CPN does not allow me to use ‘Intinf.int’. What > is ‘IntInf.int’? Is it a color type or just something in between. > But then what is the type if I want to use reals? > > It would be absolutely helpful, if you could explain me the use of a real > number by means of an example. > Thank you so much in advance. > Martina Friedrich > > > > > ---- > [[ Homepage and archive: http://www.daimi.au.dk/designCPN/email/ ]] > [[ Subscribe: http://mailman.daimi.au.dk/mailman/listinfo/designcpn ]] > ---- [[ Homepage and archive: http://www.daimi.au.dk/designCPN/email/ ]] [[ Subscribe: http://mailman.daimi.au.dk/mailman/listinfo/designcpn ]]