Skip to content
Snippets Groups Projects
Commit 3e10799c authored by Hugo Roussel's avatar Hugo Roussel
Browse files

Added/improved javadoc

parent 69e8aa37
No related branches found
No related tags found
2 merge requests!2Merge dev into develop,!1Merge Master
Showing
with 240 additions and 43 deletions
...@@ -7,6 +7,11 @@ import javafx.event.EventHandler; ...@@ -7,6 +7,11 @@ import javafx.event.EventHandler;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
/**
* Drawable to point things on the VUI, use a '+' icon as graphical representation.
* @author Hugo
*
*/
public class DrawablePoint extends Drawable { public class DrawablePoint extends Drawable {
private FontIcon icon; private FontIcon icon;
......
package agents; package agents;
import agents.percept.Percept;
import fr.irit.smac.amak.Agent; import fr.irit.smac.amak.Agent;
import fr.irit.smac.amak.tools.Loggable; import fr.irit.smac.amak.tools.Loggable;
import gui.RenderStrategy; import gui.RenderStrategy;
...@@ -53,6 +54,10 @@ public abstract class AmoebaAgent extends Agent<AMOEBA, World> implements Loggab ...@@ -53,6 +54,10 @@ public abstract class AmoebaAgent extends Agent<AMOEBA, World> implements Loggab
} }
} }
/**
* Set the name of the agent. Useful for visualization, and essential for {@link Percept}.
* @param name
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
...@@ -67,20 +72,38 @@ public abstract class AmoebaAgent extends Agent<AMOEBA, World> implements Loggab ...@@ -67,20 +72,38 @@ public abstract class AmoebaAgent extends Agent<AMOEBA, World> implements Loggab
logger().debug("CYCLE "+getAmas().getCycle(), "Agent %s destroyed.", toString()); logger().debug("CYCLE "+getAmas().getCycle(), "Agent %s destroyed.", toString());
} }
/**
* Get the name of the agent. Useful for visualization, and essential for {@link Percept}.
* @param name
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* Tell if the agent is dying. A dying agent no longer perform any useful action, but is not yet removed from its system.
* @return
*/
public boolean isDying() { public boolean isDying() {
return dying; return dying;
} }
/**
* Set the render strategy of an agent.<br/>
* {@link RenderStrategy#delete()} the old one, and {@link RenderStrategy#initialize()} the new one.
* @param renderStrategy
* @see RenderStrategy
*/
public void setRenderStrategy(RenderStrategy renderStrategy) { public void setRenderStrategy(RenderStrategy renderStrategy) {
if(this.renderStrategy != null) this.renderStrategy.delete(); if(this.renderStrategy != null) this.renderStrategy.delete();
this.renderStrategy = renderStrategy; this.renderStrategy = renderStrategy;
if(this.renderStrategy != null) this.renderStrategy.initialize(); if(this.renderStrategy != null) this.renderStrategy.initialize();
} }
/**
* Get the render strategy of an agent.
* @return
*/
public RenderStrategy getRenderStrategy() { public RenderStrategy getRenderStrategy() {
return renderStrategy; return renderStrategy;
} }
......
...@@ -72,7 +72,7 @@ public class Head extends AmoebaAgent { ...@@ -72,7 +72,7 @@ public class Head extends AmoebaAgent {
activatedContexts.size(); activatedContexts.size();
setContextFromPropositionWasSelected(false); setContextFromPropositionWasSelected(false);
oracleValue = this.amas.getPerceptionsOrAction("oracle"); oracleValue = this.amas.getPerceptions("oracle");
/* The head memorize last used context agent */ /* The head memorize last used context agent */
lastUsedContext = bestContext; lastUsedContext = bestContext;
...@@ -90,6 +90,9 @@ public class Head extends AmoebaAgent { ...@@ -90,6 +90,9 @@ public class Head extends AmoebaAgent {
newContext = null; newContext = null;
} }
/**
* Play and use the oracle, allowing for learning.
*/
private void playWithOracle() { private void playWithOracle() {
if (activatedContexts.size() > 0) { if (activatedContexts.size() > 0) {
selectBestContext(); // using highest confidence selectBestContext(); // using highest confidence
...@@ -120,7 +123,7 @@ public class Head extends AmoebaAgent { ...@@ -120,7 +123,7 @@ public class Head extends AmoebaAgent {
} }
/** /**
* Play without oracle. * Play without oracle, no learning.
*/ */
private void playWithoutOracle() { private void playWithoutOracle() {
......
...@@ -29,12 +29,37 @@ public class Percept extends AmoebaAgent { ...@@ -29,12 +29,37 @@ public class Percept extends AmoebaAgent {
@Override @Override
protected void onAct() { protected void onAct() {
value = amas.getPerceptionsOrAction(name); value = amas.getPerceptions(name);
ajustMinMax(); ajustMinMax();
computeContextProjectionValidity(); computeContextProjectionValidity();
} }
public void computeContextProjectionValidity() { public void computeContextProjectionValidity() {
/* The algorithm used here :
*
* Variables :
* global set allContexts
* global set validContexts
* local set myValidContexts
*
* Algorithm : for each percept do :
* myValidContexts <- validContexts
* if myValidContexts = null then
* myValidContexts <- allContexts
* fi
*
* for context in myValidContext do
* if not isValid(context) then
* myValidContexts.remove(context)
* fi
* done
*
* validContexts <- intersect(validContexts, myValidContexts)
* #we use an intersect to allow multithreading, avoiding that a percept override the work of another
*
*/
validContextProjection = new HashSet<Context>(); validContextProjection = new HashSet<Context>();
// To avoid unnecessary tests, we only compute validity on context // To avoid unnecessary tests, we only compute validity on context
......
...@@ -20,6 +20,7 @@ import javafx.scene.control.Menu; ...@@ -20,6 +20,7 @@ import javafx.scene.control.Menu;
import javafx.scene.control.ToggleButton; import javafx.scene.control.ToggleButton;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import kernel.AMOEBA; import kernel.AMOEBA;
import kernel.SaveHelper;
/** /**
* The main window for AMOEBA GUI. * The main window for AMOEBA GUI.
...@@ -28,8 +29,11 @@ import kernel.AMOEBA; ...@@ -28,8 +29,11 @@ import kernel.AMOEBA;
*/ */
public class AmoebaWindow extends MainWindow { public class AmoebaWindow extends MainWindow {
private HashMap<String, AmakPlot> plots = new HashMap<>(); protected HashMap<String, AmakPlot> plots = new HashMap<>();
/**
* The main {@link VUI} for AMOEBA, by default it's the 2D representation of the contexts.
*/
public VUI mainVUI; public VUI mainVUI;
public Drawable point; public Drawable point;
...@@ -52,7 +56,7 @@ public class AmoebaWindow extends MainWindow { ...@@ -52,7 +56,7 @@ public class AmoebaWindow extends MainWindow {
schedulerToolbar = new SchedulerToolbar("AMOEBA", amoeba.getScheduler()); schedulerToolbar = new SchedulerToolbar("AMOEBA", amoeba.getScheduler());
AmoebaWindow.addToolbar(schedulerToolbar); AmoebaWindow.addToolbar(schedulerToolbar);
// amoeba and agent // plots
point = mainVUI.createAndAddPoint(0, 0); point = mainVUI.createAndAddPoint(0, 0);
point.setName("Cursor"); point.setName("Cursor");
plots.put("This loop NCS", new AmakPlot("This loop NCS", ChartType.LINE, "Cycle", "Number of NCS")); plots.put("This loop NCS", new AmakPlot("This loop NCS", ChartType.LINE, "Cycle", "Number of NCS"));
...@@ -119,10 +123,33 @@ public class AmoebaWindow extends MainWindow { ...@@ -119,10 +123,33 @@ public class AmoebaWindow extends MainWindow {
return (AmoebaWindow) instance; return (AmoebaWindow) instance;
} }
/**
* Get an existing {@link AmakPlot}.
* @param name name of the plot to get
* @return an existing plot.
* @see AmoebaWindow#addPlot(String, AmakPlot)
*/
public AmakPlot getPlot(String name) { public AmakPlot getPlot(String name) {
return plots.get(name); return plots.get(name);
} }
/**
* Add an {@link AmakPlot} to le map of plots. Allowing for easy access with {@code AmoebaWindow.instance().getPlot(name)}
* @param name name of the plot to add
* @param plot the plot to add
* @see AmoebaWindow#getPlot(String)
*/
public void addPlot(String name, AmakPlot plot) {
plots.put(name, plot);
}
/**
* Create a button 'Quick Save' button, when clicked create a manual save point using an amoeba's saver.
* @param amoeba
* @return
* @see AMOEBA#saver
* @see SaveHelper#newManualSave(String)
*/
public Button newManualSaveButton(AMOEBA amoeba) { public Button newManualSaveButton(AMOEBA amoeba) {
Button button = new Button("Quick save"); Button button = new Button("Quick save");
button.setTooltip(new Tooltip("Create a new save point. You will be able to find it in 'Save Explorer' -> 'Manual Saves'")); button.setTooltip(new Tooltip("Create a new save point. You will be able to find it in 'Save Explorer' -> 'Manual Saves'"));
......
...@@ -20,7 +20,7 @@ import javafx.scene.layout.VBox; ...@@ -20,7 +20,7 @@ import javafx.scene.layout.VBox;
import kernel.AMOEBA; import kernel.AMOEBA;
/** /**
* The ContextMenu that is shown when right-clicking the VUI canvas * The ContextMenu that is shown when right-clicking the {@link VUI} canvas
* @author Hugo * @author Hugo
* *
*/ */
...@@ -29,6 +29,12 @@ public class ContextMenuVUI extends ContextMenu { ...@@ -29,6 +29,12 @@ public class ContextMenuVUI extends ContextMenu {
private double reqHereX; private double reqHereX;
private double reqHereY; private double reqHereY;
/**
* Create a {@link ContextMenu} suited for our needs, composed of 2 items : "Request Here" and "Learn here".<br/>
* Set itself as the vui canvas {@link ContextMenu}.
* @param amoeba the amoeba where {@link AMOEBA#request(HashMap)} and {@link AMOEBA#learn(HashMap)} will be executed.
* @param vui the {@link VUI} hosting the {@link ContextMenuVUI}
*/
public ContextMenuVUI(AMOEBA amoeba, VUI vui) { public ContextMenuVUI(AMOEBA amoeba, VUI vui) {
// "request here" menu item // "request here" menu item
setupRequestHereMenuItem(amoeba, vui); setupRequestHereMenuItem(amoeba, vui);
...@@ -63,6 +69,12 @@ public class ContextMenuVUI extends ContextMenu { ...@@ -63,6 +69,12 @@ public class ContextMenuVUI extends ContextMenu {
this.getItems().add(reqHere); this.getItems().add(reqHere);
} }
/**
* The "Request Here" action performed when the amoeba is 2D.<br/>
* Execute a {@link AMOEBA#request(HashMap)} at the position of the click.
* @param amoeba
* @param vui
*/
private void reqTwoDimension(AMOEBA amoeba, VUI vui) { private void reqTwoDimension(AMOEBA amoeba, VUI vui) {
double x = vui.screenToWorldX(reqHereX); double x = vui.screenToWorldX(reqHereX);
double y = vui.screenToWorldY(reqHereY); double y = vui.screenToWorldY(reqHereY);
...@@ -74,6 +86,12 @@ public class ContextMenuVUI extends ContextMenu { ...@@ -74,6 +86,12 @@ public class ContextMenuVUI extends ContextMenu {
Log.defaultLog.inform("AMOEBA", "Request Here for x:"+x+" y:"+y+" -> "+res+"."); Log.defaultLog.inform("AMOEBA", "Request Here for x:"+x+" y:"+y+" -> "+res+".");
} }
/**
* The "Request Here" action performed when the amoeba is not 2D.<br/>
* Show a {@link Dialog} prompting the user to inputs value for the {@link AMOEBA#request(HashMap)}.
* @param amoeba
* @param vui
*/
private void reqNDimension(AMOEBA amoeba, VUI vui) { private void reqNDimension(AMOEBA amoeba, VUI vui) {
double x = vui.screenToWorldX(reqHereX); double x = vui.screenToWorldX(reqHereX);
double y = vui.screenToWorldY(reqHereY); double y = vui.screenToWorldY(reqHereY);
...@@ -138,6 +156,12 @@ public class ContextMenuVUI extends ContextMenu { ...@@ -138,6 +156,12 @@ public class ContextMenuVUI extends ContextMenu {
this.getItems().add(learnHere); this.getItems().add(learnHere);
} }
/**
* The "Learn Here" action performed when the amoeba is 2D.<br/>
* Execute a {@link AMOEBA#learn(HashMap)} at the position of the click.
* @param amoeba
* @param vui
*/
private void learnTwoDimension(AMOEBA amoeba, VUI vui) { private void learnTwoDimension(AMOEBA amoeba, VUI vui) {
double x = vui.screenToWorldX(reqHereX); double x = vui.screenToWorldX(reqHereX);
double y = vui.screenToWorldY(reqHereY); double y = vui.screenToWorldY(reqHereY);
...@@ -148,6 +172,12 @@ public class ContextMenuVUI extends ContextMenu { ...@@ -148,6 +172,12 @@ public class ContextMenuVUI extends ContextMenu {
amoeba.learn(req); amoeba.learn(req);
} }
/**
* The "Learn Here" action performed when the amoeba is not 2D.<br/>
* Show a {@link Dialog} prompting the user to inputs value for the {@link AMOEBA#learn(HashMap)}.
* @param amoeba
* @param vui
*/
private void learnNDimebsion(AMOEBA amoeba, VUI vui) { private void learnNDimebsion(AMOEBA amoeba, VUI vui) {
double x = vui.screenToWorldX(reqHereX); double x = vui.screenToWorldX(reqHereX);
double y = vui.screenToWorldY(reqHereY); double y = vui.screenToWorldY(reqHereY);
......
...@@ -2,24 +2,13 @@ package gui; ...@@ -2,24 +2,13 @@ package gui;
import agents.context.Context; import agents.context.Context;
import agents.percept.Percept; import agents.percept.Percept;
import fr.irit.smac.amak.ui.VUI;
import fr.irit.smac.amak.ui.drawables.DrawableRectangle; import fr.irit.smac.amak.ui.drawables.DrawableRectangle;
import gui.utils.ContextColor; import gui.utils.ContextColor;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/** /**
* A render strategy for contexts using JavaFX. * A render strategy for contexts using AMAKFX tools.<br/>
* <p> * A Context is represented by a {@link DrawableRectangle} drawn onto {@link AmoebaWindow#mainVUI}.
* Contexts have 2 visualizations that need to be rendered :
* <ul>
* <li>a drawable {@link ContextRendererFX#getDrawable()} for the {@link VUI} </li>
* <li>and a mini visualization {@link ContextRendererFX#getMini()} for the {@link ContextExplorer} </li>
* </ul>
* This class make sure that the 2 visualizations stay coherent.
* <p>
* If there's no {@link ContextExplorer} in the main window when
* {@link ContextRendererFX#initialize()} is called, a new one is created and
* added.
* *
* @author Hugo * @author Hugo
* *
...@@ -66,7 +55,7 @@ public class ContextRendererFX extends RenderStrategy { ...@@ -66,7 +55,7 @@ public class ContextRendererFX extends RenderStrategy {
} }
/** /**
* Initialize the drawable, and may add a {@link ContextExplorer} to the main * Initialize the drawable.
* window. * window.
*/ */
@Override @Override
...@@ -83,7 +72,7 @@ public class ContextRendererFX extends RenderStrategy { ...@@ -83,7 +72,7 @@ public class ContextRendererFX extends RenderStrategy {
/** /**
* Return the visualization for the VUI, may create it. * Return the visualization for the VUI, may create and add it to the VUI.
* *
* @return * @return
*/ */
......
...@@ -25,9 +25,19 @@ import gui.DimensionSelector; ...@@ -25,9 +25,19 @@ import gui.DimensionSelector;
import gui.utils.ContextColor; import gui.utils.ContextColor;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/**
* Class providing methods to draw a preview of an AMOEBA onto a VUI
* @author Hugo
*
*/
public class DrawFromXml { public class DrawFromXml {
private static final String PERCEPT_NODE = "Sensor"; private static final String PERCEPT_NODE = "Sensor";
/**
* Create a {@link DimensionSelector} based on a save file
* @param path path to the save file
* @return
*/
public static DimensionSelector createDimensionSelector(Path path) { public static DimensionSelector createDimensionSelector(Path path) {
SAXBuilder sxb = new SAXBuilder(); SAXBuilder sxb = new SAXBuilder();
Document doc; Document doc;
...@@ -42,6 +52,7 @@ public class DrawFromXml { ...@@ -42,6 +52,7 @@ public class DrawFromXml {
} }
return new DimensionSelector(new ArrayList<Percept>(perceptsByName.values()), null); return new DimensionSelector(new ArrayList<Percept>(perceptsByName.values()), null);
} }
private static void loadStartingAgents(Element systemElement, Map<String, Percept> perceptsByName) { private static void loadStartingAgents(Element systemElement, Map<String, Percept> perceptsByName) {
Element startingAgentsElement = systemElement.getChild("StartingAgents"); Element startingAgentsElement = systemElement.getChild("StartingAgents");
List<Element> agentsElement = startingAgentsElement.getChildren(); List<Element> agentsElement = startingAgentsElement.getChildren();
...@@ -55,6 +66,7 @@ public class DrawFromXml { ...@@ -55,6 +66,7 @@ public class DrawFromXml {
} }
} }
} }
private static void loadSensor(Element sensorElement, Map<String, Percept> perceptsByName) { private static void loadSensor(Element sensorElement, Map<String, Percept> perceptsByName) {
Percept percept = new Percept(null); Percept percept = new Percept(null);
percept.setName(sensorElement.getAttributeValue("Name")); percept.setName(sensorElement.getAttributeValue("Name"));
...@@ -64,6 +76,15 @@ public class DrawFromXml { ...@@ -64,6 +76,15 @@ public class DrawFromXml {
perceptsByName.put(percept.getName(), percept); perceptsByName.put(percept.getName(), percept);
} }
/**
* Draw the preview of an AMOEBA from a save file onto a VUI.<br/>
* You might want to use a {@link DimensionSelector} for the dim1 and dim2 parameters.
* @param vui {@link VUI} on which the preview will be drawn
* @param path path to the save file
* @param dim1 percept name for the 1st dimension (usually x)
* @param dim2 percept name for the 2nd dimension (usually y)
* @see DrawFromXml#createDimensionSelector(Path)
*/
public static void draw(VUI vui, Path path, String dim1, String dim2) { public static void draw(VUI vui, Path path, String dim1, String dim2) {
SAXBuilder sxb = new SAXBuilder(); SAXBuilder sxb = new SAXBuilder();
Document doc; Document doc;
...@@ -109,7 +130,7 @@ public class DrawFromXml { ...@@ -109,7 +130,7 @@ public class DrawFromXml {
} }
private static void loadContext(Element contextElement, String name, VUI vui, String d1, String d2) { private static void loadContext(Element contextElement, String name, VUI vui, String d1, String d2) {
// -- Load Ranges // Load Ranges
Element rangesElement = contextElement.getChild("Ranges"); Element rangesElement = contextElement.getChild("Ranges");
Map<String, Double> starts = new HashMap<>(); Map<String, Double> starts = new HashMap<>();
Map<String, Double> ends = new HashMap<>(); Map<String, Double> ends = new HashMap<>();
...@@ -118,6 +139,8 @@ public class DrawFromXml { ...@@ -118,6 +139,8 @@ public class DrawFromXml {
double l2 = ends.get(d2)-starts.get(d2); double l2 = ends.get(d2)-starts.get(d2);
double x = starts.get(d1); double x = starts.get(d1);
double y = starts.get(d2); double y = starts.get(d2);
// Draw Ranges as 2D rectangle
Optional<Drawable> optRect = vui.getDrawables().stream().filter(d -> name.equals(d.getName())).findAny(); Optional<Drawable> optRect = vui.getDrawables().stream().filter(d -> name.equals(d.getName())).findAny();
DrawableRectangle rectangle; DrawableRectangle rectangle;
if(optRect.isPresent()) { if(optRect.isPresent()) {
...@@ -131,6 +154,8 @@ public class DrawFromXml { ...@@ -131,6 +154,8 @@ public class DrawFromXml {
Element localModelElement = contextElement.getChild("LocalModel"); Element localModelElement = contextElement.getChild("LocalModel");
List<Double> coefs = new ArrayList<>(); List<Double> coefs = new ArrayList<>();
loadLocalModel(localModelElement, rectangle, coefs); loadLocalModel(localModelElement, rectangle, coefs);
// Load and set contexts infos
rectangle.setName("Context : "+contextElement.getAttributeValue("Name")); rectangle.setName("Context : "+contextElement.getAttributeValue("Name"));
String coefsString = ""; String coefsString = "";
for(Double c : coefs) { for(Double c : coefs) {
......
...@@ -24,10 +24,13 @@ import javafx.scene.layout.Priority; ...@@ -24,10 +24,13 @@ import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.util.Callback; import javafx.util.Callback;
import kernel.AMOEBA; import kernel.AMOEBA;
import kernel.SaveHelper;
import kernel.StudiedSystem; import kernel.StudiedSystem;
/** /**
* Graphical element to browse and load (auto)save for a specific amoeba. * Graphical element to browse and load (auto)saves for a specific amoeba.
* @see SaveHelper
* @see AMOEBA
* @author Hugo * @author Hugo
* *
*/ */
...@@ -38,19 +41,24 @@ public class SaveExplorer extends VBox { ...@@ -38,19 +41,24 @@ public class SaveExplorer extends VBox {
@FXML private ComboBox<String> comboBoxA; @FXML private ComboBox<String> comboBoxA;
@FXML private ComboBox<String> comboBoxM; @FXML private ComboBox<String> comboBoxM;
/**
* create a SaveExplorer for an AMOEBA.
* The amoeba MUST have a working {@link AMOEBA#saver}.
* @param amoeba
* @see SaveHelper
*/
public SaveExplorer(AMOEBA amoeba) { public SaveExplorer(AMOEBA amoeba) {
this.amoeba = amoeba; this.amoeba = amoeba;
try { try {
//load the fxml for THIS SaveExplorer
VBox root = FXMLLoader.load(getClass().getResource("SaveExplorer.fxml"), null, null, new Callback<Class<?>, Object>() { VBox root = FXMLLoader.load(getClass().getResource("SaveExplorer.fxml"), null, null, new Callback<Class<?>, Object>() {
@Override @Override
public Object call(Class<?> param) { public Object call(Class<?> param) {
return SaveExplorer.this; return SaveExplorer.this;
} }
}); });
//System.out.println(root.getChildren());
this.getChildren().add(root); this.getChildren().add(root);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
...@@ -60,6 +68,7 @@ public class SaveExplorer extends VBox { ...@@ -60,6 +68,7 @@ public class SaveExplorer extends VBox {
} }
// Handler, A : Auto saves, M : Manual saves. --------
@FXML protected void handleRefresh(ActionEvent event) { @FXML protected void handleRefresh(ActionEvent event) {
update(); update();
} }
...@@ -129,7 +138,11 @@ public class SaveExplorer extends VBox { ...@@ -129,7 +138,11 @@ public class SaveExplorer extends VBox {
@FXML protected void handlePreviewM(ActionEvent event) { @FXML protected void handlePreviewM(ActionEvent event) {
quickDisplay(Paths.get(comboBoxM.getValue())); quickDisplay(Paths.get(comboBoxM.getValue()));
} }
// ---------------------------------------------------
/**
* Update the list of available saves
*/
public void update() { public void update() {
comboBoxA.getItems().clear(); comboBoxA.getItems().clear();
List<Path> la = amoeba.saver.listAutoSaves(); List<Path> la = amoeba.saver.listAutoSaves();
...@@ -165,6 +178,10 @@ public class SaveExplorer extends VBox { ...@@ -165,6 +178,10 @@ public class SaveExplorer extends VBox {
} }
} }
/**
* Configure a ComboBox to display a preview when its value is changed
* @param cb
*/
private void quickDisplayCombobox(ComboBox<String> cb) { private void quickDisplayCombobox(ComboBox<String> cb) {
cb.valueProperty().addListener(new ChangeListener<String>() { cb.valueProperty().addListener(new ChangeListener<String>() {
@Override @Override
...@@ -176,10 +193,10 @@ public class SaveExplorer extends VBox { ...@@ -176,10 +193,10 @@ public class SaveExplorer extends VBox {
} }
/** /**
* Create the preview of a save file * Create/update the preview in the SaveExplorer based on a save file.
* @param path * @param path path to the save file to preview
*/ */
public void quickDisplay(Path path) { private void quickDisplay(Path path) {
VUI vui = VUI.get("Save Explorer"); VUI vui = VUI.get("Save Explorer");
if(!this.getChildren().contains(vui.getPanel())) { if(!this.getChildren().contains(vui.getPanel())) {
vui.setDefaultView(200, 0, 0); vui.setDefaultView(200, 0, 0);
...@@ -241,7 +258,7 @@ public class SaveExplorer extends VBox { ...@@ -241,7 +258,7 @@ public class SaveExplorer extends VBox {
amoeba.saver.deleteFolderOnClose = false; amoeba.saver.deleteFolderOnClose = false;
//amoeba.allowGraphicalScheduler(false); //amoeba.allowGraphicalScheduler(false);
for(Percept p : amoeba.getPercepts()) { for(Percept p : amoeba.getPercepts()) {
p.setValue(amoeba.getPerceptionsOrAction(p.getName())); p.setValue(amoeba.getPerceptions(p.getName()));
} }
amoeba.updateAgentsVisualisation(); amoeba.updateAgentsVisualisation();
} }
......
...@@ -3,8 +3,21 @@ package gui.utils; ...@@ -3,8 +3,21 @@ package gui.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import agents.context.Context;
import agents.context.localModel.LocalModel;
/**
* Tools for determining the color of a {@link Context} based on the coefficients of its {@link LocalModel}
* @author Hugo
*
*/
public class ContextColor { public class ContextColor {
/**
* Compute the color of a {@link Context} based on the coefficients of its {@link LocalModel}
* @param coefs
* @return
*/
public static double[] colorFromCoefs(double[] coefs) { public static double[] colorFromCoefs(double[] coefs) {
ArrayList<Double> c = new ArrayList<Double>(); ArrayList<Double> c = new ArrayList<Double>();
for(double v : coefs) for(double v : coefs)
...@@ -12,6 +25,11 @@ public class ContextColor { ...@@ -12,6 +25,11 @@ public class ContextColor {
return colorFromCoefs(c); return colorFromCoefs(c);
} }
/**
* Compute the color of a {@link Context} based on the coefficients of its {@link LocalModel}
* @param coefs
* @return
*/
public static double[] colorFromCoefs(List<Double> coefs) { public static double[] colorFromCoefs(List<Double> coefs) {
Double r = 0.0; Double r = 0.0;
Double g = 0.0; Double g = 0.0;
......
...@@ -49,7 +49,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -49,7 +49,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
private Head head; private Head head;
private TypeLocalModel localModel = TypeLocalModel.MILLER_REGRESSION; private TypeLocalModel localModel = TypeLocalModel.MILLER_REGRESSION;
private HashMap<String, Double> perceptionsAndActionState = new HashMap<String, Double>(); private HashMap<String, Double> perceptions = new HashMap<String, Double>();
private boolean useOracle = true; private boolean useOracle = true;
private HashSet<Context> validContexts; private HashSet<Context> validContexts;
...@@ -163,7 +163,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -163,7 +163,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
if (studiedSystem != null) { if (studiedSystem != null) {
studiedSystem.playOneStep(); studiedSystem.playOneStep();
perceptionsAndActionState = studiedSystem.getOutput(); perceptions = studiedSystem.getOutput();
} }
environment.preCycleActions(); environment.preCycleActions();
head.clearAllUseableContextLists(); head.clearAllUseableContextLists();
...@@ -342,7 +342,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -342,7 +342,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
} }
/** /**
* Activate or deactivate the graphical scheduler. Allowing ordDenying the user * Activate or deactivate the graphical scheduler. Allowing or denying the user
* to change the simulation speed. * to change the simulation speed.
* *
* @param allow * @param allow
...@@ -364,6 +364,9 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -364,6 +364,9 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
super.removePendingAgents(); super.removePendingAgents();
} }
/**
* Called when a {@link IBackupSystem} has finished loading the amoeba.
*/
public void onLoadEnded() { public void onLoadEnded() {
super.addPendingAgents(); super.addPendingAgents();
nextCycleRunAllAgents(); nextCycleRunAllAgents();
...@@ -408,7 +411,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -408,7 +411,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
* @param perceptionsAndActions * @param perceptionsAndActions
*/ */
public void setPerceptionsAndActionState(HashMap<String, Double> perceptionsAndActions) { public void setPerceptionsAndActionState(HashMap<String, Double> perceptionsAndActions) {
this.perceptionsAndActionState = perceptionsAndActions; this.perceptions = perceptionsAndActions;
} }
/** /**
...@@ -483,8 +486,13 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -483,8 +486,13 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
return ret; return ret;
} }
public Double getPerceptionsOrAction(String key) { /**
return this.perceptionsAndActionState.get(key); * Get the value for a perception
* @param key key of the perception
* @return the value of the perception
*/
public Double getPerceptions(String key) {
return this.perceptions.get(key);
} }
@Override @Override
...@@ -499,14 +507,25 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -499,14 +507,25 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
runAll = true; runAll = true;
} }
/**
* Is rendering activated ?
* @return
*/
public boolean isRenderUpdate() { public boolean isRenderUpdate() {
return (!Configuration.commandLineMode) && renderUpdate; return (!Configuration.commandLineMode) && renderUpdate;
} }
/**
* Should AMOEBA use the oracle ? If false then AMOEBA will not learn.
* @return
*/
public boolean isUseOracle() { public boolean isUseOracle() {
return useOracle; return useOracle;
} }
/**
* Ask the agents to update their visualization, and update some UI element related to them.
*/
public void updateAgentsVisualisation() { public void updateAgentsVisualisation() {
for(Agent<? extends Amas<World>, World> a : getAgents()) { for(Agent<? extends Amas<World>, World> a : getAgents()) {
a.onUpdateRender(); a.onUpdateRender();
...@@ -529,7 +548,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -529,7 +548,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
* @return * @return
*/ */
public HashMap<String, Double> getPerceptionsAndActionState() { public HashMap<String, Double> getPerceptionsAndActionState() {
return perceptionsAndActionState; return perceptions;
} }
/** /**
......
...@@ -23,6 +23,9 @@ import javafx.stage.FileChooser; ...@@ -23,6 +23,9 @@ import javafx.stage.FileChooser;
* *
*/ */
public class SaveHelper { public class SaveHelper {
/**
* Path to the saves' root directory. Default is 'saves'.
*/
public static final String savesRoot = "saves"; public static final String savesRoot = "saves";
public static final String autosaveDirName = "autosave"; public static final String autosaveDirName = "autosave";
public static final String manualsaveDirName = "manual"; public static final String manualsaveDirName = "manual";
...@@ -45,20 +48,27 @@ public class SaveHelper { ...@@ -45,20 +48,27 @@ public class SaveHelper {
/** /**
* Path to the autosave directory. * Path to the autosave directory.
*/ */
public Path dirAuto; private Path dirAuto;
/** /**
* Path to the manual save directory. * Path to the manual save directory.
*/ */
public Path dirManual; private Path dirManual;
/** /**
* Path to the save directory. * Path to the save directory.
*/ */
public Path dir; private Path dir;
private AMOEBA amoeba; private AMOEBA amoeba;
/**
* Create a SaveHelper for an amoeba.<br/>
* Saves are stored in {@link SaveHelper#savesRoot}, under a directory named after the amoeba and creation time of the SaveHelper.<br/>
* Autosave for this SaveHelper can be deactivated with {@link SaveHelper#autoSave}.<br/>
* By default, the save folder for this amoeba is deleted when the application is closed, this can be changed with {@link SaveHelper#deleteFolderOnClose}.
* @param amoeba
*/
public SaveHelper(AMOEBA amoeba) { public SaveHelper(AMOEBA amoeba) {
this.amoeba = amoeba; this.amoeba = amoeba;
backupSystem = new BackupSystem(amoeba); backupSystem = new BackupSystem(amoeba);
...@@ -102,6 +112,11 @@ public class SaveHelper { ...@@ -102,6 +112,11 @@ public class SaveHelper {
} }
} }
/**
* Delete a directory and everything in it, recursively.
* @param path
* @throws IOException
*/
private void deleteDirectoryRecursion(Path path) throws IOException { private void deleteDirectoryRecursion(Path path) throws IOException {
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) { try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) {
......
...@@ -3,6 +3,8 @@ package kernel; ...@@ -3,6 +3,8 @@ package kernel;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import agents.percept.Percept;
/** /**
* Any system studied by an instance of AMOEBA must implement this interface. * Any system studied by an instance of AMOEBA must implement this interface.
* *
...@@ -10,15 +12,14 @@ import java.util.HashMap; ...@@ -10,15 +12,14 @@ import java.util.HashMap;
public interface StudiedSystem extends Serializable{ public interface StudiedSystem extends Serializable{
/** /**
* When the scheduler of AMOEBA has run one cycle, playOneStep is called to * Tell the StudiedSystem to advance its simulation of one step
* allow the studied system to perform it's own cycle.
*/ */
public void playOneStep(); public void playOneStep();
/** /**
* Gets the output. * Gets the output for the current step.
* *
* @return the output * @return an {@link HashMap} containing a value for each {@link Percept} of an {@link AMOEBA} and a value for the oracle.
*/ */
public HashMap<String, Double> getOutput(); public HashMap<String, Double> getOutput();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment