From 81310b802d19f7e704c5376e1c928eca504a6523 Mon Sep 17 00:00:00 2001
From: Hugo Roussel <hugo.roussel@univ-tlse3.fr>
Date: Fri, 12 Jul 2019 14:35:08 +0200
Subject: [PATCH] Refactor Head

Refactored Head : removed unused methods, removed useless or redondant members, added methods for code reuse.
Some methods used side effects to share data through members, since they'va been removed, this is no longer the case.
It's easier to read and understand Head's behavior.
Fixed a bug where a newly created context was added to the list of activated neighbors, resulting in a division by zero in getAverageRegressionPerformanceIndicator.
---
 AMOEBAonAMAK/src/agents/context/Context.java  |  83 +--
 AMOEBAonAMAK/src/agents/context/Range.java    |  12 -
 .../LocalModelMillerRegression.java           |  18 +-
 AMOEBAonAMAK/src/agents/head/Head.java        | 627 +-----------------
 AMOEBAonAMAK/src/agents/percept/Percept.java  |  24 +-
 AMOEBAonAMAK/src/experiments/F_XY_System.java |   2 +-
 AMOEBAonAMAK/src/experiments/MinimalMain.java |  58 +-
 .../src/experiments/SimpleReinforcement.java  |  12 +-
 AMOEBAonAMAK/src/experiments/TestingMain.java |   4 +-
 .../nDimensionsLaunchers/F_N_Launcher.java    |   8 +
 AMOEBAonAMAK/src/kernel/AMOEBA.java           |  10 -
 11 files changed, 88 insertions(+), 770 deletions(-)

diff --git a/AMOEBAonAMAK/src/agents/context/Context.java b/AMOEBAonAMAK/src/agents/context/Context.java
index 652269f8..5a38ebda 100644
--- a/AMOEBAonAMAK/src/agents/context/Context.java
+++ b/AMOEBAonAMAK/src/agents/context/Context.java
@@ -444,37 +444,6 @@ public class Context extends AmoebaAgent {
 		return maxExpansions;
 	}
 
-	// ---------
-	// TODO these methods look very similar, maybe factorization is possible ?
-	public void updateRequestNeighborState() { // faire le update dans le head attention partial et full
-		if (nonValidNeightborPercepts.size() == 0) {
-
-			getAmas().getHeadAgent().addRequestNeighbor(this);
-		} else {
-			getAmas().getHeadAgent().removeRequestNeighbor(this);
-		}
-	}
-
-	public void updateActivatedContexts() { // faire le update dans le head attention partial et full
-		if (nonValidPercepts.size() == 0) {
-
-			getAmas().getHeadAgent().addActivatedContext(this);
-		} else {
-			getAmas().getHeadAgent().removeActivatedContext(this);
-		}
-	}
-
-	public void updateActivatedContextsCopyForUpdate() { // faire le update dans le head attention partial et full
-		if (nonValidPercepts.size() == 0) {
-
-			getAmas().getHeadAgent().addActivatedContextCopy(this);
-		} else {
-			getAmas().getHeadAgent().removeActivatedContextCopy(this);
-		}
-
-	}
-	// --------
-
 	public void clearNonValidPerceptNeighbors() {
 		nonValidNeightborPercepts.clear();
 	}
