Importing release version 322 from old repos

This commit is contained in:
Marcel Kronfeld
2007-12-11 16:38:11 +00:00
parent 8cecdb016d
commit 7ae15be788
668 changed files with 109288 additions and 0 deletions

View File

@@ -0,0 +1,176 @@
package javaeva.server.modules;
/*
* Title: JavaEvA
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 306 $
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.io.Serializable;
import java.net.InetAddress;
import java.util.Vector;
import javaeva.gui.JTabbedModuleFrame;
import javaeva.gui.LogPanel;
import javaeva.server.go.InterfaceProcessor;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RemoteStateListener;
/*==========================================================================*
* ABSTRACT CLASS DECLARATION
*==========================================================================*/
/**
*
*/
abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializable {
public static boolean TRACE = false;
private static int m_InstanceCounter;
protected int m_Instance;
protected String m_AdapterName;
protected InterfaceProcessor m_Processor;
protected String m_myHostName = "not defined";
protected boolean m_Connection = true;
protected ModuleAdapter m_RemoteThis = null;
protected boolean m_RMI = true;
protected MainAdapterClient m_MainAdapterClient; // connection to client
private Vector<RemoteStateListener> m_RemoteStateListeners;
protected LogPanel logPanel = null;
/**
*
*/
abstract public JTabbedModuleFrame getModuleFrame();
/**
*
*/
protected AbstractModuleAdapter(MainAdapterClient Client) {
if (TRACE) System.out.println("AbstractModuleAdapter.AbstractModuleAdapter()");
m_InstanceCounter++;
m_Instance = m_InstanceCounter;
if (TRACE) System.out.println ("AbstractModuleAdapter Nr. "+m_InstanceCounter +" on EvAServer");
if (Client != null) {
try {
m_myHostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
System.out.println("InetAddress.getLocalHost().getHostAddress() --> ERROR" + e.getMessage());
}
} else m_myHostName = "localhost";
if ((Client==null) || Client.getHostName().equals(m_myHostName)) {
m_RMI = false;
} else {// we use RMI
m_RMI = true;
}
m_RemoteStateListeners = new Vector<RemoteStateListener>();
}
/**
* From the interface RemoteStateListener. Added this method to make progress bar possible.
*/
public void updateProgress(final int percent) {
if (TRACE) System.out.println("AbstractModuleAdapter::updateProgress");
for (RemoteStateListener listener : m_RemoteStateListeners) {
listener.updateProgress(percent);
}
}
/**
*
*/
public String getAdapterName() {
return m_AdapterName;
}
/**
*
*/
public void startOpt() {
if (TRACE) System.out.println("Module AbstractModuleAdapter on EvA-Server StartOpt called:" );
m_Processor.startOpt();
}
/**
*
*/
public void restartOpt() {
if (TRACE) System.out.println("Module AbstractModuleAdapter on EvA-Server ReStartOpt called:" );
m_Processor.restartOpt();
}
/**
*
*/
public void stopOpt() {
if (TRACE) System.out.println("Module AbstractModuleAdapter on EvA-Server StopOpt called:" );
m_Processor.stopOpt(); // This means user break
}
/**
*
*/
public void runScript() {
}
/**
*
*/
public void addRemoteStateListener(RemoteStateListener x) {
if (TRACE) System.out.println("Modul Adapter on Server addRemoteStateListener called:" );
m_RemoteStateListeners.add(x);
}
/**
*
*/
public void setConnection (boolean flag) {
if (TRACE) System.out.println("Modul Adapter on Server setConnection "+flag+" called:" );
m_Connection = flag;
}
public boolean hasConnection() {
return m_Connection;
}
/**
*
*/
public void setRemoteThis (ModuleAdapter x) {
if (TRACE) System.out.println("Modul Adapter on Server setRemoteThis called:" );
m_RemoteThis = x;
}
/**
*
*/
public String getHostName () {
if (TRACE) System.out.println("Modul Adapter on Server getHostName called:"+m_myHostName );
return m_myHostName;
}
/**
*
*/
public void performedStop () {
if (TRACE) System.out.println("AbstractModuleAdapter::performedStop");
for (RemoteStateListener listener : m_RemoteStateListeners) {
listener.performedStop();
}
// if (logPanel != null) logPanel.logMessage("Stopped optimization run");
}
public void performedStart(String infoString) {
if (TRACE) System.out.println("AbstractModuleAdapter::performedStart");
for (RemoteStateListener listener : m_RemoteStateListeners) {
listener.performedStart(infoString);
}
// if (logPanel != null) logPanel.logMessage("Started optimization " + m_Processor.getInfoString());
}
public void performedRestart(String infoString) {
if (TRACE) System.out.println("AbstractModuleAdapter::performedRestart");
for (RemoteStateListener listener : m_RemoteStateListeners) {
listener.performedRestart(infoString);
}
// if (logPanel != null) logPanel.logMessage("Restarted optimization run");
}
}

View File

