use of org.optaplanner.core.config.solver.termination.TerminationConfig in project kie-benchmarks by kiegroup.
the class VRPTailChainSwapMoveSelectorBenchmark method getTerminationConfig.
@Override
public TerminationConfig getTerminationConfig() {
TerminationConfig terminationConfig = new TerminationConfig();
terminationConfig.setTerminationClass(EasyVRPCalculateCountTermination.class);
return terminationConfig;
}
use of org.optaplanner.core.config.solver.termination.TerminationConfig in project kie-benchmarks by kiegroup.
the class CloudBalanceBenchmark method createSolver.
@Override
protected Solver<CloudBalance> createSolver() {
// the pre-defined configuration in CloudBalancing cannot be used
SolverConfig solverConfig = new SolverConfig();
solverConfig.withEntityClasses(CloudProcess.class);
solverConfig.withSolutionClass(CloudBalance.class);
ScoreDirectorFactoryConfig scoreDirectorFactoryConfig = new ScoreDirectorFactoryConfig();
scoreDirectorFactoryConfig.setInitializingScoreTrend("ONLY_DOWN");
scoreDirectorFactoryConfig.setConstraintProviderClass(CloudBalancingConstraintProvider.class);
solverConfig.setScoreDirectorFactoryConfig(scoreDirectorFactoryConfig);
solverConfig.setTerminationConfig(new TerminationConfig().withTerminationClass(CloudBalanceCalculateCountTermination.class));
SolverFactory<CloudBalance> solverFactory = SolverFactory.create(solverConfig);
return solverFactory.buildSolver();
}
use of org.optaplanner.core.config.solver.termination.TerminationConfig in project kie-benchmarks by kiegroup.
the class AbstractCloudBalanceHeuristicBenchmark method getTerminationConfig.
@Override
public TerminationConfig getTerminationConfig() {
TerminationConfig terminationConfig = new TerminationConfig();
terminationConfig.setStepCountLimit(500);
return terminationConfig;
}
use of org.optaplanner.core.config.solver.termination.TerminationConfig in project droolsjbpm-integration by kiegroup.
the class PlannerCloudBalanceIntegrationTest method solveSolution.
private void solveSolution(CloudBalance cloudBalance) {
LocalSearchPhaseConfig localSearchPhaseConfig = new LocalSearchPhaseConfig();
localSearchPhaseConfig.setTerminationConfig(new TerminationConfig().withStepCountLimit(20));
SolverConfig config = new SolverConfig().withEntityClassList(Arrays.asList(CloudProcess.class)).withSolutionClass(CloudBalance.class).withScoreDirectorFactory(new ScoreDirectorFactoryConfig().withIncrementalScoreCalculatorClass(CloudBalancingIncrementalScoreCalculator.class)).withPhases(new ConstructionHeuristicPhaseConfig().withConstructionHeuristicType(ConstructionHeuristicType.FIRST_FIT_DECREASING), localSearchPhaseConfig);
Assert.assertEquals(cloudBalance.getScore().getHardScore(), Integer.MIN_VALUE);
Assert.assertEquals(cloudBalance.getScore().getSoftScore(), Integer.MIN_VALUE);
SolverFactory<CloudBalance> solverFactory = SolverFactory.create(config);
Solver<CloudBalance> solver = solverFactory.buildSolver();
solver.solve(cloudBalance);
CloudBalance solution = solver.getBestSolution();
Assert.assertNotEquals(solution.getScore().getHardScore(), Integer.MIN_VALUE);
Assert.assertNotEquals(solution.getScore().getSoftScore(), Integer.MIN_VALUE);
}
use of org.optaplanner.core.config.solver.termination.TerminationConfig in project kogito-apps by kiegroup.
the class CounterfactualExplainerTest method testConsumers.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2 })
void testConsumers(int seed) throws ExecutionException, InterruptedException, TimeoutException {
Random random = new Random();
random.setSeed(seed);
final List<Output> goal = List.of(new Output("inside", Type.BOOLEAN, new Value(true), 0.0));
List<Feature> features = new LinkedList<>();
features.add(FeatureFactory.newNumericalFeature("f-num1", 100.0, NumericalFeatureDomain.create(0.0, 1000.0)));
features.add(FeatureFactory.newNumericalFeature("f-num2", 100.0, NumericalFeatureDomain.create(0.0, 1000.0)));
features.add(FeatureFactory.newNumericalFeature("f-num3", 100.0, NumericalFeatureDomain.create(0.0, 1000.0)));
features.add(FeatureFactory.newNumericalFeature("f-num4", 100.0, NumericalFeatureDomain.create(0.0, 1000.0)));
final TerminationConfig terminationConfig = new TerminationConfig().withScoreCalculationCountLimit(10_000L);
// for the purpose of this test, only a few steps are necessary
final SolverConfig solverConfig = SolverConfigBuilder.builder().withTerminationConfig(terminationConfig).build();
solverConfig.setRandomSeed((long) seed);
solverConfig.setEnvironmentMode(EnvironmentMode.REPRODUCIBLE);
@SuppressWarnings("unchecked") final Consumer<CounterfactualResult> assertIntermediateCounterfactualNotNull = mock(Consumer.class);
final CounterfactualConfig counterfactualConfig = new CounterfactualConfig().withSolverConfig(solverConfig).withGoalThreshold(0.01);
final CounterfactualExplainer counterfactualExplainer = new CounterfactualExplainer(counterfactualConfig);
PredictionInput input = new PredictionInput(features);
final double center = 500.0;
final double epsilon = 10.0;
final PredictionProvider model = TestUtils.getSumThresholdModel(center, epsilon);
PredictionOutput output = new PredictionOutput(goal);
Prediction prediction = new CounterfactualPrediction(input, output, null, UUID.randomUUID(), null);
final CounterfactualResult counterfactualResult = counterfactualExplainer.explainAsync(prediction, model, assertIntermediateCounterfactualNotNull).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
for (CounterfactualEntity entity : counterfactualResult.getEntities()) {
logger.debug("Entity: {}", entity);
}
logger.debug("Outputs: {}", counterfactualResult.getOutput().get(0).getOutputs());
// At least one intermediate result is generated
verify(assertIntermediateCounterfactualNotNull, atLeast(1)).accept(any());
}
Aggregations