1?-use_module(library(lists)). 3:-ensure_loaded('temporalOrderCleaner.pl'). 4
5
6mapToTotalOrderPlan( Plan, Ordering ,NewOrdering) :-
7
8
9 fetchTemporalReferences(Plan, OrderingMinusAbstractTimepoints),!,
10
11 navigatePlanTree(Plan, Ordering, OrderingMinusAbstractTimepoints, t, NewOrdering),
12
13 14 !.
15
16
17navigatePlanTree(Plan, Ordering, OrderingMinusAbstractTimepoints, Timepoint, NewOrdering) :-
18
19 20 member( before(X, Timepoint), Ordering),
21
22 23 member( X, OrderingMinusAbstractTimepoints),
24
25 navigatePlanTree(Plan, Ordering, OrderingMinusAbstractTimepoints, X, NewOrdering).
26
27
29navigatePlanTree(Plan, Ordering, OrderingMinusAbstractTimepoints, Timepoint, NewOrdering) :-
30
31 32 member( before(AbstractTimepoint, Timepoint), Ordering),
33
34
35 \+ member( AbstractTimepoint, OrderingMinusAbstractTimepoints),
36
37
38 39
40 41 findall(BranchTimepoint, member( before(BranchTimepoint, AbstractTimepoint), Ordering), [Head, Tail]),
42
43 mergeBranches(Plan, Head, Tail, Timepoint,AbstractTimepoint, Ordering, NewMergedOrdering ),
44
45 navigatePlanTree(Plan, NewMergedOrdering, OrderingMinusAbstractTimepoints, Timepoint, NewOrdering ).
46
47navigatePlanTree(Plan, NewOrdering, OrderingMinusAbstractTimepoints, Timepoint, NewOrdering).
48
49
50
51
52mergeBranches(Plan, LeftBranch, RightBranch, AbstractTimepointsChild,AbstractTimepoint, Ordering, NewOrdering):-
53
54 findEndTimepoint(LeftBranch, Ordering, LeftEndTimepoint),
55
56 removeAbstractTemporalOrderings(Ordering, AbstractTimepoint, OrderingWithoutTimepoint),
57
58 append(OrderingWithoutTimepoint, [before(RightBranch, LeftEndTimepoint)], BuildingNewOrdering ),
59
60 append(BuildingNewOrdering, [before(LeftBranch, AbstractTimepointsChild)], NewOrdering).
61
62
63
64
66findEndTimepoint(Branch,Ordering, EndTimepoint):-
67
68 member(before(ParentNode,Branch), Ordering),
69
70 findEndTimepoint(ParentNode, Ordering, EndTimepoint).
71
73findEndTimepoint(Branch, Ordering, Branch).
74
75
76removeAbstractTemporalOrderings(Ordering, AbstractTimepoint, OrderingWithoutTimepoint) :-
77 findall( before(X,AbstractTimepoint), member(before(X,AbstractTimepoint), Ordering), ChildrenOrderingToDelete ),
78 findall( before(AbstractTimepoint, Y), member(before(AbstractTimepoint,Y), Ordering), ParentOrderingToDelete ),
79
80 deleteList(ChildrenOrderingToDelete, Ordering, OrderingMinusAbstractChildrenTimepoints ),
81 deleteList(ParentOrderingToDelete, OrderingMinusAbstractChildrenTimepoints, OrderingWithoutTimepoint ).
82
83
84deleteList([], Result, Result).
85deleteList([Head | Tail], WorkingList, Accum):-
86 delete(WorkingList, Head, ResultList),
87 deleteList(Tail, ResultList, Accum).
88
89
90