public SolverConfig(SolverConfig inheritedConfig) { inherit(inheritedConfig); if (environmentMode == EnvironmentMode.PRODUCTION) { environmentMode = EnvironmentMode.NON_REPRODUCIBLE; } }
public void offerRandomSeedFromSubSingleIndex(long subSingleIndex) { if (environmentMode == null || environmentMode.isReproducible()) { if (randomFactoryClass == null && randomSeed == null) { randomSeed = subSingleIndex; } } }
/** * @param solverConfigContext never null */ public EmptySolverFactory(SolverConfigContext solverConfigContext) { super(solverConfigContext); solverConfig = new SolverConfig(); }
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; }
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; }
protected Solver<CloudBalance> buildSolver() { SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource( CloudBalancingApp.SOLVER_CONFIG); solverFactory.getSolverConfig().setDaemon(true); solverFactory.getSolverConfig().setTerminationConfig(new TerminationConfig().withBestScoreFeasible(true)); return solverFactory.buildSolver(); }
@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(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()); } }
@Override public Solver<Solution_> buildSolver() { if (solverConfig == null) { throw new IllegalStateException("The solverConfig (" + solverConfig + ") is null," + " call configure(...) first."); } return solverConfig.buildSolver(solverConfigContext); }
private SolverConfig mockSolverConfigForMoveThreadCountAuto(int mockCpuCount) { SolverConfig solverConfig = spy(SolverConfig.class); when(solverConfig.getAvailableProcessors()).thenReturn(mockCpuCount); solverConfig.setMoveThreadCount(SolverConfig.MOVE_THREAD_COUNT_AUTO); return solverConfig; }
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); }
@Test public void moveThreadCountAutoIsResolvedToNullWhenCpuCountIsNegative() { final int cpuCount = -2; assertNull(mockSolverConfigForMoveThreadCountAuto(cpuCount).resolveMoveThreadCount()); }
public EnvironmentMode getEnvironmentMode() { return solverConfig.determineEnvironmentMode(); }
@Test(timeout = 5000L) public void solvingWithTooHighThreadCountFinishes() { runSolvingAndVerifySolution(10, 20, "256"); }
public <Solution_> BestSolutionRecaller<Solution_> buildBestSolutionRecaller(EnvironmentMode environmentMode) { BestSolutionRecaller<Solution_> bestSolutionRecaller = new BestSolutionRecaller<>(); if (environmentMode.isNonIntrusiveFullAsserted()) { bestSolutionRecaller.setAssertInitialScoreFromScratch(true); bestSolutionRecaller.setAssertShadowVariablesAreNotStale(true); bestSolutionRecaller.setAssertBestScoreIsUnmodified(true); } return bestSolutionRecaller; }
@Test public void moveThreadCountIsResolvedToNullWhenValueIsNone() { SolverConfig solverConfig = new SolverConfig(); solverConfig.setMoveThreadCount(SolverConfig.MOVE_THREAD_COUNT_NONE); assertNull(solverConfig.resolveMoveThreadCount()); }
@Override public SolverFactory<Solution_> cloneSolverFactory() { if (solverConfig == null) { throw new IllegalStateException("The solverConfig (" + solverConfig + ") is null," + " call configure(...) first."); } SolverConfig solverConfigClone = new SolverConfig(solverConfig); return new EmptySolverFactory<>(solverConfigContext, solverConfigClone); }
@Test public void moveThreadCountAutoIsCorrectlyResolvedWhenCpuCountIsPositive() { final int cpuCount = 16; assertEquals(Integer.valueOf(cpuCount - 2), mockSolverConfigForMoveThreadCountAuto(cpuCount).resolveMoveThreadCount()); }
@Ignore("PLANNER-1180") @Test(timeout = 5000L) public void solvingOfVerySmallProblemFinishes() { runSolvingAndVerifySolution(1, 1, "2"); }
@Test public void moveThreadCountIsCorrectlyResolvedWhenValueIsPositive() { SolverConfig solverConfig = new SolverConfig(); solverConfig.setMoveThreadCount("2"); assertEquals(Integer.valueOf(2), solverConfig.resolveMoveThreadCount()); }