Skip to content

chore: return null when the solution is invalid in calculate score - #2569

Open
Christopher-Chianelli wants to merge 1 commit into
TimefoldAI:no-loopsfrom
Christopher-Chianelli:chore/invalid-null-score
Open

chore: return null when the solution is invalid in calculate score#2569
Christopher-Chianelli wants to merge 1 commit into
TimefoldAI:no-loopsfrom
Christopher-Chianelli:chore/invalid-null-score

Conversation

@Christopher-Chianelli

Copy link
Copy Markdown
Contributor

Note: DefaultPhaseCommandContext.executeTemporary throws if the score is null/invalid (via Objects.requireNonNull(score, () -> "The move (%s) failed to calculate a score.".formatted(move));). Should that be change (i.e. what should happen when a user executes a temporary move that results in an inconsistent solution in a PhaseCommand).

logger.trace("{} Move index ({}), score ({}), move ({}).",
logIndentation, moveScope.getMoveIndex(), moveScope.getScore().raw(), moveScope.getMove());
logIndentation, moveScope.getMoveIndex(),
(score != null) ? moveScope.getScore().raw() : "invalid", moveScope.getMove());

@zepfred zepfred Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                    (moveScope.getScore() != null) ? moveScope.getScore().raw() : "invalid", moveScope.getMove());

return isConsistentSolutionAccepted(moveScope);
}

public abstract boolean isConsistentSolutionAccepted(LocalSearchMoveScope<Solution_> moveScope);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public modifier may not be ideal, as this method can still be called instead of isAccepted. Can we change it to protected to prevent this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried package-private, was getting compile errors since some implementations are in different packages. I can try protected though.

if (lastVariableUpdateSuccessful) {
return innerCalculateScore();
} else {
var invalidScore = InnerScore.invalid(getScoreDefinition().getZeroScore());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris, I'm not convinced that the new solution is better than the old approach. I believe returning a non-null value is preferable. What is the primary reason for changing this behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@triceo wanted it, so any places where it needs to be checked become obvious. We might find a different way though.

@zepfred zepfred left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris, I have a few questions regarding the proposed approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants