Advertisement
Guest User

Untitled

a guest
May 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1.  
  2. :-ensure_loaded('probleme.pl').
  3. :-ensure_loaded('testing.pl').
  4.  
  5. myconcat([], List, List).
  6. myconcat([F|R], List2, [F|S]) :- myconcat(R, List2, S).
  7.  
  8. % get_listofdays(+Problem, ?Days)/2
  9. get_listofdays(Problem, Days) :- problem(Problem, Context),
  10. member(T, Context),
  11. T = days(Days).
  12.  
  13. % get_listoftimes(+Problem, ?Times)/2
  14. get_listoftimes(Problem, Times) :- problem(Problem, Context),
  15. member(T, Context),
  16. T = times(Times).
  17.  
  18. % get_listofrooms(+Problem, ?Rooms)/2
  19. get_listofrooms(Problem, Rooms) :- problem(Problem, Context),
  20. member(T, Context),
  21. T =rooms(Rooms).
  22.  
  23. % get_listofgroups(+Problem, ?Groups)/2
  24. get_listofgroups(Problem, Groups) :- problem(Problem, Context),
  25. member(T, Context),
  26. T = groups(Groups).
  27.  
  28. % get_listofactivities(+Problem, ?Activities)/2
  29. get_listofactivities(Problem, Activities) :- problem(Problem, Context),
  30. member(T, Context),
  31. T = activities(Activities).
  32.  
  33. % get_listofstaff(+Problem, ?Staff)/2
  34. get_listofstaff(Problem, Staff) :- problem(Problem, Context),
  35. member(T, Context),
  36. T = staff(Staff).
  37.  
  38. % create_slots(+Problem, ?Slots)/2
  39. create_slots([], _, _, _, _, [Slots]) :- [Slots].
  40. create_slots(A, G, D, T, R, P, Slots) :- member(X, A), (Ac, _) = X,
  41. member(Ds, D), member(Gr, G), member(Tt, T), member(Ro, R),
  42. member(Y, P), (Ps, N) = Y, member(Ac, N), Slots = slot(Ac, Gr, Ds, Tt, Ro, Ps).
  43.  
  44.  
  45. duplu_actgrp(A, G, Dupluri) :-
  46. findall((Ac, Gr, Nr), ( member(Activitate, A), (Ac, Nr) = Activitate, member(Gr, G)), Dupluri).
  47.  
  48. duplu_multiply([],[]).
  49. duplu_multiply([H|R], [Res|Rest]) :- (Ac, Gr, Nr) = H, loop_res(Nr, Ac, Gr, Res), duplu_multiply(R, Rest).
  50.  
  51. termin_duplu(Dupluri, List) :- append(Dupluri, List).
  52.  
  53. loop_res(0, _, _, []).
  54. loop_res(Nr, Ac, Gr, [H|R]) :- Nr > 0, Nrnew is Nr - 1, Y = (Ac, Gr), H = Y , loop_res(Nrnew, Ac, Gr, R).
  55.  
  56. tuplu_DTR(D, T, R, Tupluri) :- findall((Da, Ti, Ro), (member(Da, D), member(Ti, T), member(Ro, R)), Tupluri).
  57.  
  58.  
  59.  
  60.  
  61. mstate(_,_,_,_).
  62.  
  63. initial_state(Actgrupfinal, Tpl, Staff, mstate(Actgrupfinal, Tpl, Staff, [])).
  64.  
  65. final_state(mstate([], _, _, _)).
  66.  
  67. %next_state(CurrentState, NextState)
  68.  
  69. %check_safe( Slot2, Slots1)
  70.  
  71. check_safe(_, []).
  72. check_safe(Slot2, [H|R]) :- slot(_, G1, D1, T1, R1, S1) = Slot2, slot(_, G2, D2, T2, R2, S2) = H,
  73. (D1 == D2, T1 == T2, \+ G1 == G2, \+ S1 == S2, \+ R1 == R2 ),
  74. (\+ T1 == T2),
  75. (\+ D1 == D2),
  76. check_safe(Slot2, R).
  77.  
  78. next_state( mstate([H|Agf1], [H2, Tpl1], Staff, Slots), mstate(Agf2, Tpl2, Staff, [slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume)|Slots])) :-
  79. (Ac1, Gr1) = H, (Da1, Tt1, Ro1) = H2,
  80. member(Prof, Staff), (Nume, ListaAct) = Prof, member(Ac1, ListaAct),
  81. check_safe(slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume), Slots),
  82. Tpl2 = Tpl1, Agf2 = Agf1.
  83.  
  84. search(CurrentState, Solution) :- final_state(CurrentState),
  85. !,
  86. reverse(CurrentState, Solution).
  87.  
  88. search(CurrentState, Solution) :- next_state(CurrentState, NextState),
  89. search(NextState, Solution).
  90.  
  91.  
  92.  
  93.  
  94. % schedule(+Context, -Sol)
  95. % pentru contextul descris, întoarce o soluție care respectă
  96. % constrângerile fizice și de curiculă.
  97. schedule(Context, Sol) :- problem(Problem, Context),
  98. get_listofactivities(Problem, Activity), get_listofstaff(Problem, Staffs),
  99. get_listofgroups(Problem, Group), get_listofrooms(Problem, Room),
  100. get_listoftimes(Problem, Time), get_listofdays(Problem, Day),
  101. duplu_actgrp(Activity, Group, Dupluri),
  102. duplu_multiply(Dupluri, Tmp), termin_duplu(Tmp, Actgrupfinal),
  103. tuplu_DTR(Day, Time, Room, Tupluri),
  104. initial_state(Actgrupfinal, Tupluri, Staffs, Current),
  105. search(Current, Slots),
  106. Sol = (Context, Slots).
  107.  
  108.  
  109. % cost(+Sol, -Cost)
  110. % pentru soluția dată, întoarce costul implicat de constrângerile de
  111. % preferință care au fost încălcate.
  112. cost(_, _) :- fail.
  113.  
  114. % schedule_best(+Context, -Sol, -Cost)
  115. % pentru contextul descris, întoarce soluția validă cu cel mai bun (cel
  116. % mai mic) cost (sau una dintre ele, dacă există mai multe cu același
  117. % cost)
  118. schedule_best(_, _, _) :- fail.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement