|
20 | 20 | import ai.timefold.solver.core.config.constructionheuristic.placer.PooledEntityPlacerConfig; |
21 | 21 | import ai.timefold.solver.core.config.constructionheuristic.placer.QueuedEntityPlacerConfig; |
22 | 22 | import ai.timefold.solver.core.config.constructionheuristic.placer.QueuedValuePlacerConfig; |
| 23 | +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; |
| 24 | +import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; |
23 | 25 | import ai.timefold.solver.core.config.solver.monitoring.MonitoringConfig; |
24 | 26 | import ai.timefold.solver.core.config.solver.monitoring.SolverMetric; |
| 27 | +import ai.timefold.solver.core.config.solver.termination.TerminationConfig; |
25 | 28 | import ai.timefold.solver.core.impl.phase.event.PhaseLifecycleListenerAdapter; |
26 | 29 | import ai.timefold.solver.core.impl.solver.DefaultSolver; |
27 | 30 | import ai.timefold.solver.core.impl.solver.scope.SolverScope; |
|
31 | 34 | import ai.timefold.solver.core.testdomain.list.TestdataListEntity; |
32 | 35 | import ai.timefold.solver.core.testdomain.list.TestdataListSolution; |
33 | 36 | import ai.timefold.solver.core.testdomain.list.TestdataListValue; |
| 37 | +import ai.timefold.solver.core.testdomain.list.TestdataListVarEasyScoreCalculator; |
34 | 38 | import ai.timefold.solver.core.testdomain.list.unassignedvar.TestdataAllowsUnassignedValuesListEasyScoreCalculator; |
35 | 39 | import ai.timefold.solver.core.testdomain.list.unassignedvar.TestdataAllowsUnassignedValuesListEntity; |
36 | 40 | import ai.timefold.solver.core.testdomain.list.unassignedvar.TestdataAllowsUnassignedValuesListSolution; |
37 | 41 | import ai.timefold.solver.core.testdomain.list.unassignedvar.TestdataAllowsUnassignedValuesListValue; |
| 42 | +import ai.timefold.solver.core.testdomain.multivar.list.multientity.TestdataListMultiEntityEasyScoreCalculator; |
| 43 | +import ai.timefold.solver.core.testdomain.multivar.list.multientity.TestdataListMultiEntityFirstEntity; |
| 44 | +import ai.timefold.solver.core.testdomain.multivar.list.multientity.TestdataListMultiEntitySecondEntity; |
| 45 | +import ai.timefold.solver.core.testdomain.multivar.list.multientity.TestdataListMultiEntitySolution; |
| 46 | +import ai.timefold.solver.core.testdomain.multivar.list.singleentity.TestdataListMultiVarEasyScoreCalculator; |
| 47 | +import ai.timefold.solver.core.testdomain.multivar.list.singleentity.TestdataListMultiVarEntity; |
| 48 | +import ai.timefold.solver.core.testdomain.multivar.list.singleentity.TestdataListMultiVarOtherValue; |
| 49 | +import ai.timefold.solver.core.testdomain.multivar.list.singleentity.TestdataListMultiVarSolution; |
| 50 | +import ai.timefold.solver.core.testdomain.multivar.list.singleentity.TestdataListMultiVarValue; |
38 | 51 | import ai.timefold.solver.core.testdomain.pinned.TestdataPinnedEntity; |
39 | 52 | import ai.timefold.solver.core.testdomain.pinned.TestdataPinnedSolution; |
40 | 53 | import ai.timefold.solver.core.testdomain.pinned.unassignedvar.TestdataPinnedAllowsUnassignedEntity; |
@@ -388,4 +401,121 @@ void failWithPooledEntityPlacers() { |
388 | 401 | "The Construction Heuristic configuration (ConstructionHeuristicPhaseConfig) does not support multiple configurations when using the pooled placer configuration PooledEntityPlacerConfig."); |
389 | 402 | } |
390 | 403 |
|
| 404 | + @Test |
| 405 | + void failMultiEntityWithListAndBasicVariables() { |
| 406 | + var solverConfig = PlannerTestUtils.buildSolverConfig( |
| 407 | + TestdataListMultiEntitySolution.class, TestdataListMultiEntityFirstEntity.class, |
| 408 | + TestdataListMultiEntitySecondEntity.class) |
| 409 | + .withPhases(new ConstructionHeuristicPhaseConfig() |
| 410 | + .withTerminationConfig(new TerminationConfig().withStepCountLimit(16))) |
| 411 | + .withEasyScoreCalculatorClass(TestdataListMultiVarEasyScoreCalculator.class); |
| 412 | + |
| 413 | + var problem = TestdataListMultiEntitySolution.generateUninitializedSolution(2, 2, 2); |
| 414 | + assertThatCode(() -> PlannerTestUtils.solve(solverConfig, problem)) |
| 415 | + .hasMessageContaining("has no entityClass configured and because there are multiple in the entityClassSet") |
| 416 | + .hasMessageContaining("it cannot be deduced automatically"); |
| 417 | + } |
| 418 | + |
| 419 | + @Test |
| 420 | + void solveWithListAndBasicVariables() { |
| 421 | + var solverConfig = PlannerTestUtils.buildSolverConfig( |
| 422 | + TestdataListMultiVarSolution.class, TestdataListMultiVarEntity.class, TestdataListMultiVarValue.class, |
| 423 | + TestdataListMultiVarOtherValue.class) |
| 424 | + .withPhases(new ConstructionHeuristicPhaseConfig() |
| 425 | + .withTerminationConfig(new TerminationConfig().withStepCountLimit(16))) |
| 426 | + .withEasyScoreCalculatorClass(TestdataListMultiVarEasyScoreCalculator.class); |
| 427 | + |
| 428 | + var problem = TestdataListMultiVarSolution.generateUninitializedSolution(2, 2, 2); |
| 429 | + var solution = PlannerTestUtils.solve(solverConfig, problem); |
| 430 | + assertThat(solution.getEntityList().stream() |
| 431 | + .filter(e -> e.getBasicValue() == null || e.getSecondBasicValue() == null || e.getValueList().isEmpty())) |
| 432 | + .isEmpty(); |
| 433 | + } |
| 434 | + |
| 435 | + @Test |
| 436 | + void solveCustomConfigurationMultiEntityWithListAndBasicVariables() { |
| 437 | + var valueSelectorConfig = new ValueSelectorConfig("valueList") |
| 438 | + .withId("valueList"); |
| 439 | + var mimicReplayingValueSelectorConfig = new ValueSelectorConfig() |
| 440 | + .withMimicSelectorRef("valueList") |
| 441 | + .withVariableName("valueList"); |
| 442 | + var valuePlacerConfig = new QueuedValuePlacerConfig() |
| 443 | + .withValueSelectorConfig(valueSelectorConfig) |
| 444 | + .withMoveSelectorConfig(new ListChangeMoveSelectorConfig() |
| 445 | + .withValueSelectorConfig(mimicReplayingValueSelectorConfig)) |
| 446 | + .withEntityClass(TestdataListMultiEntityFirstEntity.class); |
| 447 | + var entityPlacerConfig = new QueuedEntityPlacerConfig(); |
| 448 | + |
| 449 | + var solverConfig = PlannerTestUtils.buildSolverConfig( |
| 450 | + TestdataListMultiEntitySolution.class, TestdataListMultiEntityFirstEntity.class, |
| 451 | + TestdataListMultiEntitySecondEntity.class) |
| 452 | + .withPhases(new ConstructionHeuristicPhaseConfig() |
| 453 | + .withEntityPlacerConfigList(valuePlacerConfig, entityPlacerConfig) |
| 454 | + .withTerminationConfig(new TerminationConfig().withStepCountLimit(16))) |
| 455 | + .withEasyScoreCalculatorClass(TestdataListMultiEntityEasyScoreCalculator.class); |
| 456 | + |
| 457 | + var problem = TestdataListMultiEntitySolution.generateUninitializedSolution(2, 2, 2); |
| 458 | + var solution = PlannerTestUtils.solve(solverConfig, problem); |
| 459 | + assertThat(solution.getEntityList().stream() |
| 460 | + .filter(e -> e.getValueList().isEmpty())) |
| 461 | + .isEmpty(); |
| 462 | + assertThat(solution.getOtherEntityList().stream() |
| 463 | + .filter(e -> e.getBasicValue() == null || e.getSecondBasicValue() == null)) |
| 464 | + .isEmpty(); |
| 465 | + } |
| 466 | + |
| 467 | + @Test |
| 468 | + void solveCustomConfigurationWithListAndBasicVariables() { |
| 469 | + var valueSelectorConfig = new ValueSelectorConfig("valueList") |
| 470 | + .withId("valueList"); |
| 471 | + var mimicReplayingValueSelectorConfig = new ValueSelectorConfig() |
| 472 | + .withMimicSelectorRef("valueList") |
| 473 | + .withVariableName("valueList"); |
| 474 | + var valuePlacerConfig = new QueuedValuePlacerConfig() |
| 475 | + .withValueSelectorConfig(valueSelectorConfig) |
| 476 | + .withMoveSelectorConfig(new ListChangeMoveSelectorConfig() |
| 477 | + .withValueSelectorConfig(mimicReplayingValueSelectorConfig)); |
| 478 | + var entityPlacerConfig = new QueuedEntityPlacerConfig(); |
| 479 | + |
| 480 | + var solverConfig = PlannerTestUtils.buildSolverConfig( |
| 481 | + TestdataListMultiVarSolution.class, TestdataListMultiVarEntity.class, TestdataListMultiVarValue.class, |
| 482 | + TestdataListMultiVarOtherValue.class) |
| 483 | + .withPhases(new ConstructionHeuristicPhaseConfig() |
| 484 | + .withEntityPlacerConfigList(valuePlacerConfig, entityPlacerConfig) |
| 485 | + .withTerminationConfig(new TerminationConfig().withStepCountLimit(16))) |
| 486 | + .withEasyScoreCalculatorClass(TestdataListMultiVarEasyScoreCalculator.class); |
| 487 | + |
| 488 | + var problem = TestdataListMultiVarSolution.generateUninitializedSolution(2, 2, 2); |
| 489 | + var solution = PlannerTestUtils.solve(solverConfig, problem); |
| 490 | + assertThat(solution.getEntityList().stream() |
| 491 | + .filter(e -> e.getBasicValue() == null || e.getSecondBasicValue() == null || e.getValueList().isEmpty())) |
| 492 | + .isEmpty(); |
| 493 | + } |
| 494 | + |
| 495 | + @Test |
| 496 | + void solveCustomConfigurationWithListVariables() { |
| 497 | + var valueSelectorConfig = new ValueSelectorConfig("valueList") |
| 498 | + .withId("valueList"); |
| 499 | + var mimicReplayingValueSelectorConfig = new ValueSelectorConfig() |
| 500 | + .withMimicSelectorRef("valueList") |
| 501 | + .withVariableName("valueList"); |
| 502 | + var valuePlacerConfig = new QueuedValuePlacerConfig() |
| 503 | + .withValueSelectorConfig(valueSelectorConfig) |
| 504 | + .withMoveSelectorConfig(new ListChangeMoveSelectorConfig() |
| 505 | + .withValueSelectorConfig(mimicReplayingValueSelectorConfig)); |
| 506 | + |
| 507 | + var solverConfig = PlannerTestUtils.buildSolverConfig( |
| 508 | + TestdataListSolution.class, TestdataListEntity.class, TestdataListValue.class) |
| 509 | + .withPhases(new ConstructionHeuristicPhaseConfig() |
| 510 | + .withEntityPlacerConfigList(valuePlacerConfig) |
| 511 | + .withTerminationConfig(new TerminationConfig().withStepCountLimit(16))) |
| 512 | + .withEasyScoreCalculatorClass(TestdataListVarEasyScoreCalculator.class); |
| 513 | + |
| 514 | + var problem = TestdataListSolution.generateUninitializedSolution(2, 2); |
| 515 | + var solution = PlannerTestUtils.solve(solverConfig, problem); |
| 516 | + assertThat(solution.getEntityList().stream() |
| 517 | + .filter(e -> e.getValueList().isEmpty())) |
| 518 | + .isEmpty(); |
| 519 | + } |
| 520 | + |
391 | 521 | } |
0 commit comments