Skip to content

Commit f16de02

Browse files
committed
docs: fix assorted issues
1 parent ec2f492 commit f16de02

2 files changed

Lines changed: 19 additions & 24 deletions

File tree

docs/src/modules/ROOT/pages/optimization-algorithms/move-selector-reference.adoc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,9 @@ For example, don't change a gym lecture to a room which is not a gym room.
436436
It's usually better to not use move filtering for such cases,
437437
because it allows the metaheuristics to temporarily break hard constraints to escape local optima.
438438
+
439-
[NOTE]
440-
====
441-
Any built-in hard constraint must probably be filtered on every move type of every solver phase.
439+
NOTE: Any built-in hard constraint must probably be filtered on every move type of every solver phase.
442440
For example if it filters the change move of Local Search, it must also filter the swap move that swaps the room of a gym lecture with another lecture for which the other lecture's original room isn't a gym room.
443441
Furthermore, it must also filter the change moves of the Construction Heuristics (which requires an advanced configuration).
444-
====
445442
446443
If a move is unaccepted by the filter, it's not executed and the score isn't calculated.
447444
@@ -459,21 +456,16 @@ public interface SelectionFilter<Solution_, T> {
459456
----
460457
461458
Implement the `accept` method to return `false` on a discarded `selection` (see below).
459+
Implementations are expected to be stateless,
460+
as the solver may choose to reuse them in different contexts.
461+
462462
Filtered selection can happen on any Selector in the selector tree, including any ``MoveSelector``, `EntitySelector`
463463
or ``ValueSelector``.
464464
It works with any `cacheType` and ``selectionOrder``.
465465
466-
[NOTE]
467-
====
468466
Apply the filter on the lowest level possible.
469467
In most cases, you'll need to know both the entity and the value involved so you'll have to apply it on the move selector.
470-
====
471468
472-
[NOTE]
473-
====
474-
`SelectionFilter` implementations are expected to be stateless.
475-
The solver may choose to reuse them in different contexts.
476-
====
477469
478470
[#filteredMoveSelection]
479471
===== Filtered move selection
@@ -482,12 +474,14 @@ Unaccepted moves will not be selected and will therefore never need to be undone
482474
483475
[source,java,options="nowrap"]
484476
----
485-
public class DifferentCourseSwapMoveFilter implements SelectionFilter<CourseSchedule, SwapMove> {
477+
public class DifferentCourseSwapMoveFilter
478+
implements SelectionFilter<CourseSchedule, SwapMove<CourseSchedule, Lecture>> {
486479
487480
@Override
488-
public boolean accept(ScoreDirector<CourseSchedule> scoreDirector, SwapMove move) {
489-
Lecture leftLecture = (Lecture) move.getLeftEntity();
490-
Lecture rightLecture = (Lecture) move.getRightEntity();
481+
public boolean accept(ScoreDirector<CourseSchedule> scoreDirector,
482+
SwapMove<CourseSchedule, Lecture> move) {
483+
var leftLecture = (Lecture) move.getLeftEntity();
484+
var rightLecture = (Lecture) move.getRightEntity();
491485
return !leftLecture.getCourse().equals(rightLecture.getCourse());
492486
}
493487
@@ -999,6 +993,7 @@ only set the distribution type (so without a `distributionSizeMaximum` parameter
999993
<betaDistributionBeta>5</betaDistributionBeta>
1000994
</nearbySelection>
1001995
----
996+
1002997
[#basicMoveSelectors]
1003998
== Move selectors for basic variables
1004999

docs/src/modules/ROOT/pages/optimization-algorithms/neighborhoods.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ from the `Timetable` planning solution class:
176176
----
177177
PlanningSolutionMetaModel<Timetable> solutionMetaModel = ...; // The solver will give this to you.
178178
PlanningVariableMetaModel<Timetable, Lesson, Timeslot> timeslotVariable =
179-
solutionMetaModel.entity(Lesson.class)
180-
.genuineVariable("timeslot");
179+
solutionMetaModel.genuineEntity(Lesson.class)
180+
.basicVariable("timeslot", Timeslot.class);
181181
----
182182

183183
If any of the entities or variables cannot be found,
@@ -189,8 +189,8 @@ The code above can often be simplified with Java's local type inference:
189189
[source,java,options="nowrap"]
190190
----
191191
var solutionMetaModel = ...; // The solver will give this to you.
192-
var timeslotVariable = solutionMetaModel.entity(Lesson.class)
193-
.genuineVariable("timeslot", Timeslot.class);
192+
var timeslotVariable = solutionMetaModel.genuineEntity(Lesson.class)
193+
.basicVariable("timeslot", Timeslot.class);
194194
----
195195

196196
NOTE: Long-time users of Timefold Solver may be familiar with the concept of variable descriptors.
@@ -343,7 +343,7 @@ void testChangeMove() {
343343
var newRoom = timetable.getRooms().get(1);
344344
345345
var solutionMetaModel = PlanningSolutionMetaModel.of(Timetable.class, Lesson.class);
346-
var variableMetaModel = solutionMetaModel.entity(Lesson.class)
346+
var variableMetaModel = solutionMetaModel.genuineEntity(Lesson.class)
347347
.basicVariable("room", Room.class);
348348
349349
var move = Moves.change(variableMetaModel, lesson, newRoom);
@@ -374,7 +374,7 @@ void testMoveThenUndo() {
374374
var newRoom = timetable.getRooms().get(1);
375375
376376
var solutionMetaModel = PlanningSolutionMetaModel.of(Timetable.class, Lesson.class);
377-
var variableMetaModel = solutionMetaModel.entity(Lesson.class)
377+
var variableMetaModel = solutionMetaModel.genuineEntity(Lesson.class)
378378
.basicVariable("room", Room.class);
379379
380380
var move = Moves.change(variableMetaModel, lesson, newRoom);
@@ -765,8 +765,8 @@ public class MyNeighborhoodProvider implements NeighborhoodProvider<MySolution>
765765
@Override
766766
public Neighborhood defineNeighborhood(NeighborhoodBuilder<MySolution> builder) {
767767
var timeslotVariable = builder.getSolutionMetaModel()
768-
.entity(Lesson.class)
769-
.variable("timeslot", Timeslot.class);
768+
.genuineEntity(Lesson.class)
769+
.basicVariable("timeslot", Timeslot.class);
770770
return builder.add(new TimeslotChangeMoveProvider(timeslotVariable))
771771
.build();
772772
}

0 commit comments

Comments
 (0)