@@ -0,0 +1,29 @@
package javaeva.server.modules;
import javaeva.gui.GenericObjectEditor;
import wsi.ra.jproxy.MainAdapterClient;
/** This the DE modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:54:55
* To change this template use File | Settings | File Templates.
*/
public class DEModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Differential_Evolution";
public DEModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "DE.html", client, DEParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,251 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.F1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.DifferentialEvolution;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.tools.Serializer;
import javaeva.tools.SelectedTag;
import java.io.Serializable;
/** The class gives access to all DE parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:49:09
* To change this template use File | Settings | File Templates.
*/
public class DEParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new DifferentialEvolution();
private InterfaceOptimizationProblem m_Problem = new F1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static DEParameters getInstance() {
if (TRACE) System.out.println("DEParameters getInstance 1");
DEParameters Instance = (DEParameters) Serializer.loadObject("DEParameters.ser");
if (TRACE) System.out.println("DEParameters getInstance 2");
if (Instance == null) Instance = new DEParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("DEParameters.ser",this);
}
/**
*
*/
public DEParameters() {
if (TRACE) System.out.println("DEParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new DifferentialEvolution();
this.m_Problem = new F1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("DEParameters Constructor end");
}
/**
*
*/
private DEParameters(DEParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new DEParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nDE-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a Differential Evolution optimization method, please limit DE to real-valued genotypes.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((DifferentialEvolution)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((DifferentialEvolution)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/** This method will set the amplication factor f
* @param f
*/
public void setF (double f) {
((DifferentialEvolution)this.m_Optimizer).setF(f);
}
public double getF() {
return ((DifferentialEvolution)this.m_Optimizer).getF();
}
public String fTipText() {
return "F is a real and constant factor which controlls the ampllification of the differential variation.";
}
/** This method will set the crossover probability
* @param k
*/
public void setk (double k) {
((DifferentialEvolution)this.m_Optimizer).setk(k);
}
public double getk() {
return ((DifferentialEvolution)this.m_Optimizer).getk();
}
public String kTipText() {
return "Probability of alteration through DE1.";
}
/** This method will set greediness to move towards the best
* @param l
*/
public void setLambda (double l) {
((DifferentialEvolution)this.m_Optimizer).setLambda(l);
}
public double getLambda() {
return ((DifferentialEvolution)this.m_Optimizer).getLambda();
}
public String lambdaTipText() {
return "Enhance greediness through amplification of the differential vector to the best individual for DE2.";
}
/** This method allows you to choose the type of Differential Evolution.
* @param s The type.
*/
public void setDEType(SelectedTag s) {
((DifferentialEvolution)this.m_Optimizer).setDEType(s);
}
public SelectedTag getDEType() {
return ((DifferentialEvolution)this.m_Optimizer).getDEType();
}
public String dETypeTipText() {
return "Choose the type of Differential Evolution.";
}
}

View File

@@ -0,0 +1,27 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the EP modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:54:55
* To change this template use File | Settings | File Templates.
*/
public class EPModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Evolutionary_Programming";
public EPModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "EP.html", client, EPParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,210 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.F1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.EvolutionaryProgramming;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all EP parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:49:09
* To change this template use File | Settings | File Templates.
*/
public class EPParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new EvolutionaryProgramming();
private InterfaceOptimizationProblem m_Problem = new F1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static EPParameters getInstance() {
if (TRACE) System.out.println("EPParameters getInstance 1");
EPParameters Instance = (EPParameters) Serializer.loadObject("EPParameters.ser");
if (TRACE) System.out.println("EPParameters getInstance 2");
if (Instance == null) Instance = new EPParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("EPParameters.ser",this);
}
/**
*
*/
public EPParameters() {
if (TRACE) System.out.println("EPParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new EvolutionaryProgramming();
this.m_Problem = new F1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("EPParameters Constructor end");
}
/**
*
*/
private EPParameters(EPParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new EPParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nEP-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a Evolutionary Programming optimization method, please limit EP to mutation operators only.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((EvolutionaryProgramming)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((EvolutionaryProgramming)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/** Choose the type of environment selection to use.
* @param selection
*/
public void setEnvironmentSelection(InterfaceSelection selection) {
((EvolutionaryProgramming)this.m_Optimizer).setEnvironmentSelection(selection);
}
public InterfaceSelection getEnvironmentSelection() {
return ((EvolutionaryProgramming)this.m_Optimizer).getEnvironmentSelection();
}
public String environmentSelectionTipText() {
return "Choose a method for selecting the reduced population.";
}
}

View File

@@ -0,0 +1,27 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the GA modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:29:20
* To change this template use File | Settings | File Templates.
*/
public class GAModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Genetic_Algorithm";
public GAModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "GA.html", client, GAParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,264 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.HillClimbing;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all GA parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:29:34
* To change this template use File | Settings | File Templates.
*/
public class GAParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static GAParameters getInstance() {
if (TRACE) System.out.println("GAParameters getInstance 1");
GAParameters Instance = (GAParameters) Serializer.loadObject("GAParameters.ser");
if (TRACE) System.out.println("GAParameters getInstance 2");
if (Instance == null) Instance = new GAParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("GAParameters.ser",this);
}
/**
*
*/
public GAParameters() {
if (TRACE) System.out.println("GAParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new GeneticAlgorithm();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("GAParameters Constructor end");
}
/**
*
*/
private GAParameters(GAParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new GAParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a Genetic Algorithm, which transforms into a GP or GE if the appropriate problem and genotype is used.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((GeneticAlgorithm)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((GeneticAlgorithm)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
// /** This method will set the normation method that is to be used.
// * @param normation
// */
// public void setNormationMethod (InterfaceNormation normation) {
// this.m_NormationOperator = normation;
// }
// public InterfaceNormation getNormationMethod () {
// return this.m_NormationOperator;
// }
// public String normationMethodTipText() {
// return "Select the normation method.";
// }
/** Choose a parent selection method.
* @param selection
*/
public void setParentSelection(InterfaceSelection selection) {
((GeneticAlgorithm)this.m_Optimizer).setParentSelection(selection);
}
public InterfaceSelection getParentSelection() {
return ((GeneticAlgorithm)this.m_Optimizer).getParentSelection();
}
public String parentSelectionTipText() {
return "Choose a parent selection method.";
}
/** Enable/disable elitism.
* @param elitism
*/
public void setElitism (boolean elitism) {
((GeneticAlgorithm)this.m_Optimizer).setElitism(elitism);
}
public boolean getElitism() {
return ((GeneticAlgorithm)this.m_Optimizer).getElitism();
}
public String elitismTipText() {
return "Enable/disable elitism.";
}
/** The number of mating partners needed to create offsprings.
* @param partners
*/
public void setNumberOfPartners(int partners) {
if (partners < 0) partners = 0;
((GeneticAlgorithm)this.m_Optimizer).setNumberOfPartners(partners);
}
public int getNumberOfPartners() {
return ((GeneticAlgorithm)this.m_Optimizer).getNumberOfPartners();
}
public String numberOfPartnersTipText() {
return "The number of mating partners needed to create offsprings.";
}
/** Choose a selection method for selecting recombination partners for given parents.
* @param selection
*/
public void setPartnerSelection(InterfaceSelection selection) {
((GeneticAlgorithm)this.m_Optimizer).setPartnerSelection(selection);
}
public InterfaceSelection getPartnerSelection() {
return ((GeneticAlgorithm)this.m_Optimizer).getPartnerSelection();
}
public String partnerSelectionTipText() {
return "Choose a selection method for selecting recombination partners for given parents.";
}
}

View File

@@ -0,0 +1,34 @@
package javaeva.server.modules;
import java.io.Serializable;
import wsi.ra.jproxy.MainAdapterClient;
/**
* Starts a statistics GUI and the GOProcessor thread.
*
* User: streiche
* Date: 11.05.2003
* Time: 13:08:38
* To change this template use Options | File Templates.
*/
public class GOModuleAdapter extends GenericModuleAdapter implements ModuleAdapter, Serializable {
public static String m_Name = "Genetic_Optimization";
/**
*
*/
public static String getName() {
return m_Name;
}
/**
* Starts a statistics GUI and the GOProcessor thread.
*
* @param AdapterName the title of the ModulAdapter
* @param Client the client instance
*/
public GOModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "GO.html", client, GOParameters.getInstance(), false);
}
}

View File

@@ -0,0 +1,194 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.HillClimbing;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.tools.Serializer;
import java.io.Serializable;
import java.io.BufferedWriter;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 306 $
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
*/
public class GOParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new GeneticAlgorithm();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static GOParameters getInstance() {
if (TRACE) System.out.println("GOParameters getInstance 1");
GOParameters Instance = (GOParameters) Serializer.loadObject("GOParameters.ser");
if (TRACE) System.out.println("GOParameters getInstance 2");
if (Instance == null) Instance = new GOParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("GOParameters.ser",this);
}
/**
*
*/
public GOParameters() {
if (TRACE) System.out.println("GOParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new GeneticAlgorithm();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("GOParameters Constructor end");
}
/**
*
*/
private GOParameters(GOParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new GOParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "";//"\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem()+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "Select the optimization parameters.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed, set to zero to use current system time.";
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
// /** This method allows you to set the current optimizing algorithm
// * @param optimizer The new optimizing algorithm
// */
// public void SetOptimizer(InterfaceOptimizer optimizer) {
// this.m_Optimizer = optimizer;
// this.m_Optimizer.SetProblem(this.m_Problem);
// if (this.m_Listener != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
// }
public void setOptimizer(InterfaceOptimizer optimizer) {
this.m_Optimizer = optimizer;
this.m_Optimizer.SetProblem(this.m_Problem);
if (this.m_Listener != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
public String optimizerTipText() {
return "Choose an optimizing strategy.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
}

View File

@@ -0,0 +1,75 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.stat.StatisticsWithGUI;
import javaeva.server.stat.StatisticsParameter;
import javaeva.server.EvAServer;
import javaeva.gui.GenericObjectEditor;
import javaeva.gui.JTabbedModuleFrame;
import javaeva.gui.JModuleGeneralPanel;
import javaeva.gui.JParaPanel;
import java.io.Serializable;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RMIProxyLocal;
public class GenericModuleAdapter extends AbstractModuleAdapter implements Serializable {
private StatisticsWithGUI m_StatisticsModul;
public String helperFilename;
/**
* Constructor of the ModuleAdapter
* @param adapterName The AdapterName
* @param helperFName name of a html help file name
* @param Client The client to serve
* @param params a parameter set describing the optimizer module
* @param optimizerExpert set to true if setting the optimizer is an expert option being hidden from the gui
*/
public GenericModuleAdapter(String adapterName, String helperFName, MainAdapterClient Client, InterfaceGOParameters params, boolean optimizerExpert) {
super (Client);
if (TRACE) System.out.println("Constructor GenericModuleAdapter --> start");
m_RemoteThis = this;
m_AdapterName = adapterName;
m_MainAdapterClient = Client;
helperFilename = helperFName;
m_StatisticsModul = new StatisticsWithGUI(Client);
m_Processor = new Processor((StatisticsWithGUI)m_StatisticsModul,this, params);
// this prevents the optimizer property to be shown by the GOE if optimizerExpert is true
GenericObjectEditor.setExpertProperty(params.getClass(), "optimizer", optimizerExpert);
((Processor)m_Processor).start();
if (TRACE) System.out.println("Constructor GenericModuleAdapter <-- end");
}
/** This method returns a GUI element
* @return the JTabbedModulFrame
*/
public JTabbedModuleFrame getModuleFrame() {
if (TRACE) System.out.println("GenericModulAdapter.getModuleFrame");
ArrayList<Object> GUIContainer = new ArrayList<Object>();
StatisticsParameter Stat = ((StatisticsWithGUI)m_StatisticsModul).getStatisticsParameter();
JModuleGeneralPanel ButtonPanel = new JModuleGeneralPanel(m_RemoteThis,((Processor)m_Processor).isOptRunning());
ButtonPanel.setHelperFilename(helperFilename);
GUIContainer.add(ButtonPanel);
InterfaceGOParameters Para = ((Processor)m_Processor).getModuleParameter();
if (TRACE) System.out.println("parameters are of type "+Para.getClass());
// TODO do we really need proxies here?
if (m_RMI && !Proxy.isProxyClass(Para.getClass())) GUIContainer.add(new JParaPanel( RMIProxyLocal.newInstance(Para), Para.getName()));
else GUIContainer.add(new JParaPanel(Para, Para.getName()));
if (m_RMI && !Proxy.isProxyClass(Stat.getClass())) GUIContainer.add(new JParaPanel( RMIProxyLocal.newInstance(Stat), Stat.getName()));
else GUIContainer.add(new JParaPanel(Stat, Stat.getName()));
return new JTabbedModuleFrame(m_RemoteThis,getName(),m_myHostName+EvAServer.m_NumberOfVM,GUIContainer);
}
public static String getName() {
return null;
}
}

View File

@@ -0,0 +1,31 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the HC modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:17:02
* To change this template use File | Settings | File Templates.
*/
public class HCModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Hill_Climber";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public HCModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "HC.html", client, HCParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,198 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.HillClimbing;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.MonteCarloSearch;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all HC parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:19:20
* To change this template use File | Settings | File Templates.
*/
public class HCParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new HillClimbing();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static HCParameters getInstance() {
if (TRACE) System.out.println("HCParameters getInstance 1");
HCParameters Instance = (HCParameters) Serializer.loadObject("HCParameters.ser");
if (TRACE) System.out.println("HCParameters getInstance 2");
if (Instance == null) Instance = new HCParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("HCParameters.ser",this);
}
/**
*
*/
public HCParameters() {
if (TRACE) System.out.println("HCParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new HillClimbing();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("HCParameters Constructor end");
}
/**
*
*/
private HCParameters(HCParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new HCParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a Hill-Climber, use a population size > 1 for a Multi-Start Hill-Climber.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((HillClimbing)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((HillClimbing)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
}

View File

@@ -0,0 +1,31 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the MC modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:00:48
* To change this template use File | Settings | File Templates.
*/
public class MCModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Monte_Carlo_Search";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public MCModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "MC.html", client, MCParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,197 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.MonteCarloSearch;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all HC parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:07:40
* To change this template use File | Settings | File Templates.
*/
public class MCParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new MonteCarloSearch();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static MCParameters getInstance() {
if (TRACE) System.out.println("MCParameters getInstance 1");
MCParameters Instance = (MCParameters) Serializer.loadObject("MCParameters.ser");
if (TRACE) System.out.println("MCParameters getInstance 2");
if (Instance == null) Instance = new MCParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("MCParameters.ser",this);
}
/**
*
*/
public MCParameters() {
if (TRACE) System.out.println("MCParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new MonteCarloSearch();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("GOParameters Constructor end");
}
/**
*
*/
private MCParameters(MCParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new MCParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a simple Monte-Carlo Search, please use big populations sizes for faster drawing.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((MonteCarloSearch)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((MonteCarloSearch)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
}

View File

@@ -0,0 +1,43 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.stat.StatisticsWithGUI;
import javaeva.server.stat.StatisticsParameter;
import javaeva.server.EvAServer;
import javaeva.gui.JTabbedModuleFrame;
import javaeva.gui.JModuleGeneralPanel;
import javaeva.gui.JParaPanel;
import java.io.Serializable;
import java.util.ArrayList;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RMIProxyLocal;
/** This the MOEA modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:54:55
* To change this template use File | Settings | File Templates.
*/
public class MOEAModuleAdapter extends GenericModuleAdapter implements Serializable, ModuleAdapter {
public static String m_Name = "Multi-Objective_Evolutionary_Algorithms";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public MOEAModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "MOEA.html", client, MOEAParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,255 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.archiving.InterfaceArchiving;
import javaeva.server.go.operators.archiving.InterfaceInformationRetrieval;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.F1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.problems.TF1Problem;
import javaeva.server.go.strategies.DifferentialEvolution;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.MultiObjectiveEA;
import javaeva.tools.Serializer;
import javaeva.tools.SelectedTag;
import java.io.Serializable;
/** The class gives access to all MOEA parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.10.2004
* Time: 13:49:09
* To change this template use File | Settings | File Templates.
*/
public class MOEAParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new MultiObjectiveEA();
private InterfaceOptimizationProblem m_Problem = new TF1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static MOEAParameters getInstance() {
if (TRACE) System.out.println("MOEAParameters getInstance 1");
MOEAParameters Instance = (MOEAParameters) Serializer.loadObject("MOEAParameters.ser");
if (TRACE) System.out.println("MOEAParameters getInstance 2");
if (Instance == null) Instance = new MOEAParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("MOEAParameters.ser",this);
}
/**
*
*/
public MOEAParameters() {
if (TRACE) System.out.println("MOEAParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new MultiObjectiveEA();
this.m_Problem = new TF1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("MOEAParameters Constructor end");
}
/**
*
*/
private MOEAParameters(MOEAParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new MOEAParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nMOEA-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a multi-objective evoluationary algorithm, please limit MOEA to multi-objective problems (due to the given framework only the fitness of objective one will be plotted).";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
((MultiObjectiveEA)this.m_Optimizer).SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((MultiObjectiveEA)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((MultiObjectiveEA)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the Population used.";
}
/** This method allows you to set/get the optimizing technique to use.
* @return The current optimizing method
*/
public InterfaceOptimizer getOptimizer() {
return ((MultiObjectiveEA)this.m_Optimizer).getOptimizer();
}
// public void SetOptimizer(InterfaceOptimizer b){
// // i'm a MOEA i'll ignore that
// }
public void setOptimizer(InterfaceOptimizer b){
((MultiObjectiveEA)this.m_Optimizer).setOptimizer(b);
}
public String optimizerTipText() {
return "Choose a population based optimizing technique to use.";
}
/** This method allows you to set/get the archiving strategy to use.
* @return The current optimizing method
*/
public InterfaceArchiving getArchivingStrategy() {
return ((MultiObjectiveEA)this.m_Optimizer).getArchivingStrategy();
}
public void setArchivingStrategy(InterfaceArchiving b){
((MultiObjectiveEA)this.m_Optimizer).setArchivingStrategy(b);
}
public String archivingStrategyTipText() {
return "Choose the archiving strategy.";
}
/** This method allows you to set/get the Information Retrieval strategy to use.
* @return The current optimizing method
*/
public InterfaceInformationRetrieval getInformationRetrieval() {
return ((MultiObjectiveEA)this.m_Optimizer).getInformationRetrieval();
}
public void setInformationRetrieval(InterfaceInformationRetrieval b){
((MultiObjectiveEA)this.m_Optimizer).setInformationRetrieval(b);
}
public String informationRetrievalTipText() {
return "Choose the Information Retrieval strategy.";
}
/** This method allows you to set/get the size of the archive.
* @return The current optimizing method
*/
public int getArchiveSize() {
Population archive = ((MultiObjectiveEA)this.m_Optimizer).getPopulation().getArchive();
if (archive == null) {
archive = new Population();
((MultiObjectiveEA)this.m_Optimizer).getPopulation().SetArchive(archive);
}
return ((MultiObjectiveEA)this.m_Optimizer).getArchiveSize();
}
public void setArchiveSize(int b){
Population archive = ((MultiObjectiveEA)this.m_Optimizer).getPopulation().getArchive();
if (archive == null) {
archive = new Population();
((MultiObjectiveEA)this.m_Optimizer).getPopulation().SetArchive(archive);
}
((MultiObjectiveEA)this.m_Optimizer).getPopulation().getArchive().setPopulationSize(b);
}
public String archiveSizeTipText() {
return "Choose the size of the archive.";
}
}

View File

@@ -0,0 +1,36 @@
package javaeva.server.modules;
/*
* Title: JavaEvA
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 272 $
* $Date: 2007-11-21 18:06:36 +0100 (Wed, 21 Nov 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import javaeva.gui.JTabbedModuleFrame;
import javaeva.gui.LogPanel;
import wsi.ra.jproxy.RemoteStateListener;
/*==========================================================================*
* INTERFACE DECLARATION
*==========================================================================*/
/**
*
*/
public interface ModuleAdapter extends RemoteStateListener {
public JTabbedModuleFrame getModuleFrame();
public void startOpt(); // called from client
public void restartOpt();
public void stopOpt();
public void runScript();
public void addRemoteStateListener(RemoteStateListener x);
public String getAdapterName();
public void setConnection(boolean flag);
public boolean hasConnection();
public void setRemoteThis(ModuleAdapter x);
public String getHostName();
}

View File

@@ -0,0 +1,31 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the PBIL modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:52:22
* To change this template use File | Settings | File Templates.
*/
public class PBILModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Population_Based_Incremental_Learning";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public PBILModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "PBIL.html", client, PBILParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,282 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.MonteCarloSearch;
import javaeva.server.go.strategies.PopulationBasedIncrementalLearning;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all PBIL parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:53:29
* To change this template use File | Settings | File Templates.
*/
public class PBILParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new PopulationBasedIncrementalLearning();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static PBILParameters getInstance() {
if (TRACE) System.out.println("PBILParameters getInstance 1");
PBILParameters Instance = (PBILParameters) Serializer.loadObject("PBILParameters.ser");
if (TRACE) System.out.println("PBILParameters getInstance 2");
if (Instance == null) Instance = new PBILParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("PBILParameters.ser",this);
}
/**
*
*/
public PBILParameters() {
if (TRACE) System.out.println("PBILParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new PopulationBasedIncrementalLearning();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("PBILParameters Constructor end");
}
/**
*
*/
private PBILParameters(PBILParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new PBILParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "Please note: This optimizer requires a BitSet as genotype!!";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((PopulationBasedIncrementalLearning)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/** This method will set the selection method that is to be used
* @param selection
*/
public void setSelectionMethod(InterfaceSelection selection) {
((PopulationBasedIncrementalLearning)this.m_Optimizer).setSelectionMethod(selection);
}
public InterfaceSelection getSelectionMethod() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getSelectionMethod();
}
public String selectionMethodTipText() {
return "Choose a selection method.";
}
/** Enable/disable elitism.
* @param elitism
*/
public void setElitism (boolean elitism) {
((PopulationBasedIncrementalLearning)this.m_Optimizer).setElitism(elitism);
}
public boolean getElitism() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getElitism();
}
public String elitismTipText() {
return "Enable/disable elitism.";
}
/** This method will set the learning rate for PBIL
* @param LearningRate
*/
public void setLearningRate (double LearningRate) {
if (LearningRate < 0) LearningRate = 0;
((PopulationBasedIncrementalLearning)this.m_Optimizer).setLearningRate(LearningRate);
}
public double getLearningRate() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getLearningRate();
}
public String learningRateTipText() {
return "The learing rate of PBIL.";
}
/** This method will set the mutation rate for PBIL
* @param m
*/
public void setMutationRate (double m) {
if (m < 0) m = 0;
if (m > 1) m = 1;
((PopulationBasedIncrementalLearning)this.m_Optimizer).setMutationRate(m);
}
public double getMutationRate() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getMutationRate();
}
public String mutationRateTipText() {
return "The mutation rate of PBIL.";
}
/** This method will set the mutation sigma for PBIL
* @param m
*/
public void setMutateSigma (double m) {
if (m < 0) m = 0;
((PopulationBasedIncrementalLearning)this.m_Optimizer).setMutateSigma(m);
}
public double getMutateSigma() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getMutateSigma();
}
public String mutateSigmaTipText() {
return "Set the sigma for the mutation of the probability vector.";
}
/** This method will set the number of positive samples for PBIL
* @param PositiveSamples
*/
public void setPositiveSamples (int PositiveSamples) {
if (PositiveSamples < 1) PositiveSamples = 1;
((PopulationBasedIncrementalLearning)this.m_Optimizer).setPositiveSamples(PositiveSamples);
}
public int getPositiveSamples() {
return ((PopulationBasedIncrementalLearning)this.m_Optimizer).getPositiveSamples();
}
public String positiveSamplesTipText() {
return "The number of positive samples that update the PBIL vector.";
}
}

View File

@@ -0,0 +1,31 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the PSO modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 16.11.2004
* Time: 17:58:19
* To change this template use File | Settings | File Templates.
*/
public class PSOModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Particle_Swarm_Optimization";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public PSOModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "PSO.html", client, PSOParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,415 @@
package javaeva.server.modules;
import javaeva.gui.GenericObjectEditor;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.F1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.ParticleSwarmOptimization;
import javaeva.server.go.strategies.PopulationBasedIncrementalLearning;
import javaeva.tools.Serializer;
import javaeva.tools.SelectedTag;
import java.io.Serializable;
/** The class gives access to all PSO parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 16.11.2004
* Time: 17:58:37
* To change this template use File | Settings | File Templates.
*/
public class PSOParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new ParticleSwarmOptimization();
private InterfaceOptimizationProblem m_Problem = new F1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static PSOParameters getInstance() {
if (TRACE) System.out.println("PSOParameters getInstance 1");
PSOParameters Instance = (PSOParameters) Serializer.loadObject("PSOParameters.ser");
if (TRACE) System.out.println("PSOParameters getInstance 2");
if (Instance == null) Instance = new PSOParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("PSOParameters.ser",this);
}
/**
*
*/
public PSOParameters() {
if (TRACE) System.out.println("PSOParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new ParticleSwarmOptimization();
this.m_Problem = new F1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("PSOParameters Constructor end");
}
/**
*
*/
private PSOParameters(PSOParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new PSOParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return ((ParticleSwarmOptimization)m_Optimizer).globalInfo();
}
/**
* Take care that all properties which may be hidden (and currently are) send a "hide" message to the Java Bean properties.
* This is called by PropertySheetPanel in use with the GenericObjectEditor.
*/
public void hideHideable() {
setCheckSpeedLimit(isCheckSpeedLimit());
setTopology(getTopology());
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed, set to zero to use current time";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((ParticleSwarmOptimization)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
/** This method will set the initial velocity
* @param f
*/
public void setInitialVelocity (double f) {
((ParticleSwarmOptimization)this.m_Optimizer).setInitialVelocity(f);
}
public double getInitialVelocity() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getInitialVelocity();
}
public String initialVelocityTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).initialVelocityTipText();
}
/** This method will set the speed limit
* @param k
*/
public void setSpeedLimit (double k) {
((ParticleSwarmOptimization)this.m_Optimizer).setSpeedLimit(k);
}
public double getSpeedLimit() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getSpeedLimit();
}
public String speedLimitTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).speedLimitTipText();
}
/** This method will set the inertness
* @param k
*/
public void setInertnessOrChi(double k) {
// if (k < 0) k = 0;
// if (k > 1) k = 1;
((ParticleSwarmOptimization)this.m_Optimizer).setInertnessOrChi(k);
}
public double getInertnessOrChi() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getInertnessOrChi();
}
public String inertnessOrChiTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).inertnessOrChiTipText();
}
/** This method will set greediness to move towards the best solution
* based on the cognition model
* @param l
*/
public void setPhi1 (double l) {
((ParticleSwarmOptimization)this.m_Optimizer).setPhi1(l);
}
public double getPhi1() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getPhi1();
}
public String phi1TipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).phi1TipText();
}
/** This method will set greediness to move towards the best solution
* based on the social model
* @param l
*/
public void setPhi2 (double l) {
((ParticleSwarmOptimization)this.m_Optimizer).setPhi2(l);
}
public double getPhi2() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getPhi2();
}
public String phi2TipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).phi2TipText();
}
/** Toggle Check Constraints.
* @param s Check Constraints.
*/
public void setCheckConstraints(boolean s) {
((ParticleSwarmOptimization)this.m_Optimizer).setCheckConstraints(s);
}
public boolean isCheckConstraints() {
return ((ParticleSwarmOptimization)this.m_Optimizer).isCheckConstraints();
}
public String checkConstraintsTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).checkConstraintsTipText();
}
/** This method allows you to choose the topology type.
* @param s The type.
*/
public void setTopology(SelectedTag s) {
((ParticleSwarmOptimization)this.m_Optimizer).setTopology(s);
((ParticleSwarmOptimization)this.m_Optimizer).setGOEShowProperties(getClass());
// GenericObjectEditor.setHideProperty(getClass(), "topologyRange", (s.getSelectedTag().getID() >= 2));
// GenericObjectEditor.setHideProperty(getClass(), "subSwarmRadius", (s.getSelectedTag().getID() != 3));
// GenericObjectEditor.setHideProperty(getClass(), "subSwarmSize", (s.getSelectedTag().getID() != 3));
}
public SelectedTag getTopology() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getTopology();
}
public String topologyTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).topologyTipText();
}
/** The range of the local neighbourhood.
* @param s The range.
*/
public void setTopologyRange(int s) {
((ParticleSwarmOptimization)this.m_Optimizer).setTopologyRange(s);
}
public int getTopologyRange() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getTopologyRange();
}
public String topologyRangeTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).topologyRangeTipText();
}
public double getSubSwarmRadius() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getSubSwarmRadius();
}
public void setSubSwarmRadius(double radius) {
((ParticleSwarmOptimization)this.m_Optimizer).setSubSwarmRadius(radius);
}
public String subSwarmRadiusTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).subSwarmRadiusTipText();
}
public int getSubSwarmSize() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getSubSwarmSize();
}
public void setSubSwarmSize(int subSize) {
((ParticleSwarmOptimization)this.m_Optimizer).setSubSwarmSize(subSize);
}
public String subSwarmSizeTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).subSwarmSizeTipText();
}
/**
* @return the checkSpeedLimit
**/
public boolean isCheckSpeedLimit() {
return ((ParticleSwarmOptimization)this.m_Optimizer).isCheckSpeedLimit();
}
/**
* @param checkSpeedLimit the checkSpeedLimit to set
**/
public void setCheckSpeedLimit(boolean checkSpeedLimit) {
((ParticleSwarmOptimization)this.m_Optimizer).setCheckSpeedLimit(checkSpeedLimit);
GenericObjectEditor.setHideProperty(getClass(), "speedLimit", !checkSpeedLimit);
}
public String checkSpeedLimitTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).checkSpeedLimitTipText();
}
/** This method allows you to choose the algorithm type.
* @param s The type.
*/
public void setAlgoType(SelectedTag s) {
((ParticleSwarmOptimization)this.m_Optimizer).setAlgoType(s);
}
public SelectedTag getAlgoType() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getAlgoType();
}
public String algoTypeTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).algoTypeTipText();
}
/**
* @return the treeBranchDeg
*/
public int getTreeBranchDegree() {
return ((ParticleSwarmOptimization)this.m_Optimizer).getTreeBranchDegree();
}
/**
* @param treeBranchDeg the treeBranchDeg to set
*/
public void setTreeBranchDegree(int treeBranchDeg) {
((ParticleSwarmOptimization)this.m_Optimizer).setTreeBranchDegree(treeBranchDeg);
}
public String treeBranchDegreeTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).treeBranchDegreeTipText();
}
/**
* @return the wrapTopology
*/
public boolean isWrapTopology() {
return ((ParticleSwarmOptimization)this.m_Optimizer).isWrapTopology();
}
/**
* @param wrapTopology the wrapTopology to set
*/
public void setWrapTopology(boolean wrapTopology) {
((ParticleSwarmOptimization)this.m_Optimizer).setWrapTopology(wrapTopology);
}
public String wrapTopologyTipText() {
return ((ParticleSwarmOptimization)this.m_Optimizer).wrapTopologyTipText();
}
}

