swarm-support
[Top][All Lists]
Advanced

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

[Swarm-Support] (swarm.analysis) Averager.getMin() problem


From: Leon Barbulovic-Nad
Subject: [Swarm-Support] (swarm.analysis) Averager.getMin() problem
Date: Fri, 12 Mar 2004 02:29:16 +0100 (CET)

I would like to post a modified version of
http://www.ku.edu/~pauljohn/SwarmFaq/WorkingExampleCode/java/AveragerUsage.txt
since I am having problems with (swarm.analysis) Averager.

The output of the following code is:
count: 1
average: 1.0
total: 1.0
min: 1.0
----------------
count: 1
average: 1.0
total: 1.0
min: 0.0         ( <- INCORRECT)

As you can see, the minimum value is incorrect if the second update() is
called.  I don't see a reason why this would be the case so I wanted to
ask you if I am using update() the wrong way.

What I am trying to do is update() the averager because my list of agents
is changing with time.  This changing list is not implemented in the code
bellow, however this getMin() problem is present even with the simple
example code that most of you are familiar with.

I would be very thankfull if any of you could help me out.

Leon Barbulovic-Nad



------------- CODE -----------------------

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 int value;

    Agent (int value) {
        this.value = value;
    }

    public int getAgentValue () {
        return value;
    }
}


public class TestAverager {

    TestAverager (Zone aZone) {
        List l = new LinkedList ();

        l.add (new Agent (1));
        //l.add (new Agent (2));
        //l.add (new Agent (3));
        //l.add (new Agent (4));

        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("count: " + averager.getCount());
        System.out.println("average: " + averager.getAverage());
        System.out.println("total: " + averager.getTotal());
        System.out.println("min: " + averager.getMin());
        System.out.println("----------------");
        averager.update ();
        System.out.println("count: " + averager.getCount());
        System.out.println("average: " + averager.getAverage());
        System.out.println("total: " + averager.getTotal());
        System.out.println("min: " + averager.getMin());

    }


    public static void main (String args[]) {
        Globals.env.initSwarm ("TestAverager", "0.0",
"address@hidden",
                               args);

        new TestAverager (Globals.env.globalZone);
    }
}




reply via email to

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