0

Quick rundown, basically, the idea of the prolog program (GNU Prolog) is to search a database containing people with available time slots to a set of times (beginning time, end time) and return the first person who can meet in that time. The input has the syntax

meeting(Person,slot(time(10,0),time(12,30)))

I have a predicate which matches the above as such:

meeting(Person, slot(time(A,B),time(C,D))) :- %insert code

and the database entries look as such:

free(george,slot(time(9,30),time(11,0)))

Where I am stuck is that I'm not sure how I can compare the times in the database with the times entered when calling my meeting predicate. Not looking for a free answer, just wanting a push in the right direction and a good example :) Thanks everyone!

Jason McKindly
  • 463
  • 1
  • 8
  • 15
  • Here's something to try, which you can use as an idea in a predicate: run your `gprolog`, load your data (`free(...)` items) and enter this: `free( Person, slot(time(FromH, FromM), time(ToH, ToM))).`. With each solution presented, press `;`. – lurker Oct 19 '13 at 02:06
  • With that I just get the first person in the database returned and that's it. I understand the very very basics of how prolog works to know that it looks for the first match to the query, then assigns that match to the "Person" variable. – Jason McKindly Oct 19 '13 at 02:23
  • If you have multiple database entries, it should give you every entry in turn if you press `;` and for each entry give you a `Person`, a start time hour (`FromH`), from time minutes (`FromM`), etc for each match. If you didn't get that, then something is wrong. And the point of the exercise is that if you want to match times, you would do such a query to examine each time that's in the database. – lurker Oct 19 '13 at 02:25
  • I get: meeting.pl:12-13: warning: singleton variables [A,B,C,D,FromH,FromM,ToH,ToM] for meeting/2 ann GNU Prolog 1.4.4 (64 bits) Compiled Apr 24 2013, 16:00:30 with gcc By Daniel Diaz Copyright (C) 1999-2013 Daniel Diaz | ?- ; When I enter ; I just get a blank line and nothing happens – Jason McKindly Oct 19 '13 at 02:29
  • You're doing something incorrectly, because if I put your single line of data into `gprolog`, then enter the inquiry I gave you (`free( Person, slot(time(FromH, FromM), time(ToH, ToM))).`), then I get the following lines of output: `FromH = 9`, `FromM = 30`, `Person = george`, `ToH = 11`, and `ToM = 0`, which is what I would expect. If you have multiple database items, it would present multiple solutions. – lurker Oct 19 '13 at 02:33
  • You are right, I was using a " instead of a ' when loading in the database .pl file. Now it reads in properly – Jason McKindly Oct 19 '13 at 02:44

1 Answers1

0

Doing what mbratch said, I saw better how prolog runs through the database and I was able to easily write come comparing logic which would satisfy the requirements.

The idea is, calling free(...) as above, Person receives the first individual in the list and all the passed variables receive the data. Then I could use my logic on the data and if all the logic passes, the method runs through and the proper response is returned.

Thanks for your help!

Jason McKindly
  • 463
  • 1
  • 8
  • 15