-
Notifications
You must be signed in to change notification settings - Fork 0
/
av_utils.pl
89 lines (71 loc) · 2.47 KB
/
av_utils.pl
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
:- module(av_utils, []).
:- use_module(library(le_answer)).
%% Rules to bridge prolog and Logo
:- dynamic violation/4.
:- prolog_load_context(directory, Dir),
asserta(user:log_path(Dir)).
log(crossing, Self, CarType, LightNum) :-
(
(
color(LightNum, red),
swritef(Message, '%w %w crossed with %w light.', [CarType, Self, red]),
print_message(warning, Message)
)
; true
).
log(give_way, Self, CarType, X, LightNum) :-
color(LightNum, Light),
swritef(Message, '%w %w has given way to %w at a %w light.', [CarType, Self, X, Light]),
print_message(warning, Message).
log(stop, Self, CarType, X) :-
swritef(Message, '%w %w has given way to %w at a stop sign.', [CarType, Self, X]),
print_message(warning, Message).
log(yellow, Self, CarType, LightNum, X, Y) :-
color(LightNum, Light),
swritef(Message, '%w %w crossed with a %w light seen at position %w %w.', [CarType, Self, Light, X, Y]),
print_message(warning, Message).
color(55, green).
color(45, yellow).
color(15, red).
color(9.9, white).
emergency_vehicle(Vehicle) :-
% Set one of the colours to be the emergency vehicle
% 85 is colour cyan.
% Change to emergency_vehicle in the NetLogo and Prolog code.
% member('truck', Vehicle).
Vehicle == 'ambulance'.
emergency_vehicles(Vehicle) :-
member(ambulance, Vehicle).
pedestrian(Vehicle) :-
% Identify pedestrian by type
member(person, Vehicle).
in_intersection(InIntersection) :-
% Check if the vehicle is in the intersection
% InIntersection is true if set to 1
InIntersection == 1.
% in_intersection(X, Y) :-
% X > -5,
% Y > -5.
% in_intersection(X, Y) :-
% X > -5,
% Y > -5.
add_violation(Vehicle, CarType, Violation, Context) :-
% Context is anonymous to avoid repeating the same violation.
( violation(Vehicle, CarType, Violation, _)
-> true
; assertz(violation(Vehicle, CarType, Violation, Context))
).
log_violations :-
log_path(Path),
string_concat(Path, '/violations.pl', PathFull),
atom_string(PathAtom, PathFull),
% prolog_load_context(directory, Path),
% print_message(warning, Path),
tell(PathAtom), write(':- dynamic violation/4.'), nl, listing(violation/4), told.
% LE Methods
pl_to_le([], []).
pl_to_le([Fact|Rest], [LEFact|LERest]) :-
le_answer:translate_goal_into_LE(A,List),
atomics_to_string(List, ' ', LEFact).
query_log(ID, Facts, Query) :-
pl_to_le(Facts, LEFacts).