Advertisement
logicmoo

Untitled

Jul 1st, 2018
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.03 KB | None | 0 0
  1. /*
  2.  
  3. Joe is takin Sue on a date but he doesnt have enough money to buy them both food and drink
  4.  
  5. Joe wants food more than a drink.
  6. Sue wants to get a drink and has no thoughts about food.
  7.  
  8. */
  9.  
  10.  
  11. cost(food,35.0).
  12. cost(drink,15.0).
  13.  
  14. buyable(A):- cost(A,_).
  15. person(P):- wants(P,_,_).
  16.  
  17. has(joe,money,40.0).
  18.  
  19. has(joe,food,0.0).
  20. has(joe,drink,0.0).
  21. has(sue,food,0.0).
  22. has(sue,drink,0.0).
  23.  
  24. wants(joe,food,0.33).
  25. wants(joe,drink,0.66).
  26. wants(sue,drink,0.66).
  27.  
  28. % This rule helps us infer sue wants  food at .34
  29. wants(Person,Type,Amount):-
  30.   buyable(Type2),
  31.   person(Person),
  32.   wants(Person,Type2,Other),
  33.   Type2\==Type2,
  34.   Amount is 1.0 - Other.
  35.  
  36. wants_more(P,Thing1):-
  37.    dif(Thing1,Thing2),
  38.    wants(P,Thing1,A1),
  39.    wants(P,Thing2,A2),
  40.    A1>A2.
  41.  
  42. happy:-
  43.    dif(P1,P2),
  44.    wants_more(P1,Thing1),
  45.    wants_more(P2,Thing2),
  46.    cost(Thing1,Cost1),
  47.    cost(Thing2,Cost2),
  48.    has(P1,money,Cash),
  49.    Cash #=<
  50.      Cost1+Cost2,
  51.    nl,
  52.    write([
  53.      orders_for(Thing1,P1),
  54.      orders_for(Thing2,P2)]),nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement