Skip to content

Commit 1a6e893

Browse files
committed
docs: improve nearby documentation
1 parent 98a841f commit 1a6e893

1 file changed

Lines changed: 87 additions & 5 deletions

File tree

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

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,17 @@ public interface NearbyDistanceMeter<Origin_, Destination_> {
828828
----
829829
====
830830
831-
In a nutshell, when nearby selection is used in a list move selector,
832-
`Origin_` is always a planning value (for example `Customer`)
831+
In a nutshell, when nearby selection is applied,
832+
the `Origin_` and `Destination_` types are determined by the relevant selectors within the `nearbySelection` configuration.
833+
For a <<basicVariableNearbySelection, basic variable>>, `Origin_`
834+
is defined by the planning entity (for example `Lesson`) of the nearby definition,
835+
while `Destination_` can be either a planning value or a planning entity.
836+
In the case of a <<listVariableNearbySelection, list variable>>,
837+
`Origin_` is always a planning value (for example `Customer`),
833838
but `Destination_` can be either a planning value or a planning entity.
834-
That means that in VRP the distance meter must be able to handle both `Customer` and `Vehicle` as the `Destination_` argument:
839+
840+
As an example, consider the Vehicle Routing Problem and list variable to store the customer list for each vehicle.
841+
The distance meter must be able to handle both `Customer` and `Vehicle` as the `Destination_` argument:
835842
836843
[tabs]
837844
====
@@ -858,8 +865,82 @@ The Nearby configuration is not enabled for the Construction Heuristics
858865
because the method will analyze all possible moves.
859866
Adding Nearby in this situation would only result in unnecessary costs
860867
involving the generation of the distance matrix and sorting operations without taking advantage of the feature.
868+
869+
The previous code snippet exemplifies the implementation of a distance meter for a list variable,
870+
but the general idea remains the same for basic variables,
871+
which is that the implementation must handle the related planning values and planning entities.
872+
====
873+
874+
[#basicVariableNearbySelection]
875+
==== Nearby selection with a basic variable
876+
877+
To quickly configure nearby selection for a solution that only uses basic variables,
878+
add `nearbyDistanceMeterClass` element to your configuration file.
879+
The following enables nearby selection with a basic variable
880+
for the local search:
881+
882+
[source,xml,options="nowrap"]
883+
----
884+
<?xml version="1.0" encoding="UTF-8"?>
885+
<solver xmlns="https://timefold.ai/xsd/solver">
886+
...
887+
<nearbyDistanceMeterClass>org.acme.schooltimetabling.domain.solver.nearby.LectureNearbyDistanceMeter</nearbyDistanceMeterClass>
888+
...
889+
</solver>
890+
----
891+
892+
By default, the following move selectors are included:
893+
xref:optimization-algorithms/move-selector-reference.adoc#changeMoveSelector[Change],
894+
xref:optimization-algorithms/move-selector-reference.adoc#swapMoveSelector[Swap],
895+
Change with Nearby,
896+
and Swap with Nearby.
897+
898+
[IMPORTANT]
861899
====
900+
For a mixed model,
901+
configure nearby selection for basic-variable move selectors explicitly.
902+
====
903+
904+
===== Advanced configuration for local search
905+
906+
To customize the move selectors,
907+
add a `nearbySelection` element in the `valueSelector` of a `changeMoveSelector`
908+
or in the `secondaryEntitySelector` of a `swapMoveSelector`,
909+
and use xref:optimization-algorithms/move-selector-reference.adoc#mimicSelection[mimic selection]
910+
to specify which entity should be nearby the selection.
911+
912+
For a `changeMoveSelector`,
913+
`Origin_` is the entity selected
914+
and `Destination_` is the nearby planning value selected by the `valueSelector`.
915+
For a `swapMoveSelector`,
916+
both `Origin_` and `Destination_` are planning entities.
917+
The `Destination_` is determined by the configuration setting `secondaryEntitySelector`.
918+
919+
[source,xml,options="nowrap"]
920+
----
921+
<unionMoveSelector>
922+
<changeMoveSelector>
923+
<entitySelector id="entitySelector1"/>
924+
<valueSelector variableName="room">
925+
<nearbySelection>
926+
<originEntitySelector mimicSelectorRef="entitySelector1"/>
927+
<nearbyDistanceMeterClass>org.acme.schooltimetabling.domain.solver.nearby.LectureNearbyDistanceMeter</nearbyDistanceMeterClass>
928+
</nearbySelection>
929+
</valueSelector>
930+
</changeMoveSelector>
931+
<swapMoveSelector>
932+
<entitySelector id="entitySelector2"/>
933+
<secondaryEntitySelector>
934+
<nearbySelection>
935+
<originEntitySelector mimicSelectorRef="entitySelector2"/>
936+
<nearbyDistanceMeterClass>org.acme.schooltimetabling.domain.solver.nearby.LectureNearbyDistanceMeter</nearbyDistanceMeterClass>
937+
</nearbySelection>
938+
</secondaryEntitySelector>
939+
</swapMoveSelector>
940+
</unionMoveSelector>
941+
----
862942
943+
[#listVariableNearbySelection]
863944
==== Nearby selection with a list variable
864945
865946
To quickly configure nearby selection with a planning list variable,
@@ -880,9 +961,10 @@ for the local search:
880961
By default, the following move selectors are included:
881962
xref:optimization-algorithms/move-selector-reference.adoc#changeMoveSelector[Change],
882963
xref:optimization-algorithms/move-selector-reference.adoc#swapMoveSelector[Swap],
964+
xref:optimization-algorithms/move-selector-reference.adoc#kOptListMoveSelector[K-OPT]
883965
Change with Nearby,
884966
Swap with Nearby,
885-
and xref:optimization-algorithms/move-selector-reference.adoc#kOptListMoveSelector[2-OPT] with Nearby.
967+
and K-OPT with Nearby.
886968
887969
===== Advanced configuration for local search
888970
@@ -1064,7 +1146,7 @@ Simplest configuration:
10641146
<swapMoveSelector/>
10651147
----
10661148
1067-
If there are multiple entity classes, a simple configuration will automatically unfold
1149+
If there are multiple entity classes, a simple configuration will automatically unfold
10681150
into an <<unionMoveSelector,union>> of `SwapMove` selectors for every entity class.
10691151
10701152
Advanced configuration:

0 commit comments

Comments
 (0)