@@ -604,7 +573,7 @@ public class Context extends AmoebaAgent {
 		
 		lastDistanceToModel = getLocalModel().distance(this.getCurrentExperiment());
 		lastAverageRegressionPerformanceIndicator = head.getAverageRegressionPerformanceIndicator();
-		if(lastDistanceToModel < lastAverageRegressionPerformanceIndicator) {
+		if(lastDistanceToModel <= lastAverageRegressionPerformanceIndicator) {
 		//if(getLocalModel().distance(this.getCurrentExperiment()) < head.getAverageRegressionPerformanceIndicator()) {
 		//if (head.getCriticity(this) < head.getErrorAllowed()) {
 			confidence++;
@@ -1811,56 +1780,6 @@ public class Context extends AmoebaAgent {
 			activations++;
 			getAmas().getHeadAgent().proposition(this);
 		}
-	}
-	
-	private void onActOld() {
-
-		if (nonValidPercepts.size() == 0) {
-
-			getAmas().getHeadAgent().proposition(this);
-
-//			for (Percept pct : getAmas().getPercepts()) {
-//				getAmas().getHeadAgent().addPartiallyActivatedContextInNeighbors(pct, this);
-//			}
-
-		} else if (nonValidPercepts.size() == 1) {
-			//getAmas().getHeadAgent().addPartiallyActivatedContext(nonValidPercepts.get(0), this);
-		}
-
-		if (nonValidNeightborPercepts.size() == 0) {
-
-			getAmas().getHeadAgent().addRequestNeighbor(this);
-		} else if (nonValidNeightborPercepts.size() == 1) {
-			//getAmas().getHeadAgent().addPartialRequestNeighborContext(nonValidNeightborPercepts.get(0), this);
-		}
-
-		if ((nonValidNeightborPercepts.size() == 0) && (nonValidPercepts.size() == 1)) {
-
-			//getAmas().getHeadAgent().addPartiallyActivatedContextInNeighbors(nonValidPercepts.get(0), this);
-
-		}
-
-		this.activations = 0;
-		//this.valid = false;
-
-		// Reset percepts validities
-		for (Percept percept : perceptValidities.keySet()) {
-			perceptValidities.put(percept, false);
-			perceptNeighborhoodValidities.put(percept, false);
-		}
-		
-	}
-	
-	public void computeContextNeighborsValidity() {
-
-		
-		if (nonValidNeightborPercepts.size() == 1) {
-			getAmas().getHeadAgent().addPartiallyActivatedContextInNeighbors(nonValidNeightborPercepts.get(0), this);
-		}
-
-
-
-		
 	}
 
 	/**
diff --git a/AMOEBAonAMAK/src/agents/context/Range.java b/AMOEBAonAMAK/src/agents/context/Range.java
index 082754b3..61b53491 100644
--- a/AMOEBAonAMAK/src/agents/context/Range.java
+++ b/AMOEBAonAMAK/src/agents/context/Range.java
@@ -1484,8 +1484,6 @@ public class Range implements Serializable, Comparable, Cloneable {
 				}
 			}
 
-			this.context.updateRequestNeighborState();
-
 			if (!this.contains2(percept.getValue())) {
 				if (!this.context.getNonValidPercepts().contains(this.percept)) {
 					this.context.addNonValidPercept(this.percept);
@@ -1496,10 +1494,6 @@ public class Range implements Serializable, Comparable, Cloneable {
 				}
 			}
 
-			this.context.updateActivatedContextsCopyForUpdate();
-
-			
-
 			if (!this.context.isDying() && !context.getAmas().getSpatiallyAlteredContextForUnityUI().contains(this.context)) {
 				context.getAmas().addSpatiallyAlteredContextForUnityUI(this.context);
 			}
@@ -1548,8 +1542,6 @@ public class Range implements Serializable, Comparable, Cloneable {
 				}
 			}
 
-			this.context.updateRequestNeighborState();
-
 			if (!this.contains2(percept.getValue())) {
 				if (!this.context.getNonValidPercepts().contains(this.percept)) {
 					this.context.addNonValidPercept(this.percept);
@@ -1560,10 +1552,6 @@ public class Range implements Serializable, Comparable, Cloneable {
 				}
 			}
 
-			this.context.updateActivatedContextsCopyForUpdate();
-
-			
-
 			if (!this.context.isDying() && !context.getAmas().getSpatiallyAlteredContextForUnityUI().contains(this.context)) {
 				context.getAmas().addSpatiallyAlteredContextForUnityUI(this.context);
 			}
diff --git a/AMOEBAonAMAK/src/agents/context/localModel/LocalModelMillerRegression.java b/AMOEBAonAMAK/src/agents/context/localModel/LocalModelMillerRegression.java
index 23bd2275..1a9bcee4 100644
--- a/AMOEBAonAMAK/src/agents/context/localModel/LocalModelMillerRegression.java
+++ b/AMOEBAonAMAK/src/agents/context/localModel/LocalModelMillerRegression.java
@@ -132,13 +132,13 @@ public class LocalModelMillerRegression implements LocalModel{
 			throw new ArithmeticException("First coeficient of model cannot be NaN");
 		
 		for (int i = 1 ; i < coefs.length ; i++) {
-			
-			if (Double.isNaN(coefs[i])) coefs[i] = 0.0;
-			if(coefs[i]>0) {
-				result += coefs[i] * context.getRanges().get(percepts.get(i-1)).getEnd();
+			double coef = coefs[i];
+			if (Double.isNaN(coef)) coef = 0.0;
+			if(coef>0) {
+				result += coef * context.getRanges().get(percepts.get(i-1)).getEnd();
 			}
 			else {
-				result += coefs[i] * context.getRanges().get(percepts.get(i-1)).getStart();
+				result += coef * context.getRanges().get(percepts.get(i-1)).getStart();
 			}
 		}
 	
@@ -156,21 +156,21 @@ public class LocalModelMillerRegression implements LocalModel{
 			throw new ArithmeticException("First coeficient of model cannot be NaN");
 		
 		for (int i = 1 ; i < coefs.length ; i++) {
-			
-			if (Double.isNaN(coefs[i])) coefs[i] = 0.0;
+			double coef = coefs[i];
+			if (Double.isNaN(coef)) coef = 0.0;
 			double pos;
 			Percept p = percepts.get(i-1);
 			if(fixedPercepts.containsKey(p.getName())) {
 				pos = fixedPercepts.get(p.getName());
 			} else {
-				if(coefs[i]>0) {
+				if(coef>0) {
 					pos = context.getRanges().get(p).getEnd();
 				}
 				else {
 					pos = context.getRanges().get(p).getStart();
 				}
 			}
-			double value = coefs[i] * pos;
+			double value = coef * pos;
 			result.put("oracle", result.get("oracle") + value);
 			result.put(p.getName(), pos);
 		}
diff --git a/AMOEBAonAMAK/src/agents/head/Head.java b/AMOEBAonAMAK/src/agents/head/Head.java
index 390b1281..c5608c7a 100644
--- a/AMOEBAonAMAK/src/agents/head/Head.java
+++ b/AMOEBAonAMAK/src/agents/head/Head.java
@@ -17,9 +17,8 @@ import agents.percept.Percept;
 import kernel.AMOEBA;
 import ncs.NCS;
 import utils.Pair;
-import utils.RandomUtils;
 import utils.PrintOnce;
-import utils.Quadruplet;
+import utils.RandomUtils;
 import utils.TRACE_LEVEL;
 
 /**
@@ -32,7 +31,6 @@ public class Head extends AmoebaAgent {
 	private Context bestContext;
 	private Context lastUsedContext;
 	private Context newContext;
-	private String functionSelected;
 
 	HashMap<Percept, Double> currentSituation = new HashMap<Percept, Double>();
 
@@ -40,20 +38,8 @@ public class Head extends AmoebaAgent {
 	public Criticalities endogenousCriticalities;
 
 	private ArrayList<Context> activatedContexts = new ArrayList<Context>();
-	private ArrayList<Context> activatedContextsCopyForUpdates = new ArrayList<Context>();
 	private ArrayList<Context> activatedNeighborsContexts = new ArrayList<Context>();
 
-	private HashMap<Percept, ArrayList<Context>> partiallyActivatedContextInNeighbors = new HashMap<Percept, ArrayList<Context>>();
-	private HashMap<Percept, ArrayList<Context>> partiallyActivatedContexts = new HashMap<Percept, ArrayList<Context>>();
-	private HashMap<Percept, ArrayList<Context>> partialNeighborContexts = new HashMap<Percept, ArrayList<Context>>();
-
-	private ArrayList<Context> contextsNeighborsByInfluence = new ArrayList<Context>();
-
-	private HashMap<Percept, ContextPair<Context, Context>> requestSurroundings = new HashMap<Percept, ContextPair<Context, Context>>();
-	private HashMap<Percept, ContextPair<Context, Context>> sharedIncompetenceContextPairs = new HashMap<Percept, ContextPair<Context, Context>>();
-
-	private ArrayList<Context> contextsInCompetition = new ArrayList<Context>();
-
 	Queue<EndogenousRequest> endogenousRequests = new PriorityQueue<EndogenousRequest>(new Comparator<EndogenousRequest>(){
 		   public int compare(EndogenousRequest r1, EndogenousRequest r2) {
 			      return r2.getPriority().compareTo(r1.getPriority());
@@ -81,29 +67,6 @@ public class Head extends AmoebaAgent {
 		for(int i =0 ; i< 20;i++) {
 			getAmas().data.executionTimesSums[i]=0.0;
 		}
-		
-
-		
-		
-
-	}
-	
-	
-
-	public void addPartiallyActivatedContext(Percept nonValidPercept, Context validContextExecptOnTheNonValidPercept) {
-		partiallyActivatedContexts.get(nonValidPercept).add(validContextExecptOnTheNonValidPercept);
-
-	}
-
-	public void addPartiallyActivatedContextInNeighbors(Percept nonValidPercept,
-			Context validContextExecptOnTheNonValidPercept) {
-		partiallyActivatedContextInNeighbors.get(nonValidPercept).add(validContextExecptOnTheNonValidPercept);
-
-	}
-
-	public void addPartialRequestNeighborContext(Percept nonValidPercept, Context validContextNeighborExecptOnTheNonValidPercept) {
-		partialNeighborContexts.get(nonValidPercept).add(validContextNeighborExecptOnTheNonValidPercept);
-
 	}
 
 	/**
@@ -281,28 +244,6 @@ public class Head extends AmoebaAgent {
 
 	}
 
-	public double getSpatialGeneralizationScore() {
-		return getAmas().data.spatialGeneralizationScore;
-	}
-
-	private boolean nearestLocalNeighbor(Context ctxt1, Context ctxt2) {
-
-		boolean nearestLocalNeighborTest = false;
-
-		for (Percept pct : getAmas().getPercepts()) {
-
-			if (partiallyActivatedContextInNeighbors.get(pct).contains(ctxt1)
-					&& partiallyActivatedContextInNeighbors.get(pct).contains(ctxt2)) {
-				nearestLocalNeighborTest = nearestLocalNeighborTest
-						|| (Math.abs(partiallyActivatedContextInNeighbors.get(pct).indexOf(ctxt1)
-								- partiallyActivatedContextInNeighbors.get(pct).indexOf(ctxt2)) == 1);
-			}
-
-		}
-
-		return nearestLocalNeighborTest;
-	}
-
 	public double getMinMaxVolume() {
 		double minMaxVolume = 1;
 		for (Percept pct : getAmas().getPercepts()) {
@@ -337,7 +278,6 @@ public class Head extends AmoebaAgent {
 		} else {
 
 			getAmas().data.noBestContext = true;
-			ArrayList<Context> allContexts = getAmas().getContexts();
 			Context nearestContext = this.getNearestContext(activatedNeighborsContexts);
 			if(nearestContext != null) {
 				getAmas().data.prediction = nearestContext.getActionProposal();
@@ -387,12 +327,6 @@ public class Head extends AmoebaAgent {
 		getAmas().data.endogenousPredictionActivatedContextsSharedIncompetence = null;
 		getAmas().data.endogenousPredictionNContextsByInfluence = null;
 
-		for (Percept pcpt : getAmas().getPercepts()) {
-			requestSurroundings.get(pcpt).clear();
-			sharedIncompetenceContextPairs.get(pcpt).clear();
-		}
-		contextsInCompetition.clear();
-
 		if (uniqueActivatedContext()) {
 			getAmas().data.endogenousPredictionActivatedContextsOverlaps = activatedContexts.get(0).getActionProposal();
 			getAmas().data.endogenousPredictionActivatedContextsOverlapsWorstDimInfluence = activatedContexts.get(0)
@@ -443,6 +377,7 @@ public class Head extends AmoebaAgent {
 		getAmas().data.maxConfidence = Double.NEGATIVE_INFINITY;
 		getAmas().data.minConfidence = Double.POSITIVE_INFINITY;
 
+		ArrayList<Context> contextsNeighborsByInfluence = new ArrayList<>();
 		for (Context ctxt : getAmas().getContexts()) {
 
 			if (ctxt.getConfidence() > getAmas().data.maxConfidence) {
@@ -517,20 +452,16 @@ public class Head extends AmoebaAgent {
 		// Test if there are surrounding contexts
 		boolean testSurroudingContext = false;
 
-		for (Percept pct : getAmas().getPercepts()) {
-
-			computeNearestContextsByPercept(pct);
-
-		}
+		HashMap<Percept, ContextPair<Context, Context>> sharedIncompetenceContextPairs = getSharedIncompetenceContextPair();
 
 		// displayContexts();
 
 		for (Percept pcpt : getAmas().getPercepts()) {
 
-			requestSurroundings.get(pcpt).print(pcpt);
 			if (sharedIncompetenceContextPairs.get(pcpt) != null) {
 				if (sharedIncompetenceContextPairs.get(pcpt).containTwoContexts()) {
 					testSurroudingContext = true;
+					break;
 				}
 			}
 
@@ -539,43 +470,40 @@ public class Head extends AmoebaAgent {
 		return testSurroudingContext;
 	}
 
-	private void diplayListRanges(ArrayList<Context> list, Percept prct, String range) {
-
-		System.out.print(range + " ranges list" + "  ");
-		for (Context ctxt : list) {
-			System.out.print(ctxt.getRanges().get(prct).getRange(range) + "  ");
+	private HashMap<Percept, ContextPair<Context, Context>> getSharedIncompetenceContextPair() {
+		HashMap<Percept, ContextPair<Context, Context>> sharedIncompetenceContextPairs = new HashMap<>();
+		
+		for (Percept pct : getAmas().getPercepts()) {
+			ContextPair<Context, Context> nearestContexts = computeNearestContextsByPercept(pct);
+			if (nearestContexts.getL() != null && nearestContexts.getR() != null) {
+				sharedIncompetenceContextPairs.put(pct, nearestContexts);
+			}
 		}
-		System.out.println(" ");
-
+		
+		return sharedIncompetenceContextPairs;
 	}
 
-	private void computeNearestContextsByPercept(Percept pct) {
-		ContextPair<Context, Context> nearestContexts = new ContextPair(null, null);
+	private ContextPair<Context, Context> computeNearestContextsByPercept(Percept pct) {
+		ContextPair<Context, Context> nearestContexts = new ContextPair<>(null, null);
 		boolean startNeighbor = false;
 		boolean endNeighbor = false;
 
 		ArrayList<Context> activatedContextInOtherPercepts = getAllActivatedContextsExeptForOnePercept(pct);
-
 		if (activatedContextInOtherPercepts.size() > 0) {
 
-
-
 			CustomComparator rangeStartComparator = new CustomComparator(pct, "start");
 			Collections.sort(activatedContextInOtherPercepts, rangeStartComparator);
-			// diplayListRanges(activatedContextInOtherPercepts, pct, "start");
 
 			for (Context ctxt : activatedContextInOtherPercepts) {
 				if (ctxt.getRanges().get(pct).getRange("start") > pct.getValue() && !startNeighbor) {
 					nearestContexts.setR(ctxt);
 					startNeighbor = true;
 				}
-
 			}
 
 			CustomComparator rangeEndComparator = new CustomComparator(pct, "end");
 			Collections.sort(activatedContextInOtherPercepts, rangeEndComparator);
 			Collections.reverse(activatedContextInOtherPercepts);
-			// diplayListRanges(activatedContextInOtherPercepts, pct, "end");
 
 			for (Context ctxt : activatedContextInOtherPercepts) {
 				if (ctxt.getRanges().get(pct).getRange("end") < pct.getValue() && !endNeighbor) {
@@ -584,65 +512,26 @@ public class Head extends AmoebaAgent {
 				}
 			}
 
-			// nearestContexts.print(pct);
-			requestSurroundings.put(pct, nearestContexts);
-
-			if (nearestContexts.getL() != null && nearestContexts.getR() != null) {
-				sharedIncompetenceContextPairs.put(pct, nearestContexts);
-			}
-		} else {
-
-		}
-
-	}
-
-	private ArrayList<Context> getAllActivatedContextsExeptForOnePercept(Percept onePercept) {
-
-		return partiallyActivatedContexts.get(onePercept);
-	}
-
-	private ArrayList<Context> getAllActivatedNeighborContextsExeptForOnePercept(Percept onePercept) {
-
-		return partialNeighborContexts.get(onePercept);
-	}
-
-	public void displayPartiallyActivatedContexts() {
-		//////// System.out.println("PARTIALLY ACTIVATED CONTEXTS");
-		for (Percept pct : partiallyActivatedContexts.keySet()) {
-			//// System.out.print(pct.getName() + " : ");
-			if (partiallyActivatedContexts.get(pct).size() > 0)
-				for (Context ctxt : partiallyActivatedContexts.get(pct)) {
-					//// System.out.print(ctxt.getName() + " ; ");
-				}
-			//////// System.out.println(" ");
 		}
+		return nearestContexts;
 	}
 
-	public void displayContexts() {
-		//////// System.out.println("CONTEXTS");
-		for (Context ctxt : getAmas().getContexts()) {
-			//// System.out.print(ctxt.getName() + " ; ");
-		}
-		//////// System.out.println(" ");
-	}
-
-	private Percept getDifferentPercept(Percept p) {
-		for (Percept pct : partiallyActivatedContexts.keySet()) {
-			if (p != pct) {
-				return pct;
-			}
-		}
-		return null;
-	}
-
-	private boolean contextActivateInOtherPerceptsThan(Context ctxt, Percept p1, Percept p2) {
-		boolean test = true;
-		for (Percept prct : partiallyActivatedContexts.keySet()) {
-			if (prct != p1 && prct != p2) {
-				test = test & partiallyActivatedContexts.get(prct).contains(ctxt);
+	/**
+	 * Return a list of contexts that have been activated by all percepts except a particular one.
+	 * @param pct
+	 * @return
+	 */
+	private ArrayList<Context> getAllActivatedContextsExeptForOnePercept(Percept pct) {
+		ArrayList<Percept> percepts = new ArrayList<>(getAmas().getPercepts());
+		percepts.remove(pct);
+		ArrayList<Context> ret = new ArrayList<>(getAmas().getContexts());
+		ret.removeIf(c -> {
+			for(Percept p : percepts) {
+				if(!p.activateContext(c)) return true;
 			}
-		}
-		return test;
+			return false;
+		});
+		return ret;
 	}
 
 	private void NCS_EndogenousCompetition() {
@@ -747,6 +636,7 @@ public class Head extends AmoebaAgent {
 		double smallestDistanceBetweenContexts = Double.POSITIVE_INFINITY;
 		double currentDistance;
 
+		HashMap<Percept, ContextPair<Context, Context>> sharedIncompetenceContextPairs = getSharedIncompetenceContextPair();
 		for (Percept pct : sharedIncompetenceContextPairs.keySet()) {
 			if (sharedIncompetenceContextPairs.get(pct) != null) {
 				if (sharedIncompetenceContextPairs.get(pct).containTwoContexts()) {
@@ -827,11 +717,6 @@ public class Head extends AmoebaAgent {
 
 	}
 
-	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 */
 
@@ -978,27 +863,16 @@ public class Head extends AmoebaAgent {
 		getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("------------------------------------------------------------------------------------"
 				+ "---------------------------------------- NCS DETECTION POTENTIAL REQUESTS")));
 		
-		
-
-		
 		if (activatedNeighborsContexts.size() > 1) {
-
 			int i = 1;
 			for (Context ctxt : activatedNeighborsContexts) {
-
 				for (Context otherCtxt : activatedNeighborsContexts.subList(i, activatedNeighborsContexts.size())) {
-
-					
 					if(!this.isDying() && !ctxt.isDying()) {
 						EndogenousRequest potentialRequest = ctxt.endogenousRequest(otherCtxt);
-						
 						if(potentialRequest != null) {
 							addEndogenousRequest(potentialRequest);
-							
 						}
 					}
-					
-
 				}
 				i++;
 			}
@@ -1006,100 +880,17 @@ public class Head extends AmoebaAgent {
 		
 		getEnvironment().trace(TRACE_LEVEL.STATE, new ArrayList<String>(Arrays.asList("ENDO REQUESTS", ""+endogenousRequests.size())));
 		for(EndogenousRequest endoRequest : endogenousRequests) {
-			
 			getEnvironment().trace(TRACE_LEVEL.STATE, new ArrayList<String>(Arrays.asList("" + endoRequest)));
-			
 		}
 		
 	}
 
-	private void selfAnalysationOfContexts2() {
-
-		if (activatedContexts.size() > 1) {
-			selfAnalysationOfContextOnSeveralActivatedContexts();
-
-		} else if (activatedContexts.size() == 1) {
-
-//			double distanceToOracleForActivatedContext = activatedContexts.get(0).getLocalModel().distance(activatedContexts.get(0).getCurrentExperiment());
-//			//System.out.println(distanceToOracleForActivatedContext + " ******************************************************************DISTANCE TO MODEL : " );
-//			if(activatedNeighborsContexts.size()>1) {
-//				
-//				Context closestContextToOracle = null;
-//				double minDistanceToOraclePredictionInNeighbors = Double.POSITIVE_INFINITY;
-//				double currentDistanceToOraclePrediction = 0.0; 
-//				for(Context contextNeighbor : activatedNeighborsContexts) {
-//					if(contextNeighbor != activatedContexts.get(0)) {
-//						currentDistanceToOraclePrediction = contextNeighbor.getLocalModel().distance(contextNeighbor.getCurrentExperiment());
-//						if(currentDistanceToOraclePrediction<minDistanceToOraclePredictionInNeighbors) {
-//							minDistanceToOraclePredictionInNeighbors = currentDistanceToOraclePrediction;
-//							closestContextToOracle = contextNeighbor;
-//						} 
-//					}
-//				}
-//				
-//				if(minDistanceToOraclePredictionInNeighbors>distanceToOracleForActivatedContext) {
-//					//System.out.println("OLD COEFS " + activatedContexts.get(0).getLocalModel().coefsToString());
-//					activatedContexts.get(0).getLocalModel().updateModel(activatedContexts.get(0).getCurrentExperiment(),learningSpeed,numberOfPointsForRegression);
-//					//System.out.println("NEW COEFS " + activatedContexts.get(0).getLocalModel().coefsToString());
-//					
-//				}else {
-//					closestContextToOracle.solveNCS_IncompetentHead(this);
-//					//activatedContexts.get(0).setLocalModel(new LocalModelMillerRegression(world, activatedContexts.get(0), closestContextToOracle.getLocalModel().getCoef(),closestContextToOracle.getLocalModel().getFirstExperiments()));
-//					//LocalModelAgent remplacementModel = new LocalModelMillerRegression(world, activatedContexts.get(0), closestContextToOracle.getLocalModel().getCoef().clone());
-//					//activatedContexts.get(0).setLocalModel(remplacementModel);
-//					
-//				}
-//
-//				
-//			}else {
-//				//System.out.println("OLD COEFS " + activatedContexts.get(0).getLocalModel().coefsToString());
-//				activatedContexts.get(0).getLocalModel().updateModel(activatedContexts.get(0).getCurrentExperiment(),learningSpeed,numberOfPointsForRegression);
-//				//System.out.println("NEW COEFS " + activatedContexts.get(0).getLocalModel().coefsToString());
-//				
-//				
-//			}
-
-			selfAnalysationOfContextOnUniqueActivatedContext();
-
-		}
-
-		for (Context ctxt : activatedNeighborsContexts) {
-
-			if (!activatedContexts.contains(ctxt)) {
-				ctxt.NCSDetection_Uselessness();
-			}
-
-		}
-	}
-
-	private void selfAnalysationOfContexts3() {
-
-		if (activatedContexts.size() > 1) {
-
-			selfAnalysationOfContextOnSeveralActivatedContexts();
-
-		} else if (activatedContexts.size() == 1) {
-
-			selfAnalysationOfContextOnUniqueActivatedContext();
-
-		}
-
-		for (Context ctxt : activatedNeighborsContexts) {
-
-			if (!activatedContexts.contains(ctxt)) {
-				ctxt.NCSDetection_Uselessness();
-			}
-
-		}
-	}
-
 	private void selfAnalysationOfContexts4() {
 
 		getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("------------------------------------------------------------------------------------"
 				+ "---------------------------------------- SELF ANALYSIS OF CTXT")));
 		
 		double currentDistanceToOraclePrediction;
-		Context closestContextToOracle = null;
 		double minDistanceToOraclePrediction = Double.POSITIVE_INFINITY;
 
 		for (Context activatedContext : activatedContexts) {
@@ -1123,7 +914,6 @@ public class Head extends AmoebaAgent {
 
 			if (currentDistanceToOraclePrediction < minDistanceToOraclePrediction) {
 				minDistanceToOraclePrediction = currentDistanceToOraclePrediction;
-				closestContextToOracle = activatedContext;
 			}
 
 			if (!getAmas().data.contextNotFinished) {
@@ -1163,135 +953,6 @@ public class Head extends AmoebaAgent {
 		}
 	}
 
-	private void selfAnalysationOfContextOnUniqueActivatedContext() {
-
-		if (activatedNeighborsContexts.size() > 0) {
-			double distanceToOracleForActivatedContext = activatedContexts.get(0).getLocalModel()
-					.distance(activatedContexts.get(0).getCurrentExperiment());
-			Quadruplet<Context, Double, Context, Double> closestAndFarestContextsToPredictionWithDistance = closestAndFarestContextsToPrediction();
-
-			double distanceToMin = Math
-					.abs(distanceToOracleForActivatedContext - closestAndFarestContextsToPredictionWithDistance.getB());
-			double distanceToMax = Math
-					.abs(distanceToOracleForActivatedContext - closestAndFarestContextsToPredictionWithDistance.getD());
-
-			if (distanceToMin < distanceToMax) {
-				getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("MODEL DISTANCE",
-						activatedContexts.get(0).getName(), "" + distanceToOracleForActivatedContext)));
-				activatedContexts.get(0).getLocalModel().updateModel(activatedContexts.get(0).getCurrentExperiment(),
-						getAmas().data.learningSpeed);
-
-			}
-		} else {
-			getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(
-					Arrays.asList("MODEL DISTANCE", activatedContexts.get(0).getName(), "" + activatedContexts.get(0)
-							.getLocalModel().distance(activatedContexts.get(0).getCurrentExperiment()))));
-			activatedContexts.get(0).getLocalModel().updateModel(activatedContexts.get(0).getCurrentExperiment(),
-					getAmas().data.learningSpeed);
-		}
-
-		// world.trace(new ArrayList<String>(Arrays.asList("MODEL
-		// DISTANCE",activatedContexts.get(0).getName(),
-		// ""+activatedContexts.get(0).getLocalModel().distance(activatedContexts.get(0).getCurrentExperiment()))));
-		// activatedContexts.get(0).getLocalModel().updateModel(activatedContexts.get(0).getCurrentExperiment(),learningSpeed,numberOfPointsForRegression);
-		activatedContexts.get(0).analyzeResults3(this, activatedContexts.get(0));
-	}
-
-	private Pair<Context, Double> maxModelDistanceToOraclePredictionInNeighbors() {
-		Context farestContextToOracle = null;
-		double maxDistanceToOraclePredictionInNeighbors = Double.NEGATIVE_INFINITY;
-		double currentDistanceToOraclePrediction = 0.0;
-		for (Context contextNeighbor : activatedNeighborsContexts) {
-			if (contextNeighbor != activatedContexts.get(0)) {
-				currentDistanceToOraclePrediction = contextNeighbor.getLocalModel()
-						.distance(contextNeighbor.getCurrentExperiment());
-				getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("MODEL DISTANCE", contextNeighbor.getName(),
-						"" + currentDistanceToOraclePrediction)));
-				if (currentDistanceToOraclePrediction > maxDistanceToOraclePredictionInNeighbors) {
-					maxDistanceToOraclePredictionInNeighbors = currentDistanceToOraclePrediction;
-					farestContextToOracle = contextNeighbor;
-				}
-			}
-		}
-		return new Pair<Context, Double>(farestContextToOracle, maxDistanceToOraclePredictionInNeighbors);
-	}
-
-	private Pair<Context, Double> minModelDistanceToOraclePredictionInNeighbors() {
-		Context closestContextToOracle = null;
-		double minDistanceToOraclePredictionInNeighbors = Double.POSITIVE_INFINITY;
-		double currentDistanceToOraclePrediction = 0.0;
-		for (Context contextNeighbor : activatedNeighborsContexts) {
-			if (contextNeighbor != activatedContexts.get(0)) {
-				currentDistanceToOraclePrediction = contextNeighbor.getLocalModel()
-						.distance(contextNeighbor.getCurrentExperiment());
-				getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("MODEL DISTANCE", contextNeighbor.getName(),
-						"" + currentDistanceToOraclePrediction)));
-				if (currentDistanceToOraclePrediction < minDistanceToOraclePredictionInNeighbors) {
-					minDistanceToOraclePredictionInNeighbors = currentDistanceToOraclePrediction;
-					closestContextToOracle = contextNeighbor;
-				}
-			}
-		}
-		return new Pair<Context, Double>(closestContextToOracle, minDistanceToOraclePredictionInNeighbors);
-	}
-
-	private Quadruplet<Context, Double, Context, Double> closestAndFarestContextsToPrediction() {
-		Context farestContextToOracle = null;
-		double maxDistanceToOraclePredictionInNeighbors = Double.NEGATIVE_INFINITY;
-		Context closestContextToOracle = null;
-		double minDistanceToOraclePredictionInNeighbors = Double.POSITIVE_INFINITY;
-
-		double currentDistanceToOraclePrediction = 0.0;
-		for (Context contextNeighbor : activatedNeighborsContexts) {
-			if (contextNeighbor != activatedContexts.get(0)) {
-				currentDistanceToOraclePrediction = contextNeighbor.getLocalModel()
-						.distance(contextNeighbor.getCurrentExperiment());
-				getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("MODEL DISTANCE", contextNeighbor.getName(),
-						"" + currentDistanceToOraclePrediction)));
-				if (currentDistanceToOraclePrediction > maxDistanceToOraclePredictionInNeighbors) {
-					maxDistanceToOraclePredictionInNeighbors = currentDistanceToOraclePrediction;
-					farestContextToOracle = contextNeighbor;
-				}
-				if (currentDistanceToOraclePrediction < minDistanceToOraclePredictionInNeighbors) {
-					minDistanceToOraclePredictionInNeighbors = currentDistanceToOraclePrediction;
-					closestContextToOracle = contextNeighbor;
-				}
-			}
-		}
-		return new Quadruplet<Context, Double, Context, Double>(closestContextToOracle,
-				minDistanceToOraclePredictionInNeighbors, farestContextToOracle,
-				maxDistanceToOraclePredictionInNeighbors);
-	}
-
-	private void selfAnalysationOfContextOnSeveralActivatedContexts() {
-
-		Context closestContextToOracle = null;
-		double minDistanceToOraclePrediction = Double.POSITIVE_INFINITY;
-		double currentDistanceToOraclePrediction = 0.0;
-
-		for (Context activatedContext : activatedContexts) {
-			currentDistanceToOraclePrediction = activatedContext.getLocalModel()
-					.distance(activatedContext.getCurrentExperiment());
-
-			getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("MODEL DISTANCE", activatedContext.getName(),
-					"" + activatedContext.getLocalModel().distance(activatedContext.getCurrentExperiment()))));
-			if (currentDistanceToOraclePrediction < minDistanceToOraclePrediction) {
-				minDistanceToOraclePrediction = currentDistanceToOraclePrediction;
-				closestContextToOracle = activatedContext;
-			}
-
-		}
-
-		closestContextToOracle.getLocalModel().updateModel(closestContextToOracle.getCurrentExperiment(), getAmas().data.learningSpeed);
-
-		activatedContextsCopyForUpdates = new ArrayList<Context>(activatedContexts);
-		for (Context activatedContext : activatedContexts) {
-			activatedContext.analyzeResults3(this, closestContextToOracle);
-
-		}
-		activatedContexts = activatedContextsCopyForUpdates;
-	}
-
 	private void setNearestContextAsBestContext() {
 		Context nearestContext = this.getNearestContext(activatedNeighborsContexts);
 
@@ -1304,25 +965,6 @@ public class Head extends AmoebaAgent {
 		bestContext = nearestContext;
 	}
 
-	private void setNearestGoodContextAsBestContext() {
-		Context nearestContext = this.getNearestGoodContext(activatedNeighborsContexts);
-
-		if (nearestContext != null) {
-			getAmas().data.prediction = nearestContext.getActionProposal();
-		} else {
-			getAmas().data.prediction = 0.0;
-		}
-
-		bestContext = nearestContext;
-	}
-
-	/**
-	 * Endogenous feedback.
-	 */
-	private void endogenousFeedback() {
-		// bestContext.growRanges(this);
-	}
-
 	/**
 	 * Gets the nearest good context.
 	 *
@@ -1362,28 +1004,6 @@ public class Head extends AmoebaAgent {
 
 	}
 
-	/**
-	 * Gets the distance to nearest good context.
-	 *
-	 * @param allContext the all context
-	 * @return the distance to nearest good context
-	 */
-	private Pair<Context, Double> getNearestGoodContextWithDistance(ArrayList<Context> contextNeighbors) {
-		double d = Double.MAX_VALUE;
-		Context nearestGoodContext = null;
-		for (Context c : contextNeighbors) {
-			if (Math.abs((c.getActionProposal() - getAmas().data.oracleValue)) <= getAmas().data.predictionPerformance.getPerformanceIndicator()
-					&& c != newContext && !c.isDying()) {
-				if (getExternalDistanceToContext(c) < d) {
-					d = getExternalDistanceToContext(c);
-					nearestGoodContext = c;
-				}
-			}
-		}
-		return new Pair<Context, Double>(nearestGoodContext, d);
-
-	}
-	
 	private Pair<Context, Double> getbestContextInNeighborsWithDistanceToModel(ArrayList<Context> contextNeighbors) {
 		double d = Double.MAX_VALUE;
 		Context bestContextInNeighbors = null;
@@ -1462,19 +1082,6 @@ public class Head extends AmoebaAgent {
 		return d;
 	}
 
-	private double getDistanceToContext(Context context) {
-		double totalDistance = 0.0;
-		for (Percept p : getAmas().getPercepts()) {
-			double distance = context.distance(p, p.getValue());
-			if (distance > 0) {
-				totalDistance += distance;
-			}
-
-		}
-
-		return totalDistance;
-	}
-
 	/**
 	 * One of proposed context was good.
 	 *
@@ -1949,24 +1556,6 @@ public class Head extends AmoebaAgent {
 		getAmas().data.useOracle = !getAmas().data.useOracle;
 	}
 
-	/**
-	 * Gets the function selected.
-	 *
-	 * @return the function selected
-	 */
-	public String getFunctionSelected() {
-		return functionSelected;
-	}
-
-	/**
-	 * Sets the function selected.
-	 *
-	 * @param functionSelected the new function selected
-	 */
-	public void setFunctionSelected(String functionSelected) {
-		this.functionSelected = functionSelected;
-	}
-
 	/**
 	 * Gets the n propositions received.
 	 *
@@ -2074,86 +1663,6 @@ public class Head extends AmoebaAgent {
 		this.getAmas().data.prediction = prediction;
 	}
 
-	public ArrayList<Context> getPartiallyActivatedContexts(Percept pct) {
-		return partiallyActivatedContexts.get(pct);
-	}
-
-	public ArrayList<Context> getPartiallyActivatedNeighborContexts(Percept pct) {
-		return partialNeighborContexts.get(pct);
-	}
-
-	public HashMap<Percept, ContextPair<Context, Context>> getRequestSurroundings() {
-		return requestSurroundings;
-	}
-
-	public boolean requestSurroundingContains(Context ctxt) {
-
-		for (Percept pct : requestSurroundings.keySet()) {
-
-			if (requestSurroundings.get(pct).contains(ctxt)) {
-				return true;
-			}
-		}
-		return false;
-
-	}
-
-	public ArrayList<Context> getContextsInCompetition() {
-		return contextsInCompetition;
-	}
-
-	public Head clone() throws CloneNotSupportedException {
-		return (Head) super.clone();
-	}
-
-	public void addRequestNeighbor(Context ctxt) {
-		if (!activatedNeighborsContexts.contains(ctxt)) {
-
-			activatedNeighborsContexts.add(ctxt);
-		}
-	}
-
-	public void addActivatedContext(Context ctxt) {
-		if (!activatedContexts.contains(ctxt)) {
-			activatedContexts.add(ctxt);
-
-
-			for (Context cxt : activatedContexts) {
-
-			}
-		}
-	}
-
-	public void addActivatedContextCopy(Context ctxt) {
-		if (!activatedContextsCopyForUpdates.contains(ctxt)) {
-			activatedContextsCopyForUpdates.add(ctxt);
-
-
-			for (Context cxt : activatedContextsCopyForUpdates) {
-
-			}
-		}
-	}
-
-	public void removeActivatedContext(Context ctxt) {
-		if (activatedContexts.contains(ctxt)) {
-			activatedContexts.remove(ctxt);
-		}
-	}
-
-	public void removeActivatedContextCopy(Context ctxt) {
-		if (activatedContextsCopyForUpdates.contains(ctxt)) {
-			activatedContextsCopyForUpdates.remove(ctxt);
-		}
-	}
-
-	public void removeRequestNeighbor(Context ctxt) {
-		if (activatedNeighborsContexts.contains(ctxt)) {
-
-			activatedNeighborsContexts.remove(ctxt);
-		}
-	}
-
 	public ArrayList<Context> getActivatedNeighborsContexts() {
 		return activatedNeighborsContexts;
 	}
@@ -2162,34 +1671,9 @@ public class Head extends AmoebaAgent {
 		activatedNeighborsContexts = neighbors;
 	}
 
-
-	public ArrayList<Context> getContextNeighborsByInfluence() {
-		return contextsNeighborsByInfluence;
-	}
-
-	public void displayActivatedNeighborsContexts() {
-		for (Context ctxt : activatedNeighborsContexts) {
-
-		}
-	}
-
-	public void clearActivatedNeighborsContexts() {
-		activatedNeighborsContexts.clear();
-	}
-
-	public void clearContextdNeighborsByInfluence() {
-		contextsNeighborsByInfluence.clear();
-	}
-
 	public void clearAllUseableContextLists() {
 		activatedContexts.clear();
 		activatedNeighborsContexts.clear();
-		contextsNeighborsByInfluence.clear();
-		for (Percept pct : getAmas().getPercepts()) {
-			partiallyActivatedContexts.get(pct).clear();
-			partiallyActivatedContextInNeighbors.get(pct).clear();
-			partialNeighborContexts.get(pct).clear();
-		}
 	}
 
 	public Double getMaxRadiusForContextCreation(Percept pct) {
@@ -2370,21 +1854,6 @@ public class Head extends AmoebaAgent {
 		
 	}
 	
-	public void updatePartiallyActivatedNeighbors() {
-		
-		for(Percept pct: getAmas().getPercepts()) {
-			
-			pct.computeContextNeighborsValidity(activatedNeighborsContexts);
-			
-		}
-		
-		for(Context ctxt : activatedNeighborsContexts) {
-			
-			ctxt.computeContextNeighborsValidity();
-			
-		}
-	}
-	
 	public boolean isVoid(HashMap<Percept, Double> request) {
 		boolean test;
 		
@@ -2408,18 +1877,11 @@ public class Head extends AmoebaAgent {
 		int numberOfRegressions = 0;
 		if(activatedNeighborsContexts.size()>0) {
 			double meanRegressionPerformanceIndicator = 0.0;
-			
 			for(Context ctxt : activatedNeighborsContexts) {
-				
-
-				if(ctxt.regressionPerformance != null) {
 					meanRegressionPerformanceIndicator += ctxt.regressionPerformance.performanceIndicator;
 					numberOfRegressions+=1;
-				}
-				
-				
 			}
-			
+			assert numberOfRegressions != 0;
 			return meanRegressionPerformanceIndicator/numberOfRegressions;
 		}
 		else{
@@ -2427,16 +1889,8 @@ public class Head extends AmoebaAgent {
 		}
 		
 	}
-	
-	
-	
-
-	// -----------------
-	// AMOEBAonAMAK ---
-	// -----------------
 
 	public void proposition(Context c) {
-
 		activatedContexts.add(c);
 	}
 	
@@ -2446,19 +1900,8 @@ public class Head extends AmoebaAgent {
 		getAmas().data.maxConfidence = Double.NEGATIVE_INFINITY;
 		getAmas().data.minConfidence = Double.POSITIVE_INFINITY;
 
-		// getAmas().data.mappingPerformance.setPerformanceIndicator(world.getMappingErrorAllowed());//
-		// Math.pow(world.getMappingErrorAllowed(),
-		// world.getScheduler().getPercepts().size());
-
 		criticalities = new Criticalities(getAmas().data.numberOfCriticityValuesForAverage);
 		endogenousCriticalities = new Criticalities(getAmas().data.numberOfCriticityValuesForAverageforVizualisation);
 	}
-
-	public void addPercept(Percept pct) {
-		partiallyActivatedContextInNeighbors.put(pct, new ArrayList<Context>());
-		partiallyActivatedContexts.put(pct, new ArrayList<Context>());
-		partialNeighborContexts.put(pct, new ArrayList<Context>());
-		requestSurroundings.put(pct, new ContextPair<Context, Context>(null, null));
-		sharedIncompetenceContextPairs.put(pct, new ContextPair<Context, Context>(null, null));
-	}
+	
 }
diff --git a/AMOEBAonAMAK/src/agents/percept/Percept.java b/AMOEBAonAMAK/src/agents/percept/Percept.java
index 06496946..52c9a398 100644
--- a/AMOEBAonAMAK/src/agents/percept/Percept.java
+++ b/AMOEBAonAMAK/src/agents/percept/Percept.java
@@ -53,8 +53,6 @@ public class Percept extends AmoebaAgent {
 		value = getAmas().getPerceptions(this.name);
 		ajustMinMax();
 		computeContextProjectionValidityOptimized();
-		//computeContextProjectionValidity();
-
 	}
 
 	public void computeContextProjectionValidity() {
@@ -124,7 +122,7 @@ public class Percept extends AmoebaAgent {
 		}
 		
 		for (Context c : contexts) {
-			if (contextProjections.get(c).contains(this.value)) {
+			if (activateContext(c)) {
 				validContextProjection.add(c);
 			}
 		} 
@@ -137,7 +135,7 @@ public class Percept extends AmoebaAgent {
 		}
 		
 		for (Context c : neighborsContexts) {
-			if(contextProjections.get(c).inNeighborhood()) {
+			if(inNeighborhood(c)) {
 				neighborContextProjection.add(c);
 			}
 		} 
@@ -145,6 +143,24 @@ public class Percept extends AmoebaAgent {
 		
 		logger().debug("CYCLE "+getAmas().getCycle(), "%s's valid contexts : %s", toString(), validContextProjection.toString());
 	}
+	
+	/**
+	 * Return true if the context is activated by this percept.
+	 * @param context
+	 * @return
+	 */
+	public boolean activateContext(Context context) {
+		return contextProjections.get(context).contains(this.value);
+	}
+	
+	/**
+	 * Return true if the context is in the neighborhood of this percept.
+	 * @param context
+	 * @return
+	 */
+	public boolean inNeighborhood(Context context) {
+		return contextProjections.get(context).inNeighborhood();
+	}
 
 
 	/**
diff --git a/AMOEBAonAMAK/src/experiments/F_XY_System.java b/AMOEBAonAMAK/src/experiments/F_XY_System.java
index 86a0d739..30f3fdfd 100644
--- a/AMOEBAonAMAK/src/experiments/F_XY_System.java
+++ b/AMOEBAonAMAK/src/experiments/F_XY_System.java
@@ -48,7 +48,7 @@ public class F_XY_System implements StudiedSystem {
 
 		out.put("px0", x);
 		out.put("px1", y);
-		out.put("oracle", result);
+		out.put("oracle", 0.0);
 		return out;
 	}
 
diff --git a/AMOEBAonAMAK/src/experiments/MinimalMain.java b/AMOEBAonAMAK/src/experiments/MinimalMain.java
index 60218985..b9b0bde3 100644
--- a/AMOEBAonAMAK/src/experiments/MinimalMain.java
+++ b/AMOEBAonAMAK/src/experiments/MinimalMain.java
@@ -1,12 +1,7 @@
 package experiments;
 
-import java.util.HashMap;
-
-import fr.irit.smac.amak.Configuration;
-import fr.irit.smac.amak.tools.Log;
 import kernel.AMOEBA;
 import kernel.StudiedSystem;
-import kernel.backup.SaveHelperDummy;
 
 /**
  * The most minimal main possible producing a functioning amoeba.
@@ -16,61 +11,12 @@ import kernel.backup.SaveHelperDummy;
 public class MinimalMain {
 
 	public static void main(String[] args) throws InterruptedException {
-		Configuration.commandLineMode = true;
-		Log.defaultMinLevel = Log.Level.INFORM;
 		// create a system to be studied
-		StudiedSystem studiedSystem = new NDimCube(50.0, 3);
+		StudiedSystem studiedSystem = new F_XY_System(50.0);
 		// create the amoeba
 		// Make sure the path to the config file is correct.
-		AMOEBA amoeba = new AMOEBA("resources/threeDimensionsLauncher.xml", studiedSystem);
-		amoeba.saver = new SaveHelperDummy();
+		AMOEBA amoeba = new AMOEBA("resources/twoDimensionsLauncher.xml", studiedSystem);
 		// a window should have appeared, allowing you to control and visualize the amoeba.
-		
-		Thread.sleep(5000);
-		
-		long start = System.currentTimeMillis();
-		long end = System.currentTimeMillis();
-		for(int i = 0; i < 10000; i++) {
-			studiedSystem.playOneStep();
-			amoeba.learn(studiedSystem.getOutput());
-			if(i%100 == 99) {
-				end = System.currentTimeMillis();
-				System.out.println("Time for 100 learn: "+(end-start)/1000.0);
-				start = System.currentTimeMillis();
-			}
-		}
-		
-		start = System.currentTimeMillis();
-		end = System.currentTimeMillis();
-		for(int i = 0; i < 1000; i++) {
-			studiedSystem.playOneStep();
-			amoeba.request(studiedSystem.getOutput());
-			if(i%100 == 99) {
-				end = System.currentTimeMillis();
-				System.out.println("Time for 100 request: "+(end-start)/1000.0);
-				start = System.currentTimeMillis();
-			}
-		}
-		
-		start = System.currentTimeMillis();
-		end = System.currentTimeMillis();
-		for(int i = 0; i < 1000; i++) {
-			studiedSystem.playOneStep();
-			HashMap<String, Double> req = studiedSystem.getOutput();
-			req.remove("px1");
-			req.remove("px2");
-			req.remove("px3");
-			req.remove("oracle");
-			amoeba.maximize(req);
-			if(i%100 == 99) {
-				end = System.currentTimeMillis();
-				System.out.println("Time for 100 maximize: "+(end-start)/1000.0);
-				start = System.currentTimeMillis();
-			}
-		}
-		
-		System.exit(0);
-		
 	}
 
 }
diff --git a/AMOEBAonAMAK/src/experiments/SimpleReinforcement.java b/AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
index 75c015c3..b63df765 100644
--- a/AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
+++ b/AMOEBAonAMAK/src/experiments/SimpleReinforcement.java
@@ -16,6 +16,14 @@ import utils.Pair;
 import utils.RandomUtils;
 import utils.XmlConfigGenerator;
 
+/**
+ * Train an amoeba on a simple reinforcement task.
+ * The goal of the task is to get to the center. When the position of the agent cross 0, it gets a reward of 100.
+ * The agent can only moves in 2 directions, of a distance of 1. Moving give a reward of -1.
+ * If the agent moves outside of the allowed range, it gets a reward of -100. 
+ * @author Hugo
+ *
+ */
 public class SimpleReinforcement {
 	
 	private Random rand = new Random();
@@ -46,7 +54,7 @@ public class SimpleReinforcement {
 		for(int i = 0; i < 10000; i++) {
 			state.remove("oracle");
 			HashMap<String, Double> action = amoeba.maximize(state);
-			if(r.nextDouble() < 0.1 || action.get("oracle").equals(Double.NEGATIVE_INFINITY) ) {
+			if(r.nextDouble() < 0.2 || action.get("oracle").equals(Double.NEGATIVE_INFINITY) ) {
 				System.out.println("Random action");
 				action.put("a1", (r.nextBoolean() ? 10.0 : -10.0));
 			}
@@ -96,7 +104,7 @@ public class SimpleReinforcement {
 		HashMap<String, Double> ret = new HashMap<>();
 		ret.put("p1", x);
 		ret.put("oracle", reward);
-		pos.move(x, 0);
+		pos.move(x+0.5, 0.5);
 		return ret;
 	}
 	
diff --git a/AMOEBAonAMAK/src/experiments/TestingMain.java b/AMOEBAonAMAK/src/experiments/TestingMain.java
index 20332e20..55bfd61b 100644
--- a/AMOEBAonAMAK/src/experiments/TestingMain.java
+++ b/AMOEBAonAMAK/src/experiments/TestingMain.java
@@ -16,7 +16,7 @@ import kernel.backup.SaveHelperDummy;
 public class TestingMain {
 
 	public static void main(String[] args) throws InterruptedException {
-		Configuration.commandLineMode = true;
+		Configuration.commandLineMode = false;
 		Log.defaultMinLevel = Log.Level.INFORM;
 		// create a system to be studied
 		StudiedSystem studiedSystem = new NDimCube(50.0, 3);
@@ -30,7 +30,7 @@ public class TestingMain {
 		
 		long start = System.currentTimeMillis();
 		long end = System.currentTimeMillis();
-		for(int i = 0; i < 10000; i++) {
+		for(int i = 0; i < 1000; i++) {
 			studiedSystem.playOneStep();
 			amoeba.learn(studiedSystem.getOutput());
 			if(i%100 == 99) {
diff --git a/AMOEBAonAMAK/src/experiments/nDimensionsLaunchers/F_N_Launcher.java b/AMOEBAonAMAK/src/experiments/nDimensionsLaunchers/F_N_Launcher.java
index c24ccaa1..2e031071 100644
--- a/AMOEBAonAMAK/src/experiments/nDimensionsLaunchers/F_N_Launcher.java
+++ b/AMOEBAonAMAK/src/experiments/nDimensionsLaunchers/F_N_Launcher.java
@@ -85,6 +85,14 @@ public class F_N_Launcher implements Serializable {
 //		}
 //		long end = System.currentTimeMillis();
 //		System.out.println("Done in : " + (end - start) );
+//		
+//		start = System.currentTimeMillis();
+//		for (int i = 0; i < nbCycle; ++i) {
+//			studiedSystem.playOneStep();
+//			amoeba.request(studiedSystem.getOutput());
+//		}
+//		end = System.currentTimeMillis();
+//		System.out.println("Done in : " + (end - start) );
 		
 		
 //		/* XP PIERRE */
diff --git a/AMOEBAonAMAK/src/kernel/AMOEBA.java b/AMOEBAonAMAK/src/kernel/AMOEBA.java
index d47419a8..502a41fd 100644
--- a/AMOEBAonAMAK/src/kernel/AMOEBA.java
+++ b/AMOEBAonAMAK/src/kernel/AMOEBA.java
@@ -679,15 +679,6 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
 		alteredContexts.add(context);
 	}
 	
-	/**
-	 * Gets the altered contexts.
-	 *
-	 * @return the altered contexts
-	 */
-	public ArrayList<Context> getAlteredContexts() {
-		return alteredContexts;
-	}
-	
 	/**
 	 * Return the current set of valid contexts.
 	 *
@@ -777,7 +768,6 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
 	
 	public void addPercept(Percept pct) {
 		percepts = null;
-		head.addPercept(pct);
 	}
 	
 }
-- 
GitLab