/*
* File name: StoreFitness.java (package eas.simulation.users.lukas.marbImplicitEvolution)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 10.02.2011 (17:38:20)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.lukas.marbImplicitEvolution;
import java.util.LinkedList;
import java.util.List;
import eas.miscellaneous.StaticMethods;
import eas.plugins.AbstractDefaultPlugin;
import eas.simulation.Wink;
import eas.simulation.agent.AbstractAgent;
import eas.simulation.agent.Evolvable;
import eas.simulation.event.EASEvent;
import eas.simulation.spatial.sim2D.standardAgents.jasmine.JasmineRobot;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;
import eas.users.lukas.marbImplicitEvolution.simpleMazeEnvironment.MARBFastEnvironment;
/**
* @author Lukas König
*
*/
public class StoragePlugin extends AbstractDefaultPlugin<MARBFastEnvironment> {
/**
*
*/
private static final long serialVersionUID = 4706745415223257098L;
@Override
public List<String> getRequiredPlugins() {
return null;
}
@Override
public List<SingleParameter> getParameters() {
LinkedList<SingleParameter> params = new LinkedList<SingleParameter>();
params.add(new SingleParameter("FileNameFitness", Datatypes.STRING, "fitness.txt", "", this.id()));
params.add(new SingleParameter("FileNameAutomata", Datatypes.STRING, "automata.txt", "", this.id()));
return params;
}
@Override
public String id() {
return "StoragePlugin";
}
private LinkedList<String> fitnesses = new LinkedList<String>();
private LinkedList<String> automata = new LinkedList<String>();
@Override
public void runBeforeSimulation(MARBFastEnvironment env, ParCollection params) {
}
@Override
public void runAfterSimulation(MARBFastEnvironment env, ParCollection params) {
StaticMethods.speichereTextAusArray(
params.getParValueString("directory"),
params.getParValueString("FileNameFitness"),
fitnesses,
params);
StaticMethods.speichereTextAusArray(
params.getParValueString("directory"),
params.getParValueString("FileNameAutomata"),
automata,
params);
}
@Override
public void runDuringSimulation(MARBFastEnvironment env, Wink simZyk, ParCollection params) {
int best = -1;
double bestVal = Double.NEGATIVE_INFINITY;
double bestValPfuschEntfernung = Double.NEGATIVE_INFINITY;
double summePfuschEntfernung = 0;
if (simZyk.getLastTick() % 1000 == 0) {
fitnesses.add((simZyk.getLastTick() + "\t" + env.getFitnessSum()).replace('.', ','));
for (AbstractAgent<?> a : env.getAgents()) {
try {
// Summe Pfuschfitness.
summePfuschEntfernung += ((JasmineRobot) a).getPfuschFitnessEntfernung();
// Pfuschfitness.
if (((JasmineRobot) a).getPfuschFitnessEntfernung() > bestValPfuschEntfernung) {
bestValPfuschEntfernung = ((JasmineRobot) a).getPfuschFitnessEntfernung();
}
System.out.println(summePfuschEntfernung);
System.out.println(bestValPfuschEntfernung);
// Fitness.
if (((Evolvable<?>) a).getEvaluation() > bestVal) {
best = a.id();
bestVal = ((Evolvable<?>) a).getEvaluation();
}
} catch (Exception e) {
}
}
if (best >= 0) {
// Zyklus | MARB | Best-Fitness | Fitnesssumme | Pfuschbester | Pfuschsumme | Pfuschfitness des besten laut Fitness
automata.add(
(simZyk.getLastTick() + "\t"
+ ((JasmineRobot) env.getAgent(best)).getBrain().getMarb().erzeugeStringSeq() + "\t"
+ (bestVal) + "\t"
+ env.getFitnessSum() + "\t"
+ bestValPfuschEntfernung + "\t"
+ summePfuschEntfernung + "\t"
+ ((JasmineRobot) env.getAgent(best)).getPfuschFitnessEntfernung()).replace('.', ','));
}
}
}
@Override
public void handleEvent(EASEvent e, MARBFastEnvironment env,
Wink lastTimeStep, ParCollection params) {
}
/* (non-Javadoc)
* @see eas.plugins.Plugin#getSupportedPlugins()
*/
@Override
public List<String> getSupportedPlugins() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onSimulationResumed(MARBFastEnvironment env, Wink resumeTime,
ParCollection params) {
}
}