基准配置 - 错误:PlanningProblem(null)不能为空

时间:2016-05-28 01:26:18

标签: optaplanner

这个问题是Implementing a SolutionIO Interface for Benchmarking的延续。

简而言之,我正在研究类似于OptaPlanner的NurseRostering问题。目前我需要实现一个基准测试,我从上面的链接中遇到了错误。

现在该错误已经解决,我收到错误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。解决方案在哪里创建?

1 个答案:

答案 0 :(得分:1)

我解决了我的问题。到现在为止,我认为有些方法在后台读取Solution,但由于我调试了很多次,我意识到我需要这样做。

解决问题的方法很简单:

CustomBenchmarkIO 类中,在读取方法中,我只输入了用于阅读其他主要内容Solution的内容(我通常运行它),它有效。