Project 3, with additional comments for Project2
5/29/91

Brad Calder  
Scott Taylor 



(** Problem 1 **)

(Part A)
   We were able to pretty much model all the aspects of the real world problem in prodigy.

   The solution found to a given problem, using our search control rule gives an optimal
solution.  It is not guaranteed to be the most optimal because there are several equally good
solutions that are optimal.

We know what the criteria for an optimal solution is because we have
written schedules for grade schools and talked with principals of
grade schools.  The consensus on what an optimal solution should have
is that:

1) Prodigy gives us a solution, this means every request (like a
reserved event (Band), or Lunch) has
   been added and included legally in the solution.

2) The teachers that are scheduled with a specialist two or more times
a week should not be scheduled
   with that specialist two days in a row.  In other words the
teacher's class needs variety.  For,
   example a schedule of (M=Music,T=PE,W=Library,Th=Music,F=PE) is
GREATLY preferred over another
   legal schedule of (M=Music,T=Music,W=Library,Th=PE,F=PE).

3) It is prefered that a teacher's class go to specialists around the
same time every day of the week.
   So, try to schedule a teacher so it goes to Music, PE and Library
around the same time.  This
   way the teacher can set up some sort of consistent schedule for its class everyday.  This preference
   isn't always achievable and is lower priority than 2) above.   This preference is hard to 
   satisfy once several teachers have been added.

4) Another aspect about the schedule that is prefered, is that all of
the recesses and lunches in a
   recess and lunch event should be grouped together if possible (which it is not always possible)
   and should be seperated by a 5 minute passing time.  This is to allow kids coming in from something
   like recess or lunch to get situated in their class room before the
kids going out to the recess
   and lunch leave.  If this passing time is not given, there is a lot of extra confusion going on 
   for the supervisors of the recess and lunch.  This also allows the supervisors to make sure the
   playground or lunch room is clear of kids.

Our domain and search control rules gives us this.  So, I hope you are
more convinced that we were able to model everything.


BUT, prodigy did not allow us to do one thing that would make some solutions a little bit better
this is talked about in (Part D).

(Part B)

   The biggest aspect of the problem came down to when we had to COUNT
the number of predicates of a certain type that were in the state.  We
found the function EXP-MATCH in the file called matching.lisp (after
many hours).  This allowed us to send to a meta function a partially
bounded predicate (which is an expression).  Then, we could send that
expresssion to EXP-MATCH and it returns a list of bindings lists.  We
can then tell how many predicates of that type were in the state by
taking the length of the list of bindings lists.  The way our domain
is set up, a few of these control rules could not have been written
without the ability to count the number of predicates (especially
non-static) of a certain type in the state, unless we rewrote our
domain.

   Another aspect is that we thought it would be real difficult to
program prodigy to come up with a legal time-outline inculding breaks,
reserved events, and lunches.  But, the code after awhile turned out
to be a small set of operators (though it took awhile, and the some of
the domain's operators are really complicated).

(Part C)
   Meta-functions were EXTREMELY useful.  Because, they allowed us to
count predicates in the state.  Without them, in order to write the
search control rules that used those Meta-Fns, we would of had to
rewrite the domain in a way that the domain kept track of the count
(like we do now with our predicate num-of-times).
   
NOTE: in most of the test cases the number of nodes used with control
rules takes around 20% of the number of nodes without search control,
BUT without search control the time it takes is about 60% of the time
as with control rules.  This is partially do to our counting of the
number of predicates in the state, which is done quite a bit.


(Part D)

1) In operator INFER-TEACHER-DONE it has a (forall (<specialist>) G P)
and I would like to be able to choose the order that the forall goes
through the bindings for <specialist>.  You cannot write a control
rule to prefer bindings like <specialist> inside a forall, because I
tried this and everytime it picks its own binding order.
     Also, the order it picks is always alphabetical.  I tried several permutations
of the static generators for the <specialist> in the initial state and the forall always tries
them in alphabetical order.  I want to be able to specify the order.

2)   Another modification is to allow prodigy use lisp functions inside prodigy without having
to write functions like less-than (just use < n prodigy).






  ------------------------------ * ADDITIONAL COMMENTS ON PROJECT *
THERE ARE ADDITIONAL COMMENTS IN THE FILE **** DOMAIN.LISP ******
  ------------------------------

