-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.0.1-planning.lp
106 lines (85 loc) · 3.24 KB
/
8.0.1-planning.lp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
time(timeConstant).
avai(D, V, 0) :- init_loc(D, V), time(0).
% #program plan(T).
%--------generation
0 {as(D, N, T): avai(D, V, T), agent(D), time(T)} 1 :- request(N, _, _, _, T), time(T).
% each drone can be assigned once at each time step.
:- as(D, N1, T), as(D, N2, T), N1 != N2, time(T).
% a request can only be assigned once
:- as(D1, N, T), as(D2, N, T), D1 != D2.
:- as(_, N, T1), as(_, N, T2), T1 != T2.
% if number requests > number avai drone: all avai drone must be assigned
:- C1 = #count{N:request(N, _, _, _, T), time(T)}, C2=#count{D:avai(D, _, T), time(T)}, C3 = #count{N: as(_, N, T), time(T)}, time(T), C1 > C2, C3 != C2.
% if number requests < number avai drone: all requests must be assigned
:- C1= #count{N:request(N, _, _, _, T), time(T)}, C2=#count{D:avai(D, _, T), time(T)}, C3 = #count{N: as(_, N, T), time(T)}, time(T), C1 <= C2, C3 != C1.
%-------change location
%location of assigned agent but not at origin
avai(D, V', T+2) :- as(D, N, T), request(N, V1, V', _, T), avai(D, V, T), V!= V1, time(T).
% location of not assign agent
avai(D, V, T+1) :- not as(D, _, T), avai(D, V, T), time(T).
%location of assigned agent at origin
avai(D, V', T+1) :- as(D, N, T), request(N, V, V', _, T), avai(D, V, T), time(T).
%---------cost
cost(N, C, T) :- as(D, N, T), request(N, V1, V', _, _), avai(D, V, T), operation_cost(V1, V, C).
iteration_cost(TC, T) :- TC = #sum {C, N: cost(N, C, T), time(T)}, time(T).
#minimize{TC: iteration_cost(TC, T), time(T)}.
%--------- auxiliary
incomplete_request(N, T+1) :- request(N, V, V', W, T), not as(_, N, _), time(T).
% request(N,V, V', W, T) :- new_request(N, T), request(N, V, V', W, _), time(T).
complete :- C = #count {N: as(_, N, _)}, total_request(TR), C = TR.
% total_cost(TC) :- TC = #sum {C, T: iteration_cost(C, T)}.
#show.
#show as(D, N, T): as(D, N, T).
#show request(N, V, V', W, T+1): incomplete_request(N, T+1), request(N, V, V', W, T).
% #show avai(D, V, T): avai(D, V, T), time(T'), T > T'.
#show avai/3.
#show complete/0.
#show iteration_cost/2.
% #show cost/3.
% #show iteration_cost/2.
% #show incomplete_request/2.
% #show request/5.
% #show avai(D, V, T) : avai(D, V, T), time(T).
% #show test/4.
% #show total_cost/1.
% #show time/1.
% #show request(N, V, V', W, T) : request(N, V, V', W, T), time(T1), T = T1.
% time(0..3).
% agent(0..2).
% vertiport(0..5).
% horizon(2).
% init_loc(0, 3).
% init_loc(1, 0).
% init_loc(2, 2).
% request(0, 1, 4, 20, 1).
% request(2, 1, 0, 22, 1).
% request(3, 2, 3, 23, 1).
% request(1, 4, 0, 21, 2).
% % request(4, 4, 1, 24, 2).
% % request(5, 2, 0, 21, 2).
% % request(6, 1, 4, 22, 2).
% operation_cost(0, 1, 21).
% operation_cost(1, 0, 21).
% operation_cost(0, 2, 23).
% operation_cost(2, 0, 23).
% operation_cost(0, 3, 24).
% operation_cost(3, 0, 24).
% operation_cost(0, 4, 22).
% operation_cost(4, 0, 22).
% operation_cost(1, 2, 24).
% operation_cost(2, 1, 24).
% operation_cost(1, 3, 22).
% operation_cost(3, 1, 22).
% operation_cost(1, 4, 22).
% operation_cost(4, 1, 22).
% operation_cost(2, 3, 20).
% operation_cost(3, 2, 20).
% operation_cost(2, 4, 20).
% operation_cost(4, 2, 20).
% operation_cost(3, 4, 24).
% operation_cost(4, 3, 24).
% operation_cost(0, 0, 0).
% operation_cost(1, 1, 0).
% operation_cost(2, 2, 0).
% operation_cost(3, 3, 0).
% operation_cost(4, 4, 0).