swarm-support
[Top][All Lists]
Advanced

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

Re: start a model schedule in the future?


From: Marcus G. Daniels
Subject: Re: start a model schedule in the future?
Date: 20 May 2000 12:14:23 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "RLR" == Rick Riolo <address@hidden> writes:

RLR> I'd like to start a model schedule at a time > 0, but then have
RLR> it repeat forever

Use setRelativeTime: on the Schedule that you want to repeat and
activate it from another Schedule, like below.  This one has an additional
schedule to shut down the run, but never mind that...

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

@interface Market: SwarmObject
- (void)stepMarket;
@end

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

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

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

  obj->updateSchedule = [[[[Schedule createBegin: aZone]
                            setRepeatInterval: 5]
                           setRelativeTime: YES]
                          createEnd];
  
  return obj;
}

- createEnd
{
  [super createEnd];
  [updateSchedule at: 2 createActionTo: self message: M(update)];
  return self;
}
  
- activateIn: swarmContext
{
  [super activateIn: swarmContext];
  [updateSchedule activateIn: self];
  return [self getActivity];
}

- (void)update
{
  printf ("[agents] update (%lu)\n", getCurrentTime ());
}
@end

@interface Controller: Swarm
{
  id <Schedule> marketSchedule;
  id <Schedule> startUpdateSchedule;
  id <Schedule> stopSchedule;
}
+ createBegin: aZone;
- createEnd;
- activateIn: swarmContext;
- startUpdates;
- (void)quit;
@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(stepMarket)];
    obj->marketSchedule = s;
  }
  obj->startUpdateSchedule = [Schedule create: aZone];
  obj->stopSchedule = [Schedule create: aZone];
  return obj;
}

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

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

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

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

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

- (void)quit
{
  [[self getActivity] terminate];
}

@end

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

  [[Controller create: globalZone] run];

  return 0;
}

/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -o 
startLateThenRepeat -Wall -Werror -g -Wno-import -I$SWARMHOME/include/swarm 
-L$SWARMHOME/lib/swarm startLateThenRepeat.m -lswarm -lobjc"
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]