-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable score analysis without justifications (#1185)
Introduces an option to disable constraint match justifications, while still keeping constraint matching enabled. In some cases, the dataset is so large that justifications are pointless, and impractical to send over the wire as well. In this case, score analysis only provides constraint match count, and not the full match analysis.
- Loading branch information
Showing
116 changed files
with
1,047 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/main/java/ai/timefold/solver/core/impl/score/constraint/ConstraintMatchPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ai.timefold.solver.core.impl.score.constraint; | ||
|
||
import ai.timefold.solver.core.api.solver.ScoreAnalysisFetchPolicy; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
|
||
/** | ||
* Determines whether constraint match is enabled and whether constraint match justification is enabled. | ||
* | ||
* @see ai.timefold.solver.core.api.score.constraint.ConstraintMatch | ||
* @see ai.timefold.solver.core.api.score.stream.ConstraintJustification | ||
*/ | ||
@NullMarked | ||
public enum ConstraintMatchPolicy { | ||
|
||
DISABLED(false, false), | ||
ENABLED_WITHOUT_JUSTIFICATIONS(true, false), | ||
ENABLED(true, true); | ||
|
||
/** | ||
* To achieve the most performance out of the underlying solver, | ||
* the policy should match whatever policy was used for score analysis. | ||
* For example, if the fetch policy specifies that only match counts are necessary and not matches themselves | ||
* ({@link ScoreAnalysisFetchPolicy#FETCH_MATCH_COUNT}), | ||
* we can configure the solver to not produce justifications ({@link #ENABLED_WITHOUT_JUSTIFICATIONS}). | ||
* | ||
* @param scoreAnalysisFetchPolicy | ||
* @return Match policy best suited for the given fetch policy. | ||
*/ | ||
public static ConstraintMatchPolicy match(ScoreAnalysisFetchPolicy scoreAnalysisFetchPolicy) { | ||
return switch (scoreAnalysisFetchPolicy) { | ||
case FETCH_MATCH_COUNT, FETCH_SHALLOW -> ENABLED_WITHOUT_JUSTIFICATIONS; | ||
case FETCH_ALL -> ENABLED; | ||
}; | ||
} | ||
|
||
private final boolean enabled; | ||
private final boolean justificationEnabled; | ||
|
||
ConstraintMatchPolicy(boolean enabled, boolean justificationEnabled) { | ||
this.enabled = enabled; | ||
this.justificationEnabled = justificationEnabled; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public boolean isJustificationEnabled() { | ||
return justificationEnabled; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.