@@ -40,7 +40,8 @@ public DestinationSelector<Solution_> buildDestinationSelector(HeuristicConfigPo
40
40
minimumCacheType , selectionOrder , entityValueRangeRecorderId );
41
41
var baseDestinationSelector =
42
42
new ElementDestinationSelector <>(entitySelector , valueSelector , selectionOrder .toRandomSelectionBoolean ());
43
- return applyNearbySelection (configPolicy , minimumCacheType , selectionOrder , baseDestinationSelector );
43
+ return applyNearbySelection (configPolicy , minimumCacheType , selectionOrder , baseDestinationSelector ,
44
+ entityValueRangeRecorderId != null );
44
45
}
45
46
46
47
private IterableValueSelector <Solution_ > buildIterableValueSelector (
@@ -72,14 +73,34 @@ private IterableValueSelector<Solution_> buildIterableValueSelector(
72
73
}
73
74
74
75
private DestinationSelector <Solution_ > applyNearbySelection (HeuristicConfigPolicy <Solution_ > configPolicy ,
75
- SelectionCacheType minimumCacheType , SelectionOrder resolvedSelectionOrder ,
76
- ElementDestinationSelector <Solution_ > destinationSelector ) {
76
+ SelectionCacheType minimumCacheType , SelectionOrder selectionOrder ,
77
+ ElementDestinationSelector <Solution_ > destinationSelector , boolean enableEntityValueRange ) {
77
78
NearbySelectionConfig nearbySelectionConfig = config .getNearbySelectionConfig ();
78
79
if (nearbySelectionConfig == null ) {
79
80
return destinationSelector ;
80
81
}
81
- return TimefoldSolverEnterpriseService .loadOrFail (TimefoldSolverEnterpriseService .Feature .NEARBY_SELECTION )
82
- .applyNearbySelection (config , configPolicy , minimumCacheType , resolvedSelectionOrder , destinationSelector );
82
+ // The nearby selector will implement its own logic to filter out unreachable elements.
83
+ // It requires the child selectors to not be FilteringEntityValueRangeSelector or FilteringValueRangeSelector,
84
+ // as it needs to iterate over all available values to construct the distance matrix.
85
+ if (enableEntityValueRange ) {
86
+ var entitySelector =
87
+ EntitySelectorFactory .<Solution_ > create (Objects .requireNonNull (config .getEntitySelectorConfig ()))
88
+ .buildEntitySelector (configPolicy , minimumCacheType , selectionOrder );
89
+ var valueSelector = ValueSelectorFactory
90
+ .<Solution_ > create (Objects .requireNonNull (config .getValueSelectorConfig ()))
91
+ .buildValueSelector (configPolicy , entitySelector .getEntityDescriptor (), minimumCacheType ,
92
+ selectionOrder , configPolicy .isReinitializeVariableFilterEnabled (),
93
+ ValueSelectorFactory .ListValueFilteringType .ACCEPT_ASSIGNED , null , false );
94
+ var updatedDestinationSelector =
95
+ new ElementDestinationSelector <>(entitySelector , (IterableValueSelector <Solution_ >) valueSelector ,
96
+ selectionOrder .toRandomSelectionBoolean ());
97
+ return TimefoldSolverEnterpriseService .loadOrFail (TimefoldSolverEnterpriseService .Feature .NEARBY_SELECTION )
98
+ .applyNearbySelection (config , configPolicy , minimumCacheType , selectionOrder ,
99
+ updatedDestinationSelector );
100
+ } else {
101
+ return TimefoldSolverEnterpriseService .loadOrFail (TimefoldSolverEnterpriseService .Feature .NEARBY_SELECTION )
102
+ .applyNearbySelection (config , configPolicy , minimumCacheType , selectionOrder , destinationSelector );
103
+ }
83
104
}
84
105
85
106
}
0 commit comments