Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Refactor: extract method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Doyle committed Jun 4, 2021
1 parent 99c46b2 commit b70584c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crop_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ def validate(self, sample):

return errors

@property
def solution(self):
return self.dqm.map_sample(self.sampleset.first.sample)

def render_solution(self, path, show_grid_x, show_grid_y, label_all_periods):
"""Generate a visual representation of the solution.
"""
sample = self.dqm.map_sample(self.sampleset.first.sample)
sample = self.solution
labels = set() # keep track of labels so legend won't have duplicates.
width = 1
max_x = self.time_units
Expand Down Expand Up @@ -393,7 +397,7 @@ def evaluate(self):
if self.verbose:
print(self.sampleset)

sample = self.dqm.map_sample(self.sampleset.first.sample)
sample = self.solution
print(f'Solution: {dict(((k, v) for k, v in sample.items() if v))}')
print(f'Solution energy: {self.sampleset.first.energy}')

Expand Down

0 comments on commit b70584c

Please sign in to comment.