The objective of the domain: Is to construct a time-outline for each
specialist, construct legal times for all events, recceses and
lunches, and to schedule all the teachers with all of the specialists
the correct number of times as specified in the start state.  All of
the terms in this sentence are hopefully explained below and in
domain.lisp.


How our domain works:


1) It starts by generating a time-outline for each specialist in the
start state.  A time-outline is a list of time slots that are added to
the state.  The time slots look like:

(Time-Slot <specialist> <start> <end>)

so, a time-outline might look like:

      TIME-SLOT PE 955 1035
      TIME-SLOT PE 940 955
      TIME-SLOT PE 900 940


2) In the initial state the specialists predicate looks like:

   (Specialist <specialist> <time-slot-length> <num-of-times> <grade-list> <day-list>)

   <num-of-times> = number of times each teacher, that teaches a grade
in the specialists grade-list,
                 is to visit the specialist during the week.

   <day-list> = this is the list of days that the specialist teaches on.

   An example is: (specialist main-music 40 2 (1 2 3 4 5 6) (Monday
Tuesday Wednesday Thursday Friday))


3) In creating the time-outline a time-slot can be either
   a) a slot for teachers to be scheduled in
   b) break time for the specialist
   c) a reserved event (like band) that the specialist teaches specificly

4) While creating the time-outline, we also schedule any breaks that
need to be added for the specialist.  The following predicate is in
the start state which we use to add breaks:

   (Allowed-Break <specialist> <break-name> <earliest-start> <latest-end> <break-length>)
    
    <earliest-start> and <lateset-end> are used as the window of time
that the break can be added.  This means, in order to have a schedule
the break has to be added and fit within this start and end times.

   When the break is added the predicate (Allowed-Break ...) is del
from the state and the following is added:

   (SP-Break <specialist> <break-name> <start-time> <end-time>).  This
predicate is used throughout the domain, to tell if a Time-Slot is a
break or not.  A time-slot of a specialist will be a break if the sp
name's match and the start and end times are the same.

for example:
      ADD-BREAK MAIN-MUSIC MORNING-RECESS 1020 1035
      ADD-TIME-SLOT MAIN-MUSIC 1115 1155
      ADD-TIME-SLOT MAIN-MUSIC 1035 1115
      ADD-TIME-SLOT MAIN-MUSIC 1020 1035
      ADD-TIME-SLOT MAIN-MUSIC 940 1020
      ADD-TIME-SLOT MAIN-MUSIC 900 940

  This was taken from a solution.  The main-music specialist has a break at 1020 to 1035
  Where the other time slots are used for teachers.


5) While creating the time-outline for a specialist we aslo schedule
any reserved that apply to that specialist.  We find the reserved
events that apply to the specialist by seeing if there are any
predicates of the following form in the start state:

   (Wanted-Event <specialist> <event-name> <earliest-start>
<latest-end> <event-length> <grade-list>)
    The earliest-start and earliest-end are just the same as the
breaks.

When the event is added the predicate (Wanted-Event ...) is del from
the state and the following predicate is added:

    (Reserved-Event <specialist> <event-name> <start-time> <end-time>
<grade-list>).  This predicate is used throughout the domain to tell
if a Time-Slot is a reserved event or not.  This is also used in
scheduling teachers (etc) in that if the Time-Slot we are putting the
specialist into overlaps a reserved-event, we cannot put the teacher
there if teacher's grade is in the reserved events grade list.

for example:
      ADD-RESERVED-EVENT MAIN-MUSIC BAND 1435 1505 (5 6)
      ADD-TIME-SLOT MAIN-MUSIC 1435 1505
      ADD-TIME-SLOT MAIN-MUSIC 1425 1435
      ADD-TIME-SLOT MAIN-MUSIC 1345 1425

  This was taken from a solution.  The main-music specialist teaches Band from 1435 to 1505 with
  grades 5 and 6 participating.


6) Once the time-outlines for the specialists have been made, we then
find the times for the recesses and lunches.  We use the term recess
and lunch and the term recess event and lunch event.  A recess event
contains a list of recess, and a lunch event contains a list of
lunches.  A recess or lunch event is represented by the following
predicate in the initial state:

   (Recess-Lunch <event-name> <earliest-start> <latest-end> <event-length>)
    where <earliest-start> and <latest-end> is the allowed time range
that all the recesses or lunches in the event need to be scheduled
between.
    <event-length> is the length of each recess or lunch in the event.


7) The recesses or lunches in a recess or lunch event are represented by the following predicate
in the start state:

   (Recess-Lunch-Grades <event-name> <r-l-number> <grade-list>)

    each recess or lunch has its own grade-list, which is the list of grades that 
participate in that recess or lunch.  And they also have a number since there are usually a couple
or recesses or lunches in a recess or lunch event.  ** We use the abriviation r-l to mean recess-lunch **.

An example of a recess event in the initial state with its recesess is:

                    (Recess-Lunch Morning-Recess 1000 1045 15)
                    (Recess-Lunch-Grades Morning-Recess 1 (1 2 3))
                    (Recess-Lunch-Grades Morning-Recess 2 (4 5 6))
    notice that the names are the same, that is how we associate recesses and lunches with their events.



8) Now when the start and end time for each recess and lunch is figured out the following predicate is 
added to the state to represent that recess or lunch:

   (Recess-Lunch-Time <r-l-name> <r-l-num> <start-time> <end-time>)

for example,
      ADD-RECESS-LUNCH MORNING-RECESS 1 1000 1015
      ADD-RECESS-LUNCH MORNING-RECESS 2 1020 1035

  This could be added for the above Morning-Recess event that was in the initial state.


9) So once all the recesses and lunches in recess and lunch events have their times, we are offically
done with creating the time-outline.  Now we start scheduling teachers with specialists time slots.

   We use a predicate (Num-Meetings <teacher> <specialist> <keep-track-of-number-of-times-scheduled>)
so we will schedule the teacher with the specialist the corresponding num-of-times that is specified
in the SPECIALIST predicate (the NUM-OF-TIMES is the one in the specialist predicate as descrebed in 2 above).

   In creating a schedule, the schedule is a week long and is repeated every week in a grade school.  So the
time-slots are used for the number of days that the specialist can teach as notified in its num-of-days list
from the initial specialist predicate.  An example is:

   (specialist main-music 40 2 (1 2 3 4 5 6) (Monday Tuesday Wednesday Thursday Friday))
So for this specialist the time slots can be thought of as the two dim grid as follows:


                                     Monday    Tuesday   Wednesday  Thursday    Friday
TIME-SLOT MAIN-MUSIC 1115 1155        X         X          X         X            X
TIME-SLOT MAIN-MUSIC 1035 1115       break     break     break      break       break
TIME-SLOT MAIN-MUSIC 1020 1035        X         X          X         X            X
TIME-SLOT MAIN-MUSIC 940 1020         X         X          X         X            X  
TIME-SLOT MAIN-MUSIC 900 940          X         X          X         X            X

   Where X denotes places for teachers to be put.              


   If the teacher is scheduled with the specialist the following predicate is added to the state to denote this:

      (Scheduled <teacher> <specialist> <start-time> <end-time> <day-scheduled-for>)

   In scheduling the teacher with this specialist the following preconds need to be checked and satisfied:
      A) You need to get a day that the teacher has not yet been scheduled on
      B) The day chosen is a day that the Specialist teaches on
      C) You need to find a time-slot of that specialist such that
         1) the time-slot does not have a teacher already scheduled in it
         2) the time-slot is not a break for the specialist
         3) the time-slot is not a reserved event for the specialsit
         4) the time-slot is NOT overlaped by a recess, lunch, or a reserved event such that
            the grade the teacher teaches participates in the recess, lunch, or reserved event.


The scheduling of teachers in our final domain looks like:

      ASSIGN BOZO EARLY-MUSIC 1410 1450 TUESDAY
      ASSIGN BOZO EARLY-MUSIC 1410 1450 THURSDAY
      ASSIGN BOZO LIBRARY 900 935 FRIDAY
      ASSIGN BOZO LIBRARY 900 935 MONDAY
      ASSIGN BOZO PE 1210 1250 WEDNESDAY

      ASSIGN MOE LIBRARY 1225 1300 FRIDAY
      ASSIGN MOE LIBRARY 1225 1300 WEDNESDAY
      ASSIGN MOE MAIN-MUSIC 900 940 THURSDAY
      ASSIGN MOE MAIN-MUSIC 1210 1250 TUESDAY
      ASSIGN MOE PE 1450 1530 MONDAY


10) Finally, the all the teachers need to be scheduled with the specialists, as described in 9),
    once that is done we have a solution.




