First -- here's the definitive source:

        ftp://ftp.cs.utexas.edu/pub/ops5-benchmark-suite

But the "manners" version isn't in Jess syntax. Attached see my
translations of the program and the data generator.

I think peter wrote:
> 
> I tried to google for a clips version of manners
> benchmark for Jess. Would anyone have a pointer to it?
> I did a search for temple university clips manners
> benchmark, but the URL is no longer available.
> 
> thanks in advance.
> 




---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov
;; Deftemplates

(deftemplate guest (slot name) (slot sex) (slot hobby))

(deftemplate last_seat (slot seat))

(deftemplate seating
  (slot id) (slot pid) (slot seat1) (slot name1) (slot name2) (slot seat2) (slot 
path_done))

(deftemplate path (slot id) (slot name) (slot seat))

(deftemplate chosen (slot id) (slot name) (slot hobby))

(deftemplate count (slot c))

(deftemplate context (slot state))

(defrule assign_first_seat
  ?ctxt <- (context (state start))
  (guest (name ?n))
  ?count <- (count (c ?c))
  =>
  (assert (seating (seat1 1) (name1 ?n) (name2 ?n) (seat2 1) (id ?c) (pid 0) 
(path_done yes)))
  (assert (path (id ?c) (name ?n) (seat 1)))
  (modify ?count (c (+ ?c 1)))
  (printout t seat " " 1 " " ?n " " ?n " " 1 " " ?c " " 0 " " 1 crlf)
  (modify ?ctxt (state assign_seats)))

(defrule find_seating
  ?ctxt <- (context (state assign_seats))
  (seating (seat1 ?seat1) (seat2 ?seat2) (name2 ?n2) (id ?id) (pid ?pid) (path_done 
yes))
  (guest (name ?n2) (sex ?s1) (hobby ?h1))
  (guest (name ?g2) (sex ~?s1) (hobby ?h1))
  ?count <- (count (c ?c))
  (not (path (id ?id) (name ?g2)))
  (not (chosen (id ?id) (name ?g2) (hobby ?h1)))
  =>
  (assert (seating (seat1 ?seat2) (name1 ?n2) (name2 ?g2) (seat2 (+ ?seat2 1)) (id ?c)
                   (pid ?id) (path_done no)))
  (assert (path (id ?c) (name ?g2) (seat ( + ?seat2 1))))
  (assert (chosen (id ?id) (name ?g2) (hobby ?h1)))
  (modify ?count (c (+ ?c 1)))
  (printout t seat " " ?seat2 " " ?n2 " " ?g2 crlf)
  (modify ?ctxt (state make_path)))

(defrule path_done
  ?ctxt <- (context (state make_path))
  ?seat <- (seating (path_done no))
  =>
  (modify ?seat (path_done yes))
  (modify ?ctxt (state check_done)))


(defrule make_path
  (context (state make_path))
  (seating (id ?id) (pid ?pid) (path_done no))
  (path (id ?pid)(name ?n1) (seat ?s))
  (not (path (id ?id) (name ?n1)))
  =>
  (assert (path (id ?id) (name ?n1) (seat ?s))))

(defrule continue
  ?ctxt <- (context (state check_done))
  =>
  (modify ?ctxt (state assign_seats)))

(defrule are_we_done
  ?ctxt <- (context (state check_done))
  (last_seat (seat ?l_seat))
  (seating (seat2 ?l_seat))
  =>
  (printout t crlf "Yes, we are done!!" crlf)
  (modify ?ctxt (state print_results))
)

(defrule print_results
  (context (state print_results))
  (seating (id ?id) (seat2 ?s2))
  (last_seat (seat ?s2))
  ?path <- (path (id ?id) (name ?n) (seat ?s))
  =>
  (retract ?path)
  (printout t ?n " " ?s crlf))

(defrule all_done
  (context (state print_results))
  =>
  (halt))

