Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :-ensure_loaded('probleme.pl').
- :-ensure_loaded('testing.pl').
- myconcat([], List, List).
- myconcat([F|R], List2, [F|S]) :- myconcat(R, List2, S).
- % get_listofdays(+Problem, ?Days)/2
- get_listofdays(Problem, Days) :- problem(Problem, Context),
- member(T, Context),
- T = days(Days).
- % get_listoftimes(+Problem, ?Times)/2
- get_listoftimes(Problem, Times) :- problem(Problem, Context),
- member(T, Context),
- T = times(Times).
- % get_listofrooms(+Problem, ?Rooms)/2
- get_listofrooms(Problem, Rooms) :- problem(Problem, Context),
- member(T, Context),
- T =rooms(Rooms).
- % get_listofgroups(+Problem, ?Groups)/2
- get_listofgroups(Problem, Groups) :- problem(Problem, Context),
- member(T, Context),
- T = groups(Groups).
- % get_listofactivities(+Problem, ?Activities)/2
- get_listofactivities(Problem, Activities) :- problem(Problem, Context),
- member(T, Context),
- T = activities(Activities).
- % get_listofstaff(+Problem, ?Staff)/2
- get_listofstaff(Problem, Staff) :- problem(Problem, Context),
- member(T, Context),
- T = staff(Staff).
- % create_slots(+Problem, ?Slots)/2
- create_slots([], _, _, _, _, [Slots]) :- [Slots].
- create_slots(A, G, D, T, R, P, Slots) :- member(X, A), (Ac, _) = X,
- member(Ds, D), member(Gr, G), member(Tt, T), member(Ro, R),
- member(Y, P), (Ps, N) = Y, member(Ac, N), Slots = slot(Ac, Gr, Ds, Tt, Ro, Ps).
- duplu_actgrp(A, G, Dupluri) :-
- findall((Ac, Gr, Nr), ( member(Activitate, A), (Ac, Nr) = Activitate, member(Gr, G)), Dupluri).
- duplu_multiply([],[]).
- duplu_multiply([H|R], [Res|Rest]) :- (Ac, Gr, Nr) = H, loop_res(Nr, Ac, Gr, Res), duplu_multiply(R, Rest).
- termin_duplu(Dupluri, List) :- append(Dupluri, List).
- loop_res(0, _, _, []).
- loop_res(Nr, Ac, Gr, [H|R]) :- Nr > 0, Nrnew is Nr - 1, Y = (Ac, Gr), H = Y , loop_res(Nrnew, Ac, Gr, R).
- tuplu_DTR(D, T, R, Tupluri) :- findall((Da, Ti, Ro), (member(Da, D), member(Ti, T), member(Ro, R)), Tupluri).
- mstate(_,_,_,_).
- initial_state(Actgrupfinal, Tpl, Staff, mstate(Actgrupfinal, Tpl, Staff, [])).
- final_state(mstate([], _, _, _)).
- %next_state(CurrentState, NextState)
- %check_safe( Slot2, Slots1)
- check_safe(_, []).
- check_safe(Slot2, [H|R]) :- slot(_, G1, D1, T1, R1, S1) = Slot2, slot(_, G2, D2, T2, R2, S2) = H,
- (D1 == D2, T1 == T2, \+ G1 == G2, \+ S1 == S2, \+ R1 == R2 ),
- (\+ T1 == T2),
- (\+ D1 == D2),
- check_safe(Slot2, R).
- next_state( mstate([H|Agf1], [H2, Tpl1], Staff, Slots), mstate(Agf2, Tpl2, Staff, [slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume)|Slots])) :-
- (Ac1, Gr1) = H, (Da1, Tt1, Ro1) = H2,
- member(Prof, Staff), (Nume, ListaAct) = Prof, member(Ac1, ListaAct),
- check_safe(slot(Ac1, Gr1, Da1, Tt1, Ro1, Nume), Slots),
- Tpl2 = Tpl1, Agf2 = Agf1.
- search(CurrentState, Solution) :- final_state(CurrentState),
- !,
- reverse(CurrentState, Solution).
- search(CurrentState, Solution) :- next_state(CurrentState, NextState),
- search(NextState, Solution).
- % schedule(+Context, -Sol)
- % pentru contextul descris, întoarce o soluție care respectă
- % constrângerile fizice și de curiculă.
- schedule(Context, Sol) :- problem(Problem, Context),
- get_listofactivities(Problem, Activity), get_listofstaff(Problem, Staffs),
- get_listofgroups(Problem, Group), get_listofrooms(Problem, Room),
- get_listoftimes(Problem, Time), get_listofdays(Problem, Day),
- duplu_actgrp(Activity, Group, Dupluri),
- duplu_multiply(Dupluri, Tmp), termin_duplu(Tmp, Actgrupfinal),
- tuplu_DTR(Day, Time, Room, Tupluri),
- initial_state(Actgrupfinal, Tupluri, Staffs, Current),
- search(Current, Slots),
- Sol = (Context, Slots).
- % cost(+Sol, -Cost)
- % pentru soluția dată, întoarce costul implicat de constrângerile de
- % preferință care au fost încălcate.
- cost(_, _) :- fail.
- % schedule_best(+Context, -Sol, -Cost)
- % pentru contextul descris, întoarce soluția validă cu cel mai bun (cel
- % mai mic) cost (sau una dintre ele, dacă există mai multe cu același
- % cost)
- schedule_best(_, _, _) :- fail.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement