swarm-modeling
[Top][All Lists]
Advanced

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

Re: Compare Swarm with Repast


From: Nick Collier
Subject: Re: Compare Swarm with Repast
Date: 16 Aug 2002 14:33:02 -0400

Hi,

To complicate matters further I'm not sure what we are measuring (ticks
/ min) is in fact the same in both cases (this just occurred to me),
although they may be roughly similar. I don't know what model behavior
occurs every tick (as we call them in repast land) in the swarm model
and at this point I'm not sure what happens in the repast version. I do
remember that the repast Diffuse2D space wasn't particularly efficient
when I wrote it two some years ago. In fact it was only written to
support heat bugs, and whether its ever been used again, I don't know.
At any rate the schedule mechanism for the two are very different, and I
don't know how the two are scheduled. Furthermore, the scheduling
mechanism has been entirely rewritten for repast 2.0 to be more
explicitly discrete event like. This may make it more swarm like, but I
really can't say. It certainly wasn't re-written with that in mind.


Nick

On Fri, 2002-08-16 at 14:28, Gary Polhill wrote:
> >Dear Gary:
> >
> >Please consider making a measurement of Heatbugs with my optimized 
> >HeatSpace class:
> >
> >http://lark.cc.ku.edu/~pauljohn/Swarm/MySwarmCode/HeatSpace.m 
> >
> >and report back. All you need to do is drop that file in over the old one.
> 
> The difference between your HeatSpace and the one that ships with the 
> SwarmApps doesn't come out until you set the refresh rate high enough. (That 
> is, all measurements using Obj-C Swarm with your HeatSpace are pretty much 
> the same as those posted in my earlier message.)
> 
> It then occurred to me that maybe setting the refresh rate to 100 was a 
> better way of measuring background performance than minimising the window. 
> Here are the cycles per minute:
> 
> Sun:
> 
> JavaSwarm: 4900   (!)
> ObjCSwarm (Standard HeatBugs): 4500
> ObjCSwarm (Paul's HeatBugs): 6300
> 
> PC:
> 
> JavaSwarm: 2700
> ObjCSwarm (Standard HeatBugs): 6900
> ObjCSwarm (Paul's HeatBugs): 9400
> 
> Looks like with your modifications you now get about a 50% improvement in 
> speed.
> 
> I tried hacking the HeatBugsModel.java that comes with RePast to make it do a 
> refresh rate. My efforts are attached, but since I really don't know what I'm 
> doing maybe it's not fair to compare the results I got (1700 cycles/min on my 
> PC, 1400 on the Sun FWIW) with those from Swarm above.
> 
> I've no idea how the JavaSwarm managed to beat the standard ObjCSwarm on the 
> Sun but not on the PC... There seem to be an awful lot of other factors 
> coming in to play in determining the time than just programming language and 
> model algorithm here, which makes interpreting these benchmark results a real 
> challenge! It's kind of important for us too -- we often run our model many 
> thousands of times, comparing parameter settings. If the model runs three 
> times slower on one platform and modelling environment/language than another, 
> that's 3 months to get results rather than just 1. From the results I've got 
> today it's still not really clear what the cost is (in batchmode) of 
> switching from Obj-C to JavaSwarm (anything from 1.5x slower to 3x slower), 
> and, were we to consider it, from JavaSwarm to RePast (anything from 1.5x 
> faster to 3x slower).
> 
> There are version differences across the platforms I've been benchmarking on, 
> so for the sake of thoroughness:
> 
> Sun: Solaris 8, Dual 750MHz sparc, 2.5G RAM. Swarm testing-2001-12-18, 
> Repast-1.4 both using Java 1.3.1_01. heatbugs-2.1.1 (ObjCSwarm), 
> jheatbugs-2001-03-28 (JavaSwarm), and in Repast I used the heatbugs that came 
> with repast-1.4.tar.gz
> 
> PC: Windows 2000, 1.6GHz intel, 512M RAM. Swarm-2.1.1 using Kaffe 1.0.5, 
> Repast-1.4.1 using Java 1.3.1_02. For JavaSwarm I used jheatbugs-2.1, for 
> ObjCSwarm, I used the heatbugs off the Swarm 2.1.1 CD (installing on my hard 
> drive first), and for Repast I used the heatbugs that came with 
> repast-1.4.1.zip.
> 
> Gary
> 
> 
> 
> Gary Polhill
> Research Scientist
> The Macaulay Institute
> Craigiebuckler
> Aberdeen AB15 8QH
> UK
> Tel: +(44) (0)1224 498200 Ext 2238
> Fax: +(44) (0)1224 311556
> e-mail: address@hidden
> http://www.macaulay.ac.uk/
> http://www.macaulay.ac.uk/fearlus/
> 
> ----
> 

> /*$$
>  * packages uchicago.src.*
>  * Copyright (c) 1999, Trustees of the University of Chicago
>  * All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with
>  * or without modification, are permitted provided that the following
>  * conditions are met:
>  *
>  *     Redistributions of source code must retain the above copyright notice,
>  *     this list of conditions and the following disclaimer.
>  *
>  *     Redistributions in binary form must reproduce the above copyright 
> notice,
>  *     this list of conditions and the following disclaimer in the 
> documentation
>  *     and/or other materials provided with the distribution.
>  *
>  *     Neither the name of the University of Chicago nor the names of its
>  *   contributors may be used to endorse or promote products derived from
>  *   this software without specific prior written permission.
>  *
>  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
>  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
>  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
>  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
>  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
>  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
>  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
>  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
>  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
>  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
> SOFTWARE,
>  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>  *
>  * Nick Collier
>  * address@hidden
>  *
>  * packages cern.jet.random.*
>  * Copyright (c) 1999 CERN - European Laboratory for Particle
>  * Physics. Permission to use, copy, modify, distribute and sell this
>  * software and its documentation for any purpose is hereby granted without
>  * fee, provided that the above copyright notice appear in all copies
>  * and that both that copyright notice and this permission notice appear in
>  * supporting documentation. CERN makes no representations about the
>  * suitability of this software for any purpose. It is provided "as is"
>  * without expressed or implied warranty.
>  *
>  * Wolfgang Hoschek
>  * address@hidden
>  *$$*/
> package uchicago.src.sim.heatBugs;
> 
> import java.util.Vector;
> import java.util.ArrayList;
> import java.awt.event.ActionListener;
> import java.awt.event.ActionEvent;
> 
> import uchicago.src.sim.engine.*;
> import uchicago.src.sim.gui.*;
> import uchicago.src.sim.space.*;
> import uchicago.src.sim.util.SimUtilities;
> import uchicago.src.sim.event.SliderListener;
> 
> import uchicago.src.sim.analysis.Plot;
> 
> import cern.jet.random.Uniform;
> 
> /**
>  * A translation of the Swarm example simulation Heat Bugs. The heat bugs
>  * simulation consists of heat bugs - simple agents that absorb and expel heat
>  * and a heatspace which diffuses this heat into the area surrounding the
>  * bug. Heat bugs have an ideal temperature and will move about the space
>  * in attempt to achieve this idea temperature.
>  *
>  * @author Swarm Project and Nick Collier
>  * @version $Revision: 1.5.2.1 $ $Date: 2002/04/22 14:30:19 $
>  */
> 
> public class HeatBugsModel extends SimModelImpl {
> 
>   private int numBugs = 100;
>   private double evapRate = 0.99;
>   private double diffusionConstant = 1.0;
>   private int worldXSize = 100;
>   private int worldYSize = 100;
>   private int minIdealTemp = 17000;
>   private int maxIdealTemp = 31000;
>   private int minOutputHeat = 3000;
>   private int maxOutputHeat = 10000;
>   private float randomMoveProbability = 0.0f;
> 
>   private int pauseVal = -1;
>   private int refreshRate = 1;        // Added by GP 20020816
>   private int stepCount = 0;  // Added by GP 20020816
>   private Schedule schedule;
>   private ArrayList heatBugList = new ArrayList();
>   private Object2DTorus world;
>   private HeatSpace space;
> 
>   private DisplaySurface dsurf;
>   
>   public HeatBugsModel() {}
> 
>   private void buildModel() {
>     space = new HeatSpace(diffusionConstant, evapRate, worldXSize, 
> worldYSize);
>     world = new Object2DTorus(space.getSizeX(), space.getSizeY());
> 
>     for (int i = 0; i < numBugs; i++) {
>       int idealTemp = Uniform.staticNextIntFromTo(minIdealTemp, maxIdealTemp);
>       int outputHeat = Uniform.staticNextIntFromTo(minOutputHeat, 
> maxOutputHeat);
>       int x, y;
> 
>       do {
>         x = Uniform.staticNextIntFromTo(0, space.getSizeX() - 1);
>         y = Uniform.staticNextIntFromTo(0, space.getSizeY() - 1);
>       } while (world.getObjectAt(x, y) != null);
> 
>       HeatBug bug = new HeatBug(space, world, x, y, idealTemp, outputHeat,
>                                 randomMoveProbability);
>       world.putObjectAt(x, y, bug);
>       heatBugList.add(bug);
>     }
>   }
> 
>   private void buildDisplay() {
> 
>     Object2DDisplay agentDisplay = new Object2DDisplay(world);
>     agentDisplay.setObjectList(heatBugList);
> 
>     // 64 shades of red
>     ColorMap map = new ColorMap();
>     for (int i = 0; i < 64; i++) {
>       map.mapColor(i, i / 63.0, 0, 0);
>     }
>     
>     Value2DDisplay heatDisplay = new Value2DDisplay(space, map);
>     heatDisplay.setZeroTransparent(true);
>     heatDisplay.setDisplayMapping(512, 0);
>     dsurf.addDisplayable(heatDisplay, "Heat Space");
>     dsurf.addDisplayableProbeable(agentDisplay, "Bugs");
> //    dsurf.setSnapshotFileName("./heatBugPic");
> 
>     // UNCOMMENT BELOW TO CREATE A MOVIE
>     //dsurf.setMovieName("./HeatBugMovie", DisplaySurface.QUICK_TIME);
> 
>     addSimEventListener(dsurf);
>   }
> 
>   public void step() {
>     stepCount++;              // Added by GP 20020816
>     space.diffuse();
>     for (int i = 0; i < heatBugList.size(); i++) {
>       HeatBug bug = (HeatBug)heatBugList.get(i);
>       bug.step();
>     }
> 
>     space.update();
>     if(stepCount % refreshRate == 0) {
>                               // Added by GP 20020816
>       dsurf.updateDisplay();
>     }
>   }
> 
>   private void buildSchedule() {
>     schedule.scheduleActionBeginning(1, this, "step");
> 
> 
>     /*
>      * Older style hand coded inner classes, replaced by the step method
>      * and the single line of schedule code above.
> 
>     class HeatBugsRunner extends BasicAction {
>       public void execute() {
>         space.diffuse();
>         for (int i = 0; i < heatBugList.size(); i++) {
>           HeatBug bug = (HeatBug)heatBugList.get(i);
>           bug.step();
>         }
>         space.update();
>         dsurf.updateDisplay();
> 
> 
> 
>         //System.out.println("seed: " + getRngSeed());
>         //System.out.println(Uniform.staticNextIntFromTo(0, 100));
>         //System.out.println(normal.nextDouble());
> 
>       }
>     };
>     */
>   }
> 
>   public void begin() {
>     //setRngSeed(1972L);
>     buildModel();
>     buildDisplay();
>     buildSchedule();
> 
>     dsurf.display();
>   }
> 
>   public void setup() {
> 
>     if (dsurf != null)
>       dsurf.dispose();
>     dsurf = null;
>     schedule = null;
>     System.gc();
> 
>     dsurf = new DisplaySurface(this, "Heat Bugs Display");
>     registerDisplaySurface("Main", dsurf);
>     schedule = new Schedule(1);
> 
>     numBugs = 100;
>     evapRate = 0.99;
>     diffusionConstant = 1.0;
>     worldXSize = 100;
>     worldYSize = 100;
>     minIdealTemp = 17000;
>     maxIdealTemp = 31000;
>     minOutputHeat = 3000;
>     maxOutputHeat = 10000;
>     randomMoveProbability = 0.0f;
> 
>     pauseVal = -1;
>     refreshRate = 1;          // Added by GP 20020816
>     stepCount = 0;            // Added by GP 20020816
> 
>     heatBugList = new ArrayList();
>     world = null;
>     space = null;
>     setupCustomAction();
>   }
> 
>   public String[] getInitParam() {
>     String[] params = {"evapRate", "diffusionConstant", "maxIdealTemp",
>           "minIdealTemp", "maxOutputHeat", "minOutputHeat", "worldXSize",
>           "worldYSize", "numBugs", "refreshRate", "Pause", "Model"};
>     return params;
>   }
> 
>   public Schedule getSchedule() {
>     return schedule;
>   }
> 
>   public String getName() {
>     return "HeatBugs";
>   }
> 
>   private void setupCustomAction() {
> 
>     modelManipulator.init();
> 
>     // this adds a button to the Custom Action tab that
>     // will set the heat space to 0 heat when clicked
>     modelManipulator.addButton("Deep Freeze", new ActionListener() {
>       public void actionPerformed(ActionEvent evt) {
>         for (int i = 0; i < space.getSizeX(); i++) {
>           for (int j = 0; j < space.getSizeY(); j++) {
>             space.putValueAt(i, j, 0);
>           }
>         }
>         space.update();
>       }
>     });
> 
>     // this will add a slider to the Custom Action tab that will
>     // increment the output heat of each bug by a the slider amount.
>     // The code doesn't really work when trying to decrement the heat
>     // by sliding the slider to the left. But it is a good example
>     // of what you can do with a slider.
>     modelManipulator.addSlider("Increment Heat", 0, 100, 10, new 
> SliderListener() {
>       public void execute() {
>         for (int i = 0; i < heatBugList.size(); i++) {
>           HeatBug bug = (HeatBug)heatBugList.get(i);
>           int outputHeat = bug.getOutputHeat();
>           if (isSlidingLeft && !isAdjusting) {
>             outputHeat -= outputHeat * value * .01;
>           } else if (!isSlidingLeft && !isAdjusting) {
>             outputHeat += outputHeat * value * .01;
>           }
>           bug.setOutputHeat(outputHeat);
>         }
>       }
>     });
>   }
> 
>   // properties
>   public int getNumBugs() {
>     return numBugs;
>   }
> 
>   public void setNumBugs(int numBugs) {
>     this.numBugs = numBugs;
>   }
> 
>   public double getEvapRate() {
>     return evapRate;
>   }
> 
>   public void setEvapRate(double rate) {
>     evapRate = rate;
>   }
> 
>   public double getDiffusionConstant() {
>     return diffusionConstant;
>   }
> 
>   public void setDiffusionConstant(double constant) {
>     diffusionConstant = constant;
>   }
> 
>   public int getWorldXSize() {
>     return worldXSize;
>   }
> 
>   public void setWorldXSize(int size) {
>     worldXSize = size;
>   }
> 
>   public int getWorldYSize() {
>     return worldYSize;
>   }
> 
>   public void setWorldYSize(int size) {
>     worldYSize = size;
>   }
> 
>   public int getMinIdealTemp() {
>     return minIdealTemp;
>   }
> 
>   public void setMinIdealTemp(int temp) {
>     minIdealTemp = temp;
>   }
> 
>   public int getMaxIdealTemp() {
>     return maxIdealTemp;
>   }
> 
>   public void setMaxIdealTemp(int temp) {
>     maxIdealTemp = temp;
>   }
> 
>   public int getMinOutputHeat() {
>     return minOutputHeat;
>   }
> 
>   public void setMinOutputHeat(int heat) {
>     minOutputHeat = heat;
>   }
> 
>   public int getMaxOutputHeat() {
>     return maxOutputHeat;
>   }
> 
>   public void setMaxOutputHeat(int heat) {
>     maxOutputHeat = heat;
>   }
> 
>   public float getRandomMoveProbability() {
>     return randomMoveProbability;
>   }
> 
>   public void setRandomMoveProbability(float prob) {
>     randomMoveProbability = prob;
>   }
> 
>   /* Added by GP 20020816 */
>   public int getRefreshRate() {
>     return refreshRate;
>   }
> 
>   /* Added by GP 20020816 */
>   public void setRefreshRate(int rate) {
>     refreshRate = rate;
>   }
> 
>   public static void main(String[] args) {
>     uchicago.src.sim.engine.SimInit init = new 
> uchicago.src.sim.engine.SimInit();
>     HeatBugsModel model = new HeatBugsModel();
>     if (args.length > 0) init.loadModel(model, args[0], false);
>     else init.loadModel(model, null, false);
>   }
> }
> 
-- 
Nick Collier 
Social Science Research Computing 
University of Chicago 
http://repast.sourceforge.net



                  ==================================
   Swarm-Modelling is for discussion of Simulation and Modelling techniques
   esp. using 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]