protected SolverFactory buildSolverFactory() { SolverFactory solverFactory = new XmlSolverFactory(createSolverConfigResource()); TerminationConfig terminationConfig = new TerminationConfig(); // buildAndSolve() fills in maximumMinutesSpend solverFactory.getSolverConfig().setTerminationConfig(terminationConfig); return solverFactory; }
protected Solution buildAndSolve( SolverFactory solverFactory, EnvironmentMode environmentMode, Solution planningProblem, long maximumMinutesSpend) { solverFactory .getSolverConfig() .getTerminationConfig() .setMaximumMinutesSpend(maximumMinutesSpend); SolverConfig solverConfig = solverFactory.getSolverConfig(); solverConfig.setEnvironmentMode(environmentMode); ScoreDirectorFactoryConfig assertionScoreDirectorFactory = createOverwritingAssertionScoreDirectorFactory(); if (assertionScoreDirectorFactory != null && environmentMode.isAsserted()) { solverConfig .getScoreDirectorFactoryConfig() .setAssertionScoreDirectorFactory(assertionScoreDirectorFactory); } Solver solver = solverFactory.buildSolver(); solver.setPlanningProblem(planningProblem); solver.solve(); Solution bestSolution = solver.getBestSolution(); if (bestSolution == null) { // Solver didn't make it past initialization // TODO remove me once getBestSolution() never // returns null bestSolution = planningProblem; } return bestSolution; }
@Test public void trackLocalSearch() { SolverFactory<NQueens> solverFactory = SolverFactory.createFromXmlResource(NQueensApp.SOLVER_CONFIG); SolverConfig solverConfig = solverFactory.getSolverConfig(); NQueensGenerator generator = new NQueensGenerator(); NQueens planningProblem = NQueensSolutionInitializer.initialize(generator.createNQueens(N)); LocalSearchPhaseConfig localSearchPhaseConfig = new LocalSearchPhaseConfig(); localSearchPhaseConfig.setAcceptorConfig(acceptorConfig); localSearchPhaseConfig.setForagerConfig(localSearchForagerConfig); localSearchPhaseConfig.getForagerConfig().setBreakTieRandomly(false); localSearchPhaseConfig.setMoveSelectorConfig(new ChangeMoveSelectorConfig()); localSearchPhaseConfig.getMoveSelectorConfig().setSelectionOrder(SelectionOrder.ORIGINAL); localSearchPhaseConfig.setTerminationConfig(new TerminationConfig()); localSearchPhaseConfig.getTerminationConfig().setStepCountLimit(20); solverConfig.getPhaseConfigList().set(1, localSearchPhaseConfig); NQueensStepTracker listener = new NQueensStepTracker(); DefaultSolver<NQueens> solver = (DefaultSolver<NQueens>) solverFactory.buildSolver(); solver.addPhaseLifecycleListener(listener); NQueens bestSolution = solver.solve(planningProblem); assertNotNull(bestSolution); assertTrackingList(expectedCoordinates, listener.getTrackingList()); }
protected SolverFactory buildSolverFactory() { SolverFactory solverFactory = SolverFactory.createFromXmlResource(createSolverConfigResource()); SolverConfig solverConfig = solverFactory.getSolverConfig(); solverConfig.setTerminationConfig(new TerminationConfig()); ConstructionHeuristicPhaseConfig constructionHeuristicPhaseConfig = new ConstructionHeuristicPhaseConfig(); constructionHeuristicPhaseConfig.setConstructionHeuristicType(constructionHeuristicType); solverConfig.setPhaseConfigList(Arrays.<PhaseConfig>asList(constructionHeuristicPhaseConfig)); return solverFactory; }
@Override protected SolverFactory<Solution_> buildSolverFactory() { SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(createSolverConfigResource()); SolverConfig solverConfig = solverFactory.getSolverConfig(); solverConfig.setTerminationConfig(new TerminationConfig()); ExhaustiveSearchPhaseConfig exhaustiveSearchPhaseConfig = new ExhaustiveSearchPhaseConfig(); exhaustiveSearchPhaseConfig.setExhaustiveSearchType(exhaustiveSearchType); solverConfig.setPhaseConfigList(Arrays.asList(exhaustiveSearchPhaseConfig)); return solverFactory; }
@Override protected Solver createSolver() { SolverFactory solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG); return solverFactory.buildSolver(); }
public VehicleRoutingDistanceTypeComparison() { vehicleRoutingDao = new VehicleRoutingDao(); SolverFactory solverFactory = SolverFactory.createFromXmlResource(VehicleRoutingApp.SOLVER_CONFIG); scoreDirectorFactory = solverFactory.buildSolver().getScoreDirectorFactory(); }
@Override protected Solver<CloudBalance> createSolver() { SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG); return solverFactory.buildSolver(); }