Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DefaultSolver #297

Merged
merged 9 commits into from
Oct 5, 2021
Merged

Refactor DefaultSolver #297

merged 9 commits into from
Oct 5, 2021

Conversation

AntoniusW
Copy link
Collaborator

Some refactoring/polishing inside the solver component, mostly DefaultSolver. Changes are intended to support subclassing of DefaultSolver for optimization tasks/weak constraints.

- DefaultSolver#tryAdvance broken into smaller methods, added SearchState member.
- Small polishing in PerformanceLog.
- Move writing methods to WritableAssignment.
- WritableAssignment and TrailAssignment realize didChange() method.
- DefaultSolver uses WritableAssignment#didChange, plus minor polishing.
Copy link
Collaborator

@madmike200590 madmike200590 left a comment

Choose a reason for hiding this comment

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

This looks really good! The additional methods in the solver improve readability quite a bit. There's one minor comment where I think a comment could be a bit clearer, but as far as I'm concerned, this is ready to be merged.

return;
}
// We already found one Answer-Set and are requested to find another one.
searchState.afterAllAtomsAssigned = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I read the code correctly, we reach this part of the code on the second (and subsequent) call(s) to tryAdvance (as in the first call, we'll return after initializing search space). This is not really intuitive from the comment here, I think readability would benefit from a somewhat more detailed explanation on why we only get there after finding an answer set in the comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the code is doing that. I split up the method into two separate ones.

Co-authored-by: Lorenz Leutgeb <lorenz@leutgeb.xyz>
@codecov
Copy link

codecov bot commented Sep 30, 2021

Codecov Report

Merging #297 (79f720f) into master (9118335) will increase coverage by 0.13%.
The diff coverage is 86.10%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #297      +/-   ##
============================================
+ Coverage     78.35%   78.48%   +0.13%     
+ Complexity     2659     2515     -144     
============================================
  Files           191      189       -2     
  Lines          8870     8199     -671     
  Branches       1592     1417     -175     
============================================
- Hits           6950     6435     -515     
+ Misses         1449     1324     -125     
+ Partials        471      440      -31     
Impacted Files Coverage Δ
.../java/at/ac/tuwien/kr/alpha/common/Assignment.java 86.66% <ø> (ø)
.../at/ac/tuwien/kr/alpha/common/atoms/BasicAtom.java 83.67% <0.00%> (-6.04%) ⬇️
...a/at/ac/tuwien/kr/alpha/common/rule/BasicRule.java 33.33% <0.00%> (-16.67%) ⬇️
...wien/kr/alpha/grounder/IndexedInstanceStorage.java 76.62% <ø> (ø)
.../at/ac/tuwien/kr/alpha/grounder/NaiveGrounder.java 85.82% <ø> (-2.20%) ⬇️
...a/at/ac/tuwien/kr/alpha/solver/PerformanceLog.java 100.00% <ø> (ø)
.../ac/tuwien/kr/alpha/solver/WritableAssignment.java 76.92% <ø> (ø)
...va/at/ac/tuwien/kr/alpha/solver/ChoiceManager.java 81.25% <57.14%> (+0.57%) ⬆️
...ounder/transformation/VariableEqualityRemoval.java 87.69% <62.50%> (-7.61%) ⬇️
...grounder/transformation/PredicateInternalizer.java 74.19% <63.63%> (-15.00%) ⬇️
... and 41 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1fc76c...79f720f. Read the comment docs.

- Choice provides getInverted now, renamed some variables.
- ChoiceManager refactored, provides only one backtrack method now, not two semi-duplicates.
- Backtracking code in DefaultSolver streamlined.
@AntoniusW
Copy link
Collaborator Author

@lorenzleutgeb and/or @madmike200590 please have another look.

Copy link
Collaborator

@madmike200590 madmike200590 left a comment

Choose a reason for hiding this comment

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

Looks good to me! I think the newly split version of the solver initialization part enhances readability a lot.

@lorenzleutgeb lorenzleutgeb merged commit eb047e8 into master Oct 5, 2021
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.

3 participants