forked from HSG-WAS-SS24/exercise-5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathilluminance_controller.asl
136 lines (116 loc) · 5.31 KB
/
illuminance_controller.asl
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// illuminance controller agent
/* Initial rules */
is_in_range :- target_illuminance(Target) & current_illuminance(Current) & Target - Current < 100 | Current - Target < 100.
// Inference rule for infering the belief requires_brightening if the target illuminance is higher than the current illuminance
requires_brightening :- target_illuminance(Target) & current_illuminance(Current) & Target > Current & (Target - Current) > 100.
// Inference rule for infering the belief requires_darkening if the target illuminance is lower than the current illuminance
requires_darkening :- target_illuminance(Target) & current_illuminance(Current) & Target < Current & (Current - Target) > 100.
reached_target_illuminance :- target_illuminance(Target) & current_illuminance(Current) & Target == Current | is_in_range.
/* Initial beliefs */
// The agent believes that the target illuminance is 400 lux
target_illuminance(350).
/* Initial goals */
// The agent has the initial goal to start
!start.
/*
* Plan for reacting to the addition of the goal !start
* Triggering event: addition of goal !start
* Context: true (the plan is always applicable)
* Body: every 4000ms, the agent strives to maintain the illuminance in the room at the target level
*/
@start_plan
+!start : true <-
.print("Continuously managing illuminance");
.wait(4000);
!manage_illuminance; // creates the goal !manage_illuminance
!start.
/*
* Plan for reacting to the addition of the goal !manage_illuminance
* Triggering event: addition of goal !manage_illuminance
* Context: the agent believes that the lights are off and that the room requires brightening
* Body: the agent performs the action of turning on the lights
*/
@increase_illuminance_with_lights_plan
+!manage_illuminance : lights("off") & requires_brightening & weather("cloudy") <-
.print("Turning on the lights");
turnOnLights. // performs the action of turning on the lights
/*
* Plan for reacting to the addition of the goal !manage_illuminance
* Triggering event: addition of goal !manage_illuminance
* Context: the agent believes that the lights are on and that the room requires darkening
* Body: the agent performs the action of turning off the lights
*/
@decrease_illuminance_with_lights_plan
+!manage_illuminance: lights("on") & requires_darkening <-
.print("Turning off the lights");
turnOffLights. // performs the action of turning off the lights
/*
* Plan for reacting to the addition of the goal !manage_illuminance
* Triggering event: addition of goal !manage_illuminance
* Context: the agent believes that the blinds are lowered and that the room requires brightening
* Body: the agent performs the action of raising the blinds
*/
@increase_illuminance_with_blinds_plan
+!manage_illuminance : blinds("lowered") & requires_brightening & weather("sunny") <-
.print("Raising the blinds");
raiseBlinds. // performs the action of raising the blinds
/*
* Plan for reacting to the addition of the goal !manage_illuminance
* Triggering event: addition of goal !manage_illuminance
* Context: the agent believes that the blinds are raised and that the room requires darkening
* Body: the agent performs the action of lowering the blinds
*/
@decrease_illuminance_with_blinds_plan
+!manage_illuminance: blinds("raised") & requires_darkening <-
.print("Lowering the blinds");
lowerBlinds. // performs the action of lowering the blinds
/*
* Plan for reacting to the addition of the belief current_illuminance(Current)
* Triggering event: addition of belief current_illuminance(Current)
* Context: true (the plan is always applicable)
* Body: prints the current illuminance conditions in the room
*/
@current_illuminance_plan
+current_illuminance(Current) : true <-
.print("Current illuminance level: ", Current).
/*
* Plan for reacting to the addition of the belief weather(State)
* Triggering event: addition of belief weather(State)
* Context: true (the plan is always applicable)
* Body: prints the weather conditions
*/
@weather_plan
+weather(State) : true <-
.print("The weather is ", State).
/*
* Plan for reacting to the addition of the belief blinds(State)
* Triggering event: addition of belief blinds(State)
* Context: true (the plan is always applicable)
* Body: prints the state of the blinds
*/
@blinds_plan
+blinds(State) : true <-
.print("The blinds are ", State).
/*
* Plan for reacting to the addition of the belief lights(State)
* Triggering event: addition of belief lights(State)
* Context: true (the plan is always applicable)
* Body: prints the state of the lights
*/
@lights_plan
+lights(State) : true <-
.print("The lights are ", State).
/*
* Plan for reacting to the situation where the target illuminance has been reached.
* Context: reached_target_illuminance
* Body: prints a message indicating that the target illuminance has been reached
*/
@target_illuminance_plan
-!manage_illuminance: reached_target_illuminance <-
.print("The target illuminance has been reached ").
@weather_changed_plan
-!weather("sunny"): blinds("raised") <-
.print("Lowering the blinds");
lowerBlinds.
/* Import behavior of agents that work in CArtAgO environments */
{ include("$jacamoJar/templates/common-cartago.asl") }