Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfred committed Dec 6, 2024
1 parent 81c2747 commit 78f6431
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 88 deletions.
2 changes: 1 addition & 1 deletion benchmark/src/main/resources/benchmark.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
<xs:sequence>


<xs:element maxOccurs="unbounded" minOccurs="0" name="enablePreviewFeatureList" nillable="true" type="tns:previewFeature"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="enablePreviewFeature" type="tns:previewFeature"/>


<xs:element minOccurs="0" name="environmentMode" type="tns:environmentMode"/>
Expand Down
2 changes: 1 addition & 1 deletion core/src/build/revapi-differences.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"annotationType": "jakarta.xml.bind.annotation.XmlType",
"attribute": "propOrder",
"oldValue": "{\"environmentMode\", \"daemon\", \"randomType\", \"randomSeed\", \"randomFactoryClass\", \"moveThreadCount\", \"moveThreadBufferSize\", \"threadFactoryClass\", \"monitoringConfig\", \"solutionClass\", \"entityClassList\", \"domainAccessType\", \"scoreDirectorFactoryConfig\", \"terminationConfig\", \"phaseConfigList\"}",
"newValue": "{\"enablePreviewFeatureList\", \"environmentMode\", \"daemon\", \"randomType\", \"randomSeed\", \"randomFactoryClass\", \"moveThreadCount\", \"moveThreadBufferSize\", \"threadFactoryClass\", \"monitoringConfig\", \"solutionClass\", \"entityClassList\", \"domainAccessType\", \"scoreDirectorFactoryConfig\", \"terminationConfig\", \"nearbyDistanceMeterClass\", \"phaseConfigList\"}",
"newValue": "{\"enablePreviewFeatureSet\", \"environmentMode\", \"daemon\", \"randomType\", \"randomSeed\", \"randomFactoryClass\", \"moveThreadCount\", \"moveThreadBufferSize\", \"threadFactoryClass\", \"monitoringConfig\", \"solutionClass\", \"entityClassList\", \"domainAccessType\", \"scoreDirectorFactoryConfig\", \"terminationConfig\", \"nearbyDistanceMeterClass\", \"phaseConfigList\"}",
"justification": "Enable features preview config"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ThreadFactory;
import java.util.function.Consumer;

