-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to save and restore state
- Loading branch information
Showing
11 changed files
with
246 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from platypus import NSGAII, DTLZ2, save_state, load_state | ||
|
||
try: | ||
import jsonpickle | ||
except ImportError: | ||
print("Please install jsonpickle to run this example!") | ||
|
||
problem = DTLZ2() | ||
|
||
algorithm = NSGAII(problem) | ||
algorithm.run(5000) | ||
|
||
# Save the algorithm state to a file. | ||
save_state("state.json", algorithm, json=True, indent=4) | ||
|
||
# Load the state and continue running. | ||
algorithm = load_state("state.json", json=True) | ||
algorithm.run(5000) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import math | ||
from ..core import Problem, Solution, FixedLengthArray | ||
|
||
class SolutionMixin: | ||
|
||
def createSolution(self, *args): | ||
problem = Problem(0, len(args)) | ||
solution = Solution(problem) | ||
solution.objectives[:] = [float(x) for x in args] | ||
return solution | ||
|
||
def assertSimilar(self, a, b, epsilon=0.0000001): | ||
if isinstance(a, Solution) and isinstance(b, Solution): | ||
self.assertSimilar(a.variables, b.variables) | ||
self.assertSimilar(a.objectives, b.objectives) | ||
self.assertSimilar(a.constraints, b.constraints) | ||
elif isinstance(a, (list, FixedLengthArray)) and isinstance(b, (list, FixedLengthArray)): | ||
for (x, y) in zip(a, b): | ||
self.assertSimilar(x, y, epsilon) | ||
else: | ||
self.assertLessEqual(math.fabs(b - a), epsilon) |
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
Oops, something went wrong.