swarm-support
[Top][All Lists]
Advanced

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

Re: Schedule question...


From: Marcus G. Daniels
Subject: Re: Schedule question...
Date: 16 Jun 1999 14:30:08 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.3.10

>>>>> "NG" == Natalie Guay <address@hidden> writes:

NG> ... How can I do this ???

Dynamic scheduling.

#import <simtools.h>
#import <activity.h>
#import <objectbase/Swarm.h>
#import <objectbase/SwarmObject.h>

@interface Market: SwarmObject
- step;
@end

@implementation Market
- step
{
  printf ("[market] step (%lu)\n", getCurrentTime ());
  return self;
}

@end

@interface AgentSwarm: Swarm
{
  id <Schedule> updateSchedule;
}
+ createBegin: aZone;
- activateIn: swarmContext;
- update;
@end

@implementation AgentSwarm
+ createBegin: aZone
{
  AgentSwarm *obj = [super createBegin: aZone];

  obj->updateSchedule = [Schedule create: aZone];
  return obj;
}

- activateIn: swarmContext
{
  [super activateIn: swarmContext];
  [updateSchedule activateIn: self];
  return [self getActivity];
}

- update
{
  printf ("[agents] update (%lu)\n", getCurrentTime ());
  [updateSchedule at: getCurrentTime () + 1
                  createActionTo: self
                  message: M(update)];
  return self;
}
@end

@interface Controller: Swarm
{
  id <Schedule> marketSchedule;
  id <Schedule> startUpdateSchedule;
}
+ createBegin: aZone;
- createEnd;
- activateIn: swarmContext;
- startUpdates;
@end

@implementation Controller

+ createBegin: aZone
{
  Controller *obj = [super createBegin: aZone];
  
  {
    id market = [Market create: aZone];
    id s = [Schedule createBegin: aZone];
    
    [s setRepeatInterval: 1];
    s = [s createEnd];
    [s at: 0 createActionTo: market message: M(step)];
    obj->marketSchedule = s;
  }
  obj->startUpdateSchedule = [Schedule create: aZone];
  return obj;
}

- createEnd
{
  [super createEnd];
  [startUpdateSchedule at: 2 createActionTo: self message: M(startUpdates)];
  return self;
}

- startUpdates
{
  id agentSwarm = [AgentSwarm create: self];

  printf ("[controller] startUpdates (%lu)\n", getCurrentTime ());
  [agentSwarm update];
  [agentSwarm activateIn: self];
  return self;
}

- activateIn: swarmContext
{
  [super activateIn: swarmContext];
  [startUpdateSchedule activateIn: self];
  [marketSchedule activateIn: self];
  return [self getActivity];
}

- run
{
  [self activateIn: nil];
  [[self getActivity] run];
  return self;
}

@end

int 
main (int argc, const char **argv)
{
  initSwarmBatch (argc, argv);

  [[Controller create: globalZone] run];

  return 0;
}

/*
Local Variables:
compile-command: "/opt/gnu/bin/gcc -o s3 -g -Wno-import 
-L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib 
-R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib 
-L/opt/SDGswarm/1.4.1/lib -L/opt/SDGzlib/1.1.3/lib -L/usr/local/X11/lib 
-R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib 
-L/opt/SDGhdf5/1.0.1/lib -I/opt/SDGswarm/1.4.1/include s3.m -lanalysis 
-lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase  -ldefobj 
-lcollections -lmisc  -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl 
-L/usr/openwin/lib -lhdf5 -lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread 
-lposix4"
End:
*/

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