Skip to content

Commit

Permalink
Updated MC with recent AORTA changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasschmidtjensen committed Feb 20, 2015
1 parent 021123c commit dc4a618
Show file tree
Hide file tree
Showing 114 changed files with 1,271,026 additions and 87,179 deletions.
3 changes: 2 additions & 1 deletion ajpf2014/jpf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ vm.gc = true
# threshold after which number of allocations to perform a garbage collection
# (even within the same transition, to avoid lots of short living objects)
# -1 means never
vm.max_alloc_gc = -1
#vm.max_alloc_gc = -1
vm.max_alloc_gc = 100

# do we run finalizers on collected objects (only makes sense with garbage collection)
vm.finalize = false
Expand Down
2 changes: 2 additions & 0 deletions ajpf2014/src/classes/ail/mas/ActionScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import ajpf.PerceptListener;
import ajpf.MCAPLScheduler;
import ajpf.MCAPLJobber;
import java.util.Collection;
import java.util.Set;


/**
Expand Down
7 changes: 6 additions & 1 deletion ajpf2014/src/classes/ail/semantics/AILAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ public boolean goalEntails(Event e, Plan p, Unifier un) {
}

//---------------------- REASON

String lastPrint = "";
/**
* Call the reasoning cycle. This method relies heavily on the implementation
* of the reasoning cycle and OSRule interface. While the Reasoning Cycle does
Expand All @@ -1615,6 +1615,11 @@ public boolean goalEntails(Event e, Plan p, Unifier un) {
* cycle.
*/
public void reason() {
// String print = "[" + fAgName + "] " + getGoalBase();
// if (!print.equals(lastPrint)) {
// lastPrint = print;
// System.out.println(lastPrint);
// }
if (RC.not_interrupted()) {
RC.setStopandCheck(false);

Expand Down
2 changes: 1 addition & 1 deletion ajpf2014/src/classes/ajpf/MCAPLcontroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void begin() {

public MCAPLJobber scheduling() {
List<MCAPLJobber> activeJobs = scheduler.getActiveJobbers();
//AJPFLogger.info("ajpf.MCAPLcontroller", "About to pick job");
AJPFLogger.fine("ajpf.MCAPLcontroller", "About to pick job from " + activeJobs);
if (!activeJobs.isEmpty()) {
a = null;
int job_num = pickJob(activeJobs.size());
Expand Down
4 changes: 2 additions & 2 deletions examples/2apl/auctionhouse/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.source=1.7
javac.target=1.7
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
Expand Down
13 changes: 5 additions & 8 deletions framework/src/java/aorta/AgentState.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ public class AgentState extends State {

private static final Logger logger = Logger.getLogger(AgentState.class.getName());

@FilterField
private AortaAgent agent;

@FilterField
private List<ReasoningRule> rules;

@FilterField
private Queue<OutgoingOrganizationalMessage> out;

@FilterField
private ExternalAgent externalAgent;

@FilterField
private AortaBridge bridge;

@FilterField
private List<Var> bindings;


public AgentState(AortaAgent agent, MentalState mentalState, Metamodel metamodel, List<ReasoningRule> rules) {
super(mentalState, metamodel);
this.agent = agent;
Expand All @@ -53,8 +52,6 @@ public AgentState(AortaAgent agent, MentalState mentalState, Metamodel metamodel
out = new LinkedList<>();

externalAgent = new ExternalAgent();

bindings = new ArrayList<>();
}

public void setBridge(AortaBridge bridge) {
Expand Down Expand Up @@ -111,7 +108,7 @@ public void insertMessage(IncomingOrganizationalMessage msg) {

if (insert) {
getMentalState().insert(contents);
logger.fine("insertMessage(" + msg + ")");
logger.finer("insertMessage(" + msg + ")");
setChanged(true);
}
}
Expand All @@ -137,7 +134,7 @@ public void removeTerm(Struct term, KBType type) {

public void sendMessage(OutgoingOrganizationalMessage msg) {
out.add(msg);
logger.fine("sendMessage(" + msg + ")");
logger.finer("sendMessage(" + msg + ")");
setChanged(true);
}

Expand Down
33 changes: 21 additions & 12 deletions framework/src/java/aorta/AortaAgent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package aorta;

import alice.tuprolog.NoSolutionException;
import alice.tuprolog.SolveInfo;
import alice.tuprolog.Struct;
import alice.tuprolog.Var;
import aorta.kr.KBType;
import java.util.List;

Expand All @@ -16,7 +19,8 @@
import aorta.organization.AortaArtifactAgent;
import aorta.reasoning.MessageFunction;
import aorta.reasoning.ReasoningRule;
import aorta.tracer.ExecutionTrace;
import aorta.tracer.ConsoleTrace;
import aorta.tracer.StateListener;
import aorta.tracer.Tracer;
import aorta.ts.strategy.AgentStrategy;
import cartago.ArtifactId;
Expand All @@ -28,7 +32,6 @@

public class AortaAgent {

@FilterField
private int cycle;

public static final Logger logger = Logger.getLogger(AortaAgent.class.getName());
Expand All @@ -51,7 +54,7 @@ public class AortaAgent {
private String lastTrace;

@FilterField
private final ExecutionTrace trace;
private final StateListener trace;

private boolean lastCycleChangedState = true;

Expand All @@ -61,8 +64,8 @@ public AortaAgent(String name, MentalState mentalState, Metamodel metamodel, Lis

state = new AgentState(this, mentalState, metamodel, rules);

trace = new ExecutionTrace(name);
state.addStateListener(trace);
trace = new ConsoleTrace(name);
// state.addStateListener(trace);

setup();
}
Expand Down Expand Up @@ -133,8 +136,18 @@ public Aorta getAorta() {
public void newCycle() throws StrategyFailedException {
cycle++;

String goals = "";
List<SolveInfo> infos = state.getMentalState().findAll(new Struct("goal", new Var("G")));
for (SolveInfo info : infos) {
if (info.isSuccess()) {
try {
goals += info.getVarValue("G") + ";";
} catch (NoSolutionException ex) {}
}
}

long start = System.currentTimeMillis();
logger.log(Level.FINEST, "(" + getName() + ") New AORTA cycle [" + cycle + "]. Strategy: " + strategy.getClass().getName());
logger.log(Level.FINE, "(" + getName() + ") New AORTA cycle [" + cycle + "]. Goals: " + goals);

if (cycle == 1) {
state.notifyNewState();
Expand All @@ -146,7 +159,7 @@ public void newCycle() throws StrategyFailedException {
lastCycleChangedState = state.hasChanged();

if (!state.getOut().isEmpty()) {
logger.log(Level.FINEST, "(" + getName() + ") Sending " + state.getOut().size() + " messages.");
logger.log(Level.FINE, "(" + getName() + ") Sending " + state.getOut().size() + " messages.");
Iterator<OutgoingOrganizationalMessage> it = state.getOut().iterator();
while (it.hasNext()) {
OutgoingOrganizationalMessage msg = it.next();
Expand All @@ -160,11 +173,7 @@ public void newCycle() throws StrategyFailedException {
lastTrace = Tracer.printTrace(name);

state.notifyNewState();
logger.log(Level.FINEST, "(" + getName() + ") Cycle done [" + cycle + "] (time: " + (System.currentTimeMillis() - start) + " ms)");
}

public ExecutionTrace getExecutionTrace() {
return trace;
logger.log(Level.FINE, "(" + getName() + ") Cycle done [" + cycle + "] (time: " + (System.currentTimeMillis() - start) + " ms)");
}

public String getLastTrace() {
Expand Down
8 changes: 4 additions & 4 deletions framework/src/java/aorta/reasoning/action/CommitAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx

MentalState ms = state.getMentalState();

final Term clonedObjTerm = Term.createTerm(objective.toString());
Term clonedObjTerm = Term.createTerm(objective.toString());

String bef = clonedObjTerm.toString();
ms.unify(clonedObjTerm, state.getBindings());
clonedObjTerm = ms.unify(clonedObjTerm, state.getBindings());

Term belTerm = FormulaQualifier.qualifyTerm(clonedObjTerm, KBType.BELIEF);
Term goalTerm = FormulaQualifier.qualifyTerm(clonedObjTerm, KBType.GOAL);
Expand All @@ -49,7 +49,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
if (result.isSuccess()) {
state.addBindings(result);

ms.unify(clonedObjTerm, state.getBindings());
clonedObjTerm = ms.unify(clonedObjTerm, state.getBindings());

Struct asStruct;
if (clonedObjTerm instanceof Var) {
Expand All @@ -61,7 +61,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
ActionExecution tr = new ActionExecution();
tr.add(newState, asStruct, KBType.GOAL);

logger.fine("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Executing action: commit(" + asStruct + ")");
logger.finer("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Executing action: commit(" + asStruct + ")");
Tracer.queue(state.getAgent().getName(), "commit(" + asStruct + ")");
} else {
return null;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/java/aorta/reasoning/action/DeactAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected AgentState executeAction(Term option, AgentState state)
state.addBindings(result);

Term qualified = FormulaQualifier.qualifyTerm(reaDef, KBType.ORGANIZATION.getType());
ms.unify(qualified, state.getBindings());
qualified = ms.unify(qualified, state.getBindings());

if (!qualified.isGround()) {
throw new AORTAException("Cannot execute action: term '" + qualified + "' is not ground.");
Expand All @@ -74,7 +74,7 @@ protected AgentState executeAction(Term option, AgentState state)
ActionExecution tr = new ActionExecution();
tr.remove(newState, (Struct) qualified);

logger.fine("[" + state.getAgent().getName() + "] Executing action: deact(" + qualified + ")");
logger.finer("[" + state.getAgent().getName() + "] Executing action: deact(" + qualified + ")");
Tracer.queue(state.getAgent().getName(), "deact(" + qualified + ")");
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions framework/src/java/aorta/reasoning/action/DropAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Term getObjective() {
protected AgentState executeAction(Term option, AgentState state) throws AORTAException {
AgentState newState = state;

final Term clonedObjTerm = Term.createTerm(objective.toString());
Term clonedObjTerm = Term.createTerm(objective.toString());

// Check that it is already a goal
Term goalTerm = FormulaQualifier.qualifyTerm(clonedObjTerm, KBType.GOAL.getType(), true);
Expand All @@ -42,7 +42,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
if (result.isSuccess()) {
state.addBindings(result);

ms.unify(clonedObjTerm, state.getBindings());
clonedObjTerm = ms.unify(clonedObjTerm, state.getBindings());

if (!clonedObjTerm.isGround()) {
throw new AORTAException("Cannot execute action: term '" + clonedObjTerm + "' is not ground.");
Expand All @@ -56,7 +56,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx

ActionExecution tr = new ActionExecution();
tr.remove(newState, asStruct, KBType.GOAL);
logger.fine("[" + state.getAgent().getName() + "] Executing action: drop(" + asStruct + ")");
logger.finer("[" + state.getAgent().getName() + "] Executing action: drop(" + asStruct + ")");
Tracer.queue(state.getAgent().getName(), "drop(" + asStruct + ")");
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions framework/src/java/aorta/reasoning/action/EnactAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
Term t2 = FormulaQualifier.qualifyTerm(reaDef, KBType.ORGANIZATION.getType());

Term test = Term.createTerm(t1 + ", \\+ " + t2);
ms.unify(test, state.getBindings());
test = ms.unify(test, state.getBindings());

SolveInfo result = ms.solve(test);

Expand All @@ -55,7 +55,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
state.addBindings(result);

Term qualified = FormulaQualifier.qualifyTerm(reaDef, KBType.ORGANIZATION.getType());
ms.unify(qualified, state.getBindings());
qualified = ms.unify(qualified, state.getBindings());

if (!qualified.isGround()) {
throw new AORTAException("Cannot execute action: term '" + qualified + "' is not ground.");
Expand Down Expand Up @@ -85,7 +85,7 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx
Struct send = ml.send(Term.TRUE, new Struct("tell"), qualified);
tr.add(newState, FormulaQualifier.qualifyStruct(send, KBType.OPTION));

logger.fine("[" + state.getAgent().getName() + "] Executing action: enact(" + qualified + ")");
logger.finer("[" + state.getAgent().getName() + "] Executing action: enact(" + qualified + ")");
Tracer.queue(state.getAgent().getName(), "enact(" + qualified + ")");

} else {
Expand Down
8 changes: 4 additions & 4 deletions framework/src/java/aorta/reasoning/action/SendAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ protected AgentState executeAction(Term option, AgentState state) throws AORTAEx

MentalState ms = state.getMentalState();

final Term clonedMsgTerm = Term.createTerm(message.toString());
ms.unify(clonedMsgTerm, state.getBindings());
Term clonedMsgTerm = Term.createTerm(message.toString());
clonedMsgTerm = ms.unify(clonedMsgTerm, state.getBindings());

Term recipientsTerm = Term.createTerm(recipients.toString());
ms.unify(recipientsTerm, state.getBindings());
recipientsTerm = ms.unify(recipientsTerm, state.getBindings());

List<Term> rcpList = new ArrayList<>();
if (recipientsTerm.getTerm().isList()) {
Expand Down Expand Up @@ -99,7 +99,7 @@ protected void sendMessage(List<Term> recipientList, Term message, AgentState st
OutgoingOrganizationalMessage msg = new OutgoingOrganizationalMessage(recipientList, message);
state.sendMessage(msg);

logger.fine("[" + state.getAgent().getName() + "] Executing action: send(" + recipientList + "," + message + ")");
logger.finer("[" + state.getAgent().getName() + "] Executing action: send(" + recipientList + "," + message + ")");
Tracer.queue(state.getAgent().getName(), "send(" + recipientList + "," + message + ")");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void sendMessage(List<Term> recipientList, Term message, AgentState st
OutgoingOrganizationalMessage msg = new OutgoingOrganizationalMessage(recipientList, message);
state.sendMessage(msg);

logger.fine("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Executing action: sendonce(" + recipientList + "," + message + ")");
logger.finer("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Executing action: sendonce(" + recipientList + "," + message + ")");
Tracer.queue(state.getAgent().getName(), "sendonce(" + recipientList + "," + message + ")");
}
}
Expand Down
10 changes: 5 additions & 5 deletions framework/src/java/aorta/ts/rules/ActionExecution.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ private AgentState actionExecuted(ActionRule ar, AgentState state, Formula ifCon

Term qualified = FormulaQualifier.qualifyGoal(ms, conjunctContext);

ms.unify(qualified, optionSolution);
qualified = ms.unify(qualified, optionSolution);
SolveInfo contextSolution = ms.solve(qualified);

if (contextSolution.isSuccess()) {
List<Var> bindings = AgentState.mergeBindings(optionSolution, contextSolution);
ms.unify(option, bindings);
ms.unify(qualified, bindings);
option = ms.unify(option, bindings);
qualified = ms.unify(qualified, bindings);

List<Var> prevBindings = newState.getBindings();

Expand All @@ -113,7 +113,7 @@ private AgentState actionExecuted(ActionRule ar, AgentState state, Formula ifCon
} else {
newState.setBindings(prevBindings);

logger.log(Level.FINE, "Transition was not possible (" + Tracer.getQueue(state.getAgent().getName()) + ")");
logger.log(Level.FINER, "Transition was not possible (" + Tracer.getQueue(state.getAgent().getName()) + ")");
Tracer.clearQueue(state.getAgent().getName());
}
}
Expand All @@ -122,7 +122,7 @@ private AgentState actionExecuted(ActionRule ar, AgentState state, Formula ifCon
}
} catch (AORTAException ex) {
Tracer.clearQueue(state.getAgent().getName());
logger.log(Level.FINE, "Transition was not possible (" + ex.getMessage() + ")");
logger.log(Level.FINER, "Transition was not possible (" + ex.getMessage() + ")");
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion framework/src/java/aorta/ts/rules/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AgentState execute(AgentState state) {
Struct oMsg = (Struct) iom.getMessage();
Struct msg = (Struct) oMsg.getArg(0);

logger.log(Level.FINE, "Handling msg: " + msg + " from " + iom.getSender());
logger.log(Level.FINER, "Handling msg: " + msg + " from " + iom.getSender());

Tracer.trace(state.getAgent().getName(), getName(), iom.toString());

Expand Down
4 changes: 2 additions & 2 deletions framework/src/java/aorta/ts/rules/og/DeactRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ protected AgentState execute(AgentState state) {
// TODO: create DeactTest
SolveInfo result = ms.solve(test);
if (result.isSuccess()) {
ms.unify(optRole, result);
optRole = (Struct) ms.unify(optRole, result);

if (optRole.isGround()) {
//XXX: newState = state.clone();
add(newState, optRole);

logger.fine("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Adding option: " + optRole);
logger.finer("[" + state.getAgent().getName() + "/" + state.getAgent().getCycle() + "] Adding option: " + optRole);
Tracer.trace(state.getAgent().getName(), getName(), optRole.getArg(0).toString());
} else {
logger.warning("Failed to consider role, not ground: " + optRole);
Expand Down
Loading

0 comments on commit dc4a618

Please sign in to comment.