Return-Path: <warlord@MIT.EDU>
Received: from central-city-carrier-station.mit.edu by po11.mit.edu (8.9.2/4.7) id PAA16201; Fri, 16 Aug 2002 15:08:25 -0400 (EDT)
Received: from manawatu-mail-centre.mit.edu (MANAWATU-MAIL-CENTRE.MIT.EDU [18.7.7.71])
	by central-city-carrier-station.mit.edu (8.9.2/8.9.2) with ESMTP id PAA14182;
	Fri, 16 Aug 2002 15:07:31 -0400 (EDT)
Received: from kikki.mit.edu (KIKKI.MIT.EDU [18.18.1.142])
	by manawatu-mail-centre.mit.edu (8.9.2/8.9.2) with ESMTP id PAA05973;
	Fri, 16 Aug 2002 15:07:31 -0400 (EDT)
Received: (from warlord@localhost) by kikki.mit.edu (8.9.3)
	id PAA08215; Fri, 16 Aug 2002 15:07:31 -0400 (EDT)
To: Sarah Y Siegel <ssiegel@MIT.EDU>
Cc: <sipb@MIT.EDU>
Subject: Re: java question
References: <Pine.GSO.4.30L.0208161340540.5699-100000@balder.mit.edu>
From: Derek Atkins <warlord@MIT.EDU>
Date: 16 Aug 2002 15:07:31 -0400
In-Reply-To: <Pine.GSO.4.30L.0208161340540.5699-100000@balder.mit.edu>
Message-ID: <sjmd6sifwr0.fsf@kikki.mit.edu>
Lines: 214
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

Hi,

There are a number of java hackers in SIPB, so hopefully someone can
help you.

Trying to limit the factors, what happens if you try:

        init.loadModel(model, "./Params.txt", false)

-derek

Sarah Y Siegel <ssiegel@MIT.EDU> writes:

