|
From: <jom...@us...> - 2016-04-11 18:09:40
|
Revision: 1897
http://sourceforge.net/p/jason/svn/1897
Author: jomifred
Date: 2016-04-11 18:09:37 +0000 (Mon, 11 Apr 2016)
Log Message:
-----------
avoid unnecessary use of Conf.C.SI in TS class -- and thus the concurrent access to it.
Modified Paths:
--------------
trunk/examples/food-simulation/src/java/FoodEnvironment.java
trunk/examples/gold-miners-II/arch/LocalMinerArch.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
Added Paths:
-----------
trunk/lib/npl.jar
Modified: trunk/examples/food-simulation/src/java/FoodEnvironment.java
===================================================================
--- trunk/examples/food-simulation/src/java/FoodEnvironment.java 2016-04-11 13:21:09 UTC (rev 1896)
+++ trunk/examples/food-simulation/src/java/FoodEnvironment.java 2016-04-11 18:09:37 UTC (rev 1897)
@@ -9,6 +9,7 @@
import jason.environment.grid.Location;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -41,7 +42,7 @@
}
@Override
- public List<Literal> getPercepts(String agName) {
+ public Collection<Literal> getPercepts(String agName) {
// if the agent is not in the map, add it and update its perception
if (ag2id.get(agName) == null) {
updateAgPercept(addAg2IdMap(agName));
Modified: trunk/examples/gold-miners-II/arch/LocalMinerArch.java
===================================================================
--- trunk/examples/gold-miners-II/arch/LocalMinerArch.java 2016-04-11 13:21:09 UTC (rev 1896)
+++ trunk/examples/gold-miners-II/arch/LocalMinerArch.java 2016-04-11 18:09:37 UTC (rev 1897)
@@ -1,12 +1,12 @@
package arch;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.logging.Level;
+
import jason.asSyntax.Literal;
import jason.asSyntax.NumberTerm;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Level;
-
/** architecture for local simulator */
public class LocalMinerArch extends MinerArch {
@@ -16,8 +16,8 @@
are leaved in the list of perception for the agent.
*/
@Override
- public List<Literal> perceive() {
- List<Literal> per = super.perceive();
+ public Collection<Literal> perceive() {
+ Collection<Literal> per = super.perceive();
try {
if (per != null) {
Iterator<Literal> ip = per.iterator();
Added: trunk/lib/npl.jar
===================================================================
(Binary files differ)
Index: trunk/lib/npl.jar
===================================================================
--- trunk/lib/npl.jar 2016-04-11 13:21:09 UTC (rev 1896)
+++ trunk/lib/npl.jar 2016-04-11 18:09:37 UTC (rev 1897)
Property changes on: trunk/lib/npl.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/java-archive
\ No newline at end of property
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-11 13:21:09 UTC (rev 1896)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-11 18:09:37 UTC (rev 1897)
@@ -602,20 +602,20 @@
a = conf.ag.selectAction(conf.C.getFeedbackActions());
}
if (a != null) {
- confP.C.SI = a.getIntention();
+ final Intention curInt = a.getIntention();
// remove the intention from PA (PA has all pending action, including those in FA;
// but, if the intention is not in PA, it means that the intention was dropped
// and should not return to I)
- if (C.removePendingAction(confP.C.SI.getId()) != null) {
+ if (C.removePendingAction(curInt.getId()) != null) {
if (a.getResult()) {
// add the intention back in I
- updateIntention(conf.C.SI);
- applyClrInt(confP.C.SI);
+ updateIntention(curInt);
+ applyClrInt(curInt);
if (hasGoalListener())
for (GoalListener gl: getGoalListeners())
- for (IntendedMeans im: confP.C.SI) //.getIMs())
+ for (IntendedMeans im: curInt) //.getIMs())
gl.goalResumed(im.getTrigger());
} else {
String reason = a.getFailureMsg();
@@ -623,7 +623,7 @@
ListTerm annots = JasonException.createBasicErrorAnnots("action_failed", reason);
if (a.getFailureReason() != null)
annots.append(a.getFailureReason());
- generateGoalDeletion(conf.C.SI, annots);
+ generateGoalDeletion(curInt, annots);
C.removeAtomicIntention(); // if (potential) atomic intention is not removed, it will be selected in selInt or selEv and runs again
}
} else {
@@ -659,18 +659,22 @@
private void applyExecInt() throws JasonException {
confP.stepAct = State.ClrInt; // default next step
- if (conf.C.SI.isFinished()) {
+ final Intention curInt = conf.C.SI;
+ if (curInt == null)
return;
+
+ if (curInt.isFinished()) {
+ return;
}
// get next formula in the body of the intended means
// on the top of the selected intention
- IntendedMeans im = conf.C.SI.peek();
+ IntendedMeans im = curInt.peek();
if (im.isFinished()) {
// for empty plans! may need unif, etc
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
return;
}
Unifier u = im.unif;
@@ -682,14 +686,14 @@
bTerm = bTerm.capply(u);
if (bTerm.isVar()) { // the case of !A with A not ground
String msg = h.getSrcInfo()+": "+ "Variable '"+bTerm+"' must be ground.";
- if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_without_value", msg)))
+ if (!generateGoalDeletion(curInt, JasonException.createBasicErrorAnnots("body_var_without_value", msg)))
logger.log(Level.SEVERE, msg);
return;
}
if (bTerm.isPlanBody()) {
if (h.getBodyType() != BodyType.action) { // the case of ...; A = { !g }; +g; ....
String msg = h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable '"+bTerm+"' unified with a plan body. ";
- if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_with_op", msg)))
+ if (!generateGoalDeletion(curInt, JasonException.createBasicErrorAnnots("body_var_with_op", msg)))
logger.log(Level.SEVERE, msg);
return;
}
@@ -717,7 +721,7 @@
// Rule Action
case action:
body = (Literal)body.capply(u);
- confP.C.A = new ActionExec(body, conf.C.SI);
+ confP.C.A = new ActionExec(body, curInt);
break;
case internalAction:
@@ -743,10 +747,10 @@
}
if (ok && !ia.suspendIntention())
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
} catch (JasonException e) {
errorAnnots = e.getErrorTerms();
- if (!generateGoalDeletion(conf.C.SI, errorAnnots))
+ if (!generateGoalDeletion(curInt, errorAnnots))
logger.log(Level.SEVERE, body.getErrorMsg()+": "+ e.getMessage());
ok = true; // just to not generate the event again
} catch (Exception e) {
@@ -756,7 +760,7 @@
logger.log(Level.SEVERE, body.getErrorMsg()+": "+ e.getMessage(), e);
}
if (!ok)
- generateGoalDeletion(conf.C.SI, errorAnnots);
+ generateGoalDeletion(curInt, errorAnnots);
break;
@@ -764,18 +768,18 @@
Iterator<Unifier> iu = ((LogicalFormula)bTerm).logicalConsequence(ag, u);
if (iu.hasNext()) {
im.unif = iu.next();
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
} else {
String msg = "Constraint "+h+" was not satisfied ("+h.getSrcInfo()+") un="+u;
- generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots(new Atom("constraint_failed"), msg));
+ generateGoalDeletion(curInt, JasonException.createBasicErrorAnnots(new Atom("constraint_failed"), msg));
logger.fine(msg);
}
break;
// Rule Achieve
case achieve:
- body = prepareBodyForEvent(body, u, conf.C.SI.peek());
- Event evt = conf.C.addAchvGoal(body, conf.C.SI);
+ body = prepareBodyForEvent(body, u, curInt.peek());
+ Event evt = conf.C.addAchvGoal(body, curInt);
confP.stepAct = State.StartRC;
checkHardDeadline(evt);
break;
@@ -785,22 +789,22 @@
body = prepareBodyForEvent(body, u, null);
evt = conf.C.addAchvGoal(body, Intention.EmptyInt);
checkHardDeadline(evt);
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
break;
// Rule Test
case test:
LogicalFormula f = (LogicalFormula)bTerm;
if (conf.ag.believes(f, u)) {
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
} else {
boolean fail = true;
// generate event when using literal in the test (no events for log. expr. like ?(a & b))
if (f.isLiteral() && !(f instanceof BinaryStructure)) {
- body = prepareBodyForEvent(body, u, conf.C.SI.peek());
+ body = prepareBodyForEvent(body, u, curInt.peek());
if (body.isLiteral()) { // in case body is a var with content that is not a literal (note the VarTerm pass in the instanceof Literal)
Trigger te = new Trigger(TEOperator.add, TEType.test, body);
- evt = new Event(te, conf.C.SI);
+ evt = new Event(te, curInt);
if (ag.getPL().hasCandidatePlan(te)) {
if (logger.isLoggable(Level.FINE)) logger.fine("Test Goal '" + h + "' failed as simple query. Generating internal event for it: "+te);
conf.C.addEvent(evt);
@@ -811,7 +815,7 @@
}
if (fail) {
if (logger.isLoggable(Level.FINE)) logger.fine("Test '"+h+"' failed ("+h.getSrcInfo()+").");
- generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("test_goal_failed", "Failed to test '"+h+"'"));
+ generateGoalDeletion(curInt, JasonException.createBasicErrorAnnots("test_goal_failed", "Failed to test '"+h+"'"));
}
}
break;
@@ -820,20 +824,20 @@
case delAddBel:
// -+a(1,X) ===> remove a(_,_), add a(1,X)
// change all vars to anon vars to remove it
- Literal b2 = prepareBodyForEvent(body, u, conf.C.SI.peek());
+ Literal b2 = prepareBodyForEvent(body, u, curInt.peek());
b2.makeTermsAnnon(); // do not change body (but b2), to not interfere in addBel
// to delete, create events as external to avoid that
// remove/add create two events for the same intention
// (in future releases, creates a two branches for this operator)
try {
- List<Literal>[] result = ag.brf(null, b2, conf.C.SI); // the intention is not the new focus
+ List<Literal>[] result = ag.brf(null, b2, curInt); // the intention is not the new focus
if (result != null) { // really delete something
// generate events
updateEvents(result,Intention.EmptyInt);
}
} catch (RevisionFailedException re) {
- generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("belief_revision_failed", "BRF failed for '"+body+"'"));
+ generateGoalDeletion(curInt, JasonException.createBasicErrorAnnots("belief_revision_failed", "BRF failed for '"+body+"'"));
break;
}
@@ -848,7 +852,7 @@
Intention newfocus = Intention.EmptyInt;
boolean isSameFocus = setts.sameFocus() && h.getBodyType() != BodyType.addBelNewFocus;
if (isSameFocus) {
- newfocus = conf.C.SI;
+ newfocus = curInt;
body = prepareBodyForEvent(body, u, newfocus.peek());
} else {
body = prepareBodyForEvent(body, u, null);
@@ -858,20 +862,20 @@
try {
List<Literal>[] result;
if (h.getBodyType() == BodyType.addBelEnd)
- result = ag.brf(body,null,conf.C.SI, true);
+ result = ag.brf(body,null,curInt, true);
else
- result = ag.brf(body,null,conf.C.SI); // use default (well documented and used) method in case someone has overridden it
+ result = ag.brf(body,null,curInt); // use default (well documented and used) method in case someone has overridden it
if (result != null) { // really added something
// generate events
updateEvents(result,newfocus);
if (!isSameFocus) {
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
}
} else {
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
}
} catch (RevisionFailedException re) {
- generateGoalDeletion(conf.C.SI, null);
+ generateGoalDeletion(curInt, null);
}
break;
@@ -879,25 +883,25 @@
newfocus = Intention.EmptyInt;
if (setts.sameFocus()) {
- newfocus = conf.C.SI;
+ newfocus = curInt;
body = prepareBodyForEvent(body, u, newfocus.peek());
} else {
body = prepareBodyForEvent(body, u, null);
}
// call BRF
try {
- List<Literal>[] result = ag.brf(null, body, conf.C.SI); // the intention is not the new focus
+ List<Literal>[] result = ag.brf(null, body, curInt); // the intention is not the new focus
if (result != null) { // really change something
// generate events
updateEvents(result,newfocus);
if (!setts.sameFocus()) {
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
}
} else {
- updateIntention(conf.C.SI);
+ updateIntention(curInt);
}
} catch (RevisionFailedException re) {
- generateGoalDeletion(conf.C.SI, null);
+ generateGoalDeletion(curInt, null);
}
break;
}
Modified: trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 13:21:09 UTC (rev 1896)
+++ trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 18:09:37 UTC (rev 1897)
@@ -1,10 +1,12 @@
package jason.infra.centralised;
+import java.util.Collection;
import java.util.concurrent.ExecutorService;
import jason.asSemantics.ActionExec;
import jason.asSemantics.CircumstanceListener;
import jason.asSemantics.Message;
+import jason.asSyntax.Literal;
import jason.infra.components.ActComponent;
import jason.infra.components.DeliberateComponent;
import jason.infra.components.SenseComponent;
@@ -143,7 +145,7 @@
getTS().getC().addEventListener(listener);
}
- public void receiveMsg(Message m) {
+ public void receiveMsg(Message m) {
synchronized (objSense) {
super.receiveMsg(m);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|