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

CLN : first stage

parent a43715df
No related branches found
No related tags found
1 merge request!1Merge Master
LxPlot_width=1936 LxPlot_width=1936
LxPlot_height=1176 LxPlot_height=1176
LxPlot_x=1672 LxPlot_x=439
LxPlot_y=-8 LxPlot_y=0
AMOEBA3/model_map.png

218 B

...@@ -19,30 +19,16 @@ import blackbox.BlackBoxAgent; ...@@ -19,30 +19,16 @@ import blackbox.BlackBoxAgent;
*/ */
public class Percept extends SystemAgent implements Serializable { public class Percept extends SystemAgent implements Serializable {
/** The old value. */
private double oldValue;
/** The value. */
private double value;
/** The sensor. */
private BlackBoxAgent sensor; private BlackBoxAgent sensor;
/** The targets. */
protected ArrayList<Agent> targets = new ArrayList<Agent>(); protected ArrayList<Agent> targets = new ArrayList<Agent>();
/** The activated context. */
protected ArrayList<Agent> activatedContext = new ArrayList<Agent>(); protected ArrayList<Agent> activatedContext = new ArrayList<Agent>();
/** The min. */
private double min = Double.MAX_VALUE; private double min = Double.MAX_VALUE;
/** The max. */
private double max = Double.MIN_VALUE; private double max = Double.MIN_VALUE;
/** The is enum. */ private double oldValue;
private double value;
private boolean isEnum = false; private boolean isEnum = false;
/** /**
...@@ -90,6 +76,7 @@ public class Percept extends SystemAgent implements Serializable { ...@@ -90,6 +76,7 @@ public class Percept extends SystemAgent implements Serializable {
a.setMessagesBin(obj.messagesBin); a.setMessagesBin(obj.messagesBin);
this.targets.add(obj); this.targets.add(obj);
} }
this.activatedContext = new ArrayList<Agent>(); this.activatedContext = new ArrayList<Agent>();
for(Agent obj: p.activatedContext) { for(Agent obj: p.activatedContext) {
Agent a = new Agent() { Agent a = new Agent() {
...@@ -128,23 +115,6 @@ public class Percept extends SystemAgent implements Serializable { ...@@ -128,23 +115,6 @@ public class Percept extends SystemAgent implements Serializable {
} }
/**
* Gets the context including.
*
* @param v the v
* @return the context including
*/
public ArrayList<Context> getContextIncluding(double v){
ArrayList<Context> contexts = new ArrayList<Context>();
ArrayList<Range> list = new ArrayList<Range>();
for (Range r : list) {
contexts.add(r.getContext());
}
return contexts;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see agents.Agent#computeAMessage(agents.messages.Message) * @see agents.Agent#computeAMessage(agents.messages.Message)
...@@ -205,6 +175,14 @@ public class Percept extends SystemAgent implements Serializable { ...@@ -205,6 +175,14 @@ public class Percept extends SystemAgent implements Serializable {
if (min == Double.MAX_VALUE || max == Double.MIN_VALUE) return 0; if (min == Double.MAX_VALUE || max == Double.MIN_VALUE) return 0;
return Math.abs(max - min); return Math.abs(max - min);
} }
public double getMin() {
return min;
}
public double getMax() {
return max;
}
/** /**
* Gets the activated context. * Gets the activated context.
......
package experiments.badContext;
import java.util.ArrayList;
import java.util.HashMap;
import agents.Agent;
import agents.Percept;
import agents.context.Context;
import agents.context.Range;
import agents.localModel.TypeLocalModel;
import init.amoeba.AMOEBAFactory;
import kernel.AMOEBA;
public class AMOEBA_UI {
private AMOEBA amoeba;
public AMOEBA_UI(boolean viewer, String percepts){
if(percepts.contentEquals("position")){
amoeba = AMOEBAFactory.createAMOEBA(viewer, "src/experiments/droneControl/DroneControl.xml",
"src/experiments/droneControl/DroneControl_solver.xml");
}
else if (percepts.contentEquals("speed")){
amoeba = AMOEBAFactory.createAMOEBA(viewer, "src/experiments/droneControl/DroneControlVariations.xml",
"src/experiments/droneControl/DroneControlVariations_solver.xml");
}
}
void init(){
amoeba.getScheduler().getWorld().setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba.getScheduler().getHeadAgent().setDataForErrorMargin(0.1, 1, 1, 0.1, 10, 100);
amoeba.getScheduler().getHeadAgent().setDataForInexactMargin(0.1, 1, 1, 0.1, 10, 100);
amoeba.setAVT_acceleration(1.1f);
amoeba.setAVT_deceleration(0.1);
amoeba.setAVT_percentAtStart(0.1f);
}
ArrayList<Agent> getContexts(){
return amoeba.getScheduler().getContexts();
}
public static ArrayList<Agent> getContexts(AMOEBA a){
return a.getScheduler().getContexts();
}
public static ArrayList<Context> getContextsAsContexts(AMOEBA a){
return a.getScheduler().getContextsAsContext();
}
public void learn(HashMap<String, Double> actions){
amoeba.learn(actions);
}
public double request(HashMap<String, Double> actions){
return amoeba.request(actions);
}
public ArrayList<Percept> getAllPercepts(){
return amoeba.getScheduler().getWorld().getAllPercept();
}
public static ArrayList<Percept> getAllPercepts(AMOEBA a){
return a.getScheduler().getWorld().getAllPercept();
}
public HashMap<Percept, Range> getRanges(){
return amoeba.getScheduler().getHeadAgent().getBestContext().getRanges();
}
public String getBestContextId(){
return Integer.toString(amoeba.getScheduler().getHeadAgent().getBestContext().getID());
}
public HashMap<String, Double> getBestContextPerceptCenter(){
HashMap<String, Double> goal = new HashMap<String, Double>();
double[] perceptCenter = new double[getAllPercepts().size()];
ArrayList<Percept> percepts= this.getAllPercepts();
HashMap<Percept, Range> contextRanges = this.getRanges();
for(int i=0; i<perceptCenter.length; i++){
perceptCenter[i] = (contextRanges.get(percepts.get(i)).getStart() + contextRanges.get(percepts.get(i)).getEnd())/2;
goal.put("P"+i, (contextRanges.get(percepts.get(i)).getStart() + contextRanges.get(percepts.get(i)).getEnd())/2);
}
return goal;
}
public String getBestContextMessage(){
String message ="";
ArrayList<Percept> percepts= this.getAllPercepts();
HashMap<Percept, Range> contextRanges = this.getRanges();
String[] contextDescription = new String[8];
contextDescription[0] = Double.toString((contextRanges.get(percepts.get(0)).getStart() + contextRanges.get(percepts.get(0)).getEnd())/2);
contextDescription[1] = Double.toString((contextRanges.get(percepts.get(1)).getStart() + contextRanges.get(percepts.get(1)).getEnd())/2);
contextDescription[2] = Double.toString((contextRanges.get(percepts.get(2)).getStart() + contextRanges.get(percepts.get(2)).getEnd())/2);
contextDescription[3] = Double.toString((contextRanges.get(percepts.get(0)).getLenght()));
contextDescription[4] = Double.toString((contextRanges.get(percepts.get(1)).getLenght()));
contextDescription[5] = Double.toString((contextRanges.get(percepts.get(2)).getLenght()));
contextDescription[6] = Double.toString((amoeba.getScheduler().getHeadAgent().getBestContext().getActionProposal()));
contextDescription[7] = Integer.toString(amoeba.getScheduler().getHeadAgent().getBestContext().getID());
message = message + contextDescription[0] + " " + contextDescription[1] + " " + contextDescription[2];
message = message + "_" + contextDescription[3] + " " + contextDescription[4] + " " + contextDescription[5];
message = message + "_" + contextDescription[6];
message = message + "_" + "100" + contextDescription[7] ;
return message;
}
}
package experiments.badContext; package experiments.badContext;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import agents.Agent;
import agents.Percept;
import agents.context.Context;
import agents.localModel.TypeLocalModel; import agents.localModel.TypeLocalModel;
import init.amoeba.AMOEBAFactory; import init.amoeba.AMOEBAFactory;
import kernel.AMOEBA; import kernel.AMOEBA;
...@@ -17,55 +21,70 @@ public class BadContextLauncherEasy implements Serializable { ...@@ -17,55 +21,70 @@ public class BadContextLauncherEasy implements Serializable {
public static final boolean viewer = true; public static final boolean viewer = true;
public static final boolean verboseriticity = true; public static final boolean verboseriticity = true;
public static void main(String[] args) { public static void main(String[] args) {
launch(viewer); launch(viewer);
} }
public static void launch(boolean viewer) { public static void launch(boolean viewer) {
/*Here we create AMOEBA.*/ /*Here we create AMOEBA.*/
AMOEBA amoeba = AMOEBAFactory.createAMOEBA(viewer, "src/experiments/badContext/BadContext.xml","src/experiments/badContext/BadContext_solver.xml"); AMOEBA amoeba = AMOEBAFactory.createAMOEBA(viewer, "src/experiments/badContext/BadContext.xml","src/experiments/badContext/BadContext_solver.xml");
AMOEBA amoeba2 = AMOEBAFactory.createAMOEBA(viewer, "src/experiments/badContext/BadContext.xml","src/experiments/badContext/BadContext_solver.xml");
/* These method calls allow to setup AMOEBA*/ /* These method calls allow to setup AMOEBA*/
amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION); amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba.setDataForErrorMargin(0.5, 1, 1, 0.4, 10, 100); amoeba.setDataForErrorMargin(0.5, 1, 1, 0.4, 10, 100);
amoeba.setDataForInexactMargin(0.5, 1, 1, 0.4, 10, 100); amoeba.setDataForInexactMargin(0.5, 1, 1, 0.4, 10, 100);
amoeba2.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
amoeba2.setDataForErrorMargin(0.5, 1, 1, 0.4, 10, 100);
amoeba2.setDataForInexactMargin(0.5, 1, 1, 0.4, 10, 100);
amoeba.setRememberState(false); amoeba.setRememberState(false);
amoeba.setGenerateCSV(false); amoeba.setGenerateCSV(false);
amoeba2.setRememberState(false);
amoeba2.setGenerateCSV(false);
/* This is the initialization of the studied system. It's only for the sake of example, not a part of AMOEBA initialization*/ /* This is the initialization of the studied system. It's only for the sake of example, not a part of AMOEBA initialization*/
BadContextManager bcm = new BadContextManager(); BadContextManager bcm = new BadContextManager();
bcm.setWorld(amoeba.getScheduler().getWorld()); bcm.setWorld(amoeba.getScheduler().getWorld());
for (int i = 0 ; i < 1000 ; i++) { for (int i = 0 ; i < 100 ; i++) {
/* This is the studied system part. Feel free to use any data source.*/ /* This is the studied system part. Feel free to use any data source.*/
bcm.playOneStep(0); bcm.playOneStep(0);
/*This is a learning step of AMOEBA*/ /*This is a learning step of AMOEBA*/
amoeba.learn(new HashMap<String, Double>(bcm.getOutput())); amoeba.learn(new HashMap<String, Double>(bcm.getOutput()));
amoeba2.learn(new HashMap<String, Double>(bcm.getOutput()));
try
{
Thread.sleep(1000);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
} }
for (int i = 0 ; i < 1000 ; i++) { /*for (int i = 0 ; i < 1000 ; i++) {
bcm.playOneStep(0); bcm.playOneStep(0);
HashMap<String, Double> data = new HashMap<String, Double>(bcm.getOutput()); HashMap<String, Double> data = new HashMap<String, Double>(bcm.getOutput());
// data.remove("test"); // data.remove("test");
System.out.println("Test request : " + amoeba.request(data)); System.out.println("Test request : " + amoeba.request(data));
System.out.println("Test request : " + amoeba2.request(data)); }*/
}
ArrayList<Percept> P = AMOEBA_UI.getAllPercepts(amoeba);
ArrayList<Agent> A = AMOEBA_UI.getContexts(amoeba);
ArrayList<Context> C = AMOEBA_UI.getContextsAsContexts(amoeba);
System.out.println(C);
Percept P0 = P.get(0);
Percept P1 = P.get(1);
} }
......
...@@ -337,7 +337,7 @@ public class AMOEBA extends Thread { ...@@ -337,7 +337,7 @@ public class AMOEBA extends Thread {
* @param s the s * @param s the s
* @return the all valid context but * @return the all valid context but
*/ */
public ArrayList<Context> getAllValidContextBut(HashMap<String, Double> values, String s) { /*public ArrayList<Context> getAllValidContextBut(HashMap<String, Double> values, String s) {
ArrayList<ArrayList<Context>> contextsList = new ArrayList<ArrayList<Context>>(); ArrayList<ArrayList<Context>> contextsList = new ArrayList<ArrayList<Context>>();
ArrayList<Percept> percepts = scheduler.getVariables(); ArrayList<Percept> percepts = scheduler.getVariables();
for (Percept p : percepts) { for (Percept p : percepts) {
...@@ -346,21 +346,21 @@ public class AMOEBA extends Thread { ...@@ -346,21 +346,21 @@ public class AMOEBA extends Thread {
} }
} }
return World.getIntersection(contextsList); return World.getIntersection(contextsList);
} }*/
/** /**
* Gets the studied system. * Gets the studied system.
* *
* @return the studied system * @return the studied system
*/ */
public ArrayList<Context> getAllValidContextBut(HashMap<String, Double> values) { /*public ArrayList<Context> getAllValidContextBut(HashMap<String, Double> values) {
ArrayList<ArrayList<Context>> contextsList = new ArrayList<ArrayList<Context>>(); ArrayList<ArrayList<Context>> contextsList = new ArrayList<ArrayList<Context>>();
ArrayList<Percept> percepts = scheduler.getVariables(); ArrayList<Percept> percepts = scheduler.getVariables();
for (Percept p : percepts) { for (Percept p : percepts) {
contextsList.add(p.getContextIncluding(values.get(p.getSensor().getName()))); contextsList.add(p.getContextIncluding(values.get(p.getSensor().getName())));
} }
return World.getIntersection(contextsList); return World.getIntersection(contextsList);
} }*/
public StudiedSystem getStudiedSystem() { public StudiedSystem getStudiedSystem() {
return studiedSystem; return studiedSystem;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment