Skip to content

Commit 23ff23d

Browse files
authored
feat: enable mixed models (#1645)
This PR finally enables the coexistence of basic and list variables in the same model.
1 parent fe93472 commit 23ff23d

28 files changed

+289
-44
lines changed

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/NearbyAutoConfigurationEnabled.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
public interface NearbyAutoConfigurationEnabled<Config_ extends MoveSelectorConfig<Config_>> {
1313

14+
/**
15+
* @return true if it can enable the nearby setting for the given move configuration; otherwise, it returns false.
16+
*/
17+
boolean canEnableNearbyInMixedModels();
18+
1419
/**
1520
* @return new instance with the Nearby Selection settings properly configured
1621
*/

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/composite/UnionMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ public boolean hasNearbySelectionConfig() {
206206
&& moveSelectorConfigList.stream().anyMatch(MoveSelectorConfig::hasNearbySelectionConfig);
207207
}
208208

209+
@Override
210+
public boolean canEnableNearbyInMixedModels() {
211+
return false;
212+
}
213+
209214
@Override
210215
public String toString() {
211216
return getClass().getSimpleName() + "(" + moveSelectorConfigList + ")";

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/ChangeMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public boolean hasNearbySelectionConfig() {
104104
|| (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig());
105105
}
106106

107+
@Override
108+
public boolean canEnableNearbyInMixedModels() {
109+
return false;
110+
}
111+
107112
@Override
108113
public String toString() {
109114
return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")";

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/SwapMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public boolean hasNearbySelectionConfig() {
127127
|| (secondaryEntitySelectorConfig != null && secondaryEntitySelectorConfig.hasNearbySelectionConfig());
128128
}
129129

130+
@Override
131+
public boolean canEnableNearbyInMixedModels() {
132+
return false;
133+
}
134+
130135
@Override
131136
public String toString() {
132137
return getClass().getSimpleName() + "(" + entitySelectorConfig

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/chained/TailChainSwapMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public boolean hasNearbySelectionConfig() {
108108
|| (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig());
109109
}
110110

111+
@Override
112+
public boolean canEnableNearbyInMixedModels() {
113+
return false;
114+
}
115+
111116
@Override
112117
public String toString() {
113118
return getClass().getSimpleName() + "(" + entitySelectorConfig + ", " + valueSelectorConfig + ")";

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/ListChangeMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public boolean hasNearbySelectionConfig() {
106106
|| (destinationSelectorConfig != null && destinationSelectorConfig.hasNearbySelectionConfig());
107107
}
108108

109+
@Override
110+
public boolean canEnableNearbyInMixedModels() {
111+
return true;
112+
}
113+
109114
@Override
110115
public String toString() {
111116
return getClass().getSimpleName() + "(" + valueSelectorConfig + ", " + destinationSelectorConfig + ")";

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/ListSwapMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public boolean hasNearbySelectionConfig() {
104104
|| (secondaryValueSelectorConfig != null && secondaryValueSelectorConfig.hasNearbySelectionConfig());
105105
}
106106

107+
@Override
108+
public boolean canEnableNearbyInMixedModels() {
109+
return true;
110+
}
111+
107112
@Override
108113
public String toString() {
109114
return getClass().getSimpleName() + "(" + valueSelectorConfig

core/src/main/java/ai/timefold/solver/core/config/heuristic/selector/move/generic/list/kopt/KOptListMoveSelectorConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public boolean hasNearbySelectionConfig() {
138138
|| (valueSelectorConfig != null && valueSelectorConfig.hasNearbySelectionConfig());
139139
}
140140

141+
@Override
142+
public boolean canEnableNearbyInMixedModels() {
143+
return true;
144+
}
145+
141146
@Override
142147
public String toString() {
143148
return getClass().getSimpleName() + "()";

core/src/main/java/ai/timefold/solver/core/impl/domain/solution/descriptor/SolutionDescriptor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ public static <Solution_> SolutionDescriptor<Solution_> buildSolutionDescriptor(
166166
solutionDescriptor.constraintWeightSupplier.initialize(solutionDescriptor,
167167
descriptorPolicy.getMemberAccessorFactory(), descriptorPolicy.getDomainAccessType());
168168
}
169-
// Temporally disabling the mixed model
170-
if (solutionDescriptor.hasBothBasicAndListVariables()) {
171-
throw new IllegalStateException("Combining list variable and basic variables is currently not supported.");
172-
}
173169
return solutionDescriptor;
174170
}
175171

core/src/main/java/ai/timefold/solver/core/impl/heuristic/HeuristicConfigPolicy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ public HeuristicConfigPolicy<Solution_> createPhaseConfigPolicy() {
161161
return cloneBuilder().build();
162162
}
163163

164+
public HeuristicConfigPolicy<Solution_> copyConfigPolicyWithoutNearbySetting() {
165+
return cloneBuilder()
166+
.withNearbyDistanceMeterClass(null)
167+
.build();
168+
}
169+
164170
public HeuristicConfigPolicy<Solution_> createChildThreadConfigPolicy(ChildThreadType childThreadType) {
165171
return cloneBuilder()
166172
.withLogIndentation(logIndentation + " ")

0 commit comments

Comments
 (0)