Skip to content

Commit ec76f5f

Browse files
Christopher-Chianellitriceo
authored andcommitted
chore: calculate ignoreInconsistentSolution on score director
1 parent cf53b36 commit ec76f5f

3 files changed

Lines changed: 2 additions & 15 deletions

File tree

core/src/main/java/ai/timefold/solver/core/impl/score/director/AbstractScoreDirector.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public abstract class AbstractScoreDirector<Solution_, Score_ extends Score<Scor
7474
private final @Nullable LookupManager lookUpManager;
7575
protected final ConstraintMatchPolicy constraintMatchPolicy;
7676
private boolean expectShadowVariablesInCorrectState;
77-
private boolean ignoreInconsistentSolutions;
77+
private final boolean ignoreInconsistentSolutions;
7878
private final VariableDescriptorCache<Solution_> variableDescriptorCache;
7979
protected final ShadowVariableSupport<Solution_> shadowVariableSupport;
8080
private final @Nullable SolutionTracker<Solution_> solutionTracker; // Null when tracking disabled.
@@ -110,7 +110,7 @@ protected AbstractScoreDirector(AbstractScoreDirectorBuilder<Solution_, Score_,
110110
this.lookUpManager = lookUpEnabled ? new LookupManager(solutionDescriptor.getLookUpStrategyResolver()) : null;
111111
this.constraintMatchPolicy = builder.constraintMatchPolicy;
112112
this.expectShadowVariablesInCorrectState = builder.expectShadowVariablesInCorrectState;
113-
this.ignoreInconsistentSolutions = builder.ignoreInconsistentSolutions;
113+
this.ignoreInconsistentSolutions = !solutionDescriptor.hasAnyShadowVariablesInconsistentMember();
114114
this.variableDescriptorCache = new VariableDescriptorCache<>(solutionDescriptor);
115115
this.shadowVariableSupport = ShadowVariableSupport.create(this);
116116
this.shadowVariableSupport.linkShadowVariables();
@@ -524,7 +524,6 @@ public InnerScoreDirector<Solution_, Score_> createChildThreadScoreDirector(Chil
524524
var childThreadScoreDirector = scoreDirectorFactory.createScoreDirectorBuilder()
525525
.withLookUpEnabled(lookUpEnabled)
526526
.withConstraintMatchPolicy(constraintMatchPolicy)
527-
.withIgnoreInconsistentSolutions(ignoreInconsistentSolutions)
528527
.buildDerived();
529528
// ScoreCalculationCountTermination takes into account previous phases
530529
// but the calculationCount of partitions is maxed, not summed.
@@ -534,7 +533,6 @@ public InnerScoreDirector<Solution_, Score_> createChildThreadScoreDirector(Chil
534533
var childThreadScoreDirector = scoreDirectorFactory.createScoreDirectorBuilder()
535534
.withLookUpEnabled(true)
536535
.withConstraintMatchPolicy(constraintMatchPolicy)
537-
.withIgnoreInconsistentSolutions(ignoreInconsistentSolutions)
538536
.buildDerived();
539537
childThreadScoreDirector.setWorkingSolution(cloneWorkingSolution());
540538
return childThreadScoreDirector;
@@ -807,7 +805,6 @@ private void assertScoreFromScratch(InnerScore<Score_> innerScore, Object comple
807805
// Most score directors don't need derived status; CS will override this.
808806
try (var uncorruptedScoreDirector = assertionScoreDirectorFactory.createScoreDirectorBuilder()
809807
.withConstraintMatchPolicy(ConstraintMatchPolicy.ENABLED)
810-
.withIgnoreInconsistentSolutions(ignoreInconsistentSolutions)
811808
.buildDerived()) {
812809
uncorruptedScoreDirector.setWorkingSolution(workingSolution);
813810
var uncorruptedInnerScore = uncorruptedScoreDirector.calculateScore();
@@ -1006,7 +1003,6 @@ public abstract static class AbstractScoreDirectorBuilder<Solution_, Score_ exte
10061003
protected ConstraintMatchPolicy constraintMatchPolicy = ConstraintMatchPolicy.DISABLED;
10071004
protected boolean lookUpEnabled = false;
10081005
protected boolean expectShadowVariablesInCorrectState = true;
1009-
protected boolean ignoreInconsistentSolutions = false;
10101006

10111007
protected AbstractScoreDirectorBuilder(Factory_ scoreDirectorFactory) {
10121008
this.scoreDirectorFactory = Objects.requireNonNull(scoreDirectorFactory);
@@ -1030,12 +1026,6 @@ public Builder_ withExpectShadowVariablesInCorrectState(boolean expectShadowVari
10301026
return (Builder_) this;
10311027
}
10321028

1033-
@SuppressWarnings("unchecked")
1034-
public Builder_ withIgnoreInconsistentSolutions(boolean ignoreInconsistentSolutions) {
1035-
this.ignoreInconsistentSolutions = ignoreInconsistentSolutions;
1036-
return (Builder_) this;
1037-
}
1038-
10391029
public abstract AbstractScoreDirector<Solution_, Score_, Factory_> build();
10401030

10411031
/**

core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolutionManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ private <Result_> Result_ callScoreDirector(String feature, Solution_ solution,
6565
boolean cloneSolution) {
6666
var isShadowVariableUpdateEnabled = solutionUpdatePolicy.isShadowVariableUpdateEnabled();
6767
var nonNullSolution = Objects.requireNonNull(solution);
68-
var allowsInconsistent = getScoreDirectorFactory().getSolutionDescriptor().hasAnyShadowVariablesInconsistentMember();
6968
try (var scoreDirector = getScoreDirectorFactory().createScoreDirectorBuilder().withLookUpEnabled(cloneSolution)
7069
.withConstraintMatchPolicy(constraintMatchPolicy)
71-
.withIgnoreInconsistentSolutions(!allowsInconsistent)
7270
.withExpectShadowVariablesInCorrectState(!isShadowVariableUpdateEnabled).build()) {
7371
nonNullSolution = cloneSolution ? scoreDirector.cloneSolution(nonNullSolution) : nonNullSolution;
7472
if (isShadowVariableUpdateEnabled) {

core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolverFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ public Solver<Solution_> buildSolver(SolverConfigOverride configOverride) {
126126
}
127127
var castScoreDirector = scoreDirectorFactory.createScoreDirectorBuilder()
128128
.withLookUpEnabled(true) // Custom phases and problem changes may rely on lookups.
129-
.withIgnoreInconsistentSolutions(!solutionDescriptor.hasAnyShadowVariablesInconsistentMember())
130129
.withConstraintMatchPolicy(
131130
constraintMatchEnabled ? ConstraintMatchPolicy.ENABLED : ConstraintMatchPolicy.DISABLED)
132131
.build();

0 commit comments

Comments
 (0)