swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing Averager in Java?


From: Tom Wainwright
Subject: Re: Initializing Averager in Java?
Date: Thu, 26 Jul 2001 15:55:17 -0700

Thanks!  I was almost there, but couldn't get AveragerCImpl.createEnd()
to work.  I had missed the significance of the AveragerCImpl(Averager
nextPhase) constructor, and hadn't tried that.  All this phase-switching
stuff is pretty obscure.

I ran into this trying to replace an EZGraph with a Java Swing graph
(via the "Scientific Graphics
Toolkit"--http://www.epic.noaa.gov/java/sgt/index.html).

--Tom Wainwright

"Marcus G. Daniels" wrote:
> 
> >>>>> "TW" == Tom Wainwright <address@hidden> writes:
> 
> TW> I can't figure out how to set the collection for an Averager in Java.
> 
> Usually an Averager is created via an EZGraph, but it can be used
> directly, as well.  An Averager is just a special kind of MessageProbe.
> 
> The main thing is it requires the more-complicated phase switching idioms.
> 
> import swarm.analysis.Averager;
> import swarm.analysis.AveragerC;
> import swarm.analysis.AveragerCImpl;
> import swarm.analysis.AveragerImpl;
> import swarm.defobj.Zone;
> import swarm.Globals;
> import swarm.Selector;
> import java.util.List;
> import java.util.LinkedList;
> 
> class Agent {
>     public double value;
> 
>     Agent (double value) {
>         this.value = value;
>     }
> 
>     public double getAgentValue () {
>         return value;
>     }
> }
> 
> public class TestAverager {
> 
>     TestAverager (Zone aZone) {
>         List l = new LinkedList ();
> 
>         l.add (new Agent (1.0));
>         l.add (new Agent (2.0));
>         l.add (new Agent (3.0));
>         l.add (new Agent (4.0));
> 
>         AveragerC averagerC = new AveragerCImpl (new AveragerImpl ());
> 
>         averagerC.createBegin (aZone);
>         try {
>             Selector sel = new Selector (Agent.class, "getAgentValue", false);
> 
>             averagerC.setProbedSelector (sel);
>         } catch (Exception e) {
>             e.printStackTrace (System.err);
>             System.exit (1);
>         }
>         averagerC.setCollection (l);
> 
>         Averager averager = (Averager) averagerC.createEnd ();
> 
>         averager.update ();
>         System.out.println (averager.getAverage ());
>     }
> 
> 
>     static void main (String args[]) {
>         Globals.env.initSwarm ("TestAverager", "0.0", "address@hidden",
>                                args);
> 
>         new TestAverager (Globals.env.globalZone);
>     }
> }
> 
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.

-- 
Tom Wainwright
NOAA/NMFS/NWFSC
2030 S Marine Science Dr
Newport, OR 97365 USA
address@hidden

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]