Skip to content

Commit

Permalink
added continuous_peaks_generator.py
Browse files Browse the repository at this point in the history
Ported six peaks bug from GKHayes
  • Loading branch information
hiive committed Feb 17, 2020
1 parent 33aad72 commit f31c9a4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mlrose_hiive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@

from .runners import GARunner, MIMICRunner, RHCRunner, SARunner, NNGSRunner
from .runners import (build_data_filename)
from .generators import MaxKColorGenerator, QueensGenerator, FlipFlopGenerator, TSPGenerator, KnapsackGenerator
from .generators import (MaxKColorGenerator, QueensGenerator, FlipFlopGenerator, TSPGenerator, KnapsackGenerator,
ContinuousPeaksGenerator)
9 changes: 6 additions & 3 deletions mlrose_hiive/fitness/six_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ def evaluate(self, state):
tail_1 = self.tail(1, state)

# Calculate R(X, T)
if (tail_0 > _t and head_1 > _t) or (tail_1 > _t and head_0 > _t):
_r = 0
_max_score = max(tail_0, head_1)
if tail_0 > _t and head_1 > _t:
_r = _n
else:
_r = 0
elif tail_1 > _t and head_0 > _t:
_r = _n
_max_score = max(tail_1, head_0)

# Evaluate function
fitness = max(tail_0, head_1) + _r
Expand Down
1 change: 1 addition & 0 deletions mlrose_hiive/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from .flip_flop_generator import FlipFlopGenerator
from .queens_generator import QueensGenerator
from .tsp_generator import TSPGenerator
from .continuous_peaks_generator import ContinuousPeaksGenerator
17 changes: 17 additions & 0 deletions mlrose_hiive/generators/continuous_peaks_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
""" Classes for defining optimization problem objects."""

# Author: Andrew Rollings
# License: BSD 3 clause

import numpy as np

from mlrose_hiive import DiscreteOpt, ContinuousPeaks


class ContinuousPeaksGenerator:
@staticmethod
def generate(seed, size=20, t_pct=0.1):
np.random.seed(seed)
fitness = ContinuousPeaks(t_pct=t_pct)
problem = DiscreteOpt(length=size, fitness_fn=fitness)
return problem
2 changes: 1 addition & 1 deletion mlrose_hiive/generators/flip_flop_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Classes for defining optimization problem objects."""

# Author: Genevieve Hayes
# Author: Andrew Rollings
# License: BSD 3 clause

import numpy as np
Expand Down

0 comments on commit f31c9a4

Please sign in to comment.