Menu

Tutorials

Wilfried ifeherva Anita Thomas D Melanie Schranz

Short video on installing and running FREVO

Installation Instructions

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.

Running FREVO

To simply start FREVO with its GUI, follow these steps:

  1. Start a console window and type

    java -jar createscripts.jar

    This will create the script files used to start FREVO.
  2. Based on your operating system, run the following file:

Windows: launch_Frevo.bat

Unix/Linux/Mac OSX: ./launch_Frevo.sh

Developing with FREVO:

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.

Getting around with FREVO

Composing a new simulation session and run them

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.

  • Select a problem component. Here, “Cellular automaton morphogenesis” (Cam) is selected.
  • You can adjust parameters in the table. Here, the “simulation steps” parameter is selected. To change a parameter's value, double click and enter a value.
  • When you are finished, click “Confirm” at the bottom of the screen.
  • Repeat this step to select a Method, Representation and Ranking. In each step you can adjust parameters.

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”.

Saving and loading a session

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.

Evaluate 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.

  • '#': candidates
  • Controller: the brain used for evolution
  • Hash: a calculated value out of the instantiated controller recognizing if two candidates behave identically
  • Fitness: fitness function

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.

Creating a new Problem

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:

  • Run FREVO and open the Component Creator

  • A window opens. Here you have to select the type of the component you want to create:
    • Problem with absolute fitness
    • Problem with tournament fitness
    • Method
    • Representation
    • Ranking

We will select "Problem". Then you have to enter a name and a short description.

  • Click on "Create" and follow the instructions that are shown. A new folder, containing your .java file, and an .xml file will be generated. (in this case "EmergencyExit.java" and "EmergencyExit.xml").

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;
  }
}

  • evaluateCandidate() is called to simulate without visualization, it should return a fitness value.
  • replayWithVisualization() is (as the name says) called to replay the simulation with a (possible graphical) visualization.
  • getMaximumFitness() should return the maximum Fitness that can be reached. If this Value is not known Double.MAX_VALUE should be returned. This value can be used by the optimization algorithm to stop optimization if this value has been reached

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:

  • Selected Problem: EmergencyExit
  • Selected Method: CEA2D
  • Selected Representation: FullyMeshedNet
  • Selected Ranking: Absolute Ranking

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).


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.