swarm-support
[Top][All Lists]
Advanced

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

Re: Activity bug or Paul's mistake?


From: Doug Donalson
Subject: Re: Activity bug or Paul's mistake?
Date: Fri, 3 Mar 2000 10:35:08 -0800

WARNING: Everything below may be incorrect.  My best guess with little
sleep!

Paul,

   You schedule a bunch of actions at 0.  One of those is to create agent2.
However, as part of those you also schedule actions to agent 2.  At that
point, agent2 is NULL and that is what the schedule gets.  Now, I may be
wrong, but I don't believe that changing agent2 to something later will
change the NULL value already entered into the schedule.

Think about it this way: (pseudo code follows, meant for demonstration ONLY,
not for accuracy!!!!)
-----------------------------------------------------------------
int time=0;

atTime: time createActionTo: self message: M(whatever);

time=10;
------------------------------------------------------------------

The time of the action will still be 0, not 10, even though you changed the
value of the variable time.  This is because you pass a value, not a
reference.  Does this make any sense?

Cheers,

   D3

----- Original Message -----
From: Paul Johnson <address@hidden>
To: Swarm-support <address@hidden>
Sent: Friday, March 03, 2000 9:48 AM
Subject: Activity bug or Paul's mistake?


> Dear everybody:
>
> I could direct this question just to Marcus, but I'm so proud of my work
> that I am imposing it on all of you (and the archive) too.
>
> Last week I came across a problem in a program and I thought it was
> happening because I did not understand how to pass objects by reference.
> But that had nothing to do with it.  After many hours of struggle, I've
> finally reproduced the problem in a smallish test program, that I'm
> including at the end of this note.
>
> The kernel of the problem is this.  Should I be able to put objects into
> a schedule when they are created/altered by previous steps in that
> schedule.  The ModelSwarm has 2 agents, agent and agent2.  The first is
> created in buildObjects, the second is created "on the fly" by the
> scheduled action #2 below.  That action does run, the printout to the
> console confirms that agent2 is created.  However, when item #4 runs, it
> sees agent2 as nil still.  This problem came up in another project and
> it has driven me crazy because I kept getting "frozen" objects in
> schedules.
>
>
>
> - buildActions
> {
>
>   [super buildActions];
>
>   schedule = [[[Schedule createBegin: self]
>                setRepeatInterval: 1]
>                createEnd];
>   [schedule at: 0 createActionTo: agent  message: M(printValue)];
>   [schedule at: 0  createActionTo: self message:
> M(createAgent:Arg:):agent2:(id)2];  file://#2
>   [schedule at: 0 createActionTo: self message: M(updateAgent:):agent];
>   [schedule at: 0  createActionTo: self message:
> M(updateAgent:):agent2]; file://#4
>   [schedule at: 0 createActionTo: agent  message: M(printValue)];
>   [schedule at: 0 createActionTo: agent2  message: M(printValue)];
>   return self;
> }
>
> Should this work or have I constructed a monster, or both?
>
> #import <simtools.h>
> #import <analysis.h>
> #import <defobj/Create.h>
> #import <objectbase.h>
> #import <simtoolsgui/GUISwarm.h>
> #import <random.h>
>
>
> @interface Agent: CreateDrop
> {
>   int ident;
>   double value[2];
> }
> - setAgentValue: (double*)value;
>
> - updateValue;
> - printValue;
> - (double)getValue1;
>
> - setID: (int)x;
>
> @end
>
> @implementation Agent
> - setAgentValue: (double*)theValue
> {
>   value[0] = theValue[0];
>   value[1] = theValue[1];
>   return self;
> }
>
>
> - updateValue
> {
>   int i;
>   for (i=0; i<2;i++)
>     {
>     value[i]= [uniformDblRand getDoubleWithMin: 0L withMax: 10];
>     }
>   return self;
> }
>
> -(double)getValue1
> {
>   return value[0];
> }
>
> -setID: (int)x
> {
>   ident=x;
>   return self;
> }
>
> - printValue
> {
>   int i;
>   printf("Agent %d value is\n", ident);
>   for(i=0; i<2; i++)
>     printf("%f ", value[i]);
>   printf("\n");
>   return self;
> }
>
> @end
>
>
>
>
> @interface ModelSwarm: Swarm
> {
>   id <Schedule> schedule;
>     id <List> list;
>   id agent, agent2, agent3, agent4;
> }
> - createEnd;
> - updateAgent: ag;
> - createAgent: ag Arg: (int) integ;
> - buildObjects;
> - buildActions;
>
> @end
>
> @implementation ModelSwarm
>
> #define AGENT(val) [[[Agent createBegin: globalZone] setAgentValue: val]
> createEnd]
>
> - createEnd
> {
>   [super createEnd];
>
>    return self;
> }
>
> -buildObjects
> {
>   int i;
>   double val[2];
>   [super buildObjects];
>   for(i=0;i<2;i++)
>     {
>     val[i]= [uniformDblRand getDoubleWithMin: 0L withMax: 10];
>     }
>
>   agent= AGENT ( val  );
>    [agent setID: 1];
>
>   for(i=0;i<2;i++)
>     val[i]= [uniformDblRand getDoubleWithMin: 0L withMax: 10];
>
>   return self;
> }
>
> -createAgent: ag Arg: (int) integ
> {
>   ag= [Agent create: self];
>   [ag setID: integ];
>
>   printf("Agent %d Exists, but has no value set yet.  Here is its xprint
> \n", integ);
>   xprint(ag);
>   printf("Here is Agent %d's response to the printValue
> message\n",integ);
>   [ag printValue];
>   printf("end of agent creation \n");
>   return self;
> }
>
> - updateAgent:ag
> {
>   int i;
>   double val[2];
>
>   printf("Update agent to: \n");
>
>    for(i=0;i<2;i++)
>     val[i]= [uniformDblRand getDoubleWithMin: 0L withMax: 10];
>    [ag setAgentValue: val];
>    [ag printValue];
>    return self;
> }
>
> - buildActions
> {
>   [super buildActions];
>
>   schedule = [[[Schedule createBegin: self]
>                setRepeatInterval: 1]
>                createEnd];
>   [schedule at: 0 createActionTo: agent  message: M(printValue)];
>   [schedule at: 0  createActionTo: self message:
> M(createAgent:Arg:):agent2:(id)2];
>   [schedule at: 0 createActionTo: self message: M(updateAgent:):agent];
>   [schedule at: 0  createActionTo: self message:
> M(updateAgent:):agent2];
>   [schedule at: 0 createActionTo: agent  message: M(printValue)];
>   [schedule at: 0 createActionTo: agent2  message: M(printValue)];
>   return self;
> }
>
> - activateIn: swarmContext
> {
>   [super activateIn: swarmContext];
>   [schedule activateIn: self];
>   return [self getActivity];
> }
> @end
>
>
>
>
> @interface ObserverSwarm: GUISwarm
> {
>   id modelSwarm;
> }
> +createBegin: aZone;
> -buildObjects;
> -buildActions;
> -activateIn: aZone;
> @end
>
> @implementation ObserverSwarm
>
> +createbegin: aZone
> {
>
>
>   return [super createBegin: aZone];
>
> }
>
> -buildObjects
> {
>   [super buildObjects];
>    modelSwarm=[ModelSwarm create: self];
>   [controlPanel setStateStopped];
>   [modelSwarm buildObjects];
>   return self;
> }
> -buildActions
> {
>   [super buildActions];
>   [modelSwarm buildActions];
>   return self;
> }
>
> -activateIn: aZone
> {
>   [super activateIn: aZone];
>   [modelSwarm activateIn: self];
>     return [self getActivity];
> }
>
>
> int
> main (int argc, const char **argv)
> {
>   id swarm;
>
>   initSwarm (argc, argv);
>
>   swarm = [ObserverSwarm create: globalZone];
>
>   [swarm buildObjects];
>   [swarm buildActions];
>   [swarm activateIn: nil];
>   [swarm go];
>
>   return 0;
> }
>
> /*
> Local Variables:
> compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc
> -D_GNU_SOURCE -o testapp -g -Wno-import \
>  -I$SWARMHOME/include -I$SWARMHOME/include/swarm -L$SWARMHOME/lib \
>  -L$SWARMHOME/lib/swarm PJActivityProblem.m -lswarm -lobjc "
> End:
> */
>
>
> --
> Paul E. Johnson                       email: address@hidden
> Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
> University of Kansas                  Office: (785) 864-9086
> Lawrence, Kansas 66045                FAX: (785) 864-5700
>
>                   ==================================
>    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.
>


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