X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/ecc0929cb0e011db2825e79d7495d7ef7b113e1e..45b6aba3bbf3aea1bacad077387ae77a1deb1a3c:/imago_pack/cs.py diff --git a/imago_pack/cs.py b/imago_pack/cs.py index 7c91119..09d5280 100644 --- a/imago_pack/cs.py +++ b/imago_pack/cs.py @@ -14,10 +14,10 @@ class Space(object): self.best_value, self.best = max(self.nests) def new_nest(space): - position = [2 * space.bound * random.random() - - space.bound for _ in xrange(space.dimension)] - value = space.d_function(*position) - return (value, position) + position = [2 * space.bound * random.random() + - space.bound for _ in xrange(space.dimension)] + value = space.d_function(*position) + return (value, position) def get_cuckoos(space): beta = 1.5 @@ -64,8 +64,13 @@ def next_turn(space): space.nests = [max(n, m) for (n, m) in zip(space.nests, nests)] space.best_value, space.best = max(space.nests) -def optimize(dimension, boundary, function_d, n_nest, n_turns): - space = Space(dimension, boundary, function_d, n_nest) - for _ in xrange(n_turns): - next_turn(space) - return space.best +def optimize(dimension, boundary, function_d, n_nest, n_turns, reset=1): + best_list = [] + for i in xrange(reset): + space = Space(dimension, boundary, function_d, n_nest) + for _ in xrange(n_turns / reset): + next_turn(space) + best_list.append((space.best_value, space.best)) + # print space.best_value + + return max(best_list)[1]