我从昨天开始研究Optaplanner。 首先,我分析了示例中提供的TSP问题,从头开始创建一个空Java项目并重写所有代码。
OptaPlanner的概念和文档(暂时!)对我来说很清楚,但解决后TspSolution中的 locationList 总是空的。
我已经阅读了10x的文档/代码,我变得疯了! 你有什么想法吗?列表中的插入必须在easy / increment score计算器中手动完成?
非常感谢,欢迎任何帮助!
如果是以下日志,你会找到一个例子。
START SOLVING !
INFO Solving started: time spent (17), best score (-4init/0), environment mode (REPRODUCIBLE), random (JDK with seed 0).
INFO Construction Heuristic phase (0) ended: time spent (46), best score (-6100), score calculation speed (227/sec), step total (4).
INFO Local Search phase (1) ended: time spent (5000), best score (-6100), score calculation speed (303348/sec), step total (1502180).
INFO Solving ended: time spent (5000), best score (-6100), score calculation speed (300437/sec), phase total (2), environment mode (REPRODUCIBLE).
SOLVED !!!!
TspSolution{locationList=[], domicile=DOMICILE, visitList=[VISIT_01, VISIT_02, VISIT_03, VISIT_04], score=-6100}
主要课程:
public static void main(String[] args)
{
System.out.println("START SOLVING !");
// Build the Solver
// SolverFactory<TspSolution> solverFactory = SolverFactory.createFromXmlResource("test.xml", TSPTest.class.getClassLoader());
SolverFactory<TspSolution> solverFactory = SolverFactory.createEmpty();
SolverConfig solverConfig = solverFactory.getSolverConfig();
ScanAnnotatedClassesConfig scanAnnotatedClassesConfig = new ScanAnnotatedClassesConfig();
scanAnnotatedClassesConfig.setPackageIncludeList(Arrays.asList("com.coursierprive.streams.job.utils.tsp"));
solverConfig.setScanAnnotatedClassesConfig(scanAnnotatedClassesConfig);
ScoreDirectorFactoryConfig scoreDirectorFactoryConfig = new ScoreDirectorFactoryConfig();
// scoreDirectorFactoryConfig.setEasyScoreCalculatorClass(CloudBalancingEasyScoreCalculator.class);
scoreDirectorFactoryConfig.setIncrementalScoreCalculatorClass(TspIncrementalScoreCalculator.class);
scoreDirectorFactoryConfig.setInitializingScoreTrend("ONLY_DOWN");
solverConfig.setScoreDirectorFactoryConfig(scoreDirectorFactoryConfig);
TerminationConfig terminationConfig = new TerminationConfig();
terminationConfig.setSecondsSpentLimit(5L);
solverConfig.setTerminationConfig(terminationConfig);
Solver<TspSolution> solver = solverFactory.buildSolver();
TspSolution initialSolution = new TspSolution();
initialSolution.setDomicile(new Domicile(new Location("DOMICILE", 42.0, 2.0)));
initialSolution.getVisitList().add(new Visit("V1", new Location("VISIT_01", 42.0, 3.0)));
initialSolution.getVisitList().add(new Visit("V2", new Location("VISIT_02", 43.0, 3.0)));
initialSolution.getVisitList().add(new Visit("V3", new Location("VISIT_03", 44.0, 3.0)));
initialSolution.getVisitList().add(new Visit("V4", new Location("VISIT_04", 45.0, 3.0)));
// Solve the problem
TspSolution optimizedSolution = solver.solve(initialSolution);
System.out.println("SOLVED !!!!");
System.out.println(optimizedSolution);
}
答案 0 :(得分:0)
在示例中,如果已实施,向Visit
或Docimicile
实例添加位置不会自动将其添加到解决方案的位置列表中。
解决方案首先具有位置列表的原因是将这些实例作为问题事实传递给drools(如果您使用此类计算)。但是DRL分数规则可能与Location无法匹配,因此TspSolution甚至可能不需要locationList。