/*
* File name: PrimeEnvironment.java (package eas.users.lukas.primeProperties.primeEvolution)
* Author(s): lko
* Java version: 7.0
* Generation date: 24.11.2012 (13:33:54)
*
* (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.primeProperties.primeEvolution;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.List;
import eas.math.geometry.Vector2D;
import eas.miscellaneous.StaticMethods;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.standardEnvironments.AbstractEnvironment2D;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;
import eas.users.lukas.primeProperties.primeEvolution.PolynomeGenome.doppelInt;
/**
* @author lko
*/
public class PrimeEnvironment extends AbstractEnvironment2D<PrimeAgent> {
/**
*
*/
private static final long serialVersionUID = 5010034586824419866L;
public PrimeEnvironment(int id, ParCollection params) {
super(id, params);
}
@Override
public List<SingleParameter> getParameters() {
List<SingleParameter> list = super.getParameters();
list.add(new SingleParameter("GaussStdDev", Datatypes.integerRange(1, 50000), 50, "Standard Deviation", "PRIMES"));
list.add(new SingleParameter("DatNam", Datatypes.STRING, "filename.txt", "File name", "PRIMES"));
return list;
}
private int max = 0;
// private int maxFit2 = 0;
@Override
public void step(Wink simTime) {
super.step(simTime);
for (PrimeAgent a : this.getAgents()) {
doppelInt fitness = a.getPol().fitness();
this.setAgentPosition(a.id(), new Vector2D(a.id(), -fitness.wert));
int fitness2 = a.getPol().firstNonPrime(200);
String store = "<Tick: " + simTime + "> " + "(" + fitness.wert + " + " + fitness.doppelte + ") [" + fitness2 + "] " + a.getPol();
if (fitness2 > 45) {
this.getParCollection().logInfo(store);
}
if (fitness.wert >= max) {
max = fitness.wert;
if (simTime.getLastTick() % 100 == 50 || simTime.getLastTick() + 10 >= this.getParCollection().getParValueDouble("TimeToTermination")) {
this.getParCollection().logInfo(store);
StaticMethods.speichereTextDatei(".", this.getParCollection().getParValueString("DatNam"), store, this.getParCollection());
}
} else {
if (a.getPol().getRand().nextBoolean()) {
a.getPol().mutateRandomPositionPlusMinusOne();
} else {
a.getPol().randomize(this.getParCollection().getParValueInt("GaussStdDev"));
}
}
}
}
@Override
public BufferedImage getOutsideView() {
BufferedImage img = super.getOutsideView();
Graphics2D g = img.createGraphics();
Vector2D v1 = this.getPointInVisualization(new Vector2D(-100, 0));
Vector2D v2 = this.getPointInVisualization(new Vector2D(200, 0));
g.setColor(Color.red);
g.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y);
return img;
}
}