swarm-support
[Top][All Lists]
Advanced

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

Java questions


From: William T. Stockhausen
Subject: Java questions
Date: Mon, 16 Jul 2001 13:25:21 -0400

Hi all,

I'm trying to develop a Java-based Swarm predator-prey model for blue crabs
in fragmented seagrass habitats.  Although I'm relatively experienced with
developing computer models in other languages (e.g., IDL, Fortran), Swarm is
my first experience in Objective C and Java.  Since I had a choice, I chose
to go the Java route, with the hope that whatever Java experience I gained
might be useful in other, non-Swarm applications.

First, let me describe my sytem setup.  I'm running Swarm on a Windows NT
4.0 platform (I installed it to "G:\ProgramFiles\Swarm-2.1.1" using the
binary executable).  I have also installed Sun's JDK 1.3.1 in
"G:\ProgramFiles\jdk1.3.1" while the runtime is in "C:\Program
Files\JavaSoft\jre\1.3.1"  As explained in the FAQs, I modified my
.bash_login file to add the jdk1.3.1/bin to the PATH, as well as the
swarm.jar to the ClASSPATH. To top it off, I'm using MS Visual J++ 6.0 as an
IDE (I've done some VisualBasic programming using MS Visual Studio, which is
why I happend to have it).  Believe it or not, it seems to be more
successful than not, although I don't really have any idea of what sort of
mess I'm creating for myself.

Which brings me to my first problem, although it seems fairly minor.  I can
code and compile in Visual J++ (compilation using something called
JView.exe, with a project-specific CLASSPATH pointing toward the swarm.jar
and the SUN jdk rt.jar).  When JView goes to run the application, a terminal
window pops up, but I get the error message
        "ERROR: unable to locate system class: java/lang/String"
and the terminal window closes when I press a key.  However, if I open up a
Swarm terminal, I can run the compiled classes using javaswarm (e.g.,
"javaswarm StartSeascapeSim", where StartSeascapeSim contains "main")--and
everything seems to run fine.  Has anyone else run into this problem, or am
I the only person using Visual J++?  Anything I can do to get JView to
actually run the application?

My second problem is a bit more involved.  I've modified the jheatbugs code
into a seascape model.  I've taken out the "bugs" portion of things (for the
moment) and have modified the Heatscape class into a Seascape class. The
Seascape class provides methods to create a stochastic seascape of sand and
seagrass habitats.  At present, running the model creates a new seascape
over 3 model steps--mainly just to see whether creation of the seascape
looks like its working.  I've added a custom probe map capability to the
Seascape class (I'd like to be able to modify parameters while the model
steps) by adding a private class to Seascape (ala what's done in the
Observer Swarm and Model Swarm codes).  Here's the constructor for Seascape:
//--------------------------------------------------------------------------
-------------------
  public Seascape (Zone aZone, int worldXSize, int worldYSize) {
    sizeX = worldXSize;
    sizeY = worldYSize;
    finalLattice = new Discrete2dImpl (aZone, sizeX, sizeY);
    workingLattice = new Discrete2dImpl (aZone, sizeX, sizeY);
    pPercolationMap = 0.2;
    pSand = 0.5;
    pSeagrass = 0.5;

    int i;
    for ( i=0;i<nTypes ;i++ )  clrType[i] = (byte) i;

    cold = 0;
          stepCount = 0;

    // Now, build a customized probe map using a `local' subclass
    // (a special kind of Java `inner class') of the
    // EmptyProbeMapImpl class.  Without a probe map, the default
    // is to show all variables and messages. Here we choose to
    // customize the appearance of the probe, give a nicer
    // interface.
    class SeascapeProbeMap extends EmptyProbeMapImpl {
      private VarProbe probeVariable (String name) {
        return
          Globals.env.probeLibrary.getProbeForVariable$inClass
          (name, Seascape.this.getClass ());
      }
      private MessageProbe probeMessage (String name) {
        return
          Globals.env.probeLibrary.getProbeForMessage$inClass
          (name, Seascape.this.getClass ());
      }
      private void addVar (String name) {
        addProbe (probeVariable (name));
      }
      private void addMessage (String name) {
        addProbe (probeMessage (name));
      }
      public SeascapeProbeMap (Zone _aZone, Class aClass) {
        super (_aZone, aClass);
        System.out.println ("Creating SeascapeProbeMap.\n");
        addVar ("pPercolationMap");
        addVar ("pSand");
        addVar ("pSeagrass");
        addMessage ("createPercolationMap");
        addMessage ("classifyClusters");
        addMessage ("createHabitatDistribution");
      }  // public SeascapeProbeMap (Zone _aZone, Class aClass)
<--constructor
    } // class SeascapeProbeMap extends EmptyProbeMapImpl

    // Install our custom probeMap class directly into the probeLibrary
    try{
      Globals.env.probeLibrary.setProbeMap$For
      (new SeascapeProbeMap (aZone, getClass ()), getClass ());
    }  catch (Exception e) {
      System.err.println ("Exception SeascapeProbeMap creation: " +
e.getMessage ());
    }
    System.out.println ("Seascape construction. SeascapeProbeMap set.\n");

  }  // public Seascape (Zone aZone, int worldXSize, int worldYSize)
<--constructor

The syntax for the probe map is taken almost directly out of the
ObserverSwarm code.  The following lines deal with creation of a Seascape
object and probe in the Model Swarm:

    seascape = new Seascape (getZone (), worldXSize, worldYSize);
    seascape.setPercolationMapProbability (pPercolationMap);
    seascape.setPctSand (pSand);
    seascape.setPctSeagrass (pSeagrass);
    seascape.createPercolationMap ();
    seascape.classifyClusters ();
    seascape.createHabitatDistribution ();
    System.out.println ("seascape class = "+seascape.getClass()+"\n");
    System.out.println ("seascapeModelSwarm. Creating SeascapeProbeMap.\n");
//    try{
//      Globals.env.createArchivedProbeDisplay (seascape,"seascape");
//    } catch (Exception e) {
//      System.err.println ("Exception in seascapeModelSwarm.
SeascapeProbeMap creation: " + e.getMessage ());
//    }
    System.out.println ("seascapeModelSwarm. Created SeascapeProbeMap.\n");

The code runs fine as is (i.e., with probe map creation commented out).
When I uncomment the commented-out lines to create the probe map, it
compiles in Visual J++ with no errors. When I run the application using
javaswarm, the program passes the second print statement successfully but
then fails with the messages:

        *** event raised for error: InvalidArgument
        *** function: nil_method(), file: 
/src/Swarm/swarm/src/defobj/internal.m,
line:
        1349
        The message 'getClass' was sent to nil.
        *** execution terminating due to error
        /src/Swarm/swarm/src/defobj/Symbol.m:173 -[Error(c) _raiseEvent:]
                0 [sig] Kaffe 1103 stackdump: Dumping stack trace to 
Kaffe.exe.stackdump

ANY suggestions as to how to proceed will be most appreciated.

Best regards,

Buck Stockhausen
***********************************************************************
*William T. Stockhausen                     e-mail: address@hidden     *
*Marine Scientist                           voice : 804-684-7643      *
*Virginia Institute of Marine Science       fax   : 804-684-7250      *
*College of William and Mary                http://www.vims.edu/~buck *
*PO Box 1346                                                          *
*Gloucester Point, VA 23062                                           *
***********************************************************************


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