MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

"misbehaving" Union function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24075] "misbehaving" Union function
  • From: Felix Farkas <farkas at ica.epfl.ch>
  • Date: Fri, 23 Jun 2000 02:26:43 -0400 (EDT)
  • Organization: EPFL
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
i am trying to build up a list of points. The input is,
 a list of events. I use the Union function in order to
avoid duplicate points. however i do not have the expected result.
 i really don't know where the error is coming from.
 Could somebody, please, tell me where is the fault?
I would greatly appreciate any suggestions.

Many thanks in advance.
Regards,
                Felix

Here is the function:

In[1]:= Genpoints[events_] :=
        Module[
        {ev = events, rate,
                        duration, time, burst, bytes = 0, points = {}},
                rate := ee[[3]];
                duration := ee[[2]];
                time := ee[[1]];
                burst := ee[[4]];
                While[Length[ev] != 0,
                        ee = First[ev];
                        ev = Rest[ev];
                        points = Union[points,
                                        If[rate == -1,
                                                (*then*)
                                                bytes += burst; {{time,
bytes - burst}, {time, bytes}},
                                                (*else*)
                                                bytes += rate*duration;
              Print[{{time, bytes - rate*duration}, {time + duration,
                    bytes}}];
                                                {{time, bytes -
rate*duration}, {time + duration, bytes}}]
                                ]
                ];
                points
        ]

The output generated is:

In[2]:= aa = {{0, 6, 0.3333333, 2, 2, 1},
      {6, 8, 0.5, 4, 2, 1}, {14, 1, 1, 1, 2, 1},
      {15, 10, 0.4, 4, 2, 1}, {25, 1, 1, 1, 2, 1}};
In[3]:=  po2 = Genpoints[aa]
Out[3]= {{0, 0.}, {6, 2.}, {6, 2.}, {14, 6.},
{15, 7.}, {25, 11.}, {26, 12.}}



-----------------------------------------------------------------------------
Felix Farkas
EPFL-DSC-ICA
IN-Ecublens
CH-1015 Lausanne
Switzerland

tel:       0041 21 693 6601
fax:       0041 21 693 6610
email:     felix.farkas at epfl.ch




  • Prev by Date: Re: Sequence of functions
  • Next by Date: Re: parallel computing toolkit
  • Previous by thread: Re: Output cell linebreaks
  • Next by thread: Re: "misbehaving" Union function