[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Modeling time of day tasks
From: |
Marcus G. Daniels |
Subject: |
Re: Modeling time of day tasks |
Date: |
Mon, 18 Jun 2001 10:37:52 -0600 (MDT) |
KV> I am trying to get my agents to perform certain tasks during certain
KV> times during the day. Can anyone tell me how to model time of day
KV> tasks in swarm?
Here's an example of a repeating schedule for a day's events.
(There's a separate schedule for killing the model that runs on a
multiplied timescale.)
#import <simtools.h>
#import <activity.h>
#import <objectbase.h>
#import <objectbase/Swarm.h>
#define LASTDAY 5
@interface Model: Swarm
{
unsigned day;
id <Schedule> schedule;
id <Schedule> stopSchedule;
}
@end
@implementation Model
+ createBegin: aZone
{
Model *obj = [super createBegin: aZone];
obj->day = 0;
return obj;
}
- (void)die
{
[getCurrentSwarmActivity () terminate];
}
- (void)newDay
{
printf ("new day #%u @ %u\n", day, getCurrentTime ());
day++;
}
- (void)wakeUp
{
printf ("wake up @ %u\n", getCurrentTime ());
}
- (void)startWork
{
printf ("start work @ %u\n", getCurrentTime ());
}
- (void)lunch
{
printf ("lunch @ %u\n", getCurrentTime ());
}
- (void)resumeWork
{
printf ("resume work @ %u\n", getCurrentTime ());
}
- (void)goHome
{
printf ("go home @ %u\n", getCurrentTime ());
}
- (void)sleep
{
printf ("sleep @ %u\n", getCurrentTime ());
}
- buildActions
{
stopSchedule = [Schedule create: self];
[stopSchedule at: LASTDAY * 24 createActionTo: self message: M(die)];
schedule = [Schedule create: self setRepeatInterval: 24];
[schedule at: 0 createActionTo: self message: M(newDay)];
[schedule at: 7 createActionTo: self message: M(wakeUp)];
[schedule at: 8 createActionTo: self message: M(startWork)];
[schedule at: 12 createActionTo: self message: M(lunch)];
[schedule at: 13 createActionTo: self message: M(resumeWork)];
[schedule at: 17 createActionTo: self message: M(goHome)];
[schedule at: 23 createActionTo: self message: M(sleep)];
return self;
}
- (id <Activity>)activateIn: (id <Swarm>)swarmContext
{
[super activateIn: swarmContext];
[stopSchedule activateIn: self];
[schedule activateIn: self];
return [self getActivity];
}
@end
int
main (int argc, const char **argv)
{
initSwarmBatch (argc, argv);
{
id model = [Model create: globalZone];
[model buildObjects];
[model buildActions];
[[model activateIn: nil] run];
}
}
/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc
-DAPPNAME=timeofday -D_GNU_SOURCE -o timeofday -g -Wno-import
-I$SWARMHOME/include -L$SWARMHOME/lib timeofday.m -lswarm -lobjc"
End:
*/
==================================
Swarm-Modelling is for discussion of Simulation and Modelling techniques
esp. using Swarm. For list administration needs (esp. [un]subscribing),
please send a message to <address@hidden> with "help" in the
body of the message.
==================================