View File

@@ -0,0 +1,302 @@
package javaeva.server.modules;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javaeva.gui.BeanTest;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.InterfaceProcessor;
import javaeva.server.go.PopulationInterface;
import javaeva.server.go.individuals.AbstractEAIndividual;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.tools.RandomNumberGenerator;
import javaeva.server.stat.Statistics;
import wsi.ra.jproxy.RemoteStateListener;
public class Processor extends Thread implements InterfaceProcessor, InterfacePopulationChangedEventListener {
public static final boolean TRACE=false;
private volatile boolean m_optRunning;
public volatile boolean m_doRunScript;
public Statistics m_Statistics;
public InterfaceGOParameters m_ModulParameter;
public boolean m_createInitialPopulations=true;
private RemoteStateListener m_ListenerModule;
private boolean wasRestarted = false;
private int runCounter = 0;
transient private String m_OutputPath = "";
transient private BufferedWriter m_OutputFile = null;
public void addListener(RemoteStateListener module) {
if (TRACE) System.out.println("Processor: setting module as listener: " + ((module==null) ? "null" : module.toString()));
m_ListenerModule = module;
}
/**
*/
public Processor(Statistics Stat, ModuleAdapter Adapter, InterfaceGOParameters params) {
m_ModulParameter = params;
m_Statistics = Stat;
m_ListenerModule = Adapter;
}
/**
*
*/
public Processor(Statistics Stat) {
m_Statistics = Stat;
}
protected boolean isOptRunning() {
return m_optRunning;
}
protected void setOptRunning(boolean bRun) {
m_optRunning = bRun;
}
// public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
// listener = ea;
//// hier weiter! TODO
// }
/**
*
*/
public void startOpt() {
m_createInitialPopulations = true;
if (TRACE) System.out.println("startOpt called:");
if (isOptRunning()) {
System.err.println("ERROR: Processor is already running !!");
return;
}
wasRestarted = false;
setOptRunning(true);
}
/**
*
*/
public void restartOpt() {
m_createInitialPopulations = false;
if (TRACE) System.out.println("restartOpt called:");
if (isOptRunning()) {
System.err.println("ERROR: Processor is already running !!");
return;
}
wasRestarted = false;
setOptRunning(true);
}
/**
*
*/
public void stopOpt() { // this means user break
if (TRACE) System.out.println("called StopOpt");
setOptRunning(false);
m_doRunScript = false;
if (TRACE) System.out.println("m_doRunScript = false ");
}
/**
*
*/
public void runScript() {
m_doRunScript = true;
}
/**
*
*/
public void run() {
setPriority(1);
while (true) {
try {Thread.sleep(200);} catch (Exception e) {
System.err.println ("There was an error in sleep Processor.run()" + e); }
// while (m_doRunScript == true) {
// setPriority(3);
// //doRunScript();
// setPriority(1);
// }
while (isOptRunning()) {
setPriority(3);
m_ModulParameter.saveInstance();
optimize("Run ");
setPriority(1);
}
}
}
/**
*
*/
public void optimize(String Info) {
if (!isOptRunning()) {
System.err.println("warning, this shouldnt happen in processor! Was startOpt called?");
setOptRunning(true);
}
RandomNumberGenerator.setseed(m_ModulParameter.getSeed());
if (m_ListenerModule!=null) {
if (wasRestarted) m_ListenerModule.performedRestart(getInfoString());
else m_ListenerModule.performedStart(getInfoString());
}
// if (this.show) this.m_StatusField.setText("Optimizing...");
// opening output file...
String name = this.m_ModulParameter.getOutputFileName();
if (!name.equalsIgnoreCase("none") && !name.equals("")) {
SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_'HH.mm.ss");
String m_StartDate = formatter.format(new Date());
name = this.m_OutputPath + name +"_"+this.m_ModulParameter.getOptimizer().getName()+"_"+m_StartDate+".dat";
try {
this.m_OutputFile = new BufferedWriter(new OutputStreamWriter (new FileOutputStream (name)));
} catch (FileNotFoundException e) {
System.out.println("Could not open output file! Filename: " + name);
}
this.writeToFile(" FitnessCalls\t Best\t Mean\t Worst \t" + this.m_ModulParameter.getProblem().getAdditionalFileStringHeader(this.m_ModulParameter.getOptimizer().getPopulation()));
} else {
this.m_OutputFile = null;
}
m_ModulParameter.getOptimizer().addPopulationChangedEventListener(this);
runCounter = 0;
while (isOptRunning() && (runCounter<m_Statistics.getStatisticsParameter().getMultiRuns())) {
// for (int runCounter = 0; runCounter<m_Statistics.getStatisticsParameter().getMultiRuns(); runCounter++) {
m_Statistics.printToTextListener("****** Multirun "+runCounter);
m_Statistics.startOptPerformed(Info,runCounter);
m_Statistics.printToTextListener("Module parameters:");
m_Statistics.printToTextListener(BeanTest.toString(m_ModulParameter));
m_Statistics.printToTextListener("Statistics parameters:");
m_Statistics.printToTextListener(BeanTest.toString(m_Statistics.getStatisticsParameter()));
this.m_ModulParameter.getOptimizer().SetProblem(this.m_ModulParameter.getProblem());
if (this.m_createInitialPopulations) this.m_ModulParameter.getOptimizer().init();
this.m_ModulParameter.getTerminator().init();
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
m_ListenerModule.updateProgress(getStatusPercent(m_ModulParameter.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()));
do { // main loop
this.m_ModulParameter.getOptimizer().optimize();
// m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
// m_ListenerModule.updateProgress(getStatusPercent(m_ModulParameter.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()));
} while (isOptRunning() && !this.m_ModulParameter.getTerminator().isTerminated(this.m_ModulParameter.getOptimizer().getPopulation()));
runCounter++;
// m_doOpt = true;
// while (m_doOpt) { // old main loop
// // deleted by HU m_Statistics.plotStatisticsPerformed();
// this.m_ModulParameter.getOptimizer().optimize();
// if (this.m_ModulParameter.getTerminator().isTerminated(this.m_ModulParameter.getOptimizer().getPopulation())) {
// m_doOpt = false;
// } else if (!m_doOpt) { // this means user break
// runCounter = m_Statistics.getStatisticsParameter().getMultiRuns();
// }
// m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
// m_ListenerModule.updateProgress(getStatusPercent(m_ModulParameter.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()));
// } // end of while (m_doOpt==true)
m_Statistics.stopOptPerformed(isOptRunning()); // stop is "normal" if opt wasnt set false by the user
}
setOptRunning(false); // normal finish
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
m_ListenerModule.updateProgress(0);
}
private int getStatusPercent(Population pop, int currentRun, int multiRuns) {
double x = 100/multiRuns;
int curProgress;
if (this.m_ModulParameter.getTerminator() instanceof EvaluationTerminator) {
double y = x/(double)((EvaluationTerminator)this.m_ModulParameter.getTerminator()).getFitnessCalls();
curProgress = (int)(currentRun * x + pop.getFunctionCalls()*y);
} else {
curProgress = (int)(currentRun * x);
}
return curProgress;
}
/** This method allows an optimizer to register a change in the optimizer.
* @param source The source of the event.
* @param name Could be used to indicate the nature of the event.
*/
public void registerPopulationStateChanged(Object source, String name) {
Population population = ((InterfaceOptimizer)source).getPopulation();
m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
m_ListenerModule.updateProgress(getStatusPercent(m_ModulParameter.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()));
if (this.m_OutputFile != null) {
// data to be stored in file
double tmpd = 0;
StringBuffer tmpLine = new StringBuffer("");
tmpLine.append(population.getFunctionCalls());
tmpLine.append("\t");
tmpLine.append(population.getBestEAIndividual().getFitness(0));
tmpLine.append("\t");
for (int i = 0; i < population.size(); i++) tmpd += ((AbstractEAIndividual)population.get(i)).getFitness(0)/(double)population.size();
tmpLine.append("\t");
tmpLine.append(tmpd);
tmpLine.append("\t");
tmpLine.append(population.getWorstEAIndividual().getFitness(0));
tmpLine.append("\t");
//tmpLine.append(population.getBestEAIndividual().getStringRepresentation());
tmpLine.append(this.m_ModulParameter.getProblem().getAdditionalFileStringValue(population));
this.writeToFile(tmpLine.toString());
}
}
/** This method writes Data to file.
* @param line The line that is to be added to the file
*/
private void writeToFile(String line) {
String write = line + "\n";
if (this.m_OutputFile == null) return;
try {
this.m_OutputFile.write(write, 0, write.length());
this.m_OutputFile.flush();
} catch (IOException e) {
System.out.println("Problems writing to output file!");
}
}
public String getInfoString() {
StringBuffer sb = new StringBuffer("processing ");
sb.append(this.m_ModulParameter.getProblem().getName());
sb.append(" using ");
sb.append(this.m_ModulParameter.getOptimizer().getName());
// commented out because the number of multi-runs can be changed after start
// so it might create misinformation (would still be the user's fault, though)
// sb.append(" for ");
// sb.append(m_Statistics.getStatistisParameter().getMultiRuns());
// sb.append(" runs");
return sb.toString();
}
/** This method return the Statistics object.
*/
public Statistics getStatistics() {
return m_Statistics;
}
/** These methods allow you to get and set the Modul Parameters.
*/
public InterfaceGOParameters getModuleParameter() {
return m_ModulParameter;
}
public void setModuleParameter(InterfaceGOParameters x) {
m_ModulParameter= x;
}
}