> The answer to this email suggested that I contact you guys. Can you help
> me?
> 
> Thanks.
> 
> -----Original Message-----
> Date: Fri, 16 Aug 2002 13:14:35 -0400
> To: computing-help@MIT.EDU
> From: Sarah Y Siegel <ssiegel@MIT.EDU>
> Cc:
> Subject: java
> 
> 
> Can you guys help me with a java programming question, or is that more
> specific than you guys get into? I'm guessing it's too specific. If you
> can't, do you have a suggestion as where I could get help? I'm a grad
> student using java for a research project, and I so far haven't found
> anyone in the department who can help me out. And although over the
> summer I've had a couple friends I've asked for help, it would be great
> to have a consultant I could ask. This is my current question, which is
> on a program I've written using the java libraries RePast
> (repast.sourceforge.net):
> 
> > So I'm trying to set my simulation to run in batch mode so I
>  > can collect some
>  > data. So I set it up with a data recorder, everything works
>  > fine. Then I changed
>  > one line, from
>  >
>  > init.loadModel(model, null, false);  to
>  > init.loadModel(model, "./Params.txt", true);
>  >
>  > so I changed the parameters file from nothing to one that I
>  > wrote, and then
>  > changed the batch file parameter from false to true.
>  >
>  > It now compiles fine, but when I try to run it it gives me
>  > null pointer
>  > exceptions at these lines:
>  >         x = Random.uniform.nextIntFromTo(0,width-1);
>  >         y = Random.uniform.nextIntFromTo(0,height-1);
>  >
>  > I put in some print commands to see what was going on, and it
>  > does have the
>  > right, nonzero, integer values for width and height. Any ideas? I
> just
>  > can't figure out
>  > what in the world those lines could possibly have to do with
>  > running it as a
>  > batch file.
> 
>  > Thanks!
>  >
>  > Sarah
>  >
>  > p.s. Here's more of my code, iwth all the stuff I put in to
>  > try to figure out
>  > what was going on and the error I get in case that
>  > helps--log() is a method that
>  > prints out what's in the parentheses.
>  >
>  >     public static void main(String[] args) {
>  >         uchicago.src.sim.engine.SimInit init =
>  >             new uchicago.src.sim.engine.SimInit();
>  >         FixedSchellingModel model = new FixedSchellingModel();
>  >         init.loadModel(model, "./Params.txt", true);
>  >         //init.loadModel(model, null, false);
>  >     }
>  >
>  >     public void setup() {
>  >         super.setup();
>  >         if (dsurf != null) dsurf.dispose();
>  >
>  >                System.gc();
>  >         log("setting up");
>  >         dsurf = new DisplaySurface(this, "FixedSchelling Display");
>  >         registerDisplaySurface("Main", dsurf);
>  >         generateNewSeed();
>  >         Random.createUniform();
>  >
>  >         BaseController c = getController();
>  >         c.setCellHeight(cellSize);
>  >         c.setCellWidth(cellSize);
>  >         c.setCellDepth(cellSize);
>  >         setStoppingTime(5);
>  >     }
>  >     public void buildModel() {
>  >
>  >         // the "true" or "false" parameter refers to whether
>  > the space should be a
>  > torus
>  >         space = new FixedSchellingSpace(width, height, false, this);
>  >         setupSpace();
>  >         display = space.getDisplay();
>  >         dsurf.addDisplayableProbeable(display, "FixedSchelling
>  > Display");
>  >         ((Object2DDisplay)display).setObjectList(agentList);
>  >         dsurf.display();
>  >         buildCharts();
>  >         recorder = new DataRecorder("./data815.txt", this);
>  >         recorder.addNumericDataSource("avgUtility", new
>  > NumDataSource());
>  >     }
>  >
>  >
>  >     public void setupSpace() {
>  >         //log("random placement");
>  >         double n = ((double)(width * height)*(1-(vacancies/100)));
>  >         int n1 = (int)Math.round(n*type1percent/100);
>  >         int n2 = (int)Math.round(n-n1);
>  >         //log("n1 = " + n1 + " and n2 = " + n2 + " and width =
>  > " + width + " and height
>  > = " + height);
>  >         for (int i= 0; i < n1; i++){
>  >             int x = 10;
>  >             try{
>  >                 x = Random.uniform.nextIntFromTo(0,width-1);
>  >             }
>  >             catch (NullPointerException e){
>  >                 log("something weird here");
>  >
>  >             }
>  >
>  >             int y = Random.uniform.nextIntFromTo(0,height-1);
>  >             //   System.out.println("checking if empty at " + x
>  > + ", " + y);
>  >             while (!space.isEmptyAt(x,y)){
>  >                 x = Random.uniform.nextIntFromTo(0,width-1);
>  >                     y = Random.uniform.nextIntFromTo(0,height-1);
>  >             }
>  >             FixedSchellingAgent agent = new
>  > FixedSchellingAgent(x, y, 1, 11, space);
>  >             space.addAgent(agent);
>  >             agentList.add(agent);
>  >         }
>  >
>  >         for (int i= 0; i < n2; i++){
>  >             int x = Random.uniform.nextIntFromTo(0,width-1);
>  >             int y = Random.uniform.nextIntFromTo(0,height-1);
>  >             while (!space.isEmptyAt(x,y)){
>  >                 x = Random.uniform.nextIntFromTo(0,width-1);
>  >                     y = Random.uniform.nextIntFromTo(0,height-1);
>  >             }
>  >             FixedSchellingAgent agent = new
>  > FixedSchellingAgent(x, y, 2, 21, space);
>  >             space.addAgent(agent);
>  >             agentList.add(agent);
>  >         }
>  >
>  >     }
>  >
>  >     public void step() {
>  >
>  >         //log("stepping!");
>  >         SimUtilities.shuffle(agentList);
>  >         int size = agentList.size();
>  >         for (int i = 0; i < size; i++) {
>  >             FixedSchellingAgent agent =
>  > (FixedSchellingAgent)agentList.get(i);
>  >             agent.step();
>  >         }
>  >         graph.step();
>  >         dsurf.updateDisplay();
>  >         recorder.record();
>  >     }
>  >
>  > and what prints out is:
>  >
>  > setting up
>  > Run: 1
>  > something weird here
>  > java.lang.NullPointerException
>  >         at
>  > edu.santafe.csss.fixedschelling.FixedSchellingModel.setupSpace
>  > (FixedSchellingModel.java:146)
>  >         at
>  > edu.santafe.csss.fixedschelling.FixedSchellingModel.buildModel
>  > (FixedSchellingModel.java:119)
>  >         at
>  > uchicago.src.sim.engine.SimpleModel.begin(SimpleModel.java:104)
>  >         at
>  > uchicago.src.sim.engine.BaseController.startSim(BaseController
>  > .java:345)
>  >         at
>  > uchicago.src.sim.engine.BatchController.start(BatchController.
>  > java:412)
>  >         at
>  > uchicago.src.sim.engine.BatchController$1.run(BatchController.
>  > java:383)
>  >         at java.lang.Thread.run(Thread.java:484)
>  > Batch Done
>  >
>  >
>  >
> 

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord@MIT.EDU                        PGP key available
