21
22
25parseProblem(F, O):-parseProblem(F, O, _).
26
29parseProblem(F, O, R) :-
30 read_file(F, L),
31 problem(O, L, R).
32
34:-[readFile]. 35
36
37
43:-[parseDomain]. 44problem(problem(Name, Domain, R, OD, I, G, _, MS, LS))
45 --> ['(',define,'(',problem,Name,')',
46 '(',':',domain, Domain,')'],
47 (require_def(R) ; []),
48 (object_declaration(OD) ; []),
49 init(I),
50 goal(G),
52 (metric_spec(MS) ; []),
53 (length_spec(LS) ; []),
54 [')'].
55
56object_declaration(L) --> ['(',':',objects], typed_list(name, L),[')'].
57init(I) --> ['(',':',init], zeroOrMore(init_el, I), [')'].
58
59init_el(I) --> literal(name, I).
60init_el(set(H,N)) --> ['(','='], f_head(H), number(N), [')']. 61init_el(at(N, L)) --> ['(',at], number(N), literal(name, L), [')']. 62goal(G) --> ['(',':',goal], pre_GD(G),[')'].
64pref_con_GD(and(P)) --> ['(',and], zeroOrMore(pref_con_GD, P), [')'].
67pref_con_GD(P) --> con_GD(P).
68
69con_GD(and(L)) --> ['(',and], zeroOrMore(con_GD, L), [')'].
70con_GD(forall(L, P)) --> ['(',forall,'('], typed_list(variable, L),[')'], con_GD(P), [')'].
71con_GD(at_end(P)) --> ['(',at,end], gd(P), [')'].
72con_GD(always(P)) --> ['(',always], gd(P), [')'].
73con_GD(sometime(P)) --> ['(',sometime], gd(P), [')'].
74con_GD(within(N, P)) --> ['(',within], number(N), gd(P), [')'].
75
76con_GD(at_most_once(P)) --> ['(','at-most-once'], gd(P),[')'].
77con_GD(some_time_after(P1, P2)) --> ['(','sometime-after'], gd(P1), gd(P2), [')'].
78con_GD(some_time_before(P1, P2))--> ['(','sometime-before'], gd(P1), gd(P2), [')'].
79con_GD(always_within(N, P1, P2))--> ['(','always-within'], number(N), gd(P1), gd(P2), [')'].
80con_GD(hold_during(N1, N2, P)) --> ['(','hold-during'], number(N1), number(N2), gd(P), [')'].
81con_GD(hold_after(N, P)) --> ['(','hold-after'], number(N), gd(P),[')'].
82
83metric_spec(metric(O, E)) --> ['(',':',metric], optimization(O), metric_f_exp(E), [')'].
84
85optimization(minimize) --> [minimize].
86optimization(maximize) --> [maximize].
87
88metric_f_exp(E) --> ['('], binary_op(O), metric_f_exp(E1), metric_f_exp(E2), [')'], {E =..[O, E1, E2]}.
89metric_f_exp(multi_op(O,[E1|E]))--> ['('], multi_op(O), metric_f_exp(E1), oneOrMore(metric_f_exp, E), [')']. 90metric_f_exp(E) --> ['(','-'], metric_f_exp(E1), [')'], {E=..[-, E1]}.
91metric_f_exp(N) --> number(N).
92metric_f_exp(F) --> ['('], function_symbol(S), zeroOrMore(name, Ns), [')'], { concat_atom([S|Ns], '-', F) }.
93metric_f_exp(function(S)) --> function_symbol(S).
94metric_f_exp(total_time) --> ['total-time'].
95metric_f_exp(is_violated(N)) --> ['(','is-violated'], pref_name(N), [')'].
96
98length_spec([]) --> [not_defined].