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

Commit

Permalink
Merge pull request #4 from seatim/enhancements/2
Browse files Browse the repository at this point in the history
Output utilization fraction for solution.
  • Loading branch information
Tim Doyle authored Jun 28, 2021
2 parents 47982d7 + 878777c commit 9093aaa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crop_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ def render_solution(self, path):
fig.savefig(path)
print(f'Saved illustration of solution to {path}')

@property
def utilization(self):
"""Return the fraction of the maximum possible plot utilization for the
found solution.
"""
utilization = 0
for k, plot in enumerate(self.plot_adjacency):
for period in range(1, self.time_units + 1):
crop = self.solution[f'{plot},{period}']
if crop:
utilization += self.grow_time[crop]
return utilization / (len(self.plot_adjacency) * self.time_units)

def evaluate(self):
"""Evaluate the solution.
"""
Expand All @@ -397,6 +410,7 @@ def evaluate(self):
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}')
print(f'Plot utilization: {100 * self.utilization:.1f} %')

for error in self.validate(sample):
print(f'Solution is invalid: {error}')
Expand Down

0 comments on commit 9093aaa

Please sign in to comment.