|
From: <xsp...@us...> - 2016-04-11 13:21:11
|
Revision: 1896
http://sourceforge.net/p/jason/svn/1896
Author: xsplyter
Date: 2016-04-11 13:21:09 +0000 (Mon, 11 Apr 2016)
Log Message:
-----------
Reuse code Synchronous
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -188,8 +188,8 @@
public boolean isRunning() {
return running;
}
-
- protected boolean reasoningCycle() {
+
+ protected boolean sense() {
TransitionSystem ts = getTS();
int i = 0;
@@ -202,7 +202,13 @@
i++;
}
- i = 0;
+ return true;
+ }
+
+ protected boolean deliberate() {
+ TransitionSystem ts = getTS();
+
+ int i = 0;
while (running && i < cyclesDeliberate) {
if (!ts.deliberate()) {
return false;
@@ -212,7 +218,13 @@
i++;
}
- i = 0;
+ return true;
+ }
+
+ protected boolean act() {
+ TransitionSystem ts = getTS();
+
+ int i = 0;
int ca = cyclesAct;
if (cyclesAct == 9999)
ca = ts.getC().getIntentions().size();
@@ -229,6 +241,12 @@
return true;
}
+ protected boolean reasoningCycle() {
+ if (!sense()) return false;
+ if (!deliberate()) return false;
+ if (!act()) return false;
+ return true;
+ }
public void run() {
TransitionSystem ts = getTS();
Modified: trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -151,7 +151,7 @@
/** called the the environment when the action was executed */
public void actionExecuted(ActionExec action) {
- synchronized (objSense) {
+ synchronized (objAct) {
super.actionExecuted(action);
}
}
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -1013,7 +1013,7 @@
}
}
- public void sense() {
+ public boolean sense() {
int number_cycles = getCyclesSense();
int i = 0;
@@ -1023,7 +1023,7 @@
if (runWakeAfterTS) {
wake();
}
- return;
+ return false;
} else if (getTS().canSleepSense()) {
break;
}
@@ -1033,176 +1033,28 @@
if (isRunning()) {
executor.execute(this);
}
- }
-
- public void deliberate() {
- int number_cycles = getCyclesDeliberate();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- getTS().deliberate();
-
- if (getTS().canSleepDeliberate()) {
- break;
- }
-
- i++;
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return true;
}
- public void act() {
- int number_cycles = getCyclesAct();
- int i = 0;
-
- if (number_cycles == 9999) { //TODO adjust parameter for executing one deed from each intention
- //System.out.println("# Executing one deed from each intention " + getTS().getC().getIntentions().size());
-
- while (isRunning() && i < getTS().getC().getIntentions().size()) {
-
- //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
-
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- } else {
- while (isRunning() && i < number_cycles) {
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- }
+ public boolean deliberate() {
+ boolean result = super.deliberate();
if (isRunning()) {
executor.execute(this);
}
- }
-
- @Override
- public void run() {
- switch (currentStep) {
- case 0:
- sense();
- currentStep = 1;
- break;
- case 1:
- deliberate();
- currentStep = 2;
- break;
- case 2:
- act();
- currentStep = 0;
- break;
- }
- }
- }
-
- /** an agent architecture for the infra based on thread pool */
- protected final class CentralisedAgArchSynchronousScheduled_2 extends CentralisedAgArch {
- private volatile boolean runWakeAfterTS = false;
- private int currentStep = 0;
-
- @Override
- public void sleep() {
- sleepingAgs.add(this);
- }
-
- @Override
- public void wake() {
- if (sleepingAgs.remove(this)) {
- executor.execute(this);
- } else {
- runWakeAfterTS = true;
- }
- }
-
- public void sense() {
- int number_cycles = getCyclesSense();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- runWakeAfterTS = false;
- if (!getTS().sense()) { // the agent run a cycle (did not enter in sleep)
- if (runWakeAfterTS) {
- wake();
- }
- return;
- } else if (getTS().canSleepSense()) {
- break;
- }
- i++;
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return result;
}
- public void deliberate() {
- int number_cycles = getCyclesDeliberate();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- getTS().deliberate();
-
- if (getTS().canSleepDeliberate()) {
- break;
- }
-
- i++;
- }
+ public boolean act() {
+ boolean result = super.act();
if (isRunning()) {
executor.execute(this);
}
- }
-
- public void act() {
- int number_cycles = getCyclesAct();
- int i = 0;
-
- if (number_cycles == 9999) { //TODO adjust parameter for executing one deed from each intention
- //System.out.println("# Executing one deed from each intention " + getTS().getC().getIntentions().size());
-
- while (isRunning() && i < getTS().getC().getIntentions().size()) {
-
- //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
-
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- } else {
- while (isRunning() && i < number_cycles) {
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return result;
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|