Advertisement
Guest User

Untitled

a guest
May 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 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.  
  39. duplu_actgrp(A, G, Dupluri) :-
  40. findall((Ac, Gr, Nr), ( member(Activitate, A), (Ac, Nr) = Activitate, member(Gr, G)), Dupluri).
  41.  
  42. duplu_multiply([],[]).
  43. duplu_multiply([H|R], [Res|Rest]) :- (Ac, Gr, Nr) = H, loop_res(Nr, Ac, Gr, Res), duplu_multiply(R, Rest).
  44.  
  45. termin_duplu(Dupluri, List) :- append(Dupluri, List).
  46.  
  47. loop_res(0, _, _, []).
  48. loop_res(Nr, Ac, Gr, [H|R]) :- Nr > 0, Nrnew is Nr - 1, Y = (Ac, Gr), H = Y , loop_res(Nrnew, Ac, Gr, R).
  49.  
  50. tuplu_DTR(D, T, R, Tupluri) :- findall((Da, Ti, Ro), (member(Da, D), member(Ti, T), member(Ro, R)), Tupluri).
  51.  
  52.  
  53.  
  54.  
  55. mstate(_,_,_,_).
  56.  
  57. initial_state(Actgrupfinal, Tpl, Staff, (Actgrupfinal, Tpl, Staff, [])).
  58.  
  59. final_state(([], _, _, _)).
  60.  
  61. %next_state(CurrentState, NextState)
  62.  
  63. %check_safe( Slot2, Slots1)
  64.  
  65. check_safe(_, []).
  66. check_safe(slot(_, G1, D1, T1, R1, S1), [slot(_, G2, D2, T2, R2, S2)|R]) :-
  67. ((D1 == D2, T1 == T2, \+ G1 == G2, \+ S1 == S2, \+ R1 == R2 );
  68. (\+ T1 == T2);
  69. (\+ D1 == D2)),
  70. check_safe(slot(_, G1, D1, T1, R1, S1), R).
  71.  
  72. next_state( ([H|Agf1], [H2|Tpl1], Staff, Slots), (Agf2, Tpl2, Staff, [slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume)|Slots])) :-
  73. (Ac1, Gr1) = H, (Da1, Tt1, Ro1) = H2,
  74. Agf2 = Agf1, Tpl2 = Tpl1,
  75. member(Prof, Staff), (Nume, ListaAct) = Prof, member(Ac1, ListaAct),
  76. check_safe(slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume), Slots).
  77.  
  78. next_state( (Agf, [H2|Tpl], Staff, Slots), (Agf, Tpl2, Staff, Slots)) :- myconcat(Tpl, [H2], Tpl2).
  79.  
  80. search(CurrentState, Solution) :- final_state(CurrentState),
  81. !,
  82. (_,_,_, Slots) = CurrentState,
  83. reverse(Slots, Solution).
  84.  
  85. search(CurrentState, Solution) :- next_state(CurrentState, NextState),
  86. search(NextState, Solution).
  87.  
  88.  
  89.  
  90.  
  91. % schedule(+Context, -Sol)
  92. % pentru contextul descris, întoarce o soluție care respectă
  93. % constrângerile fizice și de curiculă.
  94. schedule(Context, Sol) :- problem(Problem, Context),
  95. get_listofactivities(Problem, Activity), get_listofstaff(Problem, Staffs),
  96. get_listofgroups(Problem, Group), get_listofrooms(Problem, Room),
  97. get_listoftimes(Problem, Time), get_listofdays(Problem, Day),
  98. duplu_actgrp(Activity, Group, Dupluri),
  99. duplu_multiply(Dupluri, Tmp), termin_duplu(Tmp, Actgrupfinal),
  100. tuplu_DTR(Day, Time, Room, Tupluri),
  101. initial_state(Actgrupfinal, Tupluri, Staffs, Current),
  102. search(Current, Slots),
  103. Sol = (Context, Slots).
  104.  
  105.  
  106. % cost(+Sol, -Cost)
  107. % pentru soluția dată, întoarce costul implicat de constrângerile de
  108. % preferință care au fost încălcate.
  109. cost(_, _) :- fail.
  110.  
  111. % schedule_best(+Context, -Sol, -Cost)
  112. % pentru contextul descris, întoarce soluția validă cu cel mai bun (cel
  113. % mai mic) cost (sau una dintre ele, dacă există mai multe cu același
  114. % cost)
  115. schedule_best(_, _, _) :- fail.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement