swarm-support
[Top][All Lists]
Advanced

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

Re: Question about Entropy in Java


From: Marcus G. Daniels
Subject: Re: Question about Entropy in Java
Date: 03 Oct 2000 09:30:00 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "SB" == Bush, Stephen F (CRD) <address@hidden> writes:

SB> I have a variant of the heatbug demo in Java and would like to use
SB> the entropy class on bug properties.

SB> Can anyone provide a brief explanation, or simple example?

Sure,

import swarm.Globals;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.defobj.Zone;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.analysis.EZGraphImpl;
import swarm.analysis.EZGraph;
import swarm.analysis.EntropyCImpl;
import swarm.analysis.EntropyImpl;
import swarm.analysis.EntropyC;
import swarm.analysis.Entropy;
import swarm.Selector;
import java.util.LinkedList;
import java.util.List;

public class EntropyTest extends GUISwarmImpl {
  class Agent {
    double value;

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

    public double getProportion () {
      return value;
    }
  }
 
  List list;
  Schedule schedule;
  EZGraph ezgraph;
  Entropy entropyProbe;

  EntropyTest (Zone aZone) {
    super (aZone);
  }
  
  void addValue () {
    double v = Globals.env.uniformDblRand.getDoubleWithMin$withMax (.1, 1);
    
    list.add (new Agent (v));
  }
  
  public Object step () {
    addValue ();
    entropyProbe.update ();
    ezgraph.step ();
    getActionCache ().doTkEvents ();
    
    return this;
  }

  public Object buildObjects () {
    super.buildObjects ();

    list = new LinkedList ();
    addValue ();

    try {
      EntropyC entropyProbeC = new EntropyCImpl (new EntropyImpl ());
      entropyProbeC.createBegin (getZone ());
      entropyProbeC.setCollection (list);
      
      Selector sel = new Selector (Agent.class, "getProportion", false);
      
      entropyProbeC.setProbedSelector (sel);
      entropyProbe = (Entropy) entropyProbeC.createEnd ();
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    ezgraph = new EZGraphImpl (getZone (), "Entropy",
                               "t", "entropy",
                               "entropy");
    try { 
      Selector sel = new Selector (entropyProbe.getClass (),
                                   "getEntropy",
                                   false);
      
      ezgraph.createSequence$withFeedFrom$andSelector ("H(value)",
                                                       entropyProbe,
                                                       sel);
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    return this;
  }

  public Object buildActions () {
    super.buildActions ();
   
    schedule = new ScheduleImpl (getZone (), 1);

    try {
      Selector sel = new Selector (getClass (), "step", false);

      schedule.at$createActionTo$message (0, this, sel);
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    return this;
  }
  
  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);

    schedule.activateIn (this);
    return getActivity ();
  }
  

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

    EntropyTest entropyTest = new EntropyTest (Globals.env.globalZone);

    entropyTest.buildObjects ();
    entropyTest.buildActions ();
    entropyTest.activateIn (null);

    entropyTest.go ();
  }
}

                  ==================================
   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]