swarm-support
[Top][All Lists]
Advanced

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

Re: modelProbeMap in simpleExperSwarm.m


From: Zafar Iqbal
Subject: Re: modelProbeMap in simpleExperSwarm.m
Date: Sat, 12 Sep 1998 14:08:19 +0100 (BST)

Hi,
thanks for your help - much appreciated.

Looking through the tutorial and my 
own code I am still unable to resolve the display problem. 
Note I now have my prog along the ObserverBug2 framework.
The worldRaster is displayed but no agents. The program 
gets 'stuck' at the line (see below for complete code)
 agentDisplay = [agentDisplay createEnd];

No error is produced the prog just hangs up. I can't see 
why this is. It may possibly be something to do with the
[controlPanel setStateStopped]; command because in my code 
it is commented out but the program still stops. If I 
uncomment it I need to press start twice and the 
worldRaster widget isn't displayed at all.

I'm using the binary install of swarm-1.1

The code for my prog is :
- buildObjects
{
  // Creation of objects used by the experiment swarm itself
  // First, let our superClass build any objects it needs 
  [super buildObjects];
 
  modelSwarm = [ModelSwarm create: self];

 
  // Build a probeDisplay on ourself
  CREATE_ARCHIVED_PROBE_DISPLAY (modelSwarm);

  CREATE_ARCHIVED_PROBE_DISPLAY (self);

  // Allow the user to alter experiment parameters
//  [controlPanel setStateStopped];
printf("Zzzzzzzzzzzzzz11111111");

  // Let the modelSwarm build its objects and actions and activate
  // it in "nil", giving us a new activity. We don't start it here...
  // we will start models from the ExperSwarm schedule.
  [modelSwarm buildObjects];

printf("333333333333333");  
  // -----------------
   //Build the colorMap, which is used by many objects
  colorMap = [Colormap create: self];

  [colorMap setColor: 0 ToName: "black"];
  [colorMap setColor: 1 ToName: "red"];
  [colorMap setColor: 2 ToName: "green"];
  [colorMap setColor: 3 ToName: "blue"];


  // Next, create a 2d window for display, set its size, zoom factor, title.
  worldRaster = [ZoomRaster createBegin: self];
  SET_WINDOW_GEOMETRY_RECORD_NAME(worldRaster);
  worldRaster = [worldRaster createEnd];
  [worldRaster setColormap: colorMap];
  [worldRaster setZoomFactor: 4];
  [worldRaster setWidth: [[modelSwarm getWorld] getSizeX] 
                  Height: [[modelSwarm getWorld] getSizeY]];
  [worldRaster setWindowTitle: "Agent & plot world"];
  [worldRaster pack];                             // draw the window.
printf("Zzzzzzzzzzzzzz3333");

  // Create an Object2dDisplay: this object draws agents on
  // the worldRaster widget for us.
  agentDisplay = [Object2dDisplay createBegin: self];
printf("xxxxxxxxxxxxxxx1\n");

  [agentDisplay setDisplayWidget: worldRaster];
printf("xxxxxxxxxxxxxxx2\n");

  [agentDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]];
printf("xxxxxxxxxxxxxxx3\n");

  [agentDisplay setObjectCollection: [modelSwarm getAgentList]];
printf("xxxxxxxxxxxxxxx4\n");

  [agentDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
printf("xxxxxxxxxxxxxxx5\n");

  agentDisplay = [agentDisplay createEnd];
printf("Zzzzzzzzzzzzzz4444");



  // And also create an Object2dDisplay: for plots of land
  plotDisplay = [Object2dDisplay createBegin: self];
  [plotDisplay setDisplayWidget: worldRaster];
  [plotDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]];
  [plotDisplay setObjectCollection: [modelSwarm getPlotList]];
  [plotDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
  plotDisplay = [plotDisplay createEnd];
 
printf("Zzzzzzzzzzzzzz555");

  // Tell the world raster to send mouse clicks to the agentDisplay
  // this allows the user to right-click on the display to probe the agents.
  [worldRaster setButton: ButtonRight
               Client: agentDisplay
               Message: M(makeProbeAtX:Y:)];

  // Also tell the world raster to send mouse clicks to the plotDisplay
  // this allows the user to right-click on the display to probe the plots.
  [worldRaster setButton: ButtonRight
               Client: plotDisplay
               Message: M(makeProbeAtX:Y:)];
printf("Zzzzzzzzzzzzzz6666");

  // Build the graph widget to display totalSoil
  soilGraph = [EZGraph createBegin: self];
  SET_WINDOW_GEOMETRY_RECORD_NAME (soilGraph);
  [soilGraph setTitle: "Total soil in plots"];
  [soilGraph setAxisLabelsX: "Total soil" Y: "Run Time"];
  soilGraph = [soilGraph createEnd] ;  
  // A sequence to track total soil
 [soilGraph createSequence: "totSoil"
                 withFeedFrom: [modelSwarm getPlotList]
                  andSelector: M(getTotSoil)];
  return self;
}


****************
The code where agentList is created is:
- buildObjects
{
  PlotsOfLand *aPlotOfLand;
  Agent *anAgent;
  int x,y;
  int nagents;
  float dist, xDist, yDist;

  world = [Grid2d createBegin: self];
  [world setSizeX: worldXSize Y: worldYSize];
  world = [world createEnd];

  [world fillWithObject: nil];

  // Now, create agents to live in the world 
  // and a list to manage them
  agentList = [List create: self];

  nagents = 0;
  totalSoil= 0.0;
printf("m1");  
  for (y = 0; y < worldYSize; y++)
    for (x = 0; x < worldXSize; x++) 
      if ([uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0] <= agentDensity)
        {
          anAgent = [Agent createBegin: self];
          [anAgent setWorld: world];
          anAgent = [anAgent createEnd];
          
          [anAgent setX: x Y: y];
          [anAgent setAgentType: 1];
          [world putObject: anAgent atX: x Y: y];
          
          [agentList addLast: anAgent];
          
          nagents++;
        }
  if (nagents > -1) 
    {
      nagents--;
    }
  printf("m2\n");
  // Now, create plots of land for each agent.
  // Randomly pick x & y co-ords until each agent has a plot of land.
  plotList = [List create: self];
  while (nagents > 0)
    {
      x = [uniformIntRand getIntegerWithMin: 0 withMax: worldXSize];
      y = [uniformIntRand getIntegerWithMin: 0 withMax: worldYSize];
      if ([world getObjectAtX: x Y: y] == nil)
        {
          aPlotOfLand = [PlotsOfLand createBegin: self];
          [aPlotOfLand setWorld: world];
          [aPlotOfLand setModelSwarm: self];

          aPlotOfLand = [aPlotOfLand createEnd];
          
          [aPlotOfLand setX: x Y: y];
          [aPlotOfLand setAgentType: 0];
          [aPlotOfLand initializePlots];
          [world putObject: aPlotOfLand atX: x Y: y];
          
          [plotList addLast: aPlotOfLand];
//   printf("m3  nagents=%d \n",nagents);
          xDist = ([[agentList atOffset: nagents] getXpos]);
          yDist = ([[agentList atOffset: nagents] getYpos]);
          xDist = xDist * xDist;
          yDist = yDist * yDist;
          //note: agentList(i) = plotList(i).
          dist = (float) sqrt((int)(xDist + yDist));
          //set distance using nagents as offset.
          [[agentList atOffset: nagents] setDistance: dist]; 
          
          totalSoil += [aPlotOfLand getSoil];
          nagents--;
        }
    }  
  time = 0;
  
  return self;
}

----------------------
Zafar Iqbal
address@hidden


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