Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.50 KB | None | 0 0
  1. play(1,1).
  2. play(1,2).
  3. play(1,4).
  4. play(1,6).
  5. play(1,7).
  6. play(1,9).
  7. play(2,1).
  8. play(2,2).
  9. play(2,4).
  10. play(2,5).
  11. play(2,6).
  12. play(2,8).
  13. play(3,1).
  14. play(3,2).
  15. play(3,7).
  16. play(3,8).
  17. play(4,1).
  18. play(4,5).
  19. play(4,6).
  20. play(4,9).
  21. play(5,3).
  22. play(5,5).
  23. play(5,6).
  24. play(5,7).
  25. play(5,8).
  26. duration(1,2).
  27. duration(2,4).
  28. duration(3,1).
  29. duration(4,3).
  30. duration(5,3).
  31. duration(6,2).
  32. duration(7,5).
  33. duration(8,7).
  34. duration(9,6).
  35. solve6_3(MinWaiting):-
  36.                         length(Concert,9),
  37.                         domain(Concert,1,9),
  38.                         all_distinct(Concert),
  39.                         getWaiting(1,Concert,0,0,0,L1),
  40.                         getWaiting(2,Concert,0,0,0,L2),
  41.                         getWaiting(3,Concert,0,0,0,L3),
  42.                         getWaiting(4,Concert,0,0,0,L4),
  43.                         getWaiting(5,Concert,0,0,0,L5),
  44.                         MinWaiting #= L1+L2+L3+L4+L5,
  45.                         append(Concert,[MinWaiting],Var),
  46.                         minimize(labeling([],Var),MinWaiting).
  47.  
  48. getWaiting(_,[],_,_,Res,Res).
  49. getWaiting(Player,[Play|Rest],Played,Pending,SoFar,Res):-
  50.                                                 play(Player,Play),
  51.                                                 NewPlayed #= Played+1,
  52.                                                 NewSoFar #= SoFar + Pending,
  53.                                                 getWaiting(Player,Rest,NewPlayed,0,NewSoFar,Res).
  54. getWaiting(Player,[Play|Rest],Played,Pending,SoFar,Res):-
  55.                                                 Played #> 0,
  56.                                                 \+play(Player,Play),
  57.                                                 duration(Play,D),
  58.                                                 NewPending #= Pending + D,
  59.                                                 getWaiting(Player,Rest,Played,NewPending,SoFar,Res).
  60. getWaiting(Player,[Play|Rest],0,Pending,SoFar,Res):-
  61.                                                 \+play(Player,Play),
  62.                                                 getWaiting(Player,Rest,0,Pending,SoFar,Res).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement