portfoliobuilder portfoliobuilder - 4 months ago 41
Java Question

How to work run/implement Benchmark for optaplanner?

I need assistance with benchmarking using OptaPlanner. There are two issues I am running into. The first is seeing the results from benchmarking the provided examples. I see that the vehiclerouting example has two apps. One of them is "VehicleRoutingBenchmarkApp". I ran this application and thought that the index.html would be generated however it wasn't. So I am not clear on how to do this.

The second issue is implementation. I am just experimenting, so I added the code snippet as instructed by the documentation in the VehicleRoutingApp main() so that I can see what will happen.

Documentation link: https://docs.jboss.org/drools/release/6.0.0.CR3/optaplanner-docs/html/benchmarkingAndTweaking.html

System.out.println("-------------- benchmark stuff --------------");
PlannerBenchmarkFactory plannerBenchmarkFactory = PlannerBenchmarkFactory.createFromXmlResource(
"org/optaplanner/examples/vehiclerouting/benchmark/vehicleRoutingBenchmarkConfig.xml");
PlannerBenchmark plannerBenchmark = plannerBenchmarkFactory.buildPlannerBenchmark();
plannerBenchmark.benchmark();


The result of this was a constant stream of outputted logs. It is difficult to follow what it is being conveyed. How do I get all of that translated into a nice GUI as I believe index.html is suppose to do? Thanks in advance.

The tracestack I am getting is the following:

Exception in thread "main" java.lang.IllegalStateException: The directory dataDir (C:\Intellij\Workspace\optaplanner-developer\data\vehiclerouting) does not exist.
Either the working directory should be set to the directory that contains the data directory (which is not the data directory itself), or the system property org.optaplanner.examples.dataDir should be set properly.
The data directory is different in a git clone (optaplanner/optaplanner-examples/data) and in a release zip (examples/sources/data).
In an IDE (IntelliJ, Eclipse, NetBeans), open the "Run configuration" to change "Working directory" (or add the system property in "VM options").
at org.optaplanner.examples.common.persistence.AbstractSolutionDao.<init>(AbstractSolutionDao.java:46)
at org.optaplanner.examples.common.persistence.XStreamSolutionDao.<init>(XStreamSolutionDao.java:32)
at org.optaplanner.examples.vehiclerouting.persistence.VehicleRoutingDao.<init>(VehicleRoutingDao.java:25)
at org.optaplanner.examples.vehiclerouting.persistence.VehicleRoutingImporter.<init>(VehicleRoutingImporter.java:57)
at org.optaplanner.examples.vehiclerouting.persistence.VehicleRoutingFileIO.<init>(VehicleRoutingFileIO.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.optaplanner.core.config.util.ConfigUtils.newInstance(ConfigUtils.java:46)
at org.optaplanner.benchmark.config.ProblemBenchmarksConfig.buildSolutionFileIO(ProblemBenchmarksConfig.java:149)
at org.optaplanner.benchmark.config.ProblemBenchmarksConfig.buildProblemBenchmarkList(ProblemBenchmarksConfig.java:111)
at org.optaplanner.benchmark.config.SolverBenchmarkConfig.buildSolverBenchmark(SolverBenchmarkConfig.java:88)
at org.optaplanner.benchmark.config.PlannerBenchmarkConfig.buildPlannerBenchmark(PlannerBenchmarkConfig.java:210)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.buildPlannerBenchmark(XStreamXmlPlannerBenchmarkFactory.java:156)
at org.optaplanner.examples.common.app.CommonBenchmarkApp.buildAndBenchmark(CommonBenchmarkApp.java:68)
at org.optaplanner.examples.vehiclerouting.app.VehicleRoutingBenchmarkApp.main(VehicleRoutingBenchmarkApp.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Answer

For those trying to learn optaplanner and has the same question, the solution is in your referenced benchmarkConfig.xml file. You should create an xml that has a root <plannerBenchmark> tag. Inside of this you can add another tag called <benchmarkDiretory>. This is where you can specify where you would like your report to be generated. Be sure to set your <inputSolutionFile> to point towards the proper datasets, which can be either .xml or .vrp. The rest works like magic.

Should look something similar to the following:

<plannerBenchmark>
    <benchmarkDirectory>local/data/report/vehiclerouting</benchmarkDirectory>
    .....
    <inputSolutionFile>data/vehiclerouting/unsolved/TestCase_1.xml</inputSolutionFile>
    .....
</plannerBenchmark>
Comments