View File

@@ -0,0 +1,32 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the SA modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:25:00
* To change this template use File | Settings | File Templates.
*/
public class SAModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Simulated_Annealing";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public SAModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "SA.html", client, SAParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,227 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.GeneticAlgorithm;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.MonteCarloSearch;
import javaeva.server.go.strategies.SimulatedAnnealing;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all SA parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 08.06.2004
* Time: 21:25:12
* To change this template use File | Settings | File Templates.
*/
public class SAParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new SimulatedAnnealing();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static SAParameters getInstance() {
if (TRACE) System.out.println("SAParameters getInstance 1");
SAParameters Instance = (SAParameters) Serializer.loadObject("SAParameters.ser");
if (TRACE) System.out.println("SAParameters getInstance 2");
if (Instance == null) Instance = new SAParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("SAParameters.ser",this);
}
/**
*
*/
public SAParameters() {
if (TRACE) System.out.println("SAParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new SimulatedAnnealing();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("SAParameters Constructor end");
}
/**
*
*/
private SAParameters(SAParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new SAParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a simple Simulated Annealing Algorithm.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((SimulatedAnnealing)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((SimulatedAnnealing)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Change the number of best individuals stored (MS-SA).";
}
/** This methods allow you to set/get the temperatur of the simulated
* annealing procedure
* @return The initial temperature.
*/
public double getInitialTemperature() {
return ((SimulatedAnnealing)this.m_Optimizer).getInitialTemperature();
}
public void setInitialTemperature(double pop){
((SimulatedAnnealing)this.m_Optimizer).setInitialTemperature(pop);
}
public String initialTemperatureTipText() {
return "Set the initial temperature.";
}
/** This methods allow you to set/get the temperatur of the simulated
* annealing procedure
* @return The initial temperature.
*/
public double getAlpha() {
return ((SimulatedAnnealing)this.m_Optimizer).getAlpha();
}
public void setAlpha(double a){
if (a > 1) a = 1.0;
((SimulatedAnnealing)this.m_Optimizer).setAlpha(a);
}
public String alphaTipText() {
return "Set alpha, which is used to degrade the temperaure.";
}
}

View File

@@ -0,0 +1,31 @@
package javaeva.server.modules;
import wsi.ra.jproxy.MainAdapterClient;
/** This the SSGA modul adapter necessary to access this implementation
* form the JavaEvA top level.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 19.07.2005
* Time: 15:44:53
* To change this template use File | Settings | File Templates.
*/
public class SSGAModuleAdapter extends GenericModuleAdapter implements ModuleAdapter {
public static String m_Name = "Steady_State_Genetic_Algorithm";
/** Constructor of the Moduladapter
* @param AdapterName The AdapterName
* @param Client The client to serve
*/
public SSGAModuleAdapter(String adapterName, MainAdapterClient client) {
super (adapterName, "SSGA.html", client, SSGAParameters.getInstance(), true);
}
/** This method returns the name of the ModulAdapters
* @return The name
*/
public static String getName() {
return m_Name;
}
}

View File

@@ -0,0 +1,265 @@
package javaeva.server.modules;
import javaeva.server.go.InterfaceGOParameters;
import javaeva.server.go.InterfacePopulationChangedEventListener;
import javaeva.server.go.TerminatorInterface;
import javaeva.server.go.operators.selection.InterfaceSelection;
import javaeva.server.go.operators.selection.replacement.InterfaceReplacement;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.server.go.populations.Population;
import javaeva.server.go.problems.B1Problem;
import javaeva.server.go.problems.InterfaceOptimizationProblem;
import javaeva.server.go.strategies.InterfaceOptimizer;
import javaeva.server.go.strategies.SteadyStateGA;
import javaeva.tools.Serializer;
import java.io.Serializable;
/** The class gives access to all SSGA parameters for the JavaEvA
* top level GUI.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 19.07.2005
* Time: 15:44:34
* To change this template use File | Settings | File Templates.
*/
public class SSGAParameters implements InterfaceGOParameters, Serializable {
public static boolean TRACE = false;
private String m_Name ="not defined";
private long m_Seed = (long)100.0;
// Opt. Algorithms and Parameters
private InterfaceOptimizer m_Optimizer = new SteadyStateGA();
private InterfaceOptimizationProblem m_Problem = new B1Problem();
//private int m_FunctionCalls = 1000;
private TerminatorInterface m_Terminator = new EvaluationTerminator();
private String m_OutputFileName = "none";
transient private InterfacePopulationChangedEventListener m_Listener;
/**
*
*/
public static SSGAParameters getInstance() {
if (TRACE) System.out.println("SSGAParameters getInstance 1");
SSGAParameters Instance = (SSGAParameters) Serializer.loadObject("SSGAParameters.ser");
if (TRACE) System.out.println("SSGAParameters getInstance 2");
if (Instance == null) Instance = new SSGAParameters();
return Instance;
}
/**
*
*/
public void saveInstance() {
Serializer.storeObject("SSGAParameters.ser",this);
}
/**
*
*/
public SSGAParameters() {
if (TRACE) System.out.println("SSGAParameters Constructor start");
this.m_Name="Optimization parameters";
this.m_Optimizer = new SteadyStateGA();
this.m_Problem = new B1Problem();
//this.m_FunctionCalls = 1000;
((EvaluationTerminator)this.m_Terminator).setFitnessCalls(1000);
this.m_Optimizer.SetProblem(this.m_Problem);
if (TRACE) System.out.println("SSGAParameters Constructor end");
}
/**
*
*/
private SSGAParameters(SSGAParameters Source) {
this.m_Name = Source.m_Name;
this.m_Optimizer = Source.m_Optimizer;
this.m_Problem = Source.m_Problem;
this.m_Terminator = Source.m_Terminator;
//this.m_FunctionCalls = Source.m_FunctionCalls;
this.m_Optimizer.SetProblem(this.m_Problem);
this.m_Seed = Source.m_Seed;
}
/**
*
*/
public String getName() {
return m_Name;
}
/**
*
*/
public Object clone() {
return new SSGAParameters(this);
}
/** This method allows you to add the LectureGUI as listener to the Optimizer
* @param ea
*/
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
this.m_Listener = ea;
if (this.m_Optimizer != null) this.m_Optimizer.addPopulationChangedEventListener(this.m_Listener);
}
/**
*
*/
public String toString() {
String ret = "\r\nGO-Parameter:"+this.m_Problem.getStringRepresentationForProblem(this.m_Optimizer)+"\n"+this.m_Optimizer.getStringRepresentation();
return ret;
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "This is a steady-state GA.";
}
/** This methods allow you to set and get the Seed for the Random Number Generator.
* @param x Long seed.
*/
public void setSeed(long x) {
m_Seed = x;
}
public long getSeed() {
return m_Seed;
}
public String seedTipText() {
return "Random number seed.";
}
/** This method allows you to set the current optimizing algorithm
* @param optimizer The new optimizing algorithm
*/
public void setOptimizer(InterfaceOptimizer optimizer) {
// i'm a Monte Carlo Search Algorithm
// *pff* i'll ignore that!
}
public InterfaceOptimizer getOptimizer() {
return this.m_Optimizer;
}
/** This method allows you to choose a termination criteria for the
* evolutionary algorithm.
* @param term The new terminator
*/
public void setTerminator(TerminatorInterface term) {
this.m_Terminator = term;
}
public TerminatorInterface getTerminator() {
return this.m_Terminator;
}
public String terminatorTipText() {
return "Choose a termination criterion.";
}
/** This method will set the problem that is to be optimized
* @param problem
*/
public void setProblem (InterfaceOptimizationProblem problem) {
this.m_Problem = problem;
this.m_Optimizer.SetProblem(this.m_Problem);
}
public InterfaceOptimizationProblem getProblem() {
return this.m_Problem;
}
public String problemTipText() {
return "Choose the problem that is to optimize and the EA individual parameters.";
}
/** This method will set the output filename
* @param name
*/
public void setOutputFileName (String name) {
this.m_OutputFileName = name;
}
public String getOutputFileName () {
return this.m_OutputFileName;
}
public String outputFileNameTipText() {
return "Set the name for the output file, if 'none' no output file will be created.";
}
/** Assuming that all optimizer will store thier data in a population
* we will allow acess to this population to query to current state
* of the optimizer.
* @return The population of current solutions to a given problem.
*/
public Population getPopulation() {
return ((SteadyStateGA)this.m_Optimizer).getPopulation();
}
public void setPopulation(Population pop){
((SteadyStateGA)this.m_Optimizer).setPopulation(pop);
}
public String populationTipText() {
return "Edit the properties of the population used.";
}
// /** This method will set the normation method that is to be used.
// * @param normation
// */
// public void setNormationMethod (InterfaceNormation normation) {
// this.m_NormationOperator = normation;
// }
// public InterfaceNormation getNormationMethod () {
// return this.m_NormationOperator;
// }
// public String normationMethodTipText() {
// return "Select the normation method.";
// }
/** Choose a parent selection method.
* @param selection
*/
public void setParentSelection(InterfaceSelection selection) {
((SteadyStateGA)this.m_Optimizer).setParentSelection(selection);
}
public InterfaceSelection getParentSelection() {
return ((SteadyStateGA)this.m_Optimizer).getParentSelection();
}
public String parentSelectionTipText() {
return "Choose a parent selection method.";
}
/** This method will set the number of partners that are needed to create
* offsprings by mating
* @param partners
*/
public void setNumberOfPartners(int partners) {
if (partners < 0) partners = 0;
((SteadyStateGA)this.m_Optimizer).setNumberOfPartners(partners);
}
public int getNumberOfPartners() {
return ((SteadyStateGA)this.m_Optimizer).getNumberOfPartners();
}
public String numberOfPartnersTipText() {
return "The number of mating partners needed to create offsprings.";
}
/** Choose a selection method for selecting recombination partners for given parents.
* @param selection
*/
public void setPartnerSelection(InterfaceSelection selection) {
((SteadyStateGA)this.m_Optimizer).setPartnerSelection(selection);
}
public InterfaceSelection getPartnerSelection() {
return ((SteadyStateGA)this.m_Optimizer).getPartnerSelection();
}
public String partnerSelectionTipText() {
return "Choose a selection method for selecting recombination partners for given parents.";
}
/** Choose a replacement strategy.
* @param s A InterfaceReplacement strategy.
*/
public void setReplacementSelection(InterfaceReplacement s) {
((SteadyStateGA)this.m_Optimizer).setReplacementSelection(s);
}
public InterfaceReplacement getReplacementSelection() {
return ((SteadyStateGA)this.m_Optimizer).getReplacementSelection();
}
public String replacementSelectionTipText() {
return "Choose a replacement strategy.";
}
}