swarm-support
[Top][All Lists]
Advanced

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

Re: scheduling quandry


From: Marcus G. Daniels
Subject: Re: scheduling quandry
Date: 12 Jul 2000 09:56:51 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "PJ" == Paul E Johnson <address@hidden> writes:

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

In the case of pjrepeater4, there is a sychronization schedule set up
for the Swarm, and the subSwarms feed it.  Now, with pjrepeater5, you
are not feeding a Swarm, you're feeding a Schedule, so you just have
to to configure that masterSchedule.  I.e., you don't need to call
setSynchronizationType: on the Swarm, and if you do it isn't relevant,
anyway.

The reason for the apparent inconsistency in the pjrepeater5 output
is that you have dynamic scheduling every timestep for bugA and every
five timesteps for bugB, while startup is set up is BugSwarm's
buildActions at time 0, with bugA listed first.

So, you get [bugA step] and then [bugB step] for time step 0.  

[bugA step] has the side effect of scheduling itself for timestep 1.
[bugB step] has the side effect of scheduling itself for timestep 5.

It won't be until timestep 4 that bugA lays any claim to timestep 5.
Thus, from then on you'll see bugB first.

Here's how to configure the shared masterSchedule. 

In some cases it may be easier to look at the emergent structure of
dynamic schedules if there is a shared, e.g. xfprint (masterSchedule).

But, generally, I think it is better to have schedules in the agents
themselves.  That way it is more "agent-based" and modular.

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

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

@interface Bug: Swarm
{
 id schedule;
}

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

@implementation Bug
- scheduleSelfAt: (timeval_t)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];

  {
    id groupProto;
    
    groupProto = [ConcurrentGroup customizeBegin: self];
    [groupProto setDefaultOrder: Randomized];
    groupProto = [groupProto customizeEnd];
    
    masterSchedule = [Schedule createBegin: self];
    [masterSchedule setConcurrentGroupType: groupProto];
    [masterSchedule setAutoDrop: YES];
    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
{
  [super buildObjects];
  
  bugSwarm = [BugSwarm create: self];
  [bugSwarm buildObjects];
  return self;
}

- buildActions
{
  [super buildActions];

  [bugSwarm buildActions];
  schedule = [Schedule create: self setRepeatInterval: 1];
  [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=pjrepeater6 -o pjrepeater6 -Wall -Werror -g -Wno-import 
-I$SWARMHOME/include -I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm 
pjrepeater6.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]