BOA correct Logging

This commit is contained in:
Alexander Seitz 2012-09-30 20:03:32 +00:00
parent b136486eab
commit cd147d18be

View File

@ -29,6 +29,8 @@ import eva2.tools.Pair;
import eva2.tools.math.BayNet; import eva2.tools.math.BayNet;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Basic implementation of the Bayesian Optimization Algorithm * Basic implementation of the Bayesian Optimization Algorithm
@ -43,7 +45,8 @@ import java.io.BufferedWriter;
*/ */
public class BOA implements InterfaceOptimizer, java.io.Serializable { public class BOA implements InterfaceOptimizer, java.io.Serializable {
private static boolean TRACE = false; // private static boolean TRACE = false;
private static final Logger LOGGER = Logger.getLogger(BOA.class.getName());
transient private InterfacePopulationChangedEventListener m_Listener = null; transient private InterfacePopulationChangedEventListener m_Listener = null;
private String m_Identifier = "BOA"; private String m_Identifier = "BOA";
@ -163,7 +166,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
File theDir = new File(directoryName); File theDir = new File(directoryName);
// if the directory does not exist, create it // if the directory does not exist, create it
if (!theDir.exists()) { if (!theDir.exists()) {
System.out.println("creating directory: " + directoryName); LOGGER.log(Level.INFO, "creating directory: "+directoryName);
theDir.mkdir(); theDir.mkdir();
} }
} }
@ -199,7 +202,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
private void evaluate(AbstractEAIndividual indy) { private void evaluate(AbstractEAIndividual indy) {
// evaluate the given individual if it is not null // evaluate the given individual if it is not null
if (indy == null) { if (indy == null) {
System.err.println("tried to evaluate null"); LOGGER.log(Level.WARNING, "tried to evaluate null");
return; return;
} }
this.problem.evaluate(indy); this.problem.evaluate(indy);
@ -224,12 +227,12 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
} }
this.template = this.problem.getIndividualTemplate(); this.template = this.problem.getIndividualTemplate();
if (!(template instanceof InterfaceDataTypeBinary)) { if (!(template instanceof InterfaceDataTypeBinary)) {
System.err.println("Requiring binary data!"); LOGGER.log(Level.WARNING, "Requiring binary data!");
} else { } else {
Object dim = BeanInspector.callIfAvailable(problem, Object dim = BeanInspector.callIfAvailable(problem,
"getProblemDimension", null); "getProblemDimension", null);
if (dim == null) if (dim == null)
System.err.println("Couldnt get problem dimension!"); LOGGER.log(Level.WARNING, "Coudn't get problem dimension!");
probDim = (Integer) dim; probDim = (Integer) dim;
((InterfaceDataTypeBinary) this.template) ((InterfaceDataTypeBinary) this.template)
.SetBinaryGenotype(new BitSet(probDim)); .SetBinaryGenotype(new BitSet(probDim));
@ -347,8 +350,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
*/ */
private Population generateNewIndys(int sampleSetSize) { private Population generateNewIndys(int sampleSetSize) {
Population pop = new Population(sampleSetSize); Population pop = new Population(sampleSetSize);
if (TRACE) LOGGER.log(Level.CONFIG, "Resampling " + sampleSetSize + " indies...");
System.out.println("Resampling " + sampleSetSize + " indies...");
while (pop.size() < sampleSetSize) { while (pop.size() < sampleSetSize) {
AbstractEAIndividual indy = (AbstractEAIndividual) this.template AbstractEAIndividual indy = (AbstractEAIndividual) this.template
.clone(); .clone();
@ -469,7 +471,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
// Close the output stream // Close the output stream
out.close(); out.close();
} catch (Exception e) {// Catch exception if any } catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage()); LOGGER.log(Level.WARNING, "Error: ", e);
} }
} else { } else {
@ -483,7 +485,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
// Close the output stream // Close the output stream
out.close(); out.close();
} catch (Exception e) {// Catch exception if any } catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage()); LOGGER.log(Level.WARNING, "Error: ", e);
} }
} }
} }
@ -510,7 +512,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
// Close the output stream // Close the output stream
out.close(); out.close();
} catch (Exception e) {// Catch exception if any } catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage()); LOGGER.log(Level.WARNING, "Error: ", e);
} }
} else { } else {
@ -525,7 +527,7 @@ public class BOA implements InterfaceOptimizer, java.io.Serializable {
// Close the output stream // Close the output stream
out.close(); out.close();
} catch (Exception e) {// Catch exception if any } catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage()); LOGGER.log(Level.WARNING, "Error: ", e);
} }
} }
} }