Expand Down Expand Up @@ -61,7 +62,7 @@
*/
@XmlRootElement(name = SolverConfig.XML_ELEMENT_NAME)
@XmlType(name = SolverConfig.XML_TYPE_NAME, propOrder = {
"enablePreviewFeatureList",
"enablePreviewFeatureSet",
"environmentMode",
"daemon",
"randomType",
Expand Down Expand Up @@ -211,8 +212,8 @@ public class SolverConfig extends AbstractConfig<SolverConfig> {

// Warning: all fields are null (and not defaulted) because they can be inherited
// and also because the input config file should match the output config file

protected List<PreviewFeature> enablePreviewFeatureList = null;
@XmlElement(name = "enablePreviewFeature")
protected Set<PreviewFeature> enablePreviewFeatureSet = null;
protected EnvironmentMode environmentMode = null;
protected Boolean daemon = null;
protected RandomType randomType = null;
Expand Down Expand Up @@ -287,12 +288,12 @@ public void setClassLoader(@Nullable ClassLoader classLoader) {
this.classLoader = classLoader;
}

public @Nullable List<PreviewFeature> getEnablePreviewFeatureList() {
return enablePreviewFeatureList;
public @Nullable Set<PreviewFeature> getEnablePreviewFeatureSet() {
return enablePreviewFeatureSet;
}

public void setEnablePreviewFeatureList(@Nullable List<PreviewFeature> enablePreviewFeatureList) {
this.enablePreviewFeatureList = enablePreviewFeatureList;
public void setEnablePreviewFeatureSet(@Nullable Set<PreviewFeature> enablePreviewFeatureSet) {
this.enablePreviewFeatureSet = enablePreviewFeatureSet;
}

public @Nullable EnvironmentMode getEnvironmentMode() {
Expand Down Expand Up @@ -443,11 +444,8 @@ public void setMonitoringConfig(@Nullable MonitoringConfig monitoringConfig) {
// With methods
// ************************************************************************

public @NonNull SolverConfig withPreviewFeature(@NonNull PreviewFeature previewFeature) {
if (enablePreviewFeatureList == null) {
enablePreviewFeatureList = new ArrayList<>();
}
enablePreviewFeatureList.add(previewFeature);
public @NonNull SolverConfig withPreviewFeature(@NonNull PreviewFeature... previewFeature) {
enablePreviewFeatureSet = EnumSet.copyOf(Arrays.asList(previewFeature));
return this;
}

Expand Down Expand Up @@ -667,8 +665,8 @@ public void offerRandomSeedFromSubSingleIndex(long subSingleIndex) {
@Override
public @NonNull SolverConfig inherit(@NonNull SolverConfig inheritedConfig) {
classLoader = ConfigUtils.inheritOverwritableProperty(classLoader, inheritedConfig.getClassLoader());
enablePreviewFeatureList = ConfigUtils.inheritMergeableListProperty(enablePreviewFeatureList,
inheritedConfig.getEnablePreviewFeatureList());
enablePreviewFeatureSet = ConfigUtils.inheritMergeableEnumSetProperty(enablePreviewFeatureSet,
inheritedConfig.getEnablePreviewFeatureSet());
environmentMode = ConfigUtils.inheritOverwritableProperty(environmentMode, inheritedConfig.getEnvironmentMode());
daemon = ConfigUtils.inheritOverwritableProperty(daemon, inheritedConfig.getDaemon());
randomType = ConfigUtils.inheritOverwritableProperty(randomType, inheritedConfig.getRandomType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -211,6 +212,19 @@ public static void applyCustomProperties(@NonNull Object bean, @NonNull String b
}
}

public static <E extends Enum<E>> @Nullable Set<E> inheritMergeableEnumSetProperty(@Nullable Set<E> originalSet,
@Nullable Set<E> inheritedSet) {
if (inheritedSet == null) {
return originalSet;
} else if (originalSet == null) {
return EnumSet.copyOf(inheritedSet);
} else {
var newSet = EnumSet.copyOf(originalSet);
newSet.addAll(inheritedSet);
return newSet;
}
}

public static <T> @Nullable List<T> inheritUniqueMergeableListProperty(@Nullable List<T> originalList,
@Nullable List<T> inheritedList) {
if (inheritedList == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ai.timefold.solver.core.impl.heuristic;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadFactory;

import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySorterManner;
Expand All @@ -27,7 +27,7 @@

public class HeuristicConfigPolicy<Solution_> {

private final List<PreviewFeature> previewFeatureList;
private final Set<PreviewFeature> previewFeatureList;
private final EnvironmentMode environmentMode;
private final String logIndentation;
private final Integer moveThreadCount;
Expand Down Expand Up @@ -132,8 +132,17 @@ public Random getRandom() {
// ************************************************************************

public Builder<Solution_> cloneBuilder() {
return new Builder<>(previewFeatureList, environmentMode, moveThreadCount, moveThreadBufferSize, threadFactoryClass,
nearbyDistanceMeterClass, random, initializingScoreTrend, solutionDescriptor, classInstanceCache)
return new Builder<Solution_>()
.withPreviewFeatureList(previewFeatureList)
.withEnvironmentMode(environmentMode)
.withMoveThreadCount(moveThreadCount)
.withMoveThreadBufferSize(moveThreadBufferSize)
.withThreadFactoryClass(threadFactoryClass)
.withNearbyDistanceMeterClass(nearbyDistanceMeterClass)
.withRandom(random)
.withInitializingScoreTrend(initializingScoreTrend)
.withSolutionDescriptor(solutionDescriptor)
.withClassInstanceCache(classInstanceCache)
.withLogIndentation(logIndentation);
}

Expand Down Expand Up @@ -225,14 +234,14 @@ public String toString() {

public static class Builder<Solution_> {

private final List<PreviewFeature> previewFeatureList;
private final EnvironmentMode environmentMode;
private final Integer moveThreadCount;
private final Integer moveThreadBufferSize;
private final Class<? extends ThreadFactory> threadFactoryClass;
private final InitializingScoreTrend initializingScoreTrend;
private final SolutionDescriptor<Solution_> solutionDescriptor;
private final ClassInstanceCache classInstanceCache;
private Set<PreviewFeature> previewFeatureList;
private EnvironmentMode environmentMode;
private Integer moveThreadCount;
private Integer moveThreadBufferSize;
private Class<? extends ThreadFactory> threadFactoryClass;
private InitializingScoreTrend initializingScoreTrend;
private SolutionDescriptor<Solution_> solutionDescriptor;
private ClassInstanceCache classInstanceCache;

private String logIndentation = "";

Expand All @@ -243,24 +252,58 @@ public static class Builder<Solution_> {
private boolean initializedChainedValueFilterEnabled = false;
private boolean unassignedValuesAllowed = false;

private final Class<? extends NearbyDistanceMeter<?, ?>> nearbyDistanceMeterClass;
private final Random random;
private Class<? extends NearbyDistanceMeter<?, ?>> nearbyDistanceMeterClass;
private Random random;

public Builder(List<PreviewFeature> previewFeatureList, EnvironmentMode environmentMode, Integer moveThreadCount,
Integer moveThreadBufferSize, Class<? extends ThreadFactory> threadFactoryClass,
Class<? extends NearbyDistanceMeter<?, ?>> nearbyDistanceMeterClass, Random random,
InitializingScoreTrend initializingScoreTrend, SolutionDescriptor<Solution_> solutionDescriptor,
ClassInstanceCache classInstanceCache) {
public Builder<Solution_> withPreviewFeatureList(Set<PreviewFeature> previewFeatureList) {
this.previewFeatureList = previewFeatureList;
return this;
}

public Builder<Solution_> withEnvironmentMode(EnvironmentMode environmentMode) {
this.environmentMode = environmentMode;
return this;
}

public Builder<Solution_> withMoveThreadCount(Integer moveThreadCount) {
this.moveThreadCount = moveThreadCount;
return this;
}

public Builder<Solution_> withMoveThreadBufferSize(Integer moveThreadBufferSize) {
this.moveThreadBufferSize = moveThreadBufferSize;
return this;
}

public Builder<Solution_> withThreadFactoryClass(Class<? extends ThreadFactory> threadFactoryClass) {
this.threadFactoryClass = threadFactoryClass;
return this;
}

public Builder<Solution_>
withNearbyDistanceMeterClass(Class<? extends NearbyDistanceMeter<?, ?>> nearbyDistanceMeterClass) {
this.nearbyDistanceMeterClass = nearbyDistanceMeterClass;
return this;
}

public Builder<Solution_> withRandom(Random random) {
this.random = random;
return this;
}

public Builder<Solution_> withInitializingScoreTrend(InitializingScoreTrend initializingScoreTrend) {
this.initializingScoreTrend = initializingScoreTrend;
return this;
}

public Builder<Solution_> withSolutionDescriptor(SolutionDescriptor<Solution_> solutionDescriptor) {
this.solutionDescriptor = solutionDescriptor;
return this;
}

public Builder<Solution_> withClassInstanceCache(ClassInstanceCache classInstanceCache) {
this.classInstanceCache = classInstanceCache;
return this;
}

public Builder<Solution_> withLogIndentation(String logIndentation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private Optional<LateAcceptanceAcceptor<Solution_>> buildLateAcceptanceAcceptor(
return Optional.empty();
}

private Optional<LateAcceptanceAcceptor<Solution_>>
private Optional<DiversifiedLateAcceptanceAcceptor<Solution_>>
buildDiversifiedLateAcceptanceAcceptor(HeuristicConfigPolicy<Solution_> configPolicy) {
if (acceptorTypeListsContainsAcceptorType(AcceptorType.DIVERSIFIED_LATE_ACCEPTANCE)) {
configPolicy.ensurePreviewFeature(PreviewFeature.DIVERSIFIED_LATE_ACCEPTANCE);
Expand Down
Loading

0 comments on commit 78f6431

Please sign in to comment.