Permalink
Browse files

Moving example and tests, fixing a major bug that didn't drop previou…

…s fitness computation on mutation
  • Loading branch information...
frantzmiccoli committed Mar 30, 2014
1 parent b6dca86 commit 3895efe13769299a21cc8f090d22bbf599c4b6cc
Showing with 55 additions and 12 deletions.
  1. +4 −4 {example → examples}/getting_started_1.rb
  2. 0 {example → examples}/getting_started_2.rb
  3. +41 −0 examples/manual_instantiation.rb
  4. +0 −3 {example → examples}/population_vs_archipelago.rb
  5. +2 −2 gimuby.gemspec
  6. +2 −1 lib/gimuby/genetic/population/population.rb
  7. +1 −0 lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb
  8. +4 −0 lib/gimuby/genetic/solution/solution.rb
  9. +1 −2 rakefile
  10. 0 {test → tests}/abstract_test_case.rb
  11. 0 {test → tests}/genetic/archipelago/test_archipelago.rb
  12. 0 {test → tests}/genetic/archipelago/test_barabasi_albert_connect_strategy.rb
  13. 0 {test → tests}/genetic/archipelago/test_circle_connect_strategy.rb
  14. 0 {test → tests}/genetic/archipelago/test_clustering_coefficient_measure.rb
  15. 0 {test → tests}/genetic/archipelago/test_connected_measure.rb
  16. 0 {test → tests}/genetic/archipelago/test_constant_degree_connect_strategy.rb
  17. 0 {test → tests}/genetic/archipelago/test_diameter_measure.rb
  18. 0 {test → tests}/genetic/archipelago/test_fully_connected_connect_strategy.rb
  19. 0 {test → tests}/genetic/archipelago/test_random_connect_strategy.rb
  20. 0 {test → tests}/genetic/archipelago/test_shortest_paths_measure.rb
  21. 0 {test → tests}/genetic/archipelago/test_watts_strogatz_connect_strategy.rb
  22. 0 {test → tests}/genetic/population/test_bests_pick_strategy.rb
  23. 0 {test → tests}/genetic/population/test_population.rb
  24. 0 {test → tests}/genetic/population/test_random_wheel_pick_strategy.rb
  25. 0 {test → tests}/genetic/population/test_replace_worst_replace_strategy.rb
  26. 0 {test → tests}/genetic/population/test_tournament_pick_strategy.rb
  27. 0 {test → tests}/genetic/population/test_uniform_replace_strategy.rb
  28. 0 {test → tests}/genetic/solution/test_average_new_generation_strategy.rb
  29. 0 {test → tests}/genetic/solution/test_combined_new_generation_strategy.rb
  30. 0 {test → tests}/genetic/solution/test_cross_over_new_generation_strategy.rb
  31. 0 {test → tests}/genetic/solution/test_parent_range_new_generation_strategy.rb
  32. 0 {test → tests}/genetic/solution/test_permutation_check_strategy.rb
  33. 0 {test → tests}/genetic/solution/test_permutation_mutation_strategy.rb
  34. 0 {test → tests}/genetic/solution/test_solution_space_check_strategy.rb
  35. 0 {test → tests}/genetic/solution/test_solution_space_mutation_strategy.rb
  36. 0 {test → tests}/mock/population_mock.rb
  37. 0 {test → tests}/mock/solution_mock.rb
  38. 0 {test → tests}/problem/abstract_test_problem_solution.rb
  39. 0 {test → tests}/problem/foxholes/test_foxholes.rb
  40. 0 {test → tests}/problem/foxholes/test_foxholes_solution.rb
  41. 0 {test → tests}/problem/lennard_jones/test_lennard_jones.rb
  42. 0 {test → tests}/problem/lennard_jones/test_lennard_jones_solution.rb
  43. 0 {test → tests}/problem/rastrigin/test_rastrigin.rb
  44. 0 {test → tests}/problem/rastrigin/test_rastrigin_solution.rb
  45. 0 {test → tests}/problem/rosenbrock/test_rosenbrock_solution.rb
  46. 0 {test → tests}/problem/schaffer/test_schaffer_solution.rb
  47. 0 {test → tests}/problem/sphere/test_sphere.rb
  48. 0 {test → tests}/problem/sphere/test_sphere_solution.rb
  49. 0 {test → tests}/problem/step/test_step.rb
  50. 0 {test → tests}/problem/step/test_step_solution.rb
  51. 0 {test → tests}/problem/tsp/test_tsp.rb
  52. 0 {test → tests}/problem/tsp/test_tsp_solution.rb
  53. 0 {test → tests}/test_event_manager.rb
