Search in sources :

Example 26 with TerminationConfig

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;
}
Also used : TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig)

Example 27 with 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();
}
Also used : ScoreDirectorFactoryConfig(org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig) TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig) CloudBalance(org.optaplanner.examples.cloudbalancing.domain.CloudBalance) SolverConfig(org.optaplanner.core.config.solver.SolverConfig) CloudBalanceCalculateCountTermination(org.jboss.qa.brms.performance.examples.cloudbalancing.termination.CloudBalanceCalculateCountTermination)

Example 28 with TerminationConfig

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;
}
Also used : TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig)

Example 29 with 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);
}
Also used : ScoreDirectorFactoryConfig(org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig) TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig) CloudBalance(org.kie.karaf.itest.planner.domain.CloudBalance) LocalSearchPhaseConfig(org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig) ConstructionHeuristicPhaseConfig(org.optaplanner.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig) SolverConfig(org.optaplanner.core.config.solver.SolverConfig)

Example 30 with TerminationConfig

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());
}
Also used : PredictionInput(org.kie.kogito.explainability.model.PredictionInput) Prediction(org.kie.kogito.explainability.model.Prediction) CounterfactualPrediction(org.kie.kogito.explainability.model.CounterfactualPrediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) CounterfactualPrediction(org.kie.kogito.explainability.model.CounterfactualPrediction) CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) TerminationConfig(org.optaplanner.core.config.solver.termination.TerminationConfig) Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Value(org.kie.kogito.explainability.model.Value) SolverConfig(org.optaplanner.core.config.solver.SolverConfig) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TerminationConfig (org.optaplanner.core.config.solver.termination.TerminationConfig)32 SolverConfig (org.optaplanner.core.config.solver.SolverConfig)17 CounterfactualPrediction (org.kie.kogito.explainability.model.CounterfactualPrediction)10 Prediction (org.kie.kogito.explainability.model.Prediction)10 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)10 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)10 Feature (org.kie.kogito.explainability.model.Feature)9 Output (org.kie.kogito.explainability.model.Output)9 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)9 LinkedList (java.util.LinkedList)7 Test (org.junit.jupiter.api.Test)7 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)6 Value (org.kie.kogito.explainability.model.Value)6 CounterfactualConfig (org.kie.kogito.explainability.local.counterfactual.CounterfactualConfig)5 CounterfactualExplainer (org.kie.kogito.explainability.local.counterfactual.CounterfactualExplainer)5 CounterfactualResult (org.kie.kogito.explainability.local.counterfactual.CounterfactualResult)5 LocalSearchPhaseConfig (org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig)5 Random (java.util.Random)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ScoreDirectorFactoryConfig (org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig)4