swarm-support
[Top][All Lists]
Advanced

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

scheduling and re-scheduling problems


From: William S. Shu
Subject: scheduling and re-scheduling problems
Date: Tue, 31 Aug 1999 21:23:50 +0100

I have two scheduling problems.
A) I want to schedule a behaviour of an object to executed from time
step t1 to time step t2 (0 <= t1 <= t2  and measured w.r.t. current
time).  Since swarm complains if t1 is not within repeatInterval of an
action, intend to implement things thus:
    1)    create a schedule (of action(s)) for the behaviour. call it
bhvSchedule.
    2)    schedule a separate activity, startSchedule, with the sole
purpose to start bhvSchedule at time t1.
    3)    schedule another activity, stopSchedule, with the sole purpose
of stopping bhvSchedule.  (it simply calls method terminate on the
activity created for bhvSchedule)

I implemented the above -- excluding startSchedule, for the time being
-- and when I call it with:
    [self scheduleFrom: 10 To: 20 Behaviour: M(breed)];

I get segmentation fault. Where am I going wrong? Also, execution of
'breed' is done in a lot more than 11 (= 20-10+1) time steps!  Why is
this so?

The relevant code fragment is given below, as well as GDB output.
(Working under windows 98 with swarm 1.4.1).


B) My second problem, which is really a plea, simplifies to this:
    I want reschedule all the future actions of a given
schedule/activity or whatever (and its subActivities or whatever) by
scaling (up or down) its repeat cycle and the start times of all its
actions (be they individual or in action groups).  (Please don't ask why
anyone would want to do this!)

In trying to do it, I seem to wade through the docs without quite
putting my finger on all the things I may need.  (Yes, I have also
looked at a scheduling example given by Marcus some weeks back.
Unfortunately, I calls for "taking over" the scheduling process -- but I
am not that brave!)  My attempt is given by the method:

        - (id)reschedule: (id) schedule start: (timeval_t) t cycleScale:
(double) factor;

below.  My question (or rather, my plea) is: can someone help refine
what I have done to something sensible?


Thanks a lot!

William.


----[swarm code details


@interface MalariaPop: Population <HostProtocol>
{
...
}

- breed;           // spawn new malaria parasites

        // schedule behaviour bhv from time step t1 to time step t2 (t1
<= t2);
        // t1 is measured relative to current time.
- (id)scheduleFrom: (timeval_t) t1 To: (timeval_t) t2 Behaviour:
(SEL)bhv;


        // reschedule all further activities (and sub-activities) of
sched to start at time t, ignoring any
        // incomplete execution cycle (interval). Sched's repeat cycle,
        // if any, and the start times of each of its activity is scaled

        // (multiplied) by 'factor' and .  The actual cycle/start time
is the
        // nearest integer to the result.  If t is negative, start time
TO EACH
        // UNEXECUTED ACTIVITY IN AN UNCOMPLETED cycle is scaled by
'factor'.

- (id)reschedule: (id) schedule start: (timeval_t) t cycleScale:
(double) factor;
@end


@implementation MalariaPop

- breed {    // spawn new malaria parasites
  int n;

...
return nil;
}


- (id)scheduleFrom: (timeval_t) t1 To: (timeval_t) t2 Behaviour:
(SEL)bhv {  // schedule behaviour for t steps

  // !!! FOR NOW: t1 and t2 used only to get no. of time steps.
// Swarm complains if t1 > repeat cycle.

  id bhvActions;
  id bhvSchedule, stopSchedule;
  id myContext, myActiv2;

  return nil;
  {static chk = 0;
  if (chk) return nil;  // remove later!!! just to ensure ONE run !!!
  chk = 1;
  }

  // The actions are specific behaviours of an object, and takes
  // place over a fixed, finite period.

  bhvActions = [ActionGroup create: [self getZone]];
  [bhvActions createActionTo:      self        message: bhv];  // apply
behaviour

  // Create a schedule that executes the bhvActions with
  // repeat interval of 1 and at time 0, relative to start of
  // repeat cycle.

  bhvSchedule = [Schedule createBegin: [self getZone]];
  [bhvSchedule setRepeatInterval: 1];
  bhvSchedule = [bhvSchedule createEnd];

  // [bhvSchedule at: t1 createAction: bhvActions]; // circumvent swarm
objections later.
  [bhvSchedule at: 0 createAction: bhvActions];





  myContext = [[self getModelSwarm] getActivity];

  myActivity =
    [bhvSchedule activateIn: myContext]; // Now activate schedule


  // create an an activity/schedule to terminate myActivity.

  stopSchedule = [Schedule createBegin: [self getZone]];
  [stopSchedule setAutoDrop: YES];  // ensure its used only once
  stopSchedule = [stopSchedule createEnd];

  [stopSchedule at: [myActivity getCurrentTime] + ((t1 <= t2)? (t2-t1) :
0)
                          createActionTo: myActivity
                           message: M(terminate)];

 //  myActiv2 =
  //    [stopSchedule activateIn: myContext]; // Now activate own
schedule


  // scheduled activties are automatically run by top-level activity.
  // so we do nothing here but return new activity.

  return myActivity;   // return my activity. !!! check !!!
}



