Short video on installing and running FREVO
FREVO requires the Java environment (version min. 1.6) to be installed. Type java -version in the console to see if you have the compatible version installed.
To simply start FREVO with its GUI, follow these steps:
Windows: launch_Frevo.bat
Unix/Linux/Mac OSX: ./launch_Frevo.sh
FREVO is primarily developed using Eclipse.
(fluent experience with Neon 4.6.2)
The Eclipse project file can be found in the root directory. Use "import existing project into workspace" to import FREVO into your Eclipse workspace.
To set up a new session, start FREVO with the graphical user interface. The first thing that should be selected is the Problem Implementation. To do this, click on “Select Problem” label, outlined in red. The “Select Problem Component” window will pop up.
Now you should have defined your parameters. To run the simulation, click the “Play” button and the simulation starts.
One can use the “Reset” button to clear all ongoing simulations.
The bottom half of the screen shows information to the simulation (outlined in red) and the progress bar.
When the simulation is finished, results will be saved in the “FREVO” folder, under “Results”.
The entire simulation run is saved automatically. Nevertheless, you could click the "Pause" button and "Save" the simulation at a specific generation. This is not the final evolved one, but a specific intermediate state of evolution.
Moreover, when you click the "Replay" button, to get more information on the evolutionary produced results.
FREVO allows to evaluate the evolved results of the related problem definition in more detail. Therefore, you click File/Open/Results and navigate to the "Results" folder of FREVO. Therein, you can choose the results to your problem definition and the corresponding evolved generations.
After choosing, FREVO will get the following look: you have to defined areas
Results of Problem Definition
Parameters for evaluation
The latter summarizes the evaluation procedure. In the "Results" area you have several more information in four columns.
Further, if you hit the "Replay" button, you are able to replay the evolution by going steps back or forward and compare it with the reference.
Finally, if you click on "Details" you get a tabular overview of the parameters used in the neural network to evolve the solution to your problem definition.
In this tutorial we will implement a problem definition. In particular, it will be a simulation where agents try to find an emergency exit. As a prerequisite, you should have installed Java, eclipse, downloaded Frevo and imported it as an eclipse project.
Let's start:
We will select "Problem". Then you have to enter a name and a short description.
The generated .java file looks like this:
public class EmergencyExit extends AbstractSingleProblem {
@Override
protected double evaluateCandidate(AbstractRepresentation candidate) {
return 0;
}
@Override
public void replayWithVisualization(AbstractRepresentation candidate) {
}
@Override
public double getMaximumFitness() {
return Double.MAX_VALUE;
}
}
Implement your simulation - it is useful to extract it in an own function, so you can call it from getResult() and replayWithVisualization).
For this tutorial we start with a very simple simulation, that needs two additonal packages:
import net.jodk.lang.FastMath;
import java.util.ArrayList;
int steps;
int xpositionofEmergencyExit = 0;
int ypositionofEmergencyExit = 0;
int width;
int height;
int xpositionofAgent;
int ypositionofAgent;
AbstractRepresentation c;
void calcSim(){
xpositionofEmergencyExit = Integer.parseInt(getProperties().get("xpositionofEmergencyExit").getValue());
ypositionofEmergencyExit = Integer.parseInt(getProperties().get("ypositionofEmergencyExit").getValue());
xpositionofAgent = Integer.parseInt(getProperties().get("xpositionofAgent").getValue());
ypositionofAgent = Integer.parseInt(getProperties().get("ypositionofAgent").getValue());
for (int step = 0; step < steps; step++) {
ArrayList<Float> input = new ArrayList<Float>();
input.add((float) (xpositionofEmergencyExit - xpositionofAgent));
input.add((float) (ypositionofEmergencyExit - ypositionofAgent));
ArrayList<Float> output = c.getOutput(input);
float xVelocity = output.get(0).floatValue()*2.0f-1.0f;
float yVelocity = output.get(1).floatValue()*2.0f-1.0f;
if (xVelocity >= 1.0 && xpositionofAgent < width - 1) xpositionofAgent += 1;
else if (xVelocity <= -1.0 && xpositionofAgent > 0 ) xpositionofAgent -= 1;
if (yVelocity >= 1.0 && ypositionofAgent < height - 1) ypositionofAgent += 1;
else if (yVelocity <= -1.0 && ypositionofAgent > 0) ypositionofAgent -= 1;
}
}
The position of the emergency exit and the agent are read from the .xml file which is accessed over getProperties().get(name).getValue(). name represents the name of the value in the .xml file.
The value of "steps", "width" and "height" are written in the functions evaluateCandidate() and replayWithVisualization().
The main function of FREVO is to find the best function between input and the output automatically. So you just have to collect all the inputs and the representation (here it is c) will return the output. It is important that all the inputs and all the outputs are always in the same order. The output is always a float value between 0.0 and 1.0. You have to decide how to handle these outputs. In this simulation the output defines how the agent moves.
Now, after the functionality of the simulation is implemented, we need to call it in evaluateCandidate().
protected double evaluateCandidate(AbstractRepresentation candidate) {
steps = Integer.parseInt(getProperties().get("steps").getValue());
width = Integer.parseInt(getProperties().get("width").getValue());
height = Integer.parseInt(getProperties().get("height").getValue());
c = candidate;
calcSim();
return -FastMath.hypot(xpositionofEmergencyExit - xpositionofAgent, ypositionofEmergencyExit - ypositionofAgent);
}
As we said before the values of “steps”, “width” and “height” have to be written in this function. They are read from the .xml file. The return value of this function says how good this representation was. It the value is high, the connection of input and output is good. For the EmergencyExit simulation this value is the negative distance between the agent and the emergency exit. So if the agent reaches the emergency exit within the amount of steps, the distance will be 0, thus, it is a good way of connecting input and output.
So, we have to edit EmergencyExit.xml in order to add the component-specific properties:
<properties>
<propentry key="xpositionofEmergencyExit" type="INT" value="99"/>
<propentry key="ypositionofEmergencyExit" type="INT" value="99"/>
<propentry key="width" type="INT" value="100"/>
<propentry key="height" type="INT" value="100"/>
<propentry key="xpositionofAgent" type="INT" value="50"/>
<propentry key="ypositionofAgent" type="INT" value="50"/>
<propentry key="steps" type="INT" value="50"/>
</properties>
and to configure the number of inputs and outputs for the agent:
<reqentry key="inputnumber" type="INT" value="2"/>
<reqentry key="outputnumber" type="INT" value="2"/>
Finally, we have to implement a graphical visualization for the simulation:
import frevoutils.JGridMap.Display;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import GridVisualization.WhiteBoard;
WhiteBoard whiteboard = null;
Display display =null;
public void replayWithVisualization(AbstractRepresentation candidate) {
steps = 0;
c = candidate;
width = Integer.parseInt(getProperties().get("width").getValue());
height = Integer.parseInt(getProperties().get("height").getValue());
display = new Display(440, 495, "SimplifiedEmergencyExit");
display.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
whiteboard = new WhiteBoard(400, 400, width, height, 1);
whiteboard.addColorToScale(0, Color.WHITE);
whiteboard.addColorToScale(1, Color.BLACK);
whiteboard.addColorToScale(2, Color.GREEN);
JButton minusbutton = new JButton("-");
JButton plusbutton = new JButton("+");
display.add(whiteboard);
display.add(minusbutton);
display.add(plusbutton);
minusbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (steps > 0)
steps--;
calcSim();
displayResult();
display.setTitle("Simplified Emergency Exit Step: " + steps);
}
});
plusbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
steps++;
calcSim();
displayResult();
display.setTitle("Simplified Emergency Exit Step: " + steps);
}
});
display.setVisible(true);
calcSim();
displayResult();
display.setTitle("Simplified Emergency Exit Step: " + steps);
}
private void displayResult() {
int[][] data = new int[width][height];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if /* */ (x == xpositionofEmergencyExit && y == ypositionofEmergencyExit)
data[x][y] = 2;
else if (x == xpositionofAgent /* */ && y == ypositionofAgent)
/* */data[x][y] = 1;
else
/* */data[x][y] = 0;
}
}
whiteboard.setData(data);
whiteboard.repaint();
}
Before running FREVO, check if the right class is used as main in Run - Run Configurations...
Click on the Run button in Eclipse and FREVO will open. Use following settings for the simulation:
Beside the simulation another window appears. It shows the quality of the solution in the search space with a color code ranging from best solution (green) to worst solution (red).
Finally, you can hit two times the Replay button, and you can have a look of the Emergency Exit solution. By pressing the + or - button you can follow the agent (black square) finding the exit (green square).