swarm-support
[Top][All Lists]
Advanced

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

Re: scheduling quandry


From: Paul E Johnson
Subject: Re: scheduling quandry
Date: Wed, 12 Jul 2000 10:27:21 -0500

"Marcus G. Daniels" wrote:
> 
> >>>>> "PJ" == Paul E Johnson <address@hidden> writes:
> 
> I don't mean to restructure the bugs, just to activate them in
> an intermediate Swarm.  As I understand you, you want to have the
> ModelSwarm do something in fixed way relative to concurrent events in
> a subswarm.  If you have ModelSwarm [ BugSwarm [ Bug{A,B} ]], then you
> can tell BugSwarm to shuffle BugA and BugB events but have the
> ModelSwarm announcement message happen first by virtue of being a
> standard ActivationOrder Swarm.
> 
> Specifically, I modified your code like so:
> 
Yes, I understood your original point perfectly and was writing a
program which turned out almost exactly identical to your.

My question was just for my educational purpose and fun, to see if I
understand scheduling.  I rewrote the program you posted so that the
bugSwarm creates a "masterSchedule" and all bugs are allowed to attach
their actions to it, rather than having each bug maintain its separate
schedule.  I am puzzled because the randomization of actions at the same
time seems to be broken. On my system, all the actions after the first
have bugB before bugA.  What do you think? 

// decentralized scheduling using customized schedule type to
// randomize events that arrive on the scheduling mechanism for the
// same time.  

// pjrepeater4 note: Problem with pjrepeater3: all events at time X are
// randomized, including events scheduled by both and the ModelSwarm.
// We only want the agent actions to be randomized, kept separate from
// ModelSwarm record keeping and so forth.  pjrepeater4, by Marcus
// Daniels, adds a "bugSwarm" layer to address this problem.

// pjrepeater5 note: I (PJ) wondered if a schedule ("masterSchedule")
// could be created that all the bugs can use, rather than have
// each bug owning its own schedule object. And would such a design
// use less memory or run faster than the other way. 
 

#import <simtools.h>
#import <simtoolsgui/GUISwarm.h>
#import <objectbase/Swarm.h>

@interface Bug: Swarm
{
 id schedule;
}

- buildActions;
- scheduleSelfAt: (int) x;
- setSchedule: sch;
- step;
@end

@implementation Bug
- scheduleSelfAt: (int) x
{
  [schedule at: x createActionTo: self message: M(step)];
  return self;
}

- buildActions
{
  [super buildActions];
   return self;
}

- setSchedule: sch
{
  schedule= sch;
  return self;
}


- step
{
  printf ("I'm %s, and the current time is %ld\n",
          [self getName], 
          getCurrentTime ());
  return self;
}
@end

@interface BugA: Bug
- step;
@end

@implementation BugA
- step
{
  [super step];
  [self scheduleSelfAt: getCurrentTime () + 1];

  return self;
}


@interface BugB: Bug
- step;
@end

@implementation BugB
- step
{
  [super step];
  [self scheduleSelfAt: getCurrentTime () + 5];
  return self;
}


@interface BugSwarm: Swarm
{
  id  bugA, bugB;
  id masterSchedule;
  id bugSwarmSchedule;
}
- buildObjects;
- buildActions;
- (id <Activity>)activateIn: (id <Swarm>)swarmContext;
@end

@implementation BugSwarm
- buildObjects
{
  [super buildObjects];

  masterSchedule = [Schedule createBegin: self];
  [masterSchedule setAutoDrop: 1];
  masterSchedule = [masterSchedule createEnd];

  bugA = [BugA create: self];
  bugB = [BugB create: self];

  [bugA buildObjects];
  [bugB buildObjects];

  [bugA setSchedule: masterSchedule];
  [bugB setSchedule: masterSchedule];

  return self;
}

- buildActions
{
  [super buildActions];
 
  [masterSchedule at: 0  createActionTo: bugA message: M(step)];
  [masterSchedule at: 0  createActionTo: bugB message: M(step)];
  return self;
}

- (id <Activity>)activateIn: (id <Swarm>)swarmContext
{
  [super activateIn: swarmContext];
  [masterSchedule activateIn: self];
 
  return [self getActivity];
}

@end

@interface ModelSwarm: Swarm
{
  id <Schedule> schedule;
  id <Swarm> bugSwarm;
}
- announcement;
- buildObjects;
- buildActions;
- activateIn: swarmContext;

@end

@implementation ModelSwarm

- announcement
{
  printf ("I'm model swarm, current time is %ld\n", getCurrentTime());
  return self;
}

- buildObjects
{
  id groupProto, syncScheduleProto;

  [super buildObjects];

  groupProto = [ConcurrentGroup customizeBegin: self];
  [groupProto setDefaultOrder: Randomized];
  // [groupProto setDefaultOrder: Sequential];
  groupProto = [groupProto customizeEnd];
  
  syncScheduleProto = [Schedule customizeBegin: self];
  [syncScheduleProto setConcurrentGroupType: groupProto];
  [syncScheduleProto setAutoDrop: 1];
  syncScheduleProto = [syncScheduleProto customizeEnd];
  
  bugSwarm = [BugSwarm createBegin: self];
  
  [bugSwarm setSynchronizationType: syncScheduleProto];
  bugSwarm = [bugSwarm createEnd];
  
  [bugSwarm buildObjects];
  return self;
}

- buildActions
{
  [super buildActions];

  [bugSwarm buildActions];
  schedule = [Schedule createBegin: self];
  [schedule setRepeatInterval: 1];
  schedule = [schedule createEnd];
  
  [schedule at: 0 createActionTo: self message: M(announcement)];
  return self;
}

- activateIn: swarmContext
{
  [super activateIn: swarmContext];
  [schedule activateIn: self];
  [bugSwarm activateIn: self];
  return [self getActivity];
}  
@end

@interface ObserverSwarm: GUISwarm
{
  id <Swarm> modelSwarm;
  id displaySchedule;

}
- buildObjects;
- buildActions;
- (id <Activity>)activateIn: (id <Swarm>)swarmContext;
@end

@implementation ObserverSwarm

- buildObjects
{
  [super buildObjects]; 
  
  modelSwarm = [ModelSwarm create: self];
  [controlPanel setStateStopped];
  [modelSwarm buildObjects];
  return self;
}  

- buildActions
{
  [super buildActions];
  [modelSwarm buildActions];

   displaySchedule = [Schedule create: self setRepeatInterval: 1];
   [displaySchedule at: 0 createActionTo: actionCache message:
M(doTkEvents)];

  return self;
}

- (id <Activity>)activateIn: (id <Swarm>)swarmContext
{
  [super activateIn: swarmContext];
  [modelSwarm activateIn: self];
  [displaySchedule 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 -DAPPNAME=pjrepeater5 -o pjrepeater5 -Wall -Werror -g
-Wno-import -I$SWARMHOME/include -I$SWARMHOME/include/swarm
-L$SWARMHOME/lib/swarm pjrepeater5.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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]