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

ENH: operationnal void viewer

parent d3dc29b5
Branches
No related tags found
1 merge request!1Merge Master
...@@ -56,7 +56,7 @@ public class BadContextLauncherEasy implements Serializable { ...@@ -56,7 +56,7 @@ public class BadContextLauncherEasy implements Serializable {
bcm.setWorld(amoeba.getScheduler().getWorld()); bcm.setWorld(amoeba.getScheduler().getWorld());
ArrayList<Percept> percepts = new ArrayList<Percept>(); ArrayList<Percept> percepts = new ArrayList<Percept>();
for (int i = 0 ; i < 40 ; i++) { for (int i = 0 ; i < 20 ; 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);
......
...@@ -1200,10 +1200,32 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing ...@@ -1200,10 +1200,32 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
if(contextOverlapsByPerceptSave.get(context).get(percept)) { if(contextOverlapsByPerceptSave.get(context).get(percept)) {
double ctxt1Start = this.getRanges().get(percept).getStart(); double ctxt1Start = this.getRanges().get(percept).getStart();
double ctxtEnd = this.getRanges().get(percept).getEnd(); double ctxt1End = this.getRanges().get(percept).getEnd();
double ctxt2Start = context.getRanges().get(percept).getStart(); double ctxt2Start = context.getRanges().get(percept).getStart();
double ctxt2End = context.getRanges().get(percept).getEnd(); double ctxt2End = context.getRanges().get(percept).getEnd();
double value = (ctxt1Start + ctxtEnd + ctxt2Start + ctxt2End)/4 ;
double value = 0d;
if( percept.contextIncludedIn(this, context) ) {
value = (ctxt1Start + ctxt1End) / 2 ;
}
else if( percept.contextIncludedIn(context, this) ) {
value = (ctxt2Start + ctxt2End) / 2 ;
}
else if( percept.contextOrder(this, context) ) {
value = (ctxt2Start + ctxt1End) / 2 ;
}
else if( percept.contextOrder(context, this) ) {
value = (ctxt1Start + ctxt2End) / 2 ;
}
else {
System.out.println("PROBLEM !!!!!!!!!!!!!!!!! Void detection" );
}
voidPosition.put(percept, value); voidPosition.put(percept, value);
} }
...@@ -1213,7 +1235,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing ...@@ -1213,7 +1235,7 @@ private Percept getPerceptWithLesserImpactOnVolume(ArrayList<Percept> containing
voidPosition.put(percept, value); voidPosition.put(percept, value);
} }
else if(this.getRanges().get(percept).getEnd() + 5.0 < context.getRanges().get(percept).getStart()) { else if(this.getRanges().get(percept).getEnd() + 5.0 < context.getRanges().get(percept).getStart()) {
double value = (context.getRanges().get(percept).getEnd() + this.getRanges().get(percept).getStart())/2 ; double value = (this.getRanges().get(percept).getEnd() + context.getRanges().get(percept).getStart())/2 ;
voidPosition.put(percept, value); voidPosition.put(percept, value);
} }
else { else {
......
...@@ -21,7 +21,7 @@ public class ContextVoid implements Serializable{ ...@@ -21,7 +21,7 @@ public class ContextVoid implements Serializable{
public ContextVoid(World world, Context context1, Context context2, HashMap<Percept,Double> position) { public ContextVoid(World world, Context context1, Context context2, HashMap<Percept,Double> position) {
this.world = world; this.world = world;
this.name = "[VOID]" + context1.getName() + context2.getName(); this.name = context1.getName() + context2.getName();
this.surroundingContexts.add(context1); this.surroundingContexts.add(context1);
this.surroundingContexts.add(context2); this.surroundingContexts.add(context2);
this.position = position; this.position = position;
...@@ -81,4 +81,8 @@ public class ContextVoid implements Serializable{ ...@@ -81,4 +81,8 @@ public class ContextVoid implements Serializable{
return surroundingContexts.contains(context); return surroundingContexts.contains(context);
} }
public ArrayList<Context> getSurroundingContexts(){
return surroundingContexts;
}
} }
...@@ -63,7 +63,7 @@ public class Scheduler implements Serializable{ ...@@ -63,7 +63,7 @@ public class Scheduler implements Serializable{
private long time; private long time;
private int temporisation = 50; private int temporisation = 200;
/** /**
...@@ -688,6 +688,15 @@ public class Scheduler implements Serializable{ ...@@ -688,6 +688,15 @@ public class Scheduler implements Serializable{
return null; return null;
} }
public ContextVoid getContextVoidByName(String name) {
for(ContextVoid contextVoid: contextVoids) {
if(contextVoid.getName().equals(name)) {
return contextVoid;
}
}
return null;
}
public void setPerceptionsAndActionState(HashMap<String,Double> perceptionsAndActions) { public void setPerceptionsAndActionState(HashMap<String,Double> perceptionsAndActions) {
this.perceptionsAndActionState = perceptionsAndActions; this.perceptionsAndActionState = perceptionsAndActions;
} }
......
...@@ -1117,6 +1117,11 @@ private void startPanelController() { ...@@ -1117,6 +1117,11 @@ private void startPanelController() {
for(ContextOverlap contextOverlap : context.contextOverlaps) { for(ContextOverlap contextOverlap : context.contextOverlaps) {
world.getScheduler().getView().getTabbedPanel().getPanelTwoDimStandard().drawOverlap(contextOverlap); world.getScheduler().getView().getTabbedPanel().getPanelTwoDimStandard().drawOverlap(contextOverlap);
} }
for(ContextVoid contextVoid : context.contextVoids) {
world.getScheduler().getView().getTabbedPanel().getPanelTwoDimStandard().drawVoid(contextVoid);
}
} }
} }
...@@ -1243,6 +1248,76 @@ private void startPanelController() { ...@@ -1243,6 +1248,76 @@ private void startPanelController() {
}
}
}
public void highlightVoidContexts(ContextVoid contextVoid) {
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (String name : world.getAgents().keySet()) {
SystemAgent a = world.getAgents().get(name);
if (a instanceof Context) {
double val = ((Context) a).getActionProposal();
if (val < min) {
min = val;
}
if (val > max) {
max = val;
}
}
}
for (Context ctxt : contextVoid.getSurroundingContexts()) {
Node node = graph.getNode(ctxt.getName());
node.addAttribute("ui.class","ContextColorDynamic");
node.setAttribute("ui.color", 0.5 );
}
}
public void highlightContexts(Context context) {
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (String name : world.getAgents().keySet()) {
SystemAgent a = world.getAgents().get(name);
if (a instanceof Context) {
double val = ((Context) a).getActionProposal();
if (val < min) {
min = val;
}
if (val > max) {
max = val;
}
}
}
for (String name : world.getAgents().keySet()) {
SystemAgent a = world.getAgents().get(name);
if (a instanceof Context) {
Context n = (Context)a;
Node node = graph.getNode(name);
node.addAttribute("ui.class","ContextColorDynamic");
node.setAttribute("ui.color", 0.1 );
node.setAttribute("ui.color", 0.5 );
} }
} }
...@@ -1356,6 +1431,18 @@ private void startPanelController() { ...@@ -1356,6 +1431,18 @@ private void startPanelController() {
} }
} }
else if(world.getScheduler().getContextVoidByName(id)!=null) {
ContextVoid pushedContextVoid = world.getScheduler().getContextVoidByName(id);
setContextVoidTextAreaInfo(id);
if (sliderValue == currentTick || (!rememberState)) {
if (rightClick) {
popupMenuForVoidVisualization(id);
rightClick = false;
}
}
}
//String info = world.getAgents().get(id).toString(); //String info = world.getAgents().get(id).toString();
...@@ -1436,6 +1523,36 @@ private void startPanelController() { ...@@ -1436,6 +1523,36 @@ private void startPanelController() {
} }
private void setContextVoidTextAreaInfo(String id) {
System.out.println("Context Void pushed : " + id);
String info = "";
if (rememberState) {
Observation o = getObservationByTick(sliderValue);
if (o != null) {
ContextVoid contextVoid = world.getScheduler().getContextVoidByName(id);
if ( contextVoid != null ) {
info = "State :" + sliderValue + "\n";
info = info.concat(contextVoid.toString());
info = info.replace("Current", "\nCurrent");
info = info.replace("AVT", "\nAVT");
} else {
info = "No context";
}
}
} else {
info = "State :" + currentTick + "\n";
info = info.concat(world.getScheduler().getContextVoidByName(id).toString());
info = info.replace("Current", "\nCurrent");
info = info.replace("AVT", "\nAVT");
}
textarea.setText(info);
}
/** /**
* Start panel criterion. * Start panel criterion.
* *
...@@ -1538,6 +1655,18 @@ private void startPanelController() { ...@@ -1538,6 +1655,18 @@ private void startPanelController() {
popup.show(this, this.getX() + mouseEvent.getX(), this.getY() + mouseEvent.getY()); popup.show(this, this.getX() + mouseEvent.getX(), this.getY() + mouseEvent.getY());
} }
public void popupMenuForVoidVisualization(String id) {
JPopupMenu popup = new JPopupMenu("Visualization");
JMenuItem itemShowContextNeighbours = new JMenuItem("Contexts");
itemShowContextNeighbours.addActionListener(e -> {hightlightContextVoid(id);});
JMenuItem itemShowAll = new JMenuItem("Both");
itemShowAll.addActionListener( e -> {hightlightContextVoid(id);});
popup.add(itemShowContextNeighbours);
popup.add(itemShowAll);
popup.show(this, this.getX() + mouseEvent.getX(), this.getY() + mouseEvent.getY());
}
public void popupMenuForOverlapVisualization(String id) { public void popupMenuForOverlapVisualization(String id) {
JPopupMenu popup = new JPopupMenu("Visualization"); JPopupMenu popup = new JPopupMenu("Visualization");
...@@ -1563,6 +1692,9 @@ private void startPanelController() { ...@@ -1563,6 +1692,9 @@ private void startPanelController() {
} }
private void hightlightContextVoid(String id) {
highlightVoidContexts(world.getScheduler().getContextVoidByName(id));
}
private void updateOverlapsAndNeighbours() { private void updateOverlapsAndNeighbours() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment