-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan-choice.dl
95 lines (77 loc) · 3.28 KB
/
plan-choice.dl
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
.type ParkId <: symbol
.type CampId <: symbol
.type Name <: symbol
.type Distance <: float
.decl camp(camp:CampId, park: ParkId, name:Name)
.input camp(filename="campground.facts")
.decl park(park:ParkId, name:Name)
.input park(filename="park.facts")
.decl distance(camp1:CampId, camp2:CampId, dist:Distance)
.input distance(filename="distance.facts")
.decl location(camp:CampId, lat:float, long: float)
.input location(filename="location.facts")
.decl amenities(camp:CampId, rv:number, internet:symbol, cell:symbol, dump:symbol)
.input amenities(filename="amenities.facts")
// Starting point park
.decl starting_point_park(park:ParkId)
.input starting_point_park(IO=file, filename="from_park")
// Starting campground
.decl starting_point(camp:CampId)
starting_point(c) :- camp(c, p, _), starting_point_park(p).
// Ending at park
.decl final_dest_park(park:ParkId)
.input final_dest_park(IO=file, filename="to_park")
// Ending campground
.decl final_dest(camp:CampId)
final_dest(c) :- camp(c, p, _), final_dest_park(p).
// Campgrounds that fit our RV
// (note: some campgrounds don't have accurate rv limits here and just list 0)
.decl rv_camp(id:CampId)
rv_camp(id) :- camp(id, _, _), amenities(id, rv_len, _, _, _), (rv_len = 0 ; rv_len >= 34).
// Distances between campgrounds that fit our RV
.decl rv_dist(camp1:CampId, camp2:CampId, dist:Distance)
rv_dist(from, to, len) :- distance(from, to, len), rv_camp(from), rv_camp(to).
rv_dist(to, from, len) :- distance(from, to, len), rv_camp(from), rv_camp(to).
// Optimized road trip segments
// 1. Limit 600mi between stops
// 2. Make 200mi progress towards final destination
.decl segment(camp1:CampId, camp2:CampId, dist:Distance)
segment(from, to, len) :-
rv_dist(from, to, len),
len <= 600,
rv_dist(from, end, dist_from),
rv_dist(to, end, dist_to),
dist_from - dist_to > 200,
final_dest(end).
// Generate a non-deterministic path
.decl road_trip_segment(from:CampId, to:CampId, dist:Distance, acc:Distance, stop_ix:number) choice-domain from
road_trip_segment("start", s, 0, 0, 1) :- starting_point(s).
road_trip_segment(f, t, d, acc+d, ix+1) :-
road_trip_segment(_, f, _, acc, ix),
segment(f, t, d).
// Generate a path with minimum distance between stops
.decl road_trip_segment_min(from:CampId, to:CampId, dist:Distance, acc:Distance, stop_ix:number) choice-domain from
road_trip_segment_min("start", s, 0, 0, 1) :- starting_point(s).
road_trip_segment_min(f, t, d, acc+d, ix+1) :-
road_trip_segment_min(_, f, _, acc, ix),
d = min l : segment(f, t, l).
// Generate a path maintaining service
.decl road_trip_segment_cell(from:CampId, to:CampId, dist:Distance, acc:Distance, stop_ix:number) choice-domain from
road_trip_segment_cell("start", s, 0, 0, 1) :- starting_point(s).
road_trip_segment_cell(f, t, d, acc+d, ix+1) :-
road_trip_segment_cell(_, f, _, acc, ix),
segment(f, t, d),
amenities(t, _, int, cell, _),
(!(int = "No") ; !(cell = "No")).
.decl ex(p:Name, c:Name, acc:Distance, ix:number)
.output ex(filename="souffle-plan-choice.tsv")
ex(p, c, acc, ix) :-
road_trip_segment(_, t, _, acc, ix),
camp(t, pid, c),
park(pid, p).
.decl ex_min(p:Name, c:Name, acc:Distance, ix:number)
.output ex_min(filename="souffle-plan-choice-min.tsv")
ex_min(p, c, acc, ix) :-
road_trip_segment_min(_, t, _, acc, ix),
camp(t, pid, c),
park(pid, p).