@@ -12,10 +12,6 @@
# STEP 1: First we define a solution
class SampleProblemSolution < FunctionBasedSolution
def initialize(x_values = nil)
super(x_values)
end
def evaluate
product = 1.0
@x_values.each do |x_value|
@@ -52,6 +48,10 @@ def get_dimension_number
end
# STEP 3: We get back the found solution
r = optimizer.get_best_solution.get_solution_representation
e = [-2.46835042100562,1.88147457884558,-0.467589756441865]
puts '[' + optimizer.get_best_solution.get_solution_representation.join(',') + ']'
puts optimizer.get_best_fitness
@@ -0,0 +1,41 @@
require 'gimuby/genetic/archipelago/archipelago'
require 'gimuby/genetic/archipelago/connect_strategy/fully_connected_connect_strategy'
require 'gimuby/genetic/population/population'
require 'gimuby/genetic/population/pick_strategy/tournament_pick_strategy'
require 'gimuby/genetic/population/replace_strategy/replace_worst_replace_strategy'
require 'gimuby/problem/step/step_solution'
# Manual archipelago creation
archipelago = Archipelago.new
archipelago.connect_strategy = FullyConnectedConnectStrategy.new
archipelago.migration_rate = 10.0 / 100.0
archipelago.migration_symmetric = true
archipelago.migration_type = :synchronized
10.times do
# Manual population creation
population = Population.new
population.pick_strategy = TournamentPickStrategy.new
population.replace_strategy = ReplaceWorstReplaceStrategy.new
# We add solution of the relevant problem
30.times do
solution = StepSolution.new
population.add_solution(solution)
end
# The current population is attached to the archipelago
archipelago.add_population(population)
end
# Every population is here, we connect them together
archipelago.connect_all
# We run the algorithm
100.times do
archipelago.generation_step
end
puts archipelago.get_best_fitness
@@ -4,9 +4,6 @@
SolutionClass = StepSolution
srand(ARGV[0].to_i)
puts ARGV[0]
# Let's test the following configurations, the optimizer is either population
# for a standard genetic algorithm, either archipelago for a "distributed"
# version of the algorithm (nothing is distributed in Gimuby)
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
'algorithm (named population) and distributed genetic algorithm or ' +
'island model (named archipelago).' + "\n" +
'The presented archipelago are NOT distributed (nor with threads, ' +
'process, or physical machine). However they let the user benefits of' +
'processes, or physical machines). However they let the user benefits of' +
'the leverage they represent to obtain a better solution with the same ' +
'amount of resources spent.' + "\n" +
'Similar to: AI4R, gga4r and darwinning'
@@ -27,4 +27,4 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '~> 1.8'
spec.license = 'MIT'
end
end
@@ -78,9 +78,10 @@ def get_best_fitness
end
def get_best_solution
@solutions.min_by do |solution|
best_solution = @solutions.min_by do |solution|
solution.get_fitness
end
best_solution
end
protected
@@ -11,6 +11,7 @@ def initialize(mutation_rate = 0.01)
def mutate(solution)
if rand < @mutation_rate
perform_mutation(solution)
solution.reset_fitness_state
end
end
@@ -33,6 +33,10 @@ def get_fitness
@fitness
end
def reset_fitness_state
@fitness = nil
end
def mutate
@mutation_strategy.mutate(self)
end
@@ -1,8 +1,7 @@
require 'rake/testtask'
Rake::TestTask.new do |test|
Dir.chdir './test'
test.libs << "./test"
Dir.chdir './tests'
test.libs << "../lib"
test.test_files = FileList['**/test*.rb']
test.verbose = true
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3895efe

Please sign in to comment.