Environment Programming in Mas: With Cartago
Environment Programming in Mas: With Cartago
ENVIRONMENT
PROGRAMMING IN MAS
WITH CARTAGO
Alessandro Ricci
aliCE group at DEIS, Universit di Bologna, Cesena
[email protected]
joint work with:
- Michele Piunti, PhD student at DEIS
- Mirko Viroli, Andrea Omicini
OUTLINE
PART I
ENVIRONMENT PROGRAMMING
IN (PROGRAMMING) MAS
- The ROAD to CARTAGO -
AGENT(s)
percepts
actions
ENVIRONMENT
MAS ENVIRONMENT
actions
SIMULATED
WORLD
mimicking
REAL WORLD
(PHYSICAL OR
COMPUTATIONAL)
OR
EXTERNAL
WORLD
INTERFACE
(PHYSICAL OR
COMPUTATIONAL)
OR
percepts
AGENTS
WRAPPER TO
EXISTING
TECHNOLOGY
Example:
JAVA
PLATFORM
ENVIRONMENT MODEL
IN MAS PROGRAMMING
generator of percepts
e.g. Java
JASON EXAMPLE
- GOLD-MINER DEMO public class MiningPlanet extends jason.environment.Environment {
...
public void init(String[] args) {...}
public boolean executeAction(String ag, Structure action) {
boolean result = false;
int agId = getAgIdBasedOnName(ag);
if (action.equals(up)) {
result = model.move(Move.UP, agId);
} else if (action.equals(down)) {
result = model.move(Move.DOWN, agId);
} else if (action.equals(right)) {
...
}
return result;
}
private void updateAgPercept(String agName, int ag) {clearPercepts(agName);
// its location
Location l = model.getAgPos(ag);
addPercept(agName, Literal.parseLiteral("pos(" + l.x + "," + l.y + ")"));
if (model.isCarryingGold(ag)) {
addPercept(agName, Literal.parseLiteral("carrying_gold"));
}
// what's around
updateAgPercept(agName, l.x - 1, l.y - 1);
updateAgPercept(agName, l.x - 1, l.y);
...
}
}
designing good and effective place for agents to live and work in
BACKGROUND LITERATURE
In human science
Abstraction
MAS
actions
Modularity
Orthogonality
percepts
MAS
(Dynamic) extendibility
actions
Reusability
percepts
AGENTS
PART II
A&A MODEL and CARTAGO
PROGRAMMING MODEL & PLATFORM
WHITEBOARD
artifact
BAKERY
workspace
agents can join
dynamically the workspace
ARCHIVE
artifact
COM. CHANNEL
artifact
RESOURCE
artifact
TASK SCHEDULER
artifact
Agents
Artifacts
Workspaces
agent
ARTIFACTS
ARE IN THE
MAINSTREAM
an artifact
agent
SISMA 2008/2009 Seminar, Oct. 2008
agent
artifacts
Environment Programming in CARTAGO
?
percepts
AGENTS
wsp
AGENTS
Abstraction
encapsulation
information hiding
Modularization
extendibility
reuse
wsp
EXTERNAL
WORLD
(PHYSICAL OR
COMPUTATIONAL)
wsp
gui
AGENTS
wsp
HUMAN
USERS
blackboard
wsp
AGENTS
wsp
wsp
GUI
AGENTS
wsp
ObsPropName
Value
ObsPropName
Value
...
...
OBSERVABLE
PROPERTIES
OPERATION X
OpControlName(Params)
USAGE
INTERFACE
ARTIFACT
MANUAL
OpControlName(Params)
OPERATION Y
...
LINK
INTERFACE
Environment Programming in CARTAGO
INTERACTION MODEL:
USE & OBSERVATION
use
ObsPropName
Value
ObsPropName
Value
...
...
myOpControl(x)
myOpControl(X)
AGENT
use action
INTERACTION MODEL:
USE & OBSERVATION
ObsPropName
Value
ObsPropName
Value
...
...
myOpControl(X)
AGENT
OPERATION EXECUTION
INTERACTION MODEL:
USE & OBSERVATION
EVENTS
ObsPropName
Value
OBS PROPERTIES
CHANGE
myOpControl(X)
AGENT
observable effects
INTERACTION MODEL:
USE & OBSERVATION
PName
observe
property
(+PName,?Value)
Value
myOpControl(X)
AGENT
observeProperty action
INTERACTION MODEL:
USE & OBSERVATION
ObsPropName(Value).
ObsPropName(Value).
...
Belief base
(or alike)
ObsPropName
Value
ObsPropName
Value
...
...
focus
myOpControl(X)
AGENT
INTERACTION MODEL:
USE & OBSERVATION
ObsPropName(Value).
ObsPropName(Value).
...
ObsPropName
Value
ObsPropName
Value
Belief base
(or alike)
myOpControl(X)
USE
AGENT
continuous observation
properties, events
EXAMPLES OF ARTIFACTS
LOGIC-BASED SPREADSHEET
ARTIFACT SKETCH
A1
p(1).
p(2).
B1
A2
r(X):-p(X),q(X).
A3
result of ?- r(1).
...
...
q(1).
q(3).
B2
result of ?- q(5).
B3
...
...
...
CARTAGO
Open-source technology
available at http://cartago.sourceforge.net
...AND FRIENDS
Outcome
CARTAGO ARCHITECTURE
Application Agents
MAS
Application
workspaces
blackboard
blackboard
shared
shared
kbKB
Agent Framworks /
Middlewares
artifacts
Execution
Platform
JASON
JASON
MAS
Middleware
Layer
JADEX
3APL
...
JADE
Any
OS
map
map
Application
Specific
Logic
JVM
agent
bodies
workspaces
CARTAGO
JVM
OS
no return value
structured
init operation
SIMPLE EXAMPLE #1
inc
USAGE INTERFACE:
inc: [ op_exec_completed ]
Observable events
event_name(Arg0,Arg1,...)
SIMPLE EXAMPLE #2
USAGE INTERFACE:
inc
inc: [ new_count_value,
op_exec_completed ]
Observable properties
updateObsProperty
getObsProperty
SIMPLE EXAMPLE #3
count
OBSERVABLE PROPERTIES:
count: int
inc
USAGE INTERFACE:
inc: [ op_exec_completed ]
MORE ON ARTIFACTS
Structured operations
by interleaving steps
Linkability
Artifact manual
STRUCTURED OPERATIONS
@OPSTEP methods
UI CONTROL TO TRIGGER
Guards
OP EXECUTION
G
as soon as the
once enabled, the operationG step is executed
OP STEP
guard is evaluated
to true
>
-
GUARDS
OP STEP
OP STEP
EXAMPLE
public class MyArtifact extends requestValue
Artifact { structured operation
Data valueA, valueB;
G: valuesAvailable
@OPERATION void requestValue(){
notifyValues
requestValue
valueA = valueB = null;
nextStep("notifyValues");
requestValue
}
@OPSTEP(guard="valuesAvailable") void notifyValues(){
signal(values,valueA,valueB);
insertValueA
insertValueA atomic op
}
insertValueA
insertValueB atomic op
insertValueB
@OPERATION void
insertValueA(Data v){ valueA = v; }
@OPERATION void insertValueB(Data v){ valueB = v; }
MyArtifact ARTIFACT
SISMA 2008/2009 Seminar, Oct. 2008
artifact use
artifact observation
artifact instantiation,
discovery,
management
joinWsp(Name,?WspId,+Node,+Role,+Cred)
quitWsp(Wid)
use(Aid,OpCntrName(Params),+Sensor,+Timeout,+Filter)
sense(Sensor,?Perception,+Filter,+Timeout)
grab([Aid])
release([Aid])
observeProperty(Aid,PName,?PValue)
focus(Aid,+Sensor,+Filter)
stopFocus(Aid)
makeArtifact(Name,Template,+ArtifactConfig,?Aid)
lookupArtifact(Name,?Aid)
disposeArtifact(Aid)
- factory
- registry
- security-registry
- console
A shared counter
MAS mas0a {
environment:
alice.c4jason.CEnvStandalone
USAGE INTERFACE:
inc
inc: [ new_count_value,
op_exec_completed ]
agents:
user0a agentArchClass alice.c4jason.CAgentArch;
}
package test;
import alice.cartago.*;
public class Counter0 extends Artifact {
int count;
@OPERATION void init(){
count = 0;
}
@OPERATION void inc(){
count++;
signal("new_count_value",count);
}
// user0a
!create_and_use.
+!create_and_use : true
<- cartago.makeArtifact("mycount","test.Counter0",C);
// first use
cartago.use(C,inc);
// second use
cartago.use(C,inc,s0);
cartago.sense(s0,new_count_value(V));
// log the value
cartago.use(console,println("[USER] value ",V)).
A shared counter
MAS mas0b {
environment:
alice.c4jason.CEnvStandalone
USAGE INTERFACE:
inc
inc: [ new_count_value,
op_exec_completed ]
agents:
user0b agentArchClass alice.c4jason.CAgentArch;
}
package test;
import alice.cartago.*;
public class Counter0 extends Artifact {
int count;
@OPERATION void init(){
count = 0;
}
@OPERATION void inc(){
count++;
signal("new_count_value",count);
}
// user0b
!create_and_use.
+!create_and_use : true
<- cartago.makeArtifact("mycount","test.Counter0",C);
// first use
cartago.use(C,inc);
// second use
cartago.use(C,inc).
+artifact_event(C,new_count_value(V)) : true
<- cartago.use(console,println("[USER] value ",V)).
MAS mas1 {
environment:
alice.c4jason.CEnvStandalone
OBSERVABLE PROPERTIES:
agents:
observer agentArchClass alice.c4jason.CAgentArch;
user agentArchClass alice.c4jason.CAgentArch #2;
count: int
inc
USAGE INTERFACE:
inc: [ op_exec_completed ]
package test;
public class Counter1 extends Artifact {
@OPERATION void init(){
defineObsProperty("count",0);
}
@OPERATION void inc(){
int count = getObsProperty("count").intValue();
updateObsProperty("count",count+1);
}
}
// observer
!observe.
+!observe : true
<- cartago.makeArtifact("my_counter","test.Counter1", Count);
cartago.focus(Count).
// user
!use_count.
+!use_count : true
<- ?counter_to_use(Counter) ;
+cycle(0) ;
!use_count(Counter).
+?counter_to_use(Counter) : true
<- cartago.lookupArtifact("my_counter",Counter).
-?counter_to_use(Counter) : true
<- .wait(100);
?counter_to_use(Counter).
+!use_count(C) : cycle(N) & N < 10
<- -cycle(N);
cartago.use(C,inc,mySensor0);
cartago.sense(mySensor0,"operation_completed");
!have_a_rest ;
+cycle(N+1) ;
!use_count(C).
+!use_count(C) : cycle(10).
+count(V) : true
<- cartago.use(console,println("current count observed: ",V)).
+!have_a_rest : true
<- .wait(10).
n_items
max_items
100
put
get
OBSERVABLE PROPERTIES:
n_items: int+
max_items: int
Invariants:
n_items <= max_items
@OPERATION(guard="itemAvailable") void get(){
Item item = items.removeFirst();
updateObsProperty("nItems",items.size()-1);
signal("new_item",item);
}
@GUARD boolean itemAvailable(){ return items.size() > 0; }
USAGE INTERFACE:
put(item:Item) / (n_items < max_items):
[ op_exec_completed ]
get / (n_items >= 0) :
[ new_item(item:Item), op_exec_completed ]
CONSUMERS
!consume.
+!consume: true <?bufferToUse(Buffer);
.print("Going to use ",Buffer);
!consumeItems.
+!consumeItems : true <cartago.use(myBuffer,get,s0,5000);
cartago.sense(s0,new_item(Item),5000);
!consumeItem(Item);
!consumeItems.
+!consumeItem(Item) : true <- ...
+?bufferToUse(BufferId) : true <cartago.lookupArtifact("myBuffer",BufferId).
-?bufferToUse(BufferId) : true <-
.wait(50);
?bufferToUse(BufferId).
13
false
ready
OBSERVABLE PROPERTIES:
n_participants: N > 0
all_ready: {true,false}
USAGE INTERFACE:
ready / true :
[ accepted(N), op_exec_completed ]
in Jason MAS
Distribution
PART III
ADVANCED (SELECTED) ISSUES &
ONGOING WORK
Objective
self-CHOP+CA
Reference literature
ONGOING EVALUATION
(APPLICATIONS)
ORA4MAS
CARTAGO-WS
ARTIFACT LIBRARIES
CARTAGO extensions
2APL, JADE