|
@@ -19,7 +19,6 @@ import java.util.Locale;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.DoubleConsumer;
|
|
|
-import java.util.function.IntConsumer;
|
|
|
import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -92,11 +91,11 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
|
|
|
|
|
|
//printing
|
|
|
- protected RunDataBase db;
|
|
|
- private RunPrinter printer = new RunPrinter(plottFileName(), true);
|
|
|
-
|
|
|
+ private Printer runPrinter = new Printer(plottFileName());
|
|
|
+ protected List<Double> runList = new LinkedList<Double>();
|
|
|
|
|
|
//Parameter
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
LinkedList<ParameterStepping> parameterSteppingList= new LinkedList<ParameterStepping>();
|
|
|
protected boolean useStepping = false;
|
|
|
|
|
@@ -109,12 +108,10 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
createOptionPanel() , console);
|
|
|
splitPane.setResizeWeight(0.0);
|
|
|
content.add(splitPane, BorderLayout.CENTER);
|
|
|
- content.setPreferredSize(new Dimension(800,800));
|
|
|
+ content.setPreferredSize(new Dimension(1200,800));
|
|
|
|
|
|
//Add rounds
|
|
|
- ParameterStepping<Integer> roundStepping = new ParameterStepping<Integer>(IntInput -> rounds = IntInput, () -> rounds, (a,b) -> Integer.sum(a, b), (a,b) -> a * b, 10, 2);
|
|
|
- roundStepping.useThisParameter = true;
|
|
|
- parameterSteppingList.add(roundStepping);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -135,39 +132,39 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
JPanel parameterPanel = new JPanel(null);
|
|
|
parameterPanel.setPreferredSize(new Dimension(510,300));
|
|
|
borderPanel.setLayout(new BoxLayout(borderPanel, BoxLayout.PAGE_AXIS));
|
|
|
- addIntParameter("Rounds", rounds, intInput -> rounds = intInput, 1);
|
|
|
+ addIntParameter("Rounds", rounds, intInput -> rounds = intInput, () -> rounds, 1);
|
|
|
JScrollPane scrollPane = new JScrollPane(borderPanel);
|
|
|
- scrollPane.setBounds(10, 0, 450, 292);
|
|
|
+ scrollPane.setBounds(10, 0, 850, 292);
|
|
|
scrollPane.setBorder(BorderFactory.createEmptyBorder());
|
|
|
parameterPanel.add(scrollPane);
|
|
|
|
|
|
|
|
|
|
|
|
JButton selectGroupNodeButton = new JButton("Select GroupNode");
|
|
|
- selectGroupNodeButton.setBounds(500, 0, 185, 30);
|
|
|
+ selectGroupNodeButton.setBounds(900, 0, 185, 30);
|
|
|
selectGroupNodeButton.addActionListener(actionEvent -> selectGroupNode());
|
|
|
parameterPanel.add(selectGroupNodeButton);
|
|
|
JProgressBar progressBar = runProgressbar.getJProgressBar();
|
|
|
- progressBar.setBounds(500, 35, 185, 20);
|
|
|
+ progressBar.setBounds(900, 35, 185, 20);
|
|
|
progressBar.setStringPainted(true);
|
|
|
parameterPanel.add(progressBar);
|
|
|
|
|
|
JCheckBox useElements = new JCheckBox("Elements");
|
|
|
useElements.setSelected(algoUseElements);
|
|
|
- useElements.setBounds(500, 70, 185, 20);
|
|
|
+ useElements.setBounds(900, 70, 185, 20);
|
|
|
useElements.addActionListener(actionEvent -> algoUseElements = useElements.isSelected());
|
|
|
parameterPanel.add(useElements);
|
|
|
|
|
|
JCheckBox useSwitches = new JCheckBox("Switches");
|
|
|
useSwitches.setSelected(algoUseSwitches);
|
|
|
- useSwitches.setBounds(500, 90, 185, 20);
|
|
|
+ useSwitches.setBounds(900, 90, 185, 20);
|
|
|
useSwitches.addActionListener(actionEvent -> algoUseSwitches = useSwitches.isSelected());
|
|
|
parameterPanel.add(useSwitches);
|
|
|
|
|
|
|
|
|
JCheckBox useFlexes = new JCheckBox("Flexibilities");
|
|
|
useFlexes.setSelected(algoUseFlexes);
|
|
|
- useFlexes.setBounds(500, 110, 185, 20);
|
|
|
+ useFlexes.setBounds(900, 110, 185, 20);
|
|
|
useFlexes.addActionListener(actionEvent -> algoUseFlexes = useFlexes.isSelected());
|
|
|
parameterPanel.add(useFlexes);
|
|
|
return parameterPanel;
|
|
@@ -184,10 +181,6 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
cancelButton.addActionListener(actionEvent -> cancel());
|
|
|
buttonPanel.add(cancelButton);
|
|
|
|
|
|
- JButton plottButton = new JButton("Plott");
|
|
|
- plottButton.addActionListener(actionEvent -> plott());
|
|
|
- buttonPanel.add(plottButton);
|
|
|
-
|
|
|
JButton fitnessButton = new JButton("Fitness");
|
|
|
fitnessButton.setToolTipText("Fitness for the current state.");
|
|
|
fitnessButton.addActionListener(actionEvent -> fitness());
|
|
@@ -211,15 +204,15 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
//ParameterImports
|
|
|
|
|
|
//int
|
|
|
- protected void addIntParameter(String parameterName, int parameterValue, IntConsumer setter) {
|
|
|
- this.addIntParameter(parameterName, parameterValue, setter, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
|
|
+ protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter) {
|
|
|
+ this.addIntParameter(parameterName, parameterValue, setter, getter, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
|
|
}
|
|
|
|
|
|
- protected void addIntParameter(String parameterName, int parameterValue, IntConsumer setter, int parameterMinValue) {
|
|
|
- this.addIntParameter(parameterName, parameterValue, setter, parameterMinValue, Integer.MAX_VALUE);
|
|
|
+ protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter, int parameterMinValue) {
|
|
|
+ this.addIntParameter(parameterName, parameterValue, setter, getter, parameterMinValue, Integer.MAX_VALUE);
|
|
|
}
|
|
|
|
|
|
- protected void addIntParameter(String parameterName, int parameterValue, IntConsumer setter, int parameterMinValue, int parameterMaxValue) {
|
|
|
+ protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter, int parameterMinValue, int parameterMaxValue) {
|
|
|
JPanel singleParameterPanel = new JPanel();
|
|
|
singleParameterPanel.setLayout(new BoxLayout(singleParameterPanel, BoxLayout.LINE_AXIS));
|
|
|
singleParameterPanel.setAlignmentX(0.0f);
|
|
@@ -241,22 +234,76 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
singleParameterTextField.setMaximumSize(new Dimension(200, 30));
|
|
|
singleParameterTextField.setPreferredSize(new Dimension(200, 30));
|
|
|
singleParameterPanel.add(singleParameterTextField);
|
|
|
+
|
|
|
+
|
|
|
+ ParameterStepping<Integer> intParameterStepping = new ParameterStepping<Integer>(setter, getter, Integer::sum , (a,b) -> a * b, 1, 1);
|
|
|
+ intParameterStepping.useThisParameter = false;
|
|
|
+ parameterSteppingList.add(intParameterStepping);
|
|
|
+
|
|
|
+ JCheckBox useSteppingCheckBox = new JCheckBox();
|
|
|
+ useSteppingCheckBox.setSelected(false);
|
|
|
+ singleParameterPanel.add(useSteppingCheckBox);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JLabel stepsLabel = new JLabel("Steps: ");
|
|
|
+ stepsLabel.setEnabled(false);
|
|
|
+ singleParameterPanel.add(stepsLabel);
|
|
|
+
|
|
|
+ NumberFormatter stepFormatter = new NumberFormatter(format);
|
|
|
+ stepFormatter.setMinimum(1);
|
|
|
+ stepFormatter.setMaximum(Integer.MAX_VALUE);
|
|
|
+ stepFormatter.setCommitsOnValidEdit(true);
|
|
|
+
|
|
|
+
|
|
|
+ JFormattedTextField stepsTextField = new JFormattedTextField(stepFormatter);
|
|
|
+ stepsTextField.setEnabled(false);
|
|
|
+ stepsTextField.setValue(1);
|
|
|
+ stepsTextField.setToolTipText("Only integer \u2208 [" + 1 + "," + Integer.MAX_VALUE + "]");
|
|
|
+ stepsTextField.addPropertyChangeListener(actionEvent -> intParameterStepping.stepps = Integer.parseInt(stepsTextField.getValue().toString()));
|
|
|
+ stepsTextField.setMaximumSize(new Dimension(40, 30));
|
|
|
+ stepsTextField.setPreferredSize(new Dimension(40, 30));
|
|
|
+ singleParameterPanel.add(stepsTextField);
|
|
|
+
|
|
|
+ JLabel stepsSizeLabel = new JLabel("StepsSize: ");
|
|
|
+ stepsSizeLabel.setEnabled(false);
|
|
|
+ singleParameterPanel.add(stepsSizeLabel);
|
|
|
+
|
|
|
+ JFormattedTextField stepsSizeTextField = new JFormattedTextField(stepFormatter);
|
|
|
+ stepsSizeTextField.setEnabled(false);
|
|
|
+ stepsSizeTextField.setValue(1);
|
|
|
+ stepsSizeTextField.setToolTipText("Only integer \u2208 [" + 1 + "," + Integer.MAX_VALUE + "]");
|
|
|
+ stepsSizeTextField.addPropertyChangeListener(actionEvent -> intParameterStepping.stepSize = Integer.parseInt(stepsSizeTextField.getValue().toString()));
|
|
|
+ stepsSizeTextField.setMaximumSize(new Dimension(40, 30));
|
|
|
+ stepsSizeTextField.setPreferredSize(new Dimension(40, 30));
|
|
|
+ singleParameterPanel.add(stepsSizeTextField);
|
|
|
+
|
|
|
+ useSteppingCheckBox.addActionListener(actionEvent -> {
|
|
|
+ boolean enabled = useSteppingCheckBox.isSelected();
|
|
|
+ intParameterStepping.useThisParameter = enabled;
|
|
|
+ this.useStepping = this.parameterSteppingList.stream().anyMatch(parameter -> parameter.useThisParameter);
|
|
|
+ stepsLabel.setEnabled(enabled);
|
|
|
+ stepsTextField.setEnabled(enabled);
|
|
|
+ stepsSizeLabel.setEnabled(enabled);
|
|
|
+ stepsSizeTextField.setEnabled(enabled);
|
|
|
+ });
|
|
|
+
|
|
|
borderPanel.add(singleParameterPanel);
|
|
|
}
|
|
|
|
|
|
|
|
|
//double
|
|
|
- protected void addDoubleParameter(String parameterName, double parameterValue, DoubleConsumer setter) {
|
|
|
- this.addDoubleParameter(parameterName, parameterValue, setter, Double.MIN_VALUE, Double.MAX_VALUE);
|
|
|
+ protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter) {
|
|
|
+ this.addDoubleParameter(parameterName, parameterValue, setter, getter, Double.MIN_VALUE, Double.MAX_VALUE);
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected void addDoubleParameter(String parameterName, double parameterValue, DoubleConsumer setter, double parameterMinValue) {
|
|
|
- this.addDoubleParameter(parameterName, parameterValue, setter, parameterMinValue, Double.MAX_VALUE);
|
|
|
+ protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter, double parameterMinValue) {
|
|
|
+ this.addDoubleParameter(parameterName, parameterValue, setter, getter, parameterMinValue, Double.MAX_VALUE);
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected void addDoubleParameter(String parameterName, double parameterValue, DoubleConsumer setter, double parameterMinValue, double parameterMaxValue) {
|
|
|
+ protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter, double parameterMinValue, double parameterMaxValue) {
|
|
|
JPanel singleParameterPanel = new JPanel();
|
|
|
singleParameterPanel.setLayout(new BoxLayout(singleParameterPanel, BoxLayout.LINE_AXIS));
|
|
|
singleParameterPanel.setAlignmentX(0.0f);
|
|
@@ -269,6 +316,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
|
|
|
doubleFormatter.setMinimum(parameterMinValue);
|
|
|
doubleFormatter.setMaximum(parameterMaxValue);
|
|
|
+ doubleFormatter.setCommitsOnValidEdit(true);
|
|
|
JFormattedTextField singleParameterTextField = new JFormattedTextField(doubleFormatter);
|
|
|
singleParameterTextField.setValue(parameterValue);
|
|
|
String minValue = (parameterMinValue == Double.MIN_VALUE)?"Double.MIN_VALUE":String.valueOf(parameterMinValue);
|
|
@@ -278,6 +326,62 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
singleParameterTextField.setMaximumSize(new Dimension(200, 30));
|
|
|
singleParameterTextField.setPreferredSize(new Dimension(200, 30));
|
|
|
singleParameterPanel.add(singleParameterTextField);
|
|
|
+
|
|
|
+ ParameterStepping<Double> doubleParameterStepping = new ParameterStepping<Double>(setter, getter, (a,b) -> a+b , (a,b) -> a * b, 1.0, 1);
|
|
|
+ doubleParameterStepping.useThisParameter = false;
|
|
|
+ parameterSteppingList.add(doubleParameterStepping);
|
|
|
+
|
|
|
+ JCheckBox useSteppingCheckBox = new JCheckBox();
|
|
|
+ useSteppingCheckBox.setSelected(false);
|
|
|
+ singleParameterPanel.add(useSteppingCheckBox);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JLabel stepsLabel = new JLabel("Steps: ");
|
|
|
+ stepsLabel.setEnabled(false);
|
|
|
+ singleParameterPanel.add(stepsLabel);
|
|
|
+ NumberFormat format = NumberFormat.getIntegerInstance();
|
|
|
+ format.setGroupingUsed(false);
|
|
|
+ format.setParseIntegerOnly(true);
|
|
|
+ NumberFormatter integerFormatter = new NumberFormatter(format);
|
|
|
+ integerFormatter.setMinimum(1);
|
|
|
+ integerFormatter.setMaximum(Integer.MAX_VALUE);
|
|
|
+ integerFormatter.setCommitsOnValidEdit(true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ JFormattedTextField stepsTextField = new JFormattedTextField(integerFormatter);
|
|
|
+ stepsTextField.setEnabled(false);
|
|
|
+ stepsTextField.setValue(1);
|
|
|
+ stepsTextField.setToolTipText("Only integer \u2208 [" + 1 + "," + Integer.MAX_VALUE + "]");
|
|
|
+ stepsTextField.addPropertyChangeListener(actionEvent -> doubleParameterStepping.stepps = Integer.parseInt(stepsTextField.getValue().toString()));
|
|
|
+ stepsTextField.setMaximumSize(new Dimension(40, 30));
|
|
|
+ stepsTextField.setPreferredSize(new Dimension(40, 30));
|
|
|
+ singleParameterPanel.add(stepsTextField);
|
|
|
+
|
|
|
+ JLabel stepsSizeLabel = new JLabel("StepsSize: ");
|
|
|
+ stepsSizeLabel.setEnabled(false);
|
|
|
+ singleParameterPanel.add(stepsSizeLabel);
|
|
|
+
|
|
|
+ JFormattedTextField stepsSizeTextField = new JFormattedTextField(doubleFormatter);
|
|
|
+ stepsSizeTextField.setEnabled(false);
|
|
|
+ stepsSizeTextField.setValue(1.0);
|
|
|
+ stepsSizeTextField.setToolTipText("Only double \u2208 [" + minValue + "," + maxValue + "]");
|
|
|
+ stepsSizeTextField.addPropertyChangeListener(actionEvent -> doubleParameterStepping.stepSize = Double.parseDouble(stepsSizeTextField.getValue().toString()));
|
|
|
+ stepsSizeTextField.setMaximumSize(new Dimension(40, 30));
|
|
|
+ stepsSizeTextField.setPreferredSize(new Dimension(40, 30));
|
|
|
+ singleParameterPanel.add(stepsSizeTextField);
|
|
|
+
|
|
|
+ useSteppingCheckBox.addActionListener(actionEvent -> {
|
|
|
+ boolean enabled = useSteppingCheckBox.isSelected();
|
|
|
+ doubleParameterStepping.useThisParameter = enabled;
|
|
|
+ this.useStepping = this.parameterSteppingList.stream().anyMatch(parameter -> parameter.useThisParameter);
|
|
|
+ stepsLabel.setEnabled(enabled);
|
|
|
+ stepsTextField.setEnabled(enabled);
|
|
|
+ stepsSizeLabel.setEnabled(enabled);
|
|
|
+ stepsSizeTextField.setEnabled(enabled);
|
|
|
+ });
|
|
|
+
|
|
|
borderPanel.add(singleParameterPanel);
|
|
|
}
|
|
|
//boolean
|
|
@@ -298,20 +402,12 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
private void startTimer(){
|
|
|
startTime = System.currentTimeMillis();
|
|
|
}
|
|
|
- private void printElapsedTime(){
|
|
|
+ private long printElapsedTime(){
|
|
|
long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
|
|
|
- db.executionTime = elapsedMilliSeconds;
|
|
|
console.println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
|
|
|
+ return elapsedMilliSeconds;
|
|
|
}
|
|
|
|
|
|
- private void plott() {
|
|
|
- if(db!=null) {
|
|
|
- console.println("Plott..");
|
|
|
- printer.print(algoInformationToPrint());
|
|
|
- }else {
|
|
|
- console.println("No run inistialized.");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
private void cancel() {
|
|
@@ -361,39 +457,56 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
private void run() {
|
|
|
cancel = false;
|
|
|
control.guiDisable(true);
|
|
|
+ runPrinter.openStream();
|
|
|
+ runPrinter.println("Start:" + stringStatFromActualState());
|
|
|
if(this.useStepping) {
|
|
|
initParameterStepping();
|
|
|
do {
|
|
|
executeAlgoWithParameter();
|
|
|
- plott();
|
|
|
resetState();
|
|
|
}while(updateOneParameter());
|
|
|
+ resetParameterStepping();
|
|
|
}else {
|
|
|
executeAlgoWithParameter();
|
|
|
|
|
|
}
|
|
|
updateVisual();
|
|
|
control.guiDisable(false);
|
|
|
+ runPrinter.closeStream();
|
|
|
}
|
|
|
-
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
private void initParameterStepping() {
|
|
|
for(ParameterStepping param :this.parameterSteppingList) {
|
|
|
param.init();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
+ private void resetParameterStepping() {
|
|
|
+ for(ParameterStepping param :this.parameterSteppingList) {
|
|
|
+ param.reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
private boolean updateOneParameter() {
|
|
|
- for(ParameterStepping param :this.parameterSteppingList) {
|
|
|
- if(param.useThisParameter && param.canUpdate()) {
|
|
|
+ List<ParameterStepping> parameterInUseList = this.parameterSteppingList.stream().filter(param -> param.useThisParameter).collect(Collectors.toList());
|
|
|
+ int lastParameter = parameterInUseList.size() - 1 ;
|
|
|
+ int actualParameter = 0;
|
|
|
+ for(ParameterStepping param : parameterInUseList) {
|
|
|
+
|
|
|
+ if(param.canUpdate()) {
|
|
|
param.update();
|
|
|
return true;
|
|
|
+ }else {
|
|
|
+ if(actualParameter == lastParameter) break;
|
|
|
+ param.reset();
|
|
|
}
|
|
|
+ actualParameter++;
|
|
|
}
|
|
|
//No Param can be updated
|
|
|
return false;
|
|
@@ -405,27 +518,28 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
|
|
|
|
|
|
private void executeAlgoWithParameter(){
|
|
|
+ runPrinter.println(algoInformationToPrint());
|
|
|
runProgressbar.start();
|
|
|
- int actualIteration = control.getModel().getCurIteration();
|
|
|
- db = new RunDataBase();
|
|
|
- db.startInfo = stringStatFromActualState();
|
|
|
- console.println("TimeStep:" + actualIteration);
|
|
|
- startTimer();
|
|
|
Individual runBest = new Individual();
|
|
|
runBest.fitness = Double.MAX_VALUE;
|
|
|
for(int r = 0; r < rounds; r++)
|
|
|
- {
|
|
|
+ {
|
|
|
+
|
|
|
+ startTimer();
|
|
|
Individual roundBest = executeAlgo();
|
|
|
+ long executionTime = printElapsedTime();
|
|
|
+ runPrinter.println(runList.stream().map(Object::toString).collect(Collectors.joining(", ")));
|
|
|
+ runPrinter.println(stringStatFromActualState());
|
|
|
+ runPrinter.println("ExecutionTime:" + executionTime);
|
|
|
if(cancel)return;
|
|
|
resetState();
|
|
|
if(roundBest.fitness < runBest.fitness) runBest = roundBest;
|
|
|
}
|
|
|
- printElapsedTime();
|
|
|
+
|
|
|
control.getSimManager().resetFlexManagerForTimeStep(control.getModel().getCurIteration());
|
|
|
this.extractPositionAndAccess();
|
|
|
setState(runBest.position);
|
|
|
updateVisual();
|
|
|
- db.endInfo = stringStatFromActualState();
|
|
|
console.println("AlgoResult:" + runBest.fitness);
|
|
|
if(this.algoUseFlexes)calculateAndPrintFlexInfos(control.getSimManager().getActualDecorState());
|
|
|
runProgressbar.stop();
|
|
@@ -633,6 +747,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
private JProgressBar progressBar = new JProgressBar();
|
|
|
private int count = 0;
|
|
|
private boolean isActive = false;
|
|
|
+
|
|
|
public void step() {
|
|
|
if(isActive) progressBar.setValue(count++);
|
|
|
progressBar.setMaximum(getProgressBarMaxCount());
|
|
@@ -654,66 +769,41 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
|
|
|
protected abstract String algoInformationToPrint();
|
|
|
protected abstract String plottFileName();
|
|
|
|
|
|
- public class RunDataBase{
|
|
|
- String startInfo, endInfo;
|
|
|
- long executionTime = 1;
|
|
|
- List<List<Double>> allRuns = new ArrayList<List<Double>>();
|
|
|
- public void insertNewRun(List<Double> newRun){
|
|
|
- allRuns.add(newRun);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
- public class RunPrinter{
|
|
|
- //Fields
|
|
|
+ public class Printer{
|
|
|
private JFileChooser fileChooser = new JFileChooser();
|
|
|
- private boolean append = false;
|
|
|
- //Constructor
|
|
|
- public RunPrinter(String filename) {
|
|
|
- this(filename, false);
|
|
|
- }
|
|
|
-
|
|
|
- public RunPrinter(String filename, boolean append){
|
|
|
- this.append = append;
|
|
|
+ private BufferedWriter out;
|
|
|
+ public Printer(String filename){
|
|
|
fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
|
|
- setFilename(filename);
|
|
|
- }
|
|
|
- //public methods
|
|
|
- public void enableAppend(boolean enable) {
|
|
|
- append = enable;
|
|
|
- }
|
|
|
- public void setFilename(String filename) {
|
|
|
fileChooser.setSelectedFile(new File(filename));
|
|
|
}
|
|
|
- public void print(String info) {
|
|
|
+ public void openStream() {
|
|
|
File file = fileChooser.getSelectedFile();
|
|
|
try {
|
|
|
file.createNewFile();
|
|
|
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
|
|
|
- new FileOutputStream(file, append), "UTF-8"));
|
|
|
- printToStream(out, info);
|
|
|
- out.close();
|
|
|
+ out = new BufferedWriter(new OutputStreamWriter(
|
|
|
+ new FileOutputStream(file, true), "UTF-8"));
|
|
|
} catch (IOException e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- //private methods
|
|
|
- private void printToStream(BufferedWriter out, String info) throws IOException {
|
|
|
- out.write(info);
|
|
|
- out.newLine();
|
|
|
- if(db != null)
|
|
|
- out.write(db.allRuns.stream().map(list -> list.stream().map(Object::toString).collect(Collectors.joining(","))).collect(Collectors.joining(System.lineSeparator())));
|
|
|
-
|
|
|
- out.newLine();
|
|
|
- out.write("ExecutionTime for all rounds[milliseconds]:" + db.executionTime);
|
|
|
- out.newLine();
|
|
|
- out.write("StartStats: " + db.startInfo);
|
|
|
- out.newLine();
|
|
|
- out.write("EndStats: " + db.endInfo);
|
|
|
- out.newLine();
|
|
|
- out.newLine();
|
|
|
+
|
|
|
+
|
|
|
+ public void println(String stringToPrint) {
|
|
|
+ try {
|
|
|
+ out.write(stringToPrint);
|
|
|
+ out.newLine();
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void closeStream() {
|
|
|
+ try {
|
|
|
+ out.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|