swarm-support
[Top][All Lists]
Advanced

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

Re: Initializing Averager in Java?


From: Marcus G. Daniels
Subject: Re: Initializing Averager in Java?
Date: 26 Jul 2001 16:25:58 -0600
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "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.



reply via email to

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