-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsensing_agent.asl
99 lines (80 loc) · 3.99 KB
/
sensing_agent.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
// sensing agent
/* Initial beliefs and rules */
// infers whether there is a mission for which goal G has to be achieved by an agent with role R
role_goal(R,G) :- role_mission(R,_,M) & mission_goal(M,G).
// infers whether there the agent has a plan that is relevant for goal G
has_plan_for(G) :- .relevant_plans({+!G},LP) & LP \== [].
// infers whether there is no goal associated with role R for which the agent does not have a relevant plan
i_have_plans_for(R) :- not (role_goal(R,G) & not has_plan_for(G)).
/* Initial goals */
!start. // the agent has the goal to start
/*
* Plan for reacting to the addition of the goal !start
* Triggering event: addition of goal !start
* Context: the agent believes that it can manage a group and a scheme in an organization
* Body: greets the user
*/
@start_plan
+!start : true <-
.print("Hello world").
/*
* Plan for reacting to the addition of the goal !read_temperature
* Triggering event: addition of goal !read_temperature
* Context: true (the plan is always applicable)
* Body: reads the temperature using a weather station artifact and broadcasts the reading
*/
@read_temperature_plan
+!read_temperature : true <-
.print("Reading the temperature");
readCurrentTemperature(47.42, 9.37, Celcius); // reads the current temperature using the artifact
.print("Read temperature (Celcius): ", Celcius);
.broadcast(tell, temperature(Celcius)). // broadcasts the temperature reading
/*
* Plan for reacting to the addition of the belief organization_deployed(OrgName)
* Triggering event: addition of belief organization_deployed(OrgName)
* Context: true (the plan is always applicable)
* Body: joins the workspace and the organization named OrgName, and creates the goal of adopting relevant roles
*/
@organization_deployed_plan
+organization_deployed(OrgName) : true <-
.print("Notified about organization deployment of ", OrgName);
// joins the workspace
joinWorkspace(OrgName, _);
// looks up for, and focuses on the OrgArtifact that represents the organization
lookupArtifact(OrgName, OrgId);
focus(OrgId);
// creates the goal for adopting relevant roles
!adopt_relevant_roles.
/*
* Plan for reacting to the addition of goal !adopt_relevant_roles
* Triggering event: addition of goal !adopt_relevant_roles
* Context: true (the plan is always applicable)
* Body: reasons on the organization specification and adopts all relevant roles
*/
@adopt_relevant_roles_plan
+!adopt_relevant_roles : true <-
// finds all relevant roles
.findall(Role, role(Role, Super) & i_have_plans_for(Role), RelevantRoles);
.print("Inferred that I have plans for the roles: ", RelevantRoles);
// adopts each role in the list RelevantRoles (could have also been implemented recursively)
for (.member(Role, RelevantRoles)) {
.print("Adopting the role of ", Role);
adoptRole(Role);
}.
/*
* Plan for reacting to the addition of the certified_reputation(CertificationAgent, SourceAgent, MessageContent, CRRating)
* Triggering event: addition of belief certified_reputation(CertificationAgent, SourceAgent, MessageContent, CRRating)
* Context: true (the plan is always applicable)
* Body: prints new certified reputation rating (relevant from Task 3 and on)
*/
+certified_reputation(CertificationAgent, SourceAgent, MessageContent, CRRating): true <-
.print("Certified Reputation Rating: (", CertificationAgent, ", ", SourceAgent, ", ", MessageContent, ", ", CRRating, ")").
/* Import behavior of agents that work in CArtAgO environments */
{ include("$jacamoJar/templates/common-cartago.asl") }
/* Import behavior of agents that work in MOISE organizations */
{ include("$jacamoJar/templates/common-moise.asl") }
/* Import behavior of agents that reason on MOISE organizations */
{ include("$moiseJar/asl/org-rules.asl") }
/* Import behavior of agents that react to organizational events
(if observing, i.e. being focused on the appropriate organization artifacts) */
{ include("inc/skills.asl") }