Advertisement
Guest User

Untitled

a guest
May 31st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 4.85 KB | None | 0 0
  1. roomHasSize(1, 35).
  2. roomHasSize(2, 60).
  3. roomHasSize(3, 100).
  4.  
  5. classHasSize(1, 30).
  6. classHasSize(2, 35).
  7. classHasSize(3, 100).
  8. classHasSize(4, 40).
  9. classHasSize(5, 45).
  10.  
  11.  
  12.  
  13. test2(X) :- X = [prof, smith, teaches, class, c1].
  14.  
  15. test3(X) :- X = [prof, smith, teaches, class, c1,
  16.                 prof, smith, teaches, class, c2].
  17.  
  18.  
  19. test4(X) :- X = [prof, smith, teaches, class, c1,
  20.                 prof, smith, teaches, class, c2,
  21.                 class, c1, is, in, room, 1,
  22.                 class, c2, is, in, room, 2].
  23.  
  24. test5(X) :- X = [prof, smith, teaches, class, c1,
  25.                 prof, smith, teaches, class, c2,
  26.                 class, c1, is, in, room, 1,
  27.                 classes, c1, and, c2, are, in, the, same, room].
  28.  
  29. test6(X) :- X = [prof, smith, teaches, class, c1,
  30.                 prof, smith, teaches, class, c2,
  31.                 class, c1, is, in, room, 1,
  32.                 classes, c1, and, c2, are, in, the, same, room,
  33.                 class, c1, is, after, class, c2].
  34.  
  35. test7(X) :- X = [prof, smith, teaches, class, c1,
  36.                 prof, smith, teaches, class, c2,
  37.                 class, c1, is, in, room, 1,
  38.                 classes, c1, and, c2, are, in, the, same, room,
  39.                 class, c1, is, before, class, c2].
  40.  
  41. % fails immediately, as it should
  42. testContradictionFailure(X) :- X = [prof, smith, teaches, class, c1,
  43.                 prof, smith, teaches, class, c2,
  44.                 class, c1, is, in, room, 1,
  45.                 classes, c1, and, c2, are, in, the, same, room,
  46.                 class, c1, is, before, class, c2,
  47.                 class, c1, is, after, class, c2].
  48.  
  49.  
  50. test8(X) :- X = [prof, smith, teaches, class, c1,
  51.                  prof, smith, teaches, class, c2,
  52.                  class, c1, is, in, room, 1,
  53.                  classes, c1, and, c2, are, in, the, same, room,
  54.                  class, c1, is, before, class, c2,
  55.                  classes, c1, and, c2, are, on, the, same, day].
  56.  
  57. % should fail due to preparation time problems (he has to teach 4 classes in 1 day, leaving him only one hour of free time)
  58. % he needs at least 2 per day, so this should fail
  59. testPreparationFailure(X) :- X = [prof, smith, teaches, class, c1,
  60.                  prof, smith, teaches, class, c2,
  61.                  prof, smith, teaches, class, c3,
  62.                  prof, smith, teaches, class, c4,
  63.                  classes, c1, c2, c3, and, c4, are, on, the, same, day].   
  64.  
  65. % shouldn't fail because he still has 3 hours of preparation time
  66. testPreparationLimit(X) :- X = [prof, smith, teaches, class, c1,
  67.                  prof, smith, teaches, class, c2,
  68.                  prof, smith, teaches, class, c3,
  69.                  classes, c1, c2, c3, and, c4, are, on, the, same, day].
  70.  
  71.  
  72. testAllInOneDay(X) :- X = [prof, smith, teaches, class, c1,
  73.                  prof, smith, teaches, class, c2,
  74.                  prof, smith, teaches, class, c3,
  75.                  prof, jones, teaches, classes, c4, and, c5,
  76.                  classes, c1, c2, c3, c4, and, c5, are, on, the, same, day,
  77.                  class, c1, is, before, class, c2,
  78.                  class, c2, is, before, class, c3,
  79.                  class, c3, is, before, class, c4,
  80.                  class, c4, is, before, class, c5].
  81.  
  82. testSameRoomTransitivity(X) :- X = [prof, smith, teaches, class, c1,
  83.                  prof, smith, teaches, class, c2,
  84.                  prof, smith, teaches, class, c3,
  85.                  prof, jones, teaches, classes, c4, and, c5,
  86.                  classes, c1, c2, c3, c4, and, c5, are, on, the, same, day,
  87.                  class, c1, is, before, class, c2,
  88.                  class, c2, is, before, class, c3,
  89.                  class, c3, is, before, class, c4,
  90.                  class, c4, is, before, class, c5,
  91.                  classes, c1, c2, and, c5, are, in, the, same, room,
  92.                  classes, c3, c4, and, c5, are, in, the, same, room].
  93.  
  94. % testSameRoomMultipleTransitivity
  95. testSameRoomMultipleTransitivity(X) :- X = [prof, smith, teaches, class, c1,
  96.                  prof, smith, teaches, class, c2,
  97.                  prof, smith, teaches, class, c3,
  98.                  prof, jones, teaches, classes, c4, and, c5,
  99.                  classes, c1, c2, c3, c4, and, c5, are, on, the, same, day,
  100.                  class, c1, is, before, class, c2,
  101.                  class, c2, is, before, class, c3,
  102.                  class, c3, is, before, class, c4,
  103.                  class, c4, is, before, class, c5,
  104.                  classes, c1, and, c2, are, in, the, same, room,
  105.                  classes, c2, and, c3, are, in, the, same, room,
  106.                  classes, c3, and, c4, are, in, the, same, room,
  107.                  classes, c4, and, c5, are, in, the, same, room].
  108.  
  109.  
  110. % testForceAllClassesIntoSmallRoomFailure
  111. % we will try to force all classes to happen in room 1 through transitivity
  112. % this should FAIL, since class 3, 4, 5 have more students than can fit in room 1
  113. test(X) :- X = [prof, smith, teaches, class, c1,
  114.                  prof, smith, teaches, class, c2,
  115.                  prof, smith, teaches, class, c3,
  116.                  prof, jones, teaches, classes, c4, and, c5,
  117.                  classes, c1, c2, c3, c4, and, c5, are, on, the, same, day,
  118.                  class, c1, is, before, class, c2,
  119.                  class, c2, is, before, class, c3,
  120.                  class, c3, is, before, class, c4,
  121.                  class, c4, is, before, class, c5,
  122.                  class, c1, is, in, room, 1,
  123.                  classes, c1, and, c2, are, in, the, same, room,
  124.                  classes, c2, and, c3, are, in, the, same, room,
  125.                  classes, c3, and, c4, are, in, the, same, room,
  126.                  classes, c4, and, c5, are, in, the, same, room].
  127.  
  128. %- test(Data), timetable(Data, Timetable), print_timetable(Timetable).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement