fluent(menu(_)). fluent(portion(_,_)). fluent(biggest_table(_,_)). fluent(table(_,_)). fluent(free(_)). fluent(waiting_staff(_)). fluent(errand_boy(_)). initial_state([ menu(spring_rolls), menu(dumplings), menu(peking_duck), menu(fried_rice), menu(chow_mein), menu(mapo_tofu), portion(spring_rolls, 10), portion(dumplings, 10), portion(peking_duck, 10), portion(fried_rice, 10), portion(chow_mein, 10), portion(mapo_tofu, 0), biggest_table(id8, 8), table(id1, 2), table(id2, 2), table(id3, 3), table(id4, 4), table(id5, 4), table(id6, 5), table(id7, 6), table(id8, 8), free(id1), free(id2), free(id3), free(id4), free(id5), free(id6), free(id7), free(id8), waiting_staff(andy), waiting_staff(becca), waiting_staff(charlie), waiting_staff(danni), errand_boy(jim) ]). reactive_rule( [ happens(sign_in(Staff), _T1, T2), holds(waiting_staff(Staff), T2) ], [ happens(report_duty(Staff), T3, _T4), tc(T2 =< T3) ] ). event(sign_in(_)). action(report_duty(_)). initiated(happens(report_duty(Staff), _T1, _T2), on_duty(Staff), []). initiated(happens(report_duty(Staff), _T1, _T2), staff_status(Staff, available), []). fluent(on_duty(_)). fluent(staff_status(_,_)). reactive_rule( [ happens(sign_out(Staff), _T1, T2), holds(waiting_staff(Staff), T2) ], [ happens(leave_duty(Staff), T3, _T4), tc(T2 =< T3) ] ). event(sign_out(_)). action(leave_duty(_)). terminated(happens(leave_duty(Staff), T1, _T2),on_duty(Staff), [holds(on_duty(Staff), T1)]). terminated(happens(leave_duty(Staff), T1, _T2),staff_status(Staff, _Status), [holds(staff_status(Staff, available), T1)]). reactive_rule( [ happens(arrive(People), T1, T2) ], [ happens(seat(People, T1), T3, _T4), tc(T2 =< T3), tc(T3 =< T2 + 5) ] ). event(arrive(_)). l_events(happens(seat(People, T), TS, _TE), [ lps_number(People, Size), holds(free_table(TId, Size), TS), holds(staff_status(Staff, available), TS), happens(guide(Staff, People, TId), TS, _T2), tc(T =< TS), tc(TS =< T + 10) ] ). l_int(holds(free_table(TId, Size), T), [ holds(table(TId, Size), T), holds(free(TId), T) ] ). l_int(holds(free_table(TId, Size), T), [ holds(table(TId, Size2), T), lps_leq(Size, Size2), holds(free(TId), T) ] ). d_pre([ happens(guide(Staff, People1, TId1), T1, T2), happens(guide(Staff, People2, TId2), T1, T2), lps_diff(People1, People2), lps_same(TId1, TId2) ]). action(guide(_,_,_)). terminated(happens(guide(_Staff, _People, TId), T1, _T2),free(TId), [holds(table(TId, _), T1)]). terminated(happens(guide(Staff, _People, _TId), _T1, _T2),staff_status(Staff, available), []). initiated(happens(guide(Staff, _People, _TId), _T1, _T2),staff_status(Staff, busy), []). reactive_rule( [ happens(book(Person, _Size, _Time), _T1, T2), holds(blacklisted(Person), T2) ], [ happens(reject(Person), T3, _T4), tc(T2 =< T3) ] ). fluent(blacklisted(_)). event(book(_,_,_)). action(reject(_)). l_int(holds(blacklisted(Person), T), [ holds(no_show(Person, N), T), lps_geq(N, 2) ] ). fluent(no_show(_,_)). reactive_rule( [ happens(book(Person, Size, Time), _T1, T2), holds(bookable(Person, Size, Time, TId), T2) ], [ happens(reserve(Person, TId, Time), T3, _T4), tc(T2 =< T3) ] ). d_pre([ happens(reserve(Person1, TId1, Time), T1, T2), happens(reserve(Person2, TId2, Time), T1, T2), lps_diff(Person1, Person2), lps_same(TId1, TId2) ]). action(reserve(_, _, _)). terminated(happens(reserve(_Person, TId, _Time), T1, _T2),free(TId), [holds(table(TId, _), T1)]). initiated(happens(reserve(Person, TId, Time), _T1, T2), reserved(TId, Person, Time), [holds(table(TId, _), T2)]). fluent(reserved(_,_,_)). l_int(holds(bookable(Person, Size, _Time, TId), T), [ holds(not(blacklisted(Person)), T), holds(not(reserved(_, Person, _)), T), holds(table(TId, Size), T), holds(not(reserved(TId, _, _)), T) ] ). l_int(holds(bookable(Person, Size, _Time, TId), T), [ holds(not(blacklisted(Person)), T), holds(not(reserved(_, Person, _)), T), holds(table(TId, Size2), T), lps_leq(Size, Size2), holds(not(reserved(TId, _, _)), T) ] ). reactive_rule( [ holds(reserved(_TId, Person, Time), T1), tc(Time < T1), lps_more(T1, Time) ], [ happens(strike(Person), T2, _T3), tc(T1 =< T2) ] ). l_events(happens(strike(Person), TS, TE), [ holds(no_show(Person, N), TS), lps_inc(N, N1), happens(update_no_show(Person, N1), TS, TE) ] ). l_events(happens(strike(Person), TS, TE), [ holds(not(no_show(Person, _)), TS), happens(update_no_show(Person, 1), TS, TE) ] ). action(update_no_show(_,_)). terminated(happens(update_no_show(Person, _N), _T1, _T2), no_show(Person, _X), []). terminated(happens(update_no_show(Person, _N), _T1, _T2), reserved(_, Person, _Time), []). initiated(happens(update_no_show(Person, N), _T1, _T2), no_show(Person, N), []). reactive_rule( [ happens(order(Person, TId, What), _T1, T2), holds(menu(What), T2) ], [ happens(fulfil(Person, TId, What, T2), T3, T4), tc(T2 =< T3), tc(T4 =< T2 + 10) ] ). event(order(_,_,_)). l_events(happens(fulfil(Person, TId, What, _T), TS, TE), [ holds(portion(What, N), TS), lps_geq(N, 1), happens(get_serving(What, N), TS, T2), happens(bring(Person, TId, What), T2, TE) ] ). l_events(happens(fulfil(Person, TId, What, T), TS, TE), [ holds(portion(What, N), TS), lps_less(N, 1), happens(cook(What), TS, T2), tc(TS =< T + 2), happens(get_serving(What, N), T2, T3), happens(bring(Person, TId, What), T3, TE) ] ). l_events(happens(fulfil(Person, TId, What, _T), TS, TE), [ holds(errand_boy(Boy), TS), happens(send_errand_boy(Boy, What), TS, T2), happens(return_errand_boy(Boy, What, _Amount), T3, T4), tc(T2 =< T3), tc(T3 =< T2 + 3), holds(portion(What, N), T4), happens(get_serving(What, N), T4, T5), happens(bring(Person, TId, What), T5, TE) ] ). action(send_errand_boy(_,_)). action(cook(_)). d_pre([ happens(cook(mapo_tofu), _T1, T2), holds(not(raw_ing(tofu)), T2) ]). fluent(raw_ing(_)). d_pre([ happens(get_serving(What, N), _T1, T2), holds(portion(What, N), T2), lps_less(N, 1) ]). event(return_errand_boy(_,_,_)). terminated(happens(return_errand_boy(_Boy, What, _Amount), T1, _T2), portion(What, _), [holds(portion(What, N), T1), lps_less(N, 1)]). initiated(happens(return_errand_boy(_Boy, What, Amount), _T1, _T2), portion(What, Amount), []). action(get_serving(_,_)). terminated(happens(get_serving(What, _N), _T1, _T2), portion(What, _), []). initiated(happens(get_serving(What, N), _T1, _T2), portion(What, N1), [lps_dec(N, N1)]). action(bring(_,_,_)). l_timeless(lps_number(People, Size), [my_length(People, Size)]). l_timeless(lps_same(X, Y), [X == Y]). l_timeless(lps_diff(X, Y), [X \== Y]). l_timeless(lps_less(X, Y), [X < Y]). l_timeless(lps_more(X, Y), [X > Y]). l_timeless(lps_leq(X, Y), [X =< Y]). l_timeless(lps_geq(X, Y), [X >= Y]). l_timeless(lps_inc(X, X1), [X1 is X + 1]). l_timeless(lps_dec(X, X1), [X1 is X - 1]). l_timeless(lps_write(X), [write(X),nl]). % define this here to avoid Prolog dialect (module) dependencies my_length([], 0) :- !. my_length([_|L], Size) :- my_length(L,N), Size is N+1. observe([sign_in(andy), sign_in(becca)], 1). observe([arrive([person_1, person_2, person_3]), arrive([person_4, person_5, person_6])], 2). observe([], 3). observe([], 4). observe([], 5). /* observe([book(john, 2, 4)], 1). observe([], 2). observe([], 3). observe([], 4). observe([], 5). observe([], 6). observe([book(john, 2, 9)], 7). observe([], 8). observe([], 9). observe([], 10). observe([], 11). observe([book(john, 2, 13)], 12). observe([], 13). observe([], 14). */