0

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?

Community
  • 1
  • 1
Mitch
  • 989
  • 1
  • 9
  • 25

1 Answers1

1

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>
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • The problem with that approach (at least in my situation) is that MachineReassignmentFileIO is instantiated with the default no-args constructor. A instance of the class instantiated in that manner won't have access to the various constructs that are required to create the solution. I'm currently using a static variable in MachineReassignmentFileIO to pass along what I need, and it works but is not great. I guess I could use a thread local variable, but that is not much better than static. – Mitch Apr 22 '16 at 18:37
  • Interesting point, feel free to open a jira for this. I guess we need to support alternatives to inputFileSolution elements – Geoffrey De Smet Apr 25 '16 at 07:00