private SolverConfig mockSolverConfigForMoveThreadCountAuto(int mockCpuCount) { SolverConfig solverConfig = spy(SolverConfig.class); when(solverConfig.getAvailableProcessors()).thenReturn(mockCpuCount); solverConfig.setMoveThreadCount(SolverConfig.MOVE_THREAD_COUNT_AUTO); return solverConfig; }
@Test public void moveThreadCountIsCorrectlyResolvedWhenValueIsPositive() { SolverConfig solverConfig = new SolverConfig(); solverConfig.setMoveThreadCount("2"); assertEquals(Integer.valueOf(2), solverConfig.resolveMoveThreadCount()); }
@Test public void moveThreadCountThrowsExceptionWhenValueIsNegative() { SolverConfig solverConfig = new SolverConfig(); solverConfig.setMoveThreadCount("-6"); try { solverConfig.resolveMoveThreadCount(); fail("IllegalArgumentException should have been thrown."); } catch (IllegalArgumentException expectedException) { //expected } }
@Test public void moveThreadCountIsResolvedToNullWhenValueIsNone() { SolverConfig solverConfig = new SolverConfig(); solverConfig.setMoveThreadCount(SolverConfig.MOVE_THREAD_COUNT_NONE); assertNull(solverConfig.resolveMoveThreadCount()); }
protected SolverFactory<Solution_> buildSolverFactory() { SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig); // buildAndSolve() fills in minutesSpentLimit solverFactory.getSolverConfig().setTerminationConfig(new TerminationConfig()); if (MOVE_THREAD_COUNT_OVERRIDE != null) { solverFactory.getSolverConfig().setMoveThreadCount(MOVE_THREAD_COUNT_OVERRIDE); } return solverFactory; }
private void runSolvingAndVerifySolution(final int entityCount, final int valueCount, final String moveThreadCount) { SolverFactory<TestdataSolution> solverFactory = PlannerTestUtils.buildSolverFactory( TestdataSolution.class, TestdataEntity.class); solverFactory.getSolverConfig().setMoveThreadCount(moveThreadCount); Solver<TestdataSolution> solver = solverFactory.buildSolver(); TestdataSolution solution = createTestSolution(entityCount, valueCount); solution = solver.solve(solution); assertSolution(solver, solution); }
@Before public void createUninitializedSolutions() { checkRunTurtleTests(); final VehicleRoutingImporter importer = new VehicleRoutingImporter(); for (int i = 0; i < REPETITION_COUNT; i++) { File dataSetFile = new File(CommonApp.determineDataDir(vehicleRoutingApp.getDataDirName()), DATA_SET); VehicleRoutingSolution solution = importer.readSolution(dataSetFile); vehicleRoutingSolutions[i] = solution; } solverFactory = SolverFactory.createFromXmlResource(vehicleRoutingApp.getSolverConfig()); SolverConfig solverConfig = solverFactory.getSolverConfig(); solverConfig.getPhaseConfigList().forEach(phaseConfig -> { if (LocalSearchPhaseConfig.class.isAssignableFrom(phaseConfig.getClass())) { phaseConfig.setTerminationConfig(new TerminationConfig().withStepCountLimit(STEP_LIMIT)); } }); solverConfig.setMoveThreadCount(MOVE_THREAD_COUNT); solverConfig.setEnvironmentMode(EnvironmentMode.REPRODUCIBLE); }
protected SolverFactory<Solution_> buildSolverFactory(String bestScoreLimitString, EnvironmentMode environmentMode) { SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig); solverFactory.getSolverConfig().setEnvironmentMode(environmentMode); solverFactory.getSolverConfig().setTerminationConfig( new TerminationConfig().withBestScoreLimit(bestScoreLimitString)); solverFactory.getSolverConfig().setMoveThreadCount(moveThreadCount); return solverFactory; }
@Test(timeout = 5000L) public void customThreadFactoryClassIsUsed() { SolverFactory<TestdataSolution> solverFactory = PlannerTestUtils.buildSolverFactory( TestdataSolution.class, TestdataEntity.class); solverFactory.getSolverConfig().setThreadFactoryClass(MockThreadFactory.class); solverFactory.getSolverConfig().setMoveThreadCount("2"); Solver<TestdataSolution> solver = solverFactory.buildSolver(); TestdataSolution solution = createTestSolution(3, 5); solution = solver.solve(solution); assertSolution(solver, solution); assertTrue(MockThreadFactory.hasBeenCalled()); } }
protected SolverFactory<Solution_> buildSolverFactory() { SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig); // buildAndSolve() fills in minutesSpentLimit solverFactory.getSolverConfig().setTerminationConfig(new TerminationConfig()); if (MOVE_THREAD_COUNT_OVERRIDE != null) { solverFactory.getSolverConfig().setMoveThreadCount(MOVE_THREAD_COUNT_OVERRIDE); } return solverFactory; }
@Before public void createUninitializedSolutions() { checkRunTurtleTests(); final VehicleRoutingImporter importer = new VehicleRoutingImporter(); for (int i = 0; i < REPETITION_COUNT; i++) { File dataSetFile = new File(CommonApp.determineDataDir(vehicleRoutingApp.getDataDirName()), DATA_SET); VehicleRoutingSolution solution = importer.readSolution(dataSetFile); vehicleRoutingSolutions[i] = solution; } solverFactory = SolverFactory.createFromXmlResource(vehicleRoutingApp.getSolverConfig()); SolverConfig solverConfig = solverFactory.getSolverConfig(); solverConfig.getPhaseConfigList().forEach(phaseConfig -> { if (LocalSearchPhaseConfig.class.isAssignableFrom(phaseConfig.getClass())) { phaseConfig.setTerminationConfig(new TerminationConfig().withStepCountLimit(STEP_LIMIT)); } }); solverConfig.setMoveThreadCount(MOVE_THREAD_COUNT); solverConfig.setEnvironmentMode(EnvironmentMode.REPRODUCIBLE); }
protected SolverFactory<Solution_> buildSolverFactory(String bestScoreLimitString, EnvironmentMode environmentMode) { SolverFactory<Solution_> solverFactory = SolverFactory.createFromXmlResource(solverConfig); solverFactory.getSolverConfig().setEnvironmentMode(environmentMode); solverFactory.getSolverConfig().setTerminationConfig( new TerminationConfig().withBestScoreLimit(bestScoreLimitString)); solverFactory.getSolverConfig().setMoveThreadCount(moveThreadCount); return solverFactory; }