- (id)reschedule: (id) schedule start: (timeval_t) t cycleScale:
(double) factor {


  timeval_t timeNow = getCurrentTime ();
  timeval_t cycle;
  id sched;

  // create index on schedule
  id index = [schedule createIndex: scratchZone
      fromMember: [schedule at: (id) timeNow]];


  while (sched = [index next: (id *) &timeNow]) {
    timeval_t cycle, startTime;
    id newSched;
    id newActivity;

    // get and scale repeat interval
    cycle = [sched getRepeatInterval];  // get old cycle
    cycle = (timeval_t)(cycle*factor);  // scale by factor
    cycle = (cycle < 1)? 0 : cycle;  // ensure cycle is valid

    // create new schedule with repeat interval.
    newSched = [Schedule createBegin: [self getZone]];
    [newSched setRepeatInterval: cycle];

    newSched = [newSched createEnd];

    // transfer activities from old schedule to new, scaling start
    // times as well.
    // NOTE: scaling down/rounding errors may force some start
    // times to zero or make some activities *NOT* have a repeat cycle!
    // This problem is NOT YET ADDRESSED, but an intended interpretation

    // is to cater the following options:
    //   . 'pause' such an activity, but re-activate when later scaled.
    //   . execute such once per the new cycle

... <| ... sticky details to implement ... |> ...

    // have transferred all needed information:
    // now activate new schedule and drop old one
    newActivity = [newSched activateIn: myContext]; // Now activate own
schedule

    [sched drop];
  }

  [index drop];

  return self;

}


---[debugger output for: [self scheduleFrom: 10 To: 20 Behaviour:
M(breed)];

Debugger exited abnormally with code 11
GNU gdb 4.17.1
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i586-cygwin32"...
(gdb) run
Starting program: /u/mosq/proto/persons.exe
7fce0000:/WINDOWS/SYSTEM/SHELL32.DLL
bfc00000:/WINDOWS/SYSTEM/COMCTL32.DLL
bfb50000:/WINDOWS/SYSTEM/SHLWAPI.DLL

[failed reading symbols from DLL]
"/WINDOWS/SYSTEM/COMDLG32.DLL": error reading line numbers

66300000:/SWARM-1.4.1/BIN/CYGTK80.DLL
bff20000:/WINDOWS/SYSTEM/GDI32.DLL
bff50000:/WINDOWS/SYSTEM/USER32.DLL
bff70000:/WINDOWS/SYSTEM/KERNEL32.DLL
bfea0000:/WINDOWS/SYSTEM/ADVAPI32.DLL
61000000:/SWARM-1.4.1/BIN/CYGWIN1.DLL
66000000:/SWARM-1.4.1/BIN/CYGTCL80.DLL
78810000:/WINDOWS/SYSTEM/WSOCK32.DLL
78850000:/WINDOWS/SYSTEM/WS2HELP.DLL
78000000:/WINDOWS/SYSTEM/MSVCRT.DLL
78860000:/WINDOWS/SYSTEM/WS2_32.DLL
789f0000:/WINDOWS/SYSTEM/WININET.DLL
7b120000:/WINDOWS/SYSTEM/MSWSOCK.DLL
7c110000:/WINDOWS/SYSTEM/MSAFD.DLL
10000000:/PROGRAM FILES/DATA FELLOWS/F-SECURE/ANTI-VIRUS/DFSAV32.DLL

Program received signal SIGSEGV, Segmentation fault.
0x4c7661 in objc_msg_lookup ()
(gdb) bt
#0  0x4c7661 in objc_msg_lookup ()
#1  0x448572 in _i_ActionTo_0___performAction__ (self=0x2ab9ea8,
    _cmd=0x4e6d40, anActivity=0x2aaac98)
    at /src/swarm-1.4.1/src/activity/Action.m:211
#2  0x446fc0 in _i_Activity_c___run_ (self=0x2aaac98, _cmd=0x4e6d28)
    at /src/swarm-1.4.1/src/activity/XActivity.m:185
#3  0x446f00 in _i_Activity_c___run_ (self=0x2a99568, _cmd=0x4e6d28)
    at /src/swarm-1.4.1/src/activity/XActivity.m:143
#4  0x446f00 in _i_Activity_c___run_ (self=0x2aa5e38, _cmd=0x4e6d28)
    at /src/swarm-1.4.1/src/activity/XActivity.m:143
#5  0x446f00 in _i_Activity_c___run_ (self=0x2ae3fa8, _cmd=0x4e6d28)
    at /src/swarm-1.4.1/src/activity/XActivity.m:143
#6  0x446f00 in _i_Activity_c___run_ (self=0x2a9a9c0, _cmd=0x4e6d28)
    at /src/swarm-1.4.1/src/activity/XActivity.m:143
#7  0x446f00 in _i_Activity_c___run_ (self=0x2ae2968, _cmd=0x4e6d10)
    at /src/swarm-1.4.1/src/activity/XActivity.m:143
#8  0x446e2f in _i_Activity_c__run (self=0x2ae2968, _cmd=0x4d94d0)
    at /src/swarm-1.4.1/src/activity/XActivity.m:72
#9  0x41e836 in _i_ControlPanel__startInActivity_ (self=0x2a493e8,
    _cmd=0x4d9148, activityID=0x2ae2968)
    at /src/swarm-1.4.1/src/simtoolsgui/ControlPanel.m:99
#10 0x41df71 in _i_GUISwarm__go (self=0x2a45a78, _cmd=0x4d28a0)
    at /src/swarm-1.4.1/src/simtoolsgui/GUISwarm.m:47
#11 0x408d26 in main (argc=1, argv=0x29b0d20) at TopLevel.m:63
#12 0x61004402 in _size_of_stack_reserve__ ()
#13 0x61004420 in _size_of_stack_reserve__ ()
#14 0x4cf36a in cygwin_crt0 (f=0x408c00 <main>)
    at /home/noer/src/b20/comp-tools/devo/winsup/libccrt0.cc:81
(gdb)


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