Graceful fallback when .yml files fail to load.
Only save params once per optimization.
This commit is contained in:
parent
667e069bcc
commit
17263cc023
@ -496,7 +496,7 @@ public class Main extends JFrame implements OptimizationStateListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "Working directory is: {0}", System.getProperty("user.dir"));
|
LOGGER.log(Level.INFO, "Working directory is: {0}", System.getProperty("user.dir"));
|
||||||
LOGGER.log(Level.FINE, "Class path is: {0}", System.getProperty("java.class.path", "."));
|
LOGGER.log(Level.FINE, "Class path is: {0}", System.getProperty("java.class.path", "."));
|
||||||
|
|
||||||
if (!(configurationPane.isVisible())) {
|
if (!(configurationPane.isVisible())) {
|
||||||
|
@ -48,8 +48,8 @@ public class OptimizationParameters extends AbstractOptimizationParameters imple
|
|||||||
try {
|
try {
|
||||||
FileInputStream fileStream = new FileInputStream(yamlFile);
|
FileInputStream fileStream = new FileInputStream(yamlFile);
|
||||||
instance = (OptimizationParameters) new Yaml().load(fileStream);
|
instance = (OptimizationParameters) new Yaml().load(fileStream);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (Exception ex) {
|
||||||
LOGGER.log(Level.WARNING, "Could not load instance object.", ex);
|
LOGGER.log(Level.WARNING, "Could not load OptimizationParameters.yml.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
@ -167,15 +167,17 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
|
|||||||
try {
|
try {
|
||||||
EVAERROR.clearMsgCache();
|
EVAERROR.clearMsgCache();
|
||||||
this.setName(getInfoString());
|
this.setName(getInfoString());
|
||||||
|
if (isOptimizationRunning() && saveParams) {
|
||||||
|
try {
|
||||||
|
optimizationParameters.saveInstance();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not save optimization instance!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (isOptimizationRunning()) {
|
while (isOptimizationRunning()) {
|
||||||
setPriority(3);
|
setPriority(3);
|
||||||
if (saveParams) {
|
|
||||||
try {
|
|
||||||
optimizationParameters.saveInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not save optimization instance!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultPopulation = this.optimize();
|
resultPopulation = this.optimize();
|
||||||
setPriority(1);
|
setPriority(1);
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,10 @@ import eva2.tools.StringSelection;
|
|||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
import eva2.util.annotation.Hidden;
|
import eva2.util.annotation.Hidden;
|
||||||
import eva2.util.annotation.Parameter;
|
import eva2.util.annotation.Parameter;
|
||||||
|
import eva2.yaml.BeanSerializer;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.*;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -62,13 +61,13 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
|||||||
*
|
*
|
||||||
* @return A loaded (from file) or new instance of the class.
|
* @return A loaded (from file) or new instance of the class.
|
||||||
*/
|
*/
|
||||||
public static StatisticsParameters getInstance(String serFileName) {
|
public static StatisticsParameters getInstance(String yamlFile) {
|
||||||
StatisticsParameters instance = null;
|
StatisticsParameters instance = null;
|
||||||
try {
|
try {
|
||||||
FileInputStream fileStream = new FileInputStream(serFileName);
|
FileInputStream fileStream = new FileInputStream(yamlFile);
|
||||||
instance = (StatisticsParameters) Serializer.loadObject(fileStream);
|
instance = (StatisticsParameters) new Yaml().load(fileStream);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (Exception ex) {
|
||||||
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
|
LOGGER.log(Level.WARNING, "Could not load Statistics.yml.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@ -106,9 +105,11 @@ public class StatisticsParameters implements InterfaceStatisticsParameters, Inte
|
|||||||
@Override
|
@Override
|
||||||
public void saveInstance() {
|
public void saveInstance() {
|
||||||
try {
|
try {
|
||||||
FileOutputStream fileStream = new FileOutputStream("Statistics.ser");
|
FileOutputStream fileStream = new FileOutputStream("Statistics.yml");
|
||||||
Serializer.storeObject(fileStream, this);
|
String yaml = BeanSerializer.serializeObject(this);
|
||||||
} catch (FileNotFoundException ex) {
|
fileStream.write(yaml.getBytes());
|
||||||
|
fileStream.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
|
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user