evosynth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/INSTALL +74 -0
- data/LICENSE +22 -0
- data/README +57 -0
- data/Rakefile +132 -0
- data/TODO +88 -0
- data/docs/FEATURES +111 -0
- data/docs/rdoc/classes/EvoSynth.html +2643 -0
- data/docs/rdoc/classes/EvoSynth/Adjustments.html +119 -0
- data/docs/rdoc/classes/EvoSynth/Adjustments/AdaptiveAdjustment.html +264 -0
- data/docs/rdoc/classes/EvoSynth/Adjustments/PredifinedAdjustment.html +235 -0
- data/docs/rdoc/classes/EvoSynth/ArrayGenome.html +313 -0
- data/docs/rdoc/classes/EvoSynth/BinaryGenome.html +518 -0
- data/docs/rdoc/classes/EvoSynth/Decoder.html +286 -0
- data/docs/rdoc/classes/EvoSynth/Evaluator.html +466 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers.html +469 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/AdaptiveES.html +448 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/BalancedCoevolutionary.html +439 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/DerandomizedES.html +450 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/Evolver.html +125 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/GeneticAlgorithm.html +467 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/Hillclimber.html +343 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch.html +422 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch/GreatDelugeAcceptance.html +287 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch/HillclimberAcceptance.html +197 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch/RecordToRecordTravelAcceptance.html +296 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch/SimulatedAnnealingAcceptance.html +286 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/LocalSearch/ThresholdAcceptance.html +287 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/MemeticAlgorithm.html +441 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/PopulationHillclimber.html +375 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/ProfileUsingEvolver.html +205 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/RoundRobinCoevolutionary.html +383 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/RunnableEvolver.html +279 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/RunnableEvolver/Goal.html +193 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/SelfAdaptiveES.html +394 -0
- data/docs/rdoc/classes/EvoSynth/Evolvers/SteadyStateGA.html +390 -0
- data/docs/rdoc/classes/EvoSynth/GlobalRecombinations.html +119 -0
- data/docs/rdoc/classes/EvoSynth/GlobalRecombinations/GlobalArithmeticCrossover.html +204 -0
- data/docs/rdoc/classes/EvoSynth/GlobalRecombinations/GlobalUniformCrossover.html +203 -0
- data/docs/rdoc/classes/EvoSynth/Individual.html +561 -0
- data/docs/rdoc/classes/EvoSynth/MaximizingIndividual.html +266 -0
- data/docs/rdoc/classes/EvoSynth/MetaOperators.html +149 -0
- data/docs/rdoc/classes/EvoSynth/MetaOperators/ConditionalCombinedOperator.html +278 -0
- data/docs/rdoc/classes/EvoSynth/MetaOperators/ProportionalCombinedOperator.html +285 -0
- data/docs/rdoc/classes/EvoSynth/MetaOperators/SequentialCombinedOperator.html +290 -0
- data/docs/rdoc/classes/EvoSynth/MinimizingIndividual.html +266 -0
- data/docs/rdoc/classes/EvoSynth/Mutations.html +251 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/BinaryMutation.html +336 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/EfficientBinaryMutation.html +345 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/ExchangeMutation.html +320 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/Functions.html +160 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/GaussMutation.html +311 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/Identity.html +220 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/InversionMutation.html +231 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/MixingMutation.html +233 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/OneGeneFlipping.html +295 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/SelfAdaptiveGaussMutation.html +347 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/ShiftingMutation.html +229 -0
- data/docs/rdoc/classes/EvoSynth/Mutations/UniformRealMutation.html +264 -0
- data/docs/rdoc/classes/EvoSynth/Output.html +212 -0
- data/docs/rdoc/classes/EvoSynth/Output/CSVExporter.html +211 -0
- data/docs/rdoc/classes/EvoSynth/Output/ConsoleWriter.html +194 -0
- data/docs/rdoc/classes/EvoSynth/Output/GnuPlotExporter.html +235 -0
- data/docs/rdoc/classes/EvoSynth/Output/GruffExporter.html +219 -0
- data/docs/rdoc/classes/EvoSynth/Output/Logger.html +345 -0
- data/docs/rdoc/classes/EvoSynth/Population.html +430 -0
- data/docs/rdoc/classes/EvoSynth/Problems.html +159 -0
- data/docs/rdoc/classes/EvoSynth/Problems/BinaryBenchmarkFuntions.html +258 -0
- data/docs/rdoc/classes/EvoSynth/Problems/FloatBenchmarkFuntions.html +406 -0
- data/docs/rdoc/classes/EvoSynth/Problems/GraphColouring.html +265 -0
- data/docs/rdoc/classes/EvoSynth/Problems/TSP.html +327 -0
- data/docs/rdoc/classes/EvoSynth/Profile.html +324 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations.html +251 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/ArithmeticCrossover.html +286 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/EdgeRecombination.html +203 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/Identity.html +192 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/KPointCrossover.html +286 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/OnePointCrossover.html +211 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/OrderedRecombination.html +206 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/PartiallyMappedCrossover.html +206 -0
- data/docs/rdoc/classes/EvoSynth/Recombinations/UniformCrossover.html +208 -0
- data/docs/rdoc/classes/EvoSynth/Selections.html +174 -0
- data/docs/rdoc/classes/EvoSynth/Selections/FitnessProportionalSelection.html +206 -0
- data/docs/rdoc/classes/EvoSynth/Selections/Identity.html +200 -0
- data/docs/rdoc/classes/EvoSynth/Selections/NStageTournamentSelection.html +273 -0
- data/docs/rdoc/classes/EvoSynth/Selections/RandomSelection.html +192 -0
- data/docs/rdoc/classes/EvoSynth/Selections/RouletteWheelSelection.html +212 -0
- data/docs/rdoc/classes/EvoSynth/Selections/SelectBest.html +206 -0
- data/docs/rdoc/classes/EvoSynth/Selections/TournamentSelection.html +274 -0
- data/docs/rdoc/classes/Examples.html +268 -0
- data/docs/rdoc/classes/Examples/Ants.html +198 -0
- data/docs/rdoc/classes/Examples/Ants/AntMutation.html +381 -0
- data/docs/rdoc/classes/Examples/Ants/Pheromon.html +256 -0
- data/docs/rdoc/classes/Examples/CCGAExample.html +305 -0
- data/docs/rdoc/classes/Examples/CCGAExample/CCGA2BenchmarkEvaluator.html +165 -0
- data/docs/rdoc/classes/Examples/CCGAExample/CCGABenchmarkEvaluator.html +242 -0
- data/docs/rdoc/classes/Examples/CCGAExample/CCGAIndividual.html +181 -0
- data/docs/rdoc/classes/Examples/CMBExample.html +215 -0
- data/docs/rdoc/classes/Examples/CMBExample/CMBEvaluator.html +212 -0
- data/docs/rdoc/classes/Examples/EsExample.html +270 -0
- data/docs/rdoc/classes/Examples/EsExample/BenchmarkEvaluator.html +162 -0
- data/docs/rdoc/classes/Examples/Exporter.html +208 -0
- data/docs/rdoc/classes/Examples/Exporter/ExporterEvaluator.html +196 -0
- data/docs/rdoc/classes/Examples/GraphColouring.html +199 -0
- data/docs/rdoc/classes/Examples/Hacking.html +147 -0
- data/docs/rdoc/classes/Examples/Hacking/HackingEvaluator.html +169 -0
- data/docs/rdoc/classes/Examples/LocalSearch.html +294 -0
- data/docs/rdoc/classes/Examples/LocalSearch/LocalSearchEvaluator.html +198 -0
- data/docs/rdoc/classes/Examples/MaxOnes.html +187 -0
- data/docs/rdoc/classes/Examples/MaxOnes/MaxOnesEvaluator.html +170 -0
- data/docs/rdoc/classes/Examples/Partitionproblem.html +201 -0
- data/docs/rdoc/classes/Examples/Partitionproblem/PartitionEvaluator.html +164 -0
- data/docs/rdoc/classes/Examples/Partitionproblem/PartitionIndividual.html +334 -0
- data/docs/rdoc/classes/Examples/Partitionproblem/PartitionMutation.html +199 -0
- data/docs/rdoc/classes/Examples/Partitionproblem/Testdata.html +294 -0
- data/docs/rdoc/classes/Examples/SPk.html +139 -0
- data/docs/rdoc/classes/Examples/SPk/SPkFitnessEvaluator.html +299 -0
- data/docs/rdoc/classes/Examples/TSP.html +187 -0
- data/docs/rdoc/created.rid +1 -0
- data/docs/rdoc/files/INSTALL.html +253 -0
- data/docs/rdoc/files/LICENSE.html +119 -0
- data/docs/rdoc/files/README.html +235 -0
- data/docs/rdoc/files/docs/FEATURES.html +428 -0
- data/docs/rdoc/files/examples/ants_rb.html +133 -0
- data/docs/rdoc/files/examples/ccga_example_rb.html +129 -0
- data/docs/rdoc/files/examples/cmb_example_rb.html +129 -0
- data/docs/rdoc/files/examples/evolution_strategies_rb.html +129 -0
- data/docs/rdoc/files/examples/exporter_rb.html +129 -0
- data/docs/rdoc/files/examples/graph_colouring_rb.html +129 -0
- data/docs/rdoc/files/examples/hacking_rb.html +129 -0
- data/docs/rdoc/files/examples/local_search_rb.html +129 -0
- data/docs/rdoc/files/examples/max_ones_rb.html +129 -0
- data/docs/rdoc/files/examples/partition_rb.html +131 -0
- data/docs/rdoc/files/examples/spk_rb.html +129 -0
- data/docs/rdoc/files/examples/tsp_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/core/array_genome_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/binary_genome_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/evaluator_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/core/individual_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/maximizing_individual_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/minimizing_individual_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/population_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/profile_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core/randomizer_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/core_rb.html +145 -0
- data/docs/rdoc/files/lib/evosynth/decoder/binary_to_real_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/decoder/gray_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/decoder_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/basic/genetic_algorithm_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/basic/hillclimber_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/basic/memetic_algorithm_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/basic/population_hillclimber_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/basic/steady_state_ga_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/coevolutionary/balanced_coevolutionary_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/coevolutionary/round_robin_coevolutionary_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/elitism_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/evolution_strategies/adaptive_es_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/evolution_strategies/derandomized_es_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/evolution_strategies/selfadaptive_es_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/evolver_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/acceptance_great_deluge_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/acceptance_hillclimber_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/acceptance_record_to_record_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/acceptance_simulated_annealing_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/acceptance_threshold_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/local_search/local_search_rb.html +137 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/profile_using_evolver_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/evolvers/runnable_evolver_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/evolvers_rb.html +153 -0
- data/docs/rdoc/files/lib/evosynth/operators/adjustments/adaptive_adjustment_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/adjustments/predefined_adjustment_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/adjustments_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/operators/global_recombinations/global_arithmetic_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/global_recombinations/global_uniform_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/global_recombinations_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/operators/meta_operators/conditional_combined_operator_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/meta_operators/proportional_combined_operator_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/meta_operators/sequential_combined_operator_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/meta_operators_rb.html +133 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/binary_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/efficient_binary_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/exchange_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/flip_functions_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/gauss_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/identity_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/inversion_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/mixing_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/one_gene_flipping_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/self_adaptive_gauss_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/shifting_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations/uniform_real_mutation_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/mutations_rb.html +151 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/arithmetic_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/edge_recombination_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/identity_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/k_point_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/one_point_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/ordered_recombination_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/partially_mapped_crossover_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations/uniform_crossover_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/recombinations_rb.html +143 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/best_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/fitness_proportional_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/identity_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/n_stage_tournament_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/random_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/roulette_wheel_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections/tournament_selection_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/operators/selections_rb.html +141 -0
- data/docs/rdoc/files/lib/evosynth/operators_rb.html +139 -0
- data/docs/rdoc/files/lib/evosynth/output/console_writer_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/output/exporter/csv_exporter_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/output/exporter/gnuplot_exporter_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/output/exporter/gruff_exporter_rb.html +131 -0
- data/docs/rdoc/files/lib/evosynth/output/exporter_rb.html +133 -0
- data/docs/rdoc/files/lib/evosynth/output/factory_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/output/logger_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/output_rb.html +135 -0
- data/docs/rdoc/files/lib/evosynth/problems/binary_benchmark_functions_rb.html +119 -0
- data/docs/rdoc/files/lib/evosynth/problems/float_benchmark_functions_rb.html +1630 -0
- data/docs/rdoc/files/lib/evosynth/problems/graph_colouring_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/problems/tsp_rb.html +129 -0
- data/docs/rdoc/files/lib/evosynth/problems_rb.html +135 -0
- data/docs/rdoc/files/lib/evosynth_rb.html +139 -0
- data/docs/rdoc/fr_class_index.html +245 -0
- data/docs/rdoc/fr_file_index.html +233 -0
- data/docs/rdoc/fr_method_index.html +661 -0
- data/docs/rdoc/index.html +21 -0
- data/docs/rdoc/rdoc-style.css +299 -0
- data/examples/ants.rb +237 -0
- data/examples/ccga_example.rb +150 -0
- data/examples/cmb_example.rb +117 -0
- data/examples/evolution_strategies.rb +84 -0
- data/examples/exporter.rb +90 -0
- data/examples/graph_colouring.rb +72 -0
- data/examples/hacking.rb +62 -0
- data/examples/local_search.rb +109 -0
- data/examples/max_ones.rb +83 -0
- data/examples/partition.rb +172 -0
- data/examples/spk.rb +106 -0
- data/examples/tsp.rb +83 -0
- data/lib/evosynth.rb +32 -0
- data/lib/evosynth/core.rb +33 -0
- data/lib/evosynth/core/array_genome.rb +77 -0
- data/lib/evosynth/core/binary_genome.rb +156 -0
- data/lib/evosynth/core/evaluator.rb +109 -0
- data/lib/evosynth/core/individual.rb +92 -0
- data/lib/evosynth/core/maximizing_individual.rb +71 -0
- data/lib/evosynth/core/minimizing_individual.rb +71 -0
- data/lib/evosynth/core/population.rb +120 -0
- data/lib/evosynth/core/profile.rb +110 -0
- data/lib/evosynth/core/randomizer.rb +73 -0
- data/lib/evosynth/decoder.rb +33 -0
- data/lib/evosynth/decoder/binary_to_real.rb +57 -0
- data/lib/evosynth/decoder/gray.rb +54 -0
- data/lib/evosynth/evolvers.rb +41 -0
- data/lib/evosynth/evolvers/basic/genetic_algorithm.rb +92 -0
- data/lib/evosynth/evolvers/basic/hillclimber.rb +64 -0
- data/lib/evosynth/evolvers/basic/memetic_algorithm.rb +111 -0
- data/lib/evosynth/evolvers/basic/population_hillclimber.rb +69 -0
- data/lib/evosynth/evolvers/basic/steady_state_ga.rb +85 -0
- data/lib/evosynth/evolvers/coevolutionary/balanced_coevolutionary.rb +125 -0
- data/lib/evosynth/evolvers/coevolutionary/round_robin_coevolutionary.rb +87 -0
- data/lib/evosynth/evolvers/elitism.rb +108 -0
- data/lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb +104 -0
- data/lib/evosynth/evolvers/evolution_strategies/derandomized_es.rb +120 -0
- data/lib/evosynth/evolvers/evolution_strategies/selfadaptive_es.rb +82 -0
- data/lib/evosynth/evolvers/evolver.rb +43 -0
- data/lib/evosynth/evolvers/local_search/acceptance_great_deluge.rb +60 -0
- data/lib/evosynth/evolvers/local_search/acceptance_hillclimber.rb +47 -0
- data/lib/evosynth/evolvers/local_search/acceptance_record_to_record.rb +69 -0
- data/lib/evosynth/evolvers/local_search/acceptance_simulated_annealing.rb +59 -0
- data/lib/evosynth/evolvers/local_search/acceptance_threshold.rb +60 -0
- data/lib/evosynth/evolvers/local_search/local_search.rb +74 -0
- data/lib/evosynth/evolvers/profile_using_evolver.rb +77 -0
- data/lib/evosynth/evolvers/runnable_evolver.rb +89 -0
- data/lib/evosynth/operators.rb +30 -0
- data/lib/evosynth/operators/adjustments.rb +26 -0
- data/lib/evosynth/operators/adjustments/adaptive_adjustment.rb +55 -0
- data/lib/evosynth/operators/adjustments/predefined_adjustment.rb +46 -0
- data/lib/evosynth/operators/global_recombinations.rb +26 -0
- data/lib/evosynth/operators/global_recombinations/global_arithmetic_crossover.rb +50 -0
- data/lib/evosynth/operators/global_recombinations/global_uniform_crossover.rb +49 -0
- data/lib/evosynth/operators/meta_operators.rb +36 -0
- data/lib/evosynth/operators/meta_operators/conditional_combined_operator.rb +65 -0
- data/lib/evosynth/operators/meta_operators/proportional_combined_operator.rb +84 -0
- data/lib/evosynth/operators/meta_operators/sequential_combined_operator.rb +73 -0
- data/lib/evosynth/operators/mutations.rb +47 -0
- data/lib/evosynth/operators/mutations/binary_mutation.rb +100 -0
- data/lib/evosynth/operators/mutations/efficient_binary_mutation.rb +105 -0
- data/lib/evosynth/operators/mutations/exchange_mutation.rb +107 -0
- data/lib/evosynth/operators/mutations/flip_functions.rb +45 -0
- data/lib/evosynth/operators/mutations/gauss_mutation.rb +65 -0
- data/lib/evosynth/operators/mutations/identity.rb +62 -0
- data/lib/evosynth/operators/mutations/inversion_mutation.rb +73 -0
- data/lib/evosynth/operators/mutations/mixing_mutation.rb +75 -0
- data/lib/evosynth/operators/mutations/one_gene_flipping.rb +89 -0
- data/lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb +73 -0
- data/lib/evosynth/operators/mutations/shifting_mutation.rb +88 -0
- data/lib/evosynth/operators/mutations/uniform_real_mutation.rb +59 -0
- data/lib/evosynth/operators/recombinations.rb +48 -0
- data/lib/evosynth/operators/recombinations/arithmetic_crossover.rb +67 -0
- data/lib/evosynth/operators/recombinations/edge_recombination.rb +108 -0
- data/lib/evosynth/operators/recombinations/identity.rb +42 -0
- data/lib/evosynth/operators/recombinations/k_point_crossover.rb +81 -0
- data/lib/evosynth/operators/recombinations/one_point_crossover.rb +56 -0
- data/lib/evosynth/operators/recombinations/ordered_recombination.rb +75 -0
- data/lib/evosynth/operators/recombinations/partially_mapped_crossover.rb +102 -0
- data/lib/evosynth/operators/recombinations/uniform_crossover.rb +54 -0
- data/lib/evosynth/operators/selections.rb +31 -0
- data/lib/evosynth/operators/selections/best_selection.rb +54 -0
- data/lib/evosynth/operators/selections/fitness_proportional_selection.rb +83 -0
- data/lib/evosynth/operators/selections/identity.rb +48 -0
- data/lib/evosynth/operators/selections/n_stage_tournament_selection.rb +84 -0
- data/lib/evosynth/operators/selections/random_selection.rb +44 -0
- data/lib/evosynth/operators/selections/roulette_wheel_selection.rb +54 -0
- data/lib/evosynth/operators/selections/tournament_selection.rb +71 -0
- data/lib/evosynth/output.rb +28 -0
- data/lib/evosynth/output/console_writer.rb +45 -0
- data/lib/evosynth/output/exporter.rb +27 -0
- data/lib/evosynth/output/exporter/csv_exporter.rb +62 -0
- data/lib/evosynth/output/exporter/gnuplot_exporter.rb +81 -0
- data/lib/evosynth/output/exporter/gruff_exporter.rb +70 -0
- data/lib/evosynth/output/factory.rb +38 -0
- data/lib/evosynth/output/logger.rb +83 -0
- data/lib/evosynth/problems.rb +37 -0
- data/lib/evosynth/problems/binary_benchmark_functions.rb +74 -0
- data/lib/evosynth/problems/float_benchmark_functions.rb +99 -0
- data/lib/evosynth/problems/graph_colouring.rb +89 -0
- data/lib/evosynth/problems/tsp.rb +88 -0
- data/test/benchmark/decoder_benchmark.rb +75 -0
- data/test/benchmark/mutation_benchmark.rb +88 -0
- data/test/benchmark/recombination_benchmark.rb +58 -0
- data/test/benchmark/selection_benchmark.rb +52 -0
- data/test/core/tc_array_genome.rb +154 -0
- data/test/core/tc_binary_genome.rb +160 -0
- data/test/core/tc_population.rb +154 -0
- data/test/core/tc_profile.rb +75 -0
- data/test/core/tc_randomizer.rb +165 -0
- data/test/coverage.rb +43 -0
- data/test/decoder/tc_binary_to_real.rb +52 -0
- data/test/decoder/tc_gray.rb +107 -0
- data/test/operators/adjustments/tc_adaptive_adjustment.rb +63 -0
- data/test/operators/adjustments/tc_predefined_adjustment.rb +49 -0
- data/test/operators/global_recombinations/tc_global_arithmetic_crossover.rb +78 -0
- data/test/operators/global_recombinations/tc_global_uniform_crossover.rb +90 -0
- data/test/operators/meta_operators/tc_conditional_combined_operator.rb +66 -0
- data/test/operators/meta_operators/tc_proportional_combined_operator.rb +167 -0
- data/test/operators/meta_operators/tc_sequential_combined_operator.rb +98 -0
- data/test/operators/mutations/tc_binary_mutation.rb +73 -0
- data/test/operators/mutations/tc_efficient_binary_mutation.rb +73 -0
- data/test/operators/mutations/tc_exchange_mutation.rb +127 -0
- data/test/operators/mutations/tc_gauss_mutation.rb +130 -0
- data/test/operators/mutations/tc_identity_mutation.rb +64 -0
- data/test/operators/mutations/tc_inversion_mutation.rb +70 -0
- data/test/operators/mutations/tc_mixing_mutation.rb +73 -0
- data/test/operators/mutations/tc_one_gene_flipping.rb +109 -0
- data/test/operators/mutations/tc_self_adaptive_gauss_mutation.rb +72 -0
- data/test/operators/mutations/tc_shifting_muation.rb +73 -0
- data/test/operators/mutations/tc_uniform_real_mutation.rb +65 -0
- data/test/operators/recombinations/tc_arithmetic_crossover.rb +79 -0
- data/test/operators/recombinations/tc_edge_recombination.rb +76 -0
- data/test/operators/recombinations/tc_identity_recombination.rb +81 -0
- data/test/operators/recombinations/tc_k_point_crossover.rb +81 -0
- data/test/operators/recombinations/tc_one_point_crossover.rb +80 -0
- data/test/operators/recombinations/tc_ordered_recombination.rb +76 -0
- data/test/operators/recombinations/tc_partially_mapped_crossover.rb +91 -0
- data/test/operators/recombinations/tc_uniform_crossover.rb +84 -0
- data/test/operators/selections/tc_best_selection.rb +85 -0
- data/test/operators/selections/tc_fitness_proportional_selection.rb +78 -0
- data/test/operators/selections/tc_identity.rb +91 -0
- data/test/operators/selections/tc_n_stage_tournament.rb +78 -0
- data/test/operators/selections/tc_random_selection.rb +70 -0
- data/test/operators/selections/tc_roulette_wheel_selection.rb +78 -0
- data/test/operators/selections/tc_tournament_selection.rb +83 -0
- data/test/problems/tc_binary_benchmark_functions.rb +126 -0
- data/test/problems/tc_float_benchmark_functions.rb +100 -0
- data/test/test_util/test_helper.rb +128 -0
- data/test/ts_adjustments.rb +26 -0
- data/test/ts_core.rb +29 -0
- data/test/ts_decoder.rb +26 -0
- data/test/ts_global_recombinations.rb +26 -0
- data/test/ts_meta_operators.rb +27 -0
- data/test/ts_mutations.rb +35 -0
- data/test/ts_problems.rb +26 -0
- data/test/ts_recombinations.rb +32 -0
- data/test/ts_selections.rb +31 -0
- data/testdata/README +4 -0
- data/testdata/bays29.tsp +68 -0
- data/testdata/myciel4.col +77 -0
- metadata +552 -0
data/examples/hacking.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2009, 2010 Yves Adler <yves.adler@googlemail.com>
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'evosynth'
|
|
26
|
+
#require 'profile'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module Examples
|
|
30
|
+
# lets find a solution for http://www.danielgrunwald.de/coding/hacking/2936.php
|
|
31
|
+
module Hacking
|
|
32
|
+
|
|
33
|
+
GENOME_SIZE = 7
|
|
34
|
+
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
|
|
35
|
+
|
|
36
|
+
class HackingEvaluator < EvoSynth::Evaluator
|
|
37
|
+
|
|
38
|
+
def calculate_fitness(individual)
|
|
39
|
+
suma = 0.0
|
|
40
|
+
|
|
41
|
+
individual.genome.each do |gene|
|
|
42
|
+
suma *= 26
|
|
43
|
+
suma += ALPHABET.index(gene) + 1
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
(6030912063.0 - suma).abs
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
FLIP_CHAR = lambda { ALPHABET[EvoSynth.rand(ALPHABET.size)] }
|
|
51
|
+
|
|
52
|
+
profile = EvoSynth::Profile.new(
|
|
53
|
+
:individual => EvoSynth::MinimizingIndividual.new( EvoSynth::ArrayGenome.new(GENOME_SIZE) { ALPHABET[EvoSynth.rand(ALPHABET.size)] }),
|
|
54
|
+
:evaluator => Hacking::HackingEvaluator.new,
|
|
55
|
+
:mutation => EvoSynth::Mutations::BinaryMutation.new(FLIP_CHAR)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
evolver = EvoSynth::Evolvers::Hillclimber.new(profile)
|
|
59
|
+
evolver.run_until_fitness_reached(0.0)
|
|
60
|
+
puts "found passwort ('#{evolver.individual.genome.join("")}') after #{evolver.generations_computed} generations..."
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Copyright (c) 2009, 2010 Yves Adler <yves.adler@googlemail.com>
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'evosynth'
|
|
26
|
+
#require 'profile'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module Examples
|
|
30
|
+
module LocalSearch
|
|
31
|
+
|
|
32
|
+
VALUE_BITS = 16
|
|
33
|
+
DIMENSIONS = 5
|
|
34
|
+
GENERATIONS = 5000
|
|
35
|
+
GENOME_SIZE = VALUE_BITS * DIMENSIONS
|
|
36
|
+
UPPER_LIMIT = 5.12
|
|
37
|
+
LOWER_LIMIT = -5.12
|
|
38
|
+
|
|
39
|
+
class LocalSearchEvaluator < EvoSynth::Evaluator
|
|
40
|
+
|
|
41
|
+
def decode(individual)
|
|
42
|
+
values = []
|
|
43
|
+
DIMENSIONS.times do |dim|
|
|
44
|
+
values << EvoSynth::Decoder.binary_to_real(individual.genome[dim * VALUE_BITS, VALUE_BITS], LOWER_LIMIT, UPPER_LIMIT)
|
|
45
|
+
end
|
|
46
|
+
values
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def calculate_fitness(individual)
|
|
50
|
+
EvoSynth::Problems::FloatBenchmarkFuntions.sphere(decode(individual))
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def LocalSearch.create_individual
|
|
55
|
+
EvoSynth::MinimizingIndividual.new( EvoSynth::ArrayGenome.new(GENOME_SIZE) { EvoSynth.rand_bool } )
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def LocalSearch.print_acceptance_state(evolver)
|
|
59
|
+
puts "\nAcceptance:" unless evolver.acceptance.instance_variables.empty?
|
|
60
|
+
evolver.acceptance.instance_variables.each do |var|
|
|
61
|
+
is_accessor = (var.to_s.gsub("@", "") + "=").to_sym
|
|
62
|
+
puts "\t#{var} = #{evolver.acceptance.instance_variable_get(var)}" if evolver.acceptance.respond_to?(is_accessor)
|
|
63
|
+
end
|
|
64
|
+
puts
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def LocalSearch.run_with(profile, individual)
|
|
68
|
+
puts "--- Local Search with #{profile.acceptance.to_s} ---\n"
|
|
69
|
+
|
|
70
|
+
profile.individual = individual.deep_clone
|
|
71
|
+
evolver = EvoSynth::Evolvers::LocalSearch.new(profile)
|
|
72
|
+
LocalSearch.print_acceptance_state(evolver)
|
|
73
|
+
|
|
74
|
+
evolver.add_observer(EvoSynth::Output.create_console_logger(500,
|
|
75
|
+
"generations" => ->{ evolver.generations_computed },
|
|
76
|
+
"fitness" => ->{ evolver.best_solution.fitness },
|
|
77
|
+
"temperature" => ->{ evolver.acceptance.temperature },
|
|
78
|
+
"alpha" => ->{ evolver.acceptance.alpha },
|
|
79
|
+
"delta" => ->{ evolver.acceptance.delta }
|
|
80
|
+
))
|
|
81
|
+
|
|
82
|
+
result = evolver.run_until_generations_reached(GENERATIONS)
|
|
83
|
+
LocalSearch.print_acceptance_state(evolver)
|
|
84
|
+
|
|
85
|
+
puts "\n-> fitness after #{GENERATIONS} generations: #{profile.evaluator.calculate_fitness(result)}\n\n"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
profile = EvoSynth::Profile.new(
|
|
89
|
+
:mutation => EvoSynth::Mutations::BinaryMutation.new(EvoSynth::Mutations::Functions::FLIP_BOOLEAN),
|
|
90
|
+
:evaluator => LocalSearchEvaluator.new
|
|
91
|
+
)
|
|
92
|
+
individual = LocalSearch.create_individual
|
|
93
|
+
|
|
94
|
+
profile.acceptance = EvoSynth::Evolvers::LocalSearch::HillclimberAcceptance.new
|
|
95
|
+
LocalSearch.run_with(profile, individual)
|
|
96
|
+
|
|
97
|
+
profile.acceptance = EvoSynth::Evolvers::LocalSearch::SimulatedAnnealingAcceptance.new(5000.0)
|
|
98
|
+
LocalSearch.run_with(profile, individual)
|
|
99
|
+
|
|
100
|
+
profile.acceptance = EvoSynth::Evolvers::LocalSearch::ThresholdAcceptance.new(5000.0)
|
|
101
|
+
LocalSearch.run_with(profile, individual)
|
|
102
|
+
|
|
103
|
+
profile.acceptance = EvoSynth::Evolvers::LocalSearch::GreatDelugeAcceptance.new(2500.0)
|
|
104
|
+
LocalSearch.run_with(profile, individual)
|
|
105
|
+
|
|
106
|
+
profile.acceptance = EvoSynth::Evolvers::LocalSearch::RecordToRecordTravelAcceptance.new(5000.0)
|
|
107
|
+
LocalSearch.run_with(profile, individual)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright (c) 2009, 2010 Yves Adler <yves.adler@googlemail.com>
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'evosynth'
|
|
26
|
+
#require 'profile'
|
|
27
|
+
|
|
28
|
+
module Examples
|
|
29
|
+
module MaxOnes
|
|
30
|
+
|
|
31
|
+
GENOME_SIZE = 50
|
|
32
|
+
POP_SIZE = 25
|
|
33
|
+
MAX_EVALUATIONS = 5000
|
|
34
|
+
|
|
35
|
+
# this is just for the sake of demonstration stuff - you could also use
|
|
36
|
+
# EvoSynth::Problems::BinaryBenchmarkFuntions.count_ones()
|
|
37
|
+
|
|
38
|
+
class MaxOnesEvaluator < EvoSynth::Evaluator
|
|
39
|
+
def calculate_fitness(individual)
|
|
40
|
+
individual.genome.inject(0.0) { |fitness, gene| fitness += gene ? 1 : 0 }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def MaxOnes.create_individual
|
|
45
|
+
EvoSynth::MaximizingIndividual.new( EvoSynth::ArrayGenome.new(GENOME_SIZE) { EvoSynth.rand_bool } )
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
profile = EvoSynth::Profile.new(
|
|
49
|
+
:individual => MaxOnes.create_individual,
|
|
50
|
+
:population => EvoSynth::Population.new(POP_SIZE) { MaxOnes.create_individual },
|
|
51
|
+
:evaluator => MaxOnes::MaxOnesEvaluator.new,
|
|
52
|
+
:mutation => EvoSynth::Mutations::BinaryMutation.new(EvoSynth::Mutations::Functions::FLIP_BOOLEAN)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# ---------------------------- Use simple Hillclimber ---------------------------- #
|
|
56
|
+
|
|
57
|
+
evolver = EvoSynth::Evolvers::Hillclimber.new(profile)
|
|
58
|
+
evolver.add_observer(EvoSynth::Output.create_console_logger(500,
|
|
59
|
+
"generations" => ->{ evolver.generations_computed },
|
|
60
|
+
"bestfitness" => ->{ evolver.best_solution.fitness },
|
|
61
|
+
"worstfitness" => ->{ evolver.worst_solution.fitness }
|
|
62
|
+
))
|
|
63
|
+
|
|
64
|
+
puts "\nRunning Hillclimber...\n"
|
|
65
|
+
result = evolver.run_until { profile.evaluator.called < MAX_EVALUATIONS }
|
|
66
|
+
puts "\nIndividual after evolution: #{profile.individual}"
|
|
67
|
+
|
|
68
|
+
# --------------------------- Use GA with weak elistism --------------------------- #
|
|
69
|
+
|
|
70
|
+
profile.evaluator.reset_counters
|
|
71
|
+
evolver = EvoSynth::Evolvers::GeneticAlgorithm.new(profile)
|
|
72
|
+
EvoSynth::Evolvers.add_weak_elistism(evolver)
|
|
73
|
+
evolver.add_observer(EvoSynth::Output.create_console_logger(50,
|
|
74
|
+
"generations" => ->{ evolver.generations_computed },
|
|
75
|
+
"bestfitness" => ->{ evolver.best_solution.fitness },
|
|
76
|
+
"worstfitness" => ->{ evolver.worst_solution.fitness }
|
|
77
|
+
))
|
|
78
|
+
|
|
79
|
+
puts "\nRunning Genetic Algorithm with elitism...\n"
|
|
80
|
+
result = evolver.run_until { profile.evaluator.called < MAX_EVALUATIONS }
|
|
81
|
+
puts "\nBest Individual after evolution: #{result.best}"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Copyright (c) 2009, 2010 Yves Adler <yves.adler@googlemail.com>
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'set'
|
|
26
|
+
require 'evosynth'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module Examples
|
|
30
|
+
module Partitionproblem
|
|
31
|
+
|
|
32
|
+
class PartitionEvaluator < EvoSynth::Evaluator
|
|
33
|
+
def calculate_fitness(individual)
|
|
34
|
+
sum_a = individual.partition_a.inject(0) { |sum, n| sum + n }
|
|
35
|
+
sum_b = individual.partition_b.inject(0) { |sum, n| sum + n }
|
|
36
|
+
(sum_a - sum_b).abs
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# We've to carefully overwrite functions here, because we actually have 2 genomes
|
|
41
|
+
|
|
42
|
+
class PartitionIndividual < EvoSynth::MinimizingIndividual
|
|
43
|
+
|
|
44
|
+
attr_accessor :partition_a, :partition_b
|
|
45
|
+
|
|
46
|
+
def initialize(partition_a, partition_b)
|
|
47
|
+
@partition_a = partition_a;
|
|
48
|
+
@partition_b = partition_b;
|
|
49
|
+
@fitness = Float::MAX
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def fitness=(value)
|
|
53
|
+
@fitness = value
|
|
54
|
+
@partition_a.changed = false
|
|
55
|
+
@partition_b.changed = false
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def deep_clone
|
|
59
|
+
my_clone = self.clone
|
|
60
|
+
my_clone.partition_a = Marshal.load( Marshal.dump( self.partition_a ) )
|
|
61
|
+
my_clone.partition_b = Marshal.load( Marshal.dump( self.partition_b ) )
|
|
62
|
+
my_clone
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def changed?
|
|
66
|
+
@partition_a.changed? || @partition_b.changed?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def to_s
|
|
70
|
+
"partition individual <fitness = #{fitness}, partition_a.size = #{@partition_a.size}, partition_b.size = #{@partition_b.size}>"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class PartitionMutation
|
|
76
|
+
|
|
77
|
+
def mutate(individual)
|
|
78
|
+
mutated = individual.deep_clone
|
|
79
|
+
part_a, part_b = mutated.partition_a, mutated.partition_b
|
|
80
|
+
|
|
81
|
+
if EvoSynth.rand_bool
|
|
82
|
+
part_a << part_b.delete_at(EvoSynth.rand(part_b.size)) unless mutated.partition_b.empty?
|
|
83
|
+
else
|
|
84
|
+
part_b << part_a.delete_at(EvoSynth.rand(part_a.size)) unless mutated.partition_a.empty?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
mutated
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def to_s
|
|
91
|
+
"custom made mutation for the partition problem"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# these are just Testdata generators
|
|
98
|
+
|
|
99
|
+
module Testdata
|
|
100
|
+
|
|
101
|
+
def Testdata.gen_tiny_set
|
|
102
|
+
problem = Array.new(25)
|
|
103
|
+
problem.fill { |i| i }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def Testdata.gen_layer_set
|
|
107
|
+
problem = Set.new
|
|
108
|
+
problem.add(EvoSynth.rand(1000) * EvoSynth.rand(1000)) while problem.size < 200
|
|
109
|
+
problem.add(EvoSynth.rand(1000)) while problem.size < 1000
|
|
110
|
+
problem.to_a
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def Testdata.gen_standard_set
|
|
114
|
+
problem = Array.new
|
|
115
|
+
1000.times { |i| problem.insert(-1, i) }
|
|
116
|
+
problem
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def Testdata.gen_random_set
|
|
120
|
+
problem = Set.new
|
|
121
|
+
problem.add(EvoSynth.rand(1000000)) while problem.size < 1000
|
|
122
|
+
problem.to_a
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def Testdata.gen_big_set
|
|
126
|
+
problem = Set.new
|
|
127
|
+
problem.add(EvoSynth.rand(10000) * 100) while problem.size < 1000
|
|
128
|
+
problem.to_a
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# creates a new (random) individual from a given problem
|
|
133
|
+
|
|
134
|
+
def Partitionproblem.get_new_individual_from(problem)
|
|
135
|
+
border = EvoSynth.rand(problem.size)
|
|
136
|
+
part_a, part_b = EvoSynth::ArrayGenome.new, EvoSynth::ArrayGenome.new
|
|
137
|
+
|
|
138
|
+
problem.size.times do
|
|
139
|
+
|index| index < border ? part_a << problem[index] : part_b << problem[index]
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
Partitionproblem::PartitionIndividual.new(part_a, part_b)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
POPULATION_SIZE = 20
|
|
146
|
+
GENERATIONS = 500
|
|
147
|
+
GOAL = 0.0
|
|
148
|
+
|
|
149
|
+
problem = Partitionproblem::Testdata.gen_layer_set
|
|
150
|
+
base_population = EvoSynth::Population.new(POPULATION_SIZE) { Partitionproblem.get_new_individual_from(problem) }
|
|
151
|
+
|
|
152
|
+
profile = EvoSynth::Profile.new(
|
|
153
|
+
:mutation => PartitionMutation.new,
|
|
154
|
+
:parent_selection => EvoSynth::Selections::TournamentSelection.new(3),
|
|
155
|
+
:recombination => EvoSynth::Recombinations::Identity.new,
|
|
156
|
+
:evaluator => Partitionproblem::PartitionEvaluator.new
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
profile.population = base_population.deep_clone
|
|
160
|
+
puts "running MemeticAlgorithm with elitism..."
|
|
161
|
+
evolver = EvoSynth::Evolvers::MemeticAlgorithm.new(profile)
|
|
162
|
+
EvoSynth::Evolvers.add_weak_elistism(evolver)
|
|
163
|
+
evolver.add_observer(EvoSynth::Output.create_console_logger(25,
|
|
164
|
+
"generations" => ->{ evolver.generations_computed },
|
|
165
|
+
"fitness" => ->{ evolver.best_solution.fitness },
|
|
166
|
+
"best" => ->{ evolver.best_solution.to_s }
|
|
167
|
+
))
|
|
168
|
+
|
|
169
|
+
evolver.run_until { |gen, best| best.fitness <= GOAL || gen >= GENERATIONS }
|
|
170
|
+
puts "\nResult after #{evolver.generations_computed} generations: #{evolver.best_solution}"
|
|
171
|
+
end
|
|
172
|
+
end
|
data/examples/spk.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Copyright (c) 2009, 2010 Yves Adler <yves.adler@googlemail.com>
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'evosynth'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# TODO: this could be a benchmark problem
|
|
29
|
+
|
|
30
|
+
module Examples
|
|
31
|
+
module SPk
|
|
32
|
+
|
|
33
|
+
class SPkFitnessEvaluator < EvoSynth::Evaluator
|
|
34
|
+
|
|
35
|
+
def initialize(k)
|
|
36
|
+
@k = k
|
|
37
|
+
super()
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def calculate_fitness(individual)
|
|
41
|
+
fitness = 0.0
|
|
42
|
+
|
|
43
|
+
ones = individual.genome.inject(0) do |ones, gene|
|
|
44
|
+
ones += gene ? 1 : 0
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if is_valid(individual.genome)
|
|
48
|
+
fitness = individual.genome.size * (ones + 1)
|
|
49
|
+
else
|
|
50
|
+
fitness = individual.genome.size - ones
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
fitness
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def is_valid(genome)
|
|
57
|
+
valid = false
|
|
58
|
+
|
|
59
|
+
len_of_ones = calc_length_of_ones(genome)
|
|
60
|
+
max_k = (genome.size.to_f / (3.0 * @k*@k).to_f).ceil
|
|
61
|
+
valid = true if !len_of_ones.nil? && len_of_ones / @k <= max_k && len_of_ones % @k == 0
|
|
62
|
+
|
|
63
|
+
valid
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def calc_length_of_ones(genome)
|
|
67
|
+
count, len_of_ones = 0, 0
|
|
68
|
+
end_of_ones, end_of_zeros = false, false
|
|
69
|
+
|
|
70
|
+
genome.each do |gene|
|
|
71
|
+
end_of_ones_reached = !gene && !end_of_ones
|
|
72
|
+
end_of_zeros_reached = gene && end_of_ones && !end_of_zeros
|
|
73
|
+
|
|
74
|
+
if end_of_ones_reached
|
|
75
|
+
len_of_ones = count
|
|
76
|
+
end_of_ones = true
|
|
77
|
+
elsif end_of_zeros_reached
|
|
78
|
+
end_of_zeros = true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
count += 1
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
len_of_ones = count if !end_of_ones
|
|
85
|
+
len_of_ones = nil if end_of_zeros
|
|
86
|
+
len_of_ones
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
K = 2
|
|
92
|
+
GENOME_SIZE = 16
|
|
93
|
+
GENERATIONS = 5000
|
|
94
|
+
|
|
95
|
+
profile = EvoSynth::Profile.new(
|
|
96
|
+
:individual => EvoSynth::MaximizingIndividual.new( EvoSynth::ArrayGenome.new(GENOME_SIZE) { EvoSynth.rand_bool } ),
|
|
97
|
+
:mutation => EvoSynth::Mutations::BinaryMutation.new(EvoSynth::Mutations::Functions::FLIP_BOOLEAN),
|
|
98
|
+
:evaluator => SPkFitnessEvaluator.new(K)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
evolver = EvoSynth::Evolvers::Hillclimber.new(profile)
|
|
102
|
+
puts "Running #{evolver}...\n\n"
|
|
103
|
+
result = evolver.run_until_generations_reached(GENERATIONS)
|
|
104
|
+
puts "result: #{result}"
|
|
105
|
+
end
|
|
106
|
+
end
|