(set-reset-globals t)
(defglobal ?*t* = (time))
(reset)
(batch "mann90.dat")
;; (watch rules) 
;;(printout t (run) crlf)
(run)
(printout t "Elapsed time: " (- (time) ?*t*) crlf)
;; (exit)






#include <stdio.h>
#include <math.h>

/****************************************************************
  Tim Grose
  January 29, 1991
  Miss Manners Data Generator

  The purpose of this program is to generate a file of make
  statements that can be used as an input data set for the 
  Miss Manners OPS5c program.

  All input to this program will be interactively obtained from
  the user.  The file of make statements will be written to 
  file manners.dat.

  The user specifies how many guests there will be.  Each guest's
  name will be a unique integer.  Each guest is assigned a sex at
  random.  The user can specify the total number of hobbies it is
  possible for a guest to have, and a lower limit of the number
  of hobbies for a guest.  For instance, if the user chooses 10
  hobbies and a lower limit of 3 hobbies, each guest will have
  between 3 and 10 hobbies.  The hobbies will be designated with
  an integer.  Finally, the user can specify the number of seats
  available.

  The sex of the guests is assigned so that approximately half of
  the guests are male and half are female.
*****************************************************************/

main()
{
  FILE *fopen(), *output_file;
  int seed, max_hobby, min_hobby, guest_num, seat_num, max_male, max_female;
  int chosen_hobby, count, number, rand_num, hobby_num, hobby_count;
  int hobbies[100], male_count, female_count;
  char sex,fname[20];
  float num;

  printf("Miss Manners Data Generator\n\n");
  printf("How many guests will there be? ");
  scanf("%d",&guest_num);

  strcpy(fname,"mann");
  sprintf(&fname[4],"%d",guest_num);
  strcat(fname,".dat");

  output_file = fopen(fname,"w");
  if (output_file == NULL)
    {
        write("\n\nError opening output file\n");
        exit(20);
    }


  printf("How many seats are there? ");
  scanf("%d", &seat_num);
  printf("What is the maximum number of hobbies? ");
  scanf("%d", &max_hobby);
  printf("What is the minimum number of hobbies? ");
  scanf("%d", &min_hobby);

  seed = 10;
  srand(seed);
  
  male_count = 0;
  female_count = 0;
  max_male = guest_num / 2;
  max_female = guest_num - max_male;

  /****************************************************************/
  /* For each guest, assign a sex and the hobbies for that guest. */
  /****************************************************************/

  for(count = 1; count <= guest_num; ++count)
     {
       rand_num = rand();

       if (rand_num < 1073741824)
         sex = 'm';
       else
         sex = 'f';

       if ((sex == 'm') && (male_count == max_male))
         sex = 'f';

       if ((sex == 'f') && (female_count == max_female))
         sex = 'm';

       if (sex == 'm')
         male_count = male_count + 1;

       if (sex == 'f')
         female_count = female_count + 1;

      for(hobby_count = 1; hobby_count <= max_hobby; ++hobby_count)
        hobbies[hobby_count-1] = -1;

 /************************************************************/
 /* Determine the number of hobbies for this guest, then     */
 /* choose them.                                             */
 /************************************************************/

      rand_num = rand();
      num = (float) rand_num / 2147483647.0;
      hobby_num = (float) min_hobby + num *  (float) (max_hobby-min_hobby+1);

      for(hobby_count=1; hobby_count <= hobby_num; ++hobby_count)
        {
          do
            {
              rand_num = rand();
              num = (float) rand_num / 2147483647.0;
              chosen_hobby = 1.0 + num * (float) max_hobby;
            }
          while(hobbies[chosen_hobby - 1] != -1);

          hobbies[chosen_hobby - 1] = chosen_hobby;

          fprintf(output_file, "(assert (guest (name %d) (sex %c) (hobby %d)))\n",
                               count, sex, chosen_hobby);
        }

     }

  fprintf(output_file, "(assert (last_seat (seat %d)))\n", seat_num);
  fprintf(output_file, "(assert (count (c 1)))\n");
  fprintf(output_file, "(assert (context (state start)))\n");

} 

Reply via email to