0
votes

I'm trying to set up an OptaPlanner benchmark run. Loading the problemBenchmarks from a file is proving to be problematic, as a lot of my classes are not serializable. It will take a LOT of work to get that to function.

Is there a way to run a benchmark using the same unsolved solution that I use when I start my normal planner run, which is already constructed by my existing Java code? It would be trivial to start the benchmark if that would work somehow.

I find a partial solution in OptaPlanner benchmarking without XML inputSolutionFile.

I was able to make that work, by coding an implementation of SolutionFileIO and using a static variable to pass along the unsolved solution that has already been created.

This works in a limited capacity.

Is there any way to set the unsolved solution directly on the PlannerBenchmarkFactory or the PlannerBenchmark, so that I don't have to use a static variable?

1

1 Answers

1
votes

Yes, just create a text file, for example input1.txt which is empty or only contains a 1 line identifier. Then implement a SolutionFileIO

public class MachineReassignmentFileIO implements SolutionFileIO<MachineReassignment> {

    public static final String FILE_EXTENSION = "txt";

    @Override
    public String getInputFileExtension() {
        return FILE_EXTENSION;
    }

    @Override
    public String getOutputFileExtension() {
        return FILE_EXTENSION;
    }

    @Override
    public MachineReassignment read(File inputSolutionFile) {
        // Ignore the inputSolutionFile or just read the id
        return ... // Create your solution manually
    }

    @Override
    public void write(MachineReassignment solution, File outputSolutionFile) {
        throw new UnsupportedOperationException();
    }

}

then just configure that

<problemBenchmarks>
  <solutionFileIOClass>org...MachineReassignmentFileIO</solutionFileIOClass>
  <inputSolutionFile>data/machinereassignment/import/input1.txt</inputSolutionFile>
  <problemStatisticType>BEST_SCORE</problemStatisticType>
</problemBenchmarks>