Skip to content
Snippets Groups Projects
Commit 7853cbf8 authored by BrunoDatoMeneses's avatar BrunoDatoMeneses
Browse files

ADD: first steps of endogenous exploitation

parent 2f5f54cb
Branches
No related tags found
1 merge request!1Merge Master
Showing
with 591 additions and 67 deletions
......@@ -35,8 +35,8 @@ public class BadContextLauncherEasy implements Serializable {
/* These method calls allow to setup AMOEBA*/
amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba.setDataForErrorMargin(10, 0.01, 0.01, 10, 5, 5);
amoeba.setDataForInexactMargin(0.1, 0.01, 0.01, 0.1, 5, 5);
amoeba.setDataForErrorMargin(1, 0.01, 0.01, 1, 5, 5);
amoeba.setDataForInexactMargin(0.5, 0.01, 0.01, 0.5, 5, 5);
/* Default */
// amoeba.setAVT_acceleration(2);
......
package experiments.badContext;
//Packages importer afin d'utiliser l'objet File
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class FILE {
PrintWriter pw;
public FILE(String path, String folder, String name){
try {
pw = new PrintWriter(path + folder + "/" + name + ".csv");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void write(Double f1, Double f2){
pw.println(f1.toString() + ";" + f2.toString());
}
public void write(Double f1, Double f2, Double f3){
pw.println(f1.toString() + ";" + f2.toString() + ";" + f3.toString());
}
public void write(Double f1, Double f2, Double f3, Double f4){
pw.println(f1.toString() + ";" + f2.toString() + ";" + f3.toString() + ";" + f4.toString());
}
public void write(Double f1, Double f2, Double f3, Double f4, Double f5){
pw.println(f1.toString() + ";" + f2.toString() + ";" + f3.toString() + ";" + f4.toString() + ";" + f5.toString());
}
public void write(String f1, String f2, String f3, String f4, String f5){
pw.println(f1 + ";" + f2 + ";" + f3 + ";" + f4 + ";" + f5);
}
public void write(String f1, String f2, String f3, String f4){
pw.println(f1 + ";" + f2 + ";" + f3 + ";" + f4);
}
public void write(String f1, String f2, String f3){
pw.println(f1 + ";" + f2 + ";" + f3);
}
public void write(String f1, String f2){
pw.println(f1 + ";" + f2);
}
public void close(){
pw.close();
}
public static void main(String[] args) {
FILE test = new FILE("","19122017","test");
test.write(0.0000d, 0.0045d);
test.write(0.0000d, 0.0045d);
test.close();
}
}
package experiments.badContext;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.SimpleTimeZone;
import mas.agents.Agent;
import mas.agents.percept.ContextProjection;
import mas.agents.percept.Percept;
import mas.agents.context.Context;
import mas.agents.localModel.TypeLocalModel;
import mas.init.amoeba.AMOEBAFactory;
import mas.kernel.AMOEBA;
// TODO: Auto-generated Javadoc
/**
* The Class BadContextLauncherEasy.
*/
public class F_XY_ComparativeLauncher implements Serializable {
public static final boolean viewer = false;
public static final boolean verboseriticity = true;
public static void main(String[] args) {
launch(viewer);
}
public static void launch(boolean viewer) {
/*Here we create AMOEBA.*/
AMOEBA amoeba1 = AMOEBAFactory.createAMOEBA(viewer,"BadContext_solver.xml");
AMOEBA amoeba2 = AMOEBAFactory.createAMOEBA(true,"BadContext_solver.xml");
AMOEBA amoeba3 = AMOEBAFactory.createAMOEBA(true,"BadContext_solver.xml");
AMOEBA amoeba4 = AMOEBAFactory.createAMOEBA(viewer,"BadContext_solver.xml");
FILE criticitiesFile = new FILE("C:/Users/dato/Documents/THESE/XP/","23102018", "Test_Errors_Cycles1000_FIX200_100_50_25NB40_80_80_160");
FILE agentsContextesFile = new FILE("C:/Users/dato/Documents/THESE/XP/","23102018", "Test_NB_CTXT_Cycles1000_FIX200_100_50_25NB40_80_80_160");
/* These method calls allow to setup AMOEBA*/
amoeba1.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba2.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba3.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba4.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
//Errors margins
amoeba1.setDataForErrorMargin(200, 5, 0.4, 0.1, 50000, 10000);
amoeba1.setDataForInexactMargin(100.05, 2.5, 0.2, 0.05, 5000, 10000);
amoeba2.setDataForErrorMargin(50, 5, 0.4, 0.1, 10000, 20000);
amoeba2.setDataForInexactMargin(25, 2.5, 0.2, 0.05, 10000, 20000);
amoeba3.setDataForErrorMargin(0.1, 5, 0.4, 0.1, 40, 80);
amoeba3.setDataForInexactMargin(0.05, 2.5, 0.2, 0.05, 40, 80);
amoeba4.setDataForErrorMargin(0.1, 5, 0.4, 0.1, 80, 160);
amoeba4.setDataForInexactMargin(0.05, 2.5, 0.2, 0.05, 80, 160);
criticitiesFile.write("ErrorMargin(200, 5, 0.4, 0.1, 50000, 10000) InexactMargin(100.05, 2.5, 0.2, 0.05, 5000, 10000)",
"ErrorMargin(50, 5, 0.4, 0.1, 10000, 20000) InexactMargin(25, 2.5, 0.2, 0.05, 10000, 20000)",
"ErrorMargin(0.1, 5, 0.4, 0.1, 40, 80) InexactMargin(0.05, 2.5, 0.2, 0.05, 40, 80)",
"ErrorMargin(0.1, 5, 0.4, 0.1, 80, 160) InexactMargin(0.05, 2.5, 0.2, 0.05, 80, 160)");
agentsContextesFile.write("ErrorMargin(200, 5, 0.4, 0.1, 50000, 10000) InexactMargin(100.05, 2.5, 0.2, 0.05, 5000, 10000)",
"ErrorMargin(50, 5, 0.4, 0.1, 10000, 20000) InexactMargin(25, 2.5, 0.2, 0.05, 10000, 20000)",
"ErrorMargin(0.1, 5, 0.4, 0.1, 40, 80) InexactMargin(0.05, 2.5, 0.2, 0.05, 40, 80)",
"ErrorMargin(0.1, 5, 0.4, 0.1, 80, 160) InexactMargin(0.05, 2.5, 0.2, 0.05, 80, 160)");
amoeba1.setRememberState(false);
amoeba1.setGenerateCSV(false);
amoeba2.setRememberState(false);
amoeba2.setGenerateCSV(false);
amoeba3.setRememberState(false);
amoeba3.setGenerateCSV(false);
amoeba4.setRememberState(false);
amoeba4.setGenerateCSV(false);
/* This is the initialization of the studied system. It's only for the sake of example, not a part of AMOEBA initialization*/
F_XY_Manager bcm = new F_XY_Manager(50.0);
double averageCriticity1 = 0.0;
double averageCriticity2 = 0.0;
double averageCriticity3 = 0.0;
double averageCriticity4 = 0.0;
for (int i = 0 ; i < 100 ; i++) {
/* This is the studied system part. Feel free to use any data source.*/
bcm.playOneStep(0);
/*This is a learning step of AMOEBA*/
amoeba1.learn(new HashMap<String, Double>(bcm.getOutput()));
averageCriticity1 = amoeba1.getAveragePredictionCriticity();
amoeba2.learn(new HashMap<String, Double>(bcm.getOutput()));
averageCriticity2 = amoeba2.getAveragePredictionCriticity();
amoeba3.learn(new HashMap<String, Double>(bcm.getOutput()));
averageCriticity3 = amoeba3.getAveragePredictionCriticity();
amoeba4.learn(new HashMap<String, Double>(bcm.getOutput()));
averageCriticity4 = amoeba4.getAveragePredictionCriticity();
criticitiesFile.write(averageCriticity1, averageCriticity2, averageCriticity3, averageCriticity4);
agentsContextesFile.write(amoeba1.getNumberOfContextAgents(), amoeba2.getNumberOfContextAgents(), amoeba3.getNumberOfContextAgents(), amoeba4.getNumberOfContextAgents());
}
/*for (int i = 0 ; i < 1000 ; i++) {
bcm.playOneStep(0);
HashMap<String, Double> data = new HashMap<String, Double>(bcm.getOutput());
// data.remove("test");
System.out.println("Test request : " + amoeba.request(data));
}*/
criticitiesFile.close();
agentsContextesFile.close();
}
}
......@@ -36,9 +36,19 @@ public class F_XY_Launcher implements Serializable {
/* These method calls allow to setup AMOEBA*/
amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
//Beau rsultat
amoeba.setDataForErrorMargin(0.1, 5, 0.4, 0.1, 5, 10);
amoeba.setDataForInexactMargin(0.05, 2.5, 0.2, 0.05, 5, 10);
//Dynamic errors
amoeba.setDataForErrorMargin(1000, 5, 0.4, 0.1, 40, 80);
amoeba.setDataForInexactMargin(500, 2.5, 0.2, 0.05, 40, 80);
//amoeba.setDataForErrorMargin(100, 5, 0.4, 0.1, 10000, 20000);
//amoeba.setDataForInexactMargin(50, 2.5, 0.2, 0.05, 10000, 20000);
//Static errors
/*amoeba.setDataForErrorMargin(5, 5, 0.4, 200, 5000, 100000);
amoeba.setDataForInexactMargin(2.5, 2.5, 0.2, 100, 5000, 100000);*/
//amoeba.setDataForErrorMargin(200, 5, 0.4, 200, 5000, 100000);
//amoeba.setDataForInexactMargin(100, 2.5, 0.2, 100, 5000, 100000);
/* Default */
// amoeba.setAVT_acceleration(2);
......@@ -54,11 +64,11 @@ public class F_XY_Launcher implements Serializable {
amoeba.setGenerateCSV(false);
/* This is the initialization of the studied system. It's only for the sake of example, not a part of AMOEBA initialization*/
//F_XY_ManagerSphere bcm = new F_XY_ManagerSphere(50.0);
F_XY_Manager bcm = new F_XY_Manager(50.0);
bcm.setWorld(amoeba.getScheduler().getWorld());
ArrayList<Percept> percepts = new ArrayList<Percept>();
for (int i = 0 ; i < 1000 ; i++) {
for (int i = 0 ; i < 10 ; i++) {
/* This is the studied system part. Feel free to use any data source.*/
bcm.playOneStep(0);
......
......@@ -30,7 +30,6 @@ public class F_XY_Manager implements StudiedSystem, Serializable{
double spaceSize;
/** The world. */
World world;
Random generator;
......@@ -79,14 +78,6 @@ public class F_XY_Manager implements StudiedSystem, Serializable{
}
/**
* Sets the world.
*
* @param world the new world
*/
public void setWorld(World world) {
this.world = world;
}
......
package experiments.badContext;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Random;
import mas.agents.context.Context;
import mas.agents.head.Head;
import mas.kernel.StudiedSystem;
import mas.kernel.World;
// TODO: Auto-generated Javadoc
/**
* The Class BadContextManager.
*/
public class F_XY_ManagerSphere implements StudiedSystem, Serializable{
/** The x. */
double x = 0;
/** The y. */
double y = 0;
/** The result. */
double result = 0;
/** The first step. */
boolean firstStep = true;
double spaceSize;
/** The world. */
Random generator;
public F_XY_ManagerSphere(double size) {
this.spaceSize= size;
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#playOneStep(double)
*/
@Override
public void playOneStep(double action) {
if (generator == null) generator = new Random(29);
x = (generator.nextDouble() - 0.5) * spaceSize * 4;
y = (generator.nextDouble() - 0.5) * spaceSize * 4;
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#getOutput()
*/
@Override
public HashMap<String, Double> getOutput() {
HashMap<String, Double> out = new HashMap<String, Double>();
result = (Math.sqrt(x*x + y*y) < spaceSize) ? 2*x + y : 5*x - 8*y;
//result = (y > -spaceSize && y < spaceSize && x < spaceSize && x > -spaceSize) ? 2*x + y : 5*x - 8*y;
//result = (2*x) + (4*y) + x*y;
// result = (x > 2*y) ? 0.0 : 1.0;
out.put("px",x);
out.put("py",y);
out.put("oracle",result);
return out;
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#switchControlMode()
*/
@Override
public void switchControlMode() {
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ public class Context extends AbstractContext implements Serializable{
ArrayList<Percept> perceptSenders = new ArrayList<Percept>();
private Head controller;
private Head headAgent;
private HashMap<Percept, Range> ranges = new HashMap<Percept, Range>();
private ArrayList<Experiment> experiments = new ArrayList<Experiment>(); /*If memory is a concern, their is room for improvements here*/
......@@ -88,15 +88,15 @@ public class Context extends AbstractContext implements Serializable{
* Builds the context.
*
* @param world the world
* @param controller the controller
* @param headAgent the headAgent
*/
private void buildContext (Head controller) {
private void buildContext (Head headAgent) {
ArrayList<Percept> var = world.getAllPercept();
Experiment firstPoint = new Experiment();
this.controller = controller;
this.headAgent = headAgent;
action = this.controller.getOracleValue();
action = this.headAgent.getOracleValue();
maxActivationsRequired = var.size();
for (Percept v : var) {
......@@ -113,7 +113,7 @@ public class Context extends AbstractContext implements Serializable{
v.addContextSortedRanges(this);
}
localModel = this.world.buildLocalModel(this);
firstPoint.setProposition(this.controller.getOracleValue());
firstPoint.setProposition(this.headAgent.getOracleValue());
experiments.add(firstPoint);
localModel.updateModel(this);
this.world.getScheduler().addAlteredContext(this);
......@@ -163,7 +163,7 @@ public class Context extends AbstractContext implements Serializable{
Range range = new Range(entry.getValue());
this.ranges.put(percept, range);
}
this.controller = c.controller;
this.headAgent = c.headAgent;
this.action = c.action;
this.nSelection = c.nSelection;
this.bestContext = c.bestContext;
......@@ -278,12 +278,12 @@ public class Context extends AbstractContext implements Serializable{
super.play();
if(computeValidityByPercepts()) {
sendMessage(getActionProposal(), MessageType.PROPOSAL, headAgent);
Config.print("Message envoy", 4);
//System.out.println("Valid context by Percepts "+this.name);
}
if (computeValidity()) {
sendMessage(getActionProposal(), MessageType.PROPOSAL, controller);
Config.print("Message envoy", 4);
//System.out.println("Valid context by Context "+this.name);
}
......@@ -298,7 +298,7 @@ public class Context extends AbstractContext implements Serializable{
//ENDO
for (Percept v : ranges.keySet()) {
if (ranges.get(v).isTooSmall()){
solveNCS_Uselessness(controller);
solveNCS_Uselessness(headAgent);
break;
}
}
......@@ -354,7 +354,7 @@ public class Context extends AbstractContext implements Serializable{
*/
public void solveNCS_IncompetentHead(Head head) {
world.raiseNCS(NCS.HEAD_INCOMPETENT);
growRanges(head);
growRanges();
}
/**
......@@ -640,7 +640,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
* @return the controler
*/
public Head getControler() {
return controller;
return headAgent;
}
/**
......@@ -649,7 +649,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
* @param controler the new controler
*/
public void setControler(Head controler) {
this.controller = controler;
this.headAgent = controler;
}
/**
......@@ -676,7 +676,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
@Override
public ArrayList<? extends Agent> getTargets() {
ArrayList<Agent> arrayList = new ArrayList<Agent>();
arrayList.add(controller);
arrayList.add(headAgent);
return arrayList;
}
......@@ -931,7 +931,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
for (Percept v : var) {
exp.addDimension(v, v.getValue());
}
exp.setProposition(controller.getOracleValue());
exp.setProposition(headAgent.getOracleValue());
experiments.add(exp);
this.world.getScheduler().addAlteredContext(this);
......@@ -971,12 +971,12 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
*
* @param head the head
*/
public void growRanges(Head head) {
ArrayList<Percept> var = world.getAllPercept();
for (Percept v : var) {
boolean contain = ranges.get(v).contains(v.getValue()) == 0 ? true : false;
public void growRanges() {
ArrayList<Percept> allPercepts = world.getAllPercept();
for (Percept pct : allPercepts) {
boolean contain = ranges.get(pct).contains(pct.getValue()) == 0 ? true : false;
if (!contain) {
ranges.get(v).adapt(this, v.getValue(), v);
ranges.get(pct).adapt(this, pct.getValue(), pct);
}
}
}
......
......@@ -27,7 +27,9 @@ public class Head extends AbstractHead {
//private BlackBoxAgent oracle;
private ArrayList<Context> contexts = new ArrayList<Context>();
private ArrayList<Context> activatedContexts = new ArrayList<Context>();
private ArrayList<Context> partialyActivatedContexts = new ArrayList<Context>();
private ArrayList<Pair<Context,Context>> sharedIncompetenceContextPairs = new ArrayList<Pair<Context,Context>>();
private ArrayList<Double> xLastCriticityValues = new ArrayList<Double>();
......@@ -43,6 +45,7 @@ public class Head extends AbstractHead {
private int perfIndicatorInexact = 0;
private double prediction;
private double endogenousPrediction;
private double oracleValue;
private double oldOracleValue;
private double criticity;
......@@ -126,9 +129,13 @@ public class Head extends AbstractHead {
// contexts.clear();
if (m.getType() == MessageType.PROPOSAL) { // Value useless
contexts.add((Context) m.getSender());
activatedContexts.add((Context) m.getSender());
}
}
public void addPartiallyActivatedContext(Context partialyactivatedContext) {
partialyActivatedContexts.add(partialyactivatedContext);
}
/**
* The core method of the head agent.
......@@ -136,7 +143,7 @@ public class Head extends AbstractHead {
*/
public void play() {
nPropositionsReceived = contexts.size();
nPropositionsReceived = activatedContexts.size();
newContextWasCreated = false;
setContextFromPropositionWasSelected(false);
oldOracleValue = oracleValue;
......@@ -158,9 +165,13 @@ public class Head extends AbstractHead {
//updateStatisticalInformations(); ///regarder dans le d彋ail, possible que ce pas trop utile
}
//中
endogenousPlay();
updateStatisticalInformations(); ///regarder dans le d彋ail, possible que ce pas trop utile
contexts.clear();
activatedContexts.clear();
partialyActivatedContexts.clear();
newContext = null;
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Error allowded :" + errorAllowed);
......@@ -171,7 +182,7 @@ public class Head extends AbstractHead {
private void playWithOracle() {
if (contexts.size() > 0) {
if (activatedContexts.size() > 0) {
selectBestContext(); //using highest confidence
}
......@@ -207,7 +218,7 @@ public class Head extends AbstractHead {
*/
private void playWithoutOracle() {
Config.print("Nombre de contexte : " + contexts.size(), 1);
Config.print("Nombre de contextes activ廥: " + activatedContexts.size(), 1);
selectBestContext();
if (bestContext != this.lastUsedContext) {
......@@ -228,6 +239,63 @@ public class Head extends AbstractHead {
criticity = Math.abs(oracleValue - prediction);
}
private void endogenousPlay() {
if(uniqueActivatedContext()) {
endogenousPrediction = activatedContexts.get(0).getActionProposal();
}
else {
endogenousPrediction = 0.0;
}
/*else if(severalActivatedContexts()){
NCS_EndogenousCompetition();
}
else {
if(surroundingContexts()) {
NCS_EndogenousSharedIncompetence();
}
else {
NCS_EndogenousIncompetence();
}
}*/
}
private boolean uniqueActivatedContext() {
//Test if only one context is activated
return activatedContexts.size() == 1;
}
private boolean severalActivatedContexts() {
//Test if several context are activated
return activatedContexts.size() > 1;
}
private boolean surroundingContexts() {
//Test if there are surrounding contexts
for(Context partiallyActivatedContext : partialyActivatedContexts) {
}
return false;
}
private void NCS_EndogenousCompetition() {
// Creation if twin contexts to give the endogenous prediction
}
private void NCS_EndogenousSharedIncompetence() {
// Extrapolation of contexts by creating twin contexts that will give the prediction
}
private void NCS_EndogenousIncompetence() {
// Extrapolation of contexts by creating twin contexts that will give the prediction
}
private void NCSDetection_Create_New_Context() {
/*Finally, head agent check the need for a new context agent*/
......@@ -250,10 +318,10 @@ public class Head extends AbstractHead {
private void NCSDetection_Concurrence() {
/*If result is good, shrink redundant context (concurrence NCS)*/
if (bestContext != null && criticity <= this.errorAllowed) {
for (int i = 0 ; i < contexts.size() ; i++) {
if (contexts.get(i) != bestContext && !contexts.get(i).isDying() && this.getCriticity(contexts.get(i)) <= this.errorAllowed) {
for (int i = 0 ; i < activatedContexts.size() ; i++) {
if (activatedContexts.get(i) != bestContext && !activatedContexts.get(i).isDying() && this.getCriticity(activatedContexts.get(i)) <= this.errorAllowed) {
// System.out.println("Shrink context " + contexts.get(i).getName());
contexts.get(i).solveNCS_Concurrence(this);
activatedContexts.get(i).solveNCS_Concurrence(this);
}
}
}
......@@ -261,7 +329,7 @@ public class Head extends AbstractHead {
private void NCSDetection_IncompetentHead() {
/*If there isn't any proposition or only bad propositions, the head is incompetent. It needs help from a context.*/
if (contexts.isEmpty() || (criticity > this.errorAllowed && !oneOfProposedContextWasGood())){
if (activatedContexts.isEmpty() || (criticity > this.errorAllowed && !oneOfProposedContextWasGood())){
ArrayList<Agent> allContexts = world.getScheduler().getContexts();
Context c = getNearestGoodContext(allContexts);
......@@ -282,8 +350,8 @@ public class Head extends AbstractHead {
private void selfAnalysationOfContexts() {
/*All context which proposed itself must analyze its proposition*/
for (int i = 0 ; i < contexts.size() ; i++) {
contexts.get(i).analyzeResults(this);
for (int i = 0 ; i < activatedContexts.size() ; i++) {
activatedContexts.get(i).analyzeResults(this);
}
}
......@@ -414,7 +482,7 @@ public class Head extends AbstractHead {
*/
private boolean oneOfProposedContextWasGood() {
boolean b = false;
for (Context c : contexts) {
for (Context c : activatedContexts) {
if (oracleValue - c.getActionProposal() < errorAllowed) {
b = true;
}
......@@ -467,7 +535,7 @@ public class Head extends AbstractHead {
xLastCriticityValues.remove(0);
}
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Average Prediction Criticity :" + averagePredictionCriticity);
if (averagePredictionCriticity > errorAllowed) {
perfIndicator--;
......@@ -532,8 +600,8 @@ public class Head extends AbstractHead {
*
* @return the contexts
*/
public ArrayList<Context> getContexts() {
return contexts;
public ArrayList<Context> getActivatedContexts() {
return activatedContexts;
}
/**
......@@ -541,8 +609,8 @@ public class Head extends AbstractHead {
*
* @param contexts the new contexts
*/
public void setContexts(ArrayList<Context> contexts) {
this.contexts = contexts;
public void setActivatesContexts(ArrayList<Context> contexts) {
this.activatedContexts = contexts;
}
......@@ -552,14 +620,14 @@ public class Head extends AbstractHead {
private void selectBestContext() {
Context bc;
if (contexts.isEmpty()) {
if (activatedContexts.isEmpty()) {
bc = lastUsedContext;
} else {
bc = contexts.get(0);
bc = activatedContexts.get(0);
}
double currentConfidence = Double.NEGATIVE_INFINITY;
for (Context context : contexts) {
for (Context context : activatedContexts) {
if (context.getConfidence() > currentConfidence) {
bc = context;
currentConfidence = bc.getConfidence();
......@@ -591,17 +659,10 @@ public class Head extends AbstractHead {
*/
@Override
public ArrayList<? extends Agent> getTargets() {
return contexts;
return activatedContexts;
}
/**
* Gets the active contexts.
*
* @return the active contexts
*/
public ArrayList<Context> getActiveContexts() {
return contexts;
}
/**
* Gets the criticity.
......
package mas.agents.head;
public class Pair<L,R> {
private L l;
private R r;
public Pair(L l, R r){
this.l = l;
this.r = r;
}
public L getL(){ return l; }
public R getR(){ return r; }
public void setL(L l){ this.l = l; }
public void setR(R r){ this.r = r; }
}
......@@ -516,6 +516,12 @@ public class AMOEBA extends Thread {
scheduler.getWorld().setAVT_percentAtStart(aVT_percentAtStart);
}
public double getAveragePredictionCriticity() {
return scheduler.getHeadAgent().getAveragePredictionCriticity();
}
public double getNumberOfContextAgents() {
return scheduler.getContexts().size();
}
}
\ No newline at end of file
package visualization.view.global;
import java.awt.FlowLayout;
import javax.swing.JPanel;
import mas.kernel.World;
import mas.ncs.NCS;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import visualization.view.system.ScheduledItem;
// TODO: Auto-generated Javadoc
/**
* The Class PanelChart.
*/
public class PanelOneChart extends JPanel implements ScheduledItem {
/** The chart panel agents. */
/* Agents chart */
ChartPanel chartPanel;
/** The chart agents. */
JFreeChart chart;
/** The data set agents. */
XYSeriesCollection dataSetPredictions;
/** The world. */
World world;
/**
* Instantiates a new panel chart.
*
* @param world the world
*/
public PanelOneChart(World world) {
this.setLayout(new FlowLayout());
this.world = world;
/* Create prediction chart */
dataSetPredictions = createDataSetPredictions();
JFreeChart chart = createChart();
chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 400));
}
/*
* private JFreeChart createChart(DefaultCategoryDataset dataset2) { // TODO
* Auto-generated method stub return null; }
*
* private DefaultCategoryDataset createDataset() { // TODO Auto-generated
* method stub return null; }
*/
/**
* Creates the data set agents.
*
* @return the XY series collection
*/
private XYSeriesCollection createDataSetPredictions() {
XYSeriesCollection collection = new XYSeriesCollection();
collection.addSeries(new XYSeries("Predictions"));
collection.addSeries(new XYSeries("Endogenous Predictions"));
return collection;
}
/**
* Creates the chart.
*
* @return the j free chart
*/
private JFreeChart createChart() {
// create subplot 1...
final XYDataset data1 = dataSetPredictions;
final XYItemRenderer renderer1 = new StandardXYItemRenderer();
final NumberAxis rangeAxis1 = new NumberAxis("Agents in AMAS");
final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
// parent plot...
final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
new NumberAxis("Tick"));
plot.setGap(10.0);
// add the subplots...
plot.add(subplot1, 1);
plot.setOrientation(PlotOrientation.VERTICAL);
// return a new chart containing the overlaid plot...
return new JFreeChart(" Agents in AMAS",
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
/* (non-Javadoc)
* @see view.system.ScheduledItem#update()
*/
@Override
public void update() {
int tick = world.getScheduler().getTick();
dataSetPredictions.getSeries("Predictions").add(
tick, world.getNumberOfAgents().get("Context"));
dataSetPredictions.getSeries("Endogenous Predictions").add(
tick, world.getNumberOfAgents().get("Percept"));
}
// }
}
......@@ -11,6 +11,7 @@ import visualization.log.ConsolePanel;
import visualization.observation.Observation;
import visualization.view.blackbox.BlackBoxPanel;
import visualization.view.global.PanelChart;
import visualization.view.global.PanelOneChart;
import visualization.view.system.nDim.PanelParallelCoordinates;
import visualization.view.system.twoDim.GrapheTwoDimPanelStandard;
import mas.blackbox.BlackBox;
......@@ -33,6 +34,7 @@ public class MainTabbedPanel extends JTabbedPane{
/** The panel chart. */
private PanelChart panelChart;
private PanelOneChart exoVsEndoChart;
/** The panel two dim standard. */
private GrapheTwoDimPanelStandard panelTwoDimStandard;
......@@ -79,8 +81,10 @@ public class MainTabbedPanel extends JTabbedPane{
panelTwoDimStandard = new GrapheTwoDimPanelStandard(world);
panelParallelCoordinates = new PanelParallelCoordinates(world);
consolePanel = new ConsolePanel();
exoVsEndoChart = new PanelOneChart(world);
world.getScheduler().addScheduledItem(panelChart);
world.getScheduler().addScheduledItem(exoVsEndoChart);
//this.addTab("BlackBox", new JScrollPane(blackBoxPanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
//this.addTab("System", systemPanel);
......@@ -90,6 +94,7 @@ public class MainTabbedPanel extends JTabbedPane{
// this.addTab("TwoDim", new JScrollPane(panelTwoDim,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
// this.addTab("TwoDim", panelTwoDim);
this.addTab("Console", new JScrollPane(consolePanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
this.addTab("Exo VS endo", new JScrollPane(exoVsEndoChart,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
((Frame) this.getTopLevelAncestor()).pack();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment