Benchmark Configuration - Error:PlanningProblem(null) can't be null
Benchmark Configuration - Error:PlanningProblem(null) can't be null
此问题是 的延续。
简而言之,我正在处理一个类似于 OptaPlanner 的 NurseRostering 问题。目前我需要实施一个基准测试,在那里我遇到了上面 link 的错误。
现在该错误已解决,我收到错误 The planningProblem (null) must not be null.
基于此,我认为我的 solution
未正确读取,我需要进行一些调整。我做了一些研究,做了很多调试,但没有找到我需要做的事情。
下面是我修改的所有配置,类和界面:
CustomBenchmarkIO:
public class CustomBenchmarkIO<Solution_> implements SolutionFileIO<Solution_>{
public String getInputFileExtension() {
return null;
}
public String getOutputFileExtension() {
return null;
}
public Solution_ read(File inputSolutionFile) {
return null;
}
@Override
public void write(Solution_ solution, File outputSolutionFile) {
}
}
Note:<Solution_> is what i currently have, i tried both <Solution> and <Solution_> , both didn't work.
NurseRosterBenchmarkApp:
public static void main(String[] args) {
new NurseRosteringBenchmarkApp().buildAndBenchmark(args);
}
public NurseRosteringBenchmarkApp() {
super(
new ArgOption("name",
"org/optaplanner/examples/nurserostering/benchmark/BenchmarkConfig.xml"));
}
Note: This is the default NurseRosterBenchmarkApp.
NurseRosterConsoleApp - 我仅从控制台将 NurseRosteringApp 配置为 运行。
public class NurseRosterConsoleApp extends CommonApp{
protected NurseRosterConsoleApp(String name, String description, String solverConfig, String iconResource) {
super(name, description, solverConfig, iconResource);
// TODO Auto-generated constructor stub
}
// function for reading the solution from a file
public static Solution readSolution(File inputFile, boolean inputXmlType) {
// reading from a solution xml file
if (inputXmlType) {
return (Solution) new NurseRosteringDao().readSolution(inputFile);
} else {
Solution solution;
InputStream in = null;
try {
in = new FileInputStream(inputFile);
SAXBuilder builder = new SAXBuilder(false);
Document document = builder.build(in);
XmlInputBuilder xmlInputBuilder = new NurseRosteringImporter.NurseRosteringInputBuilder();
xmlInputBuilder.setInputFile(inputFile);
xmlInputBuilder.setDocument(document);
try {
solution = (Solution) xmlInputBuilder.readSolution();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Exception in inputFile (" + inputFile + ")", e);
} catch (IllegalStateException e) {
throw new IllegalStateException("Exception in inputFile (" + inputFile + ")", e);
}
} catch (IOException e) {
throw new IllegalArgumentException("Could not read the file (" + inputFile.getName() + ").", e);
} catch (JDOMException e) {
throw new IllegalArgumentException("Could not parse the XML file (" + inputFile.getName() + ").", e);
} finally {
IOUtils.closeQuietly(in);
}
return solution;
}
}
public static void main(String[] args) {
File inputXml = new File(Settings.inputFilePath);
SolverFactory solverFactory = SolverFactory.createFromXmlResource(Settings.SOLVER_CONFIG);
Solver solver = solverFactory.buildSolver();
Solution unsolvedNurseRoster = readSolution(inputXml, Settings.inputXmlType);
NurseRoster nurseRoster = (NurseRoster) unsolvedNurseRoster;
solver.solve(unsolvedNurseRoster);
NurseRoster solvedNurseRoster = (NurseRoster) solver.getBestSolution();
try {
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected AbstractSolutionExporter createSolutionExporter() {
return new NurseRosteringExporter();
}
@Override
protected SolutionDao createSolutionDao() {
// TODO Auto-generated method stub
return null;
}
@Override
protected SolutionPanel createSolutionPanel() {
// TODO Auto-generated method stub
return null;
}
}
Note: I extended the CommonApp class, and added all of the unimplemented methods,
but it still didn't work. Also i configured the constructor to be the same as the OptaPlanner one
(although i think it's for the GUI, correct me if i'm wrong).
BenchmarkConfig - 同上一题
<plannerBenchmark>
<benchmarkDirectory>local/data/nurserostering/location</benchmarkDirectory>
<warmUpSecondsSpentLimit>5</warmUpSecondsSpentLimit>
<inheritedSolverBenchmark>
<problemBenchmarks>
<solutionFileIOClass>org.optaplanner.examples.nurserostering.persistence.CustomBenchmarkIO</solutionFileIOClass>
<inputSolutionFile>data/nurserostering/import/importTest/Input0.xml</inputSolutionFile>
</problemBenchmarks>
我的问题是:
1.我是否缺少有关配置求解器的内容?
2。关于出口商 - 是否有必要添加我的所有计划
实体以便创建解决方案?
3。我的 NurseRosterConsoleApp 会导致基准测试出现问题吗?
4。解决方案在哪里创建?
好吧,我解决了我的问题。到目前为止,我认为某些方法会在后台读取 Solution
,但由于我调试了很多次,我意识到我需要这样做。
问题的解决方法很简单:
在 CustomBenchmarkIO class 中,在 Read 方法中,我只是输入了我用来读取 Solution
在我的另一个主要(我通常 运行 它),它工作。
此问题是
简而言之,我正在处理一个类似于 OptaPlanner 的 NurseRostering 问题。目前我需要实施一个基准测试,在那里我遇到了上面 link 的错误。
现在该错误已解决,我收到错误 The planningProblem (null) must not be null.
基于此,我认为我的 solution
未正确读取,我需要进行一些调整。我做了一些研究,做了很多调试,但没有找到我需要做的事情。
下面是我修改的所有配置,类和界面:
CustomBenchmarkIO:
public class CustomBenchmarkIO<Solution_> implements SolutionFileIO<Solution_>{
public String getInputFileExtension() {
return null;
}
public String getOutputFileExtension() {
return null;
}
public Solution_ read(File inputSolutionFile) {
return null;
}
@Override
public void write(Solution_ solution, File outputSolutionFile) {
}
}
Note:<Solution_> is what i currently have, i tried both <Solution> and <Solution_> , both didn't work.
NurseRosterBenchmarkApp:
public static void main(String[] args) {
new NurseRosteringBenchmarkApp().buildAndBenchmark(args);
}
public NurseRosteringBenchmarkApp() {
super(
new ArgOption("name",
"org/optaplanner/examples/nurserostering/benchmark/BenchmarkConfig.xml"));
}
Note: This is the default NurseRosterBenchmarkApp.
NurseRosterConsoleApp - 我仅从控制台将 NurseRosteringApp 配置为 运行。
public class NurseRosterConsoleApp extends CommonApp{
protected NurseRosterConsoleApp(String name, String description, String solverConfig, String iconResource) {
super(name, description, solverConfig, iconResource);
// TODO Auto-generated constructor stub
}
// function for reading the solution from a file
public static Solution readSolution(File inputFile, boolean inputXmlType) {
// reading from a solution xml file
if (inputXmlType) {
return (Solution) new NurseRosteringDao().readSolution(inputFile);
} else {
Solution solution;
InputStream in = null;
try {
in = new FileInputStream(inputFile);
SAXBuilder builder = new SAXBuilder(false);
Document document = builder.build(in);
XmlInputBuilder xmlInputBuilder = new NurseRosteringImporter.NurseRosteringInputBuilder();
xmlInputBuilder.setInputFile(inputFile);
xmlInputBuilder.setDocument(document);
try {
solution = (Solution) xmlInputBuilder.readSolution();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Exception in inputFile (" + inputFile + ")", e);
} catch (IllegalStateException e) {
throw new IllegalStateException("Exception in inputFile (" + inputFile + ")", e);
}
} catch (IOException e) {
throw new IllegalArgumentException("Could not read the file (" + inputFile.getName() + ").", e);
} catch (JDOMException e) {
throw new IllegalArgumentException("Could not parse the XML file (" + inputFile.getName() + ").", e);
} finally {
IOUtils.closeQuietly(in);
}
return solution;
}
}
public static void main(String[] args) {
File inputXml = new File(Settings.inputFilePath);
SolverFactory solverFactory = SolverFactory.createFromXmlResource(Settings.SOLVER_CONFIG);
Solver solver = solverFactory.buildSolver();
Solution unsolvedNurseRoster = readSolution(inputXml, Settings.inputXmlType);
NurseRoster nurseRoster = (NurseRoster) unsolvedNurseRoster;
solver.solve(unsolvedNurseRoster);
NurseRoster solvedNurseRoster = (NurseRoster) solver.getBestSolution();
try {
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected AbstractSolutionExporter createSolutionExporter() {
return new NurseRosteringExporter();
}
@Override
protected SolutionDao createSolutionDao() {
// TODO Auto-generated method stub
return null;
}
@Override
protected SolutionPanel createSolutionPanel() {
// TODO Auto-generated method stub
return null;
}
}
Note: I extended the CommonApp class, and added all of the unimplemented methods,
but it still didn't work. Also i configured the constructor to be the same as the OptaPlanner one
(although i think it's for the GUI, correct me if i'm wrong).
BenchmarkConfig - 同上一题
<plannerBenchmark>
<benchmarkDirectory>local/data/nurserostering/location</benchmarkDirectory>
<warmUpSecondsSpentLimit>5</warmUpSecondsSpentLimit>
<inheritedSolverBenchmark>
<problemBenchmarks>
<solutionFileIOClass>org.optaplanner.examples.nurserostering.persistence.CustomBenchmarkIO</solutionFileIOClass>
<inputSolutionFile>data/nurserostering/import/importTest/Input0.xml</inputSolutionFile>
</problemBenchmarks>
我的问题是:
1.我是否缺少有关配置求解器的内容?
2。关于出口商 - 是否有必要添加我的所有计划 实体以便创建解决方案?
3。我的 NurseRosterConsoleApp 会导致基准测试出现问题吗?
4。解决方案在哪里创建?
好吧,我解决了我的问题。到目前为止,我认为某些方法会在后台读取 Solution
,但由于我调试了很多次,我意识到我需要这样做。
问题的解决方法很简单:
在 CustomBenchmarkIO class 中,在 Read 方法中,我只是输入了我用来读取 Solution
在我的另一个主要(我通常 运行 它),它工作。