コード例 #1
0
from OptimizationAlgorithms import genetic as g
from problem3 import problem as p
import matplotlib.pyplot as plt

pr = p.Problem()

population_size = 1000
number_of_generations = 20
mutation_rate = 0.02
tornument_size = [2, 5, 10]
plot = False

costs = []
scores = []
for t_siz in tornument_size:
    sol = g.genetic(pr, population_size, number_of_generations, mutation_rate,
                    t_siz, plot)
    costs.append(sol.get('cost'))
    scores.append(sol.get('score'))
    print('state = {} , score = {} , cost = {} '.format(
        sol.get('state'), sol.get('score'), sol.get('cost')))

fig = plt.figure()
plt.plot(tornument_size, costs, label='cost')
plt.plot(tornument_size, scores, label='fitness')
fig.suptitle('Impact of increasing tornument size', fontsize=12)
plt.xlabel('tornument size', fontsize=8)
plt.ylabel('value', fontsize=8)
fig.savefig('3_genetic_c_3')
plt.legend()
plt.show()
コード例 #2
0
from OptimizationAlgorithms import genetic as g
from problem3 import problem as p
import matplotlib.pyplot as plt

pr = p.Problem()

population_size = [10, 100, 1000]
number_of_generations = 20
mutation_rate = 0.02
tornument_size = 4
plot = False

costs = []
scores = []
for siz in population_size:
    sol = g.genetic(pr, siz, number_of_generations, mutation_rate,
                    tornument_size, plot)
    costs.append(sol.get('cost'))
    scores.append(sol.get('score'))
    print('state = {} , score = {} , cost = {} '.format(
        sol.get('state'), sol.get('score'), sol.get('cost')))

fig = plt.figure()
plt.plot(population_size, costs, label='cost')
plt.plot(population_size, scores, label='fitness')
fig.suptitle('Impact of increasing population size', fontsize=12)
plt.xlabel('population size', fontsize=8)
plt.ylabel('value', fontsize=8)
fig.savefig('3_genetic_b')
plt.legend()
plt.show()
from OptimizationAlgorithms import genetic as g
from problem3 import problem as p
import matplotlib.pyplot as plt

pr = p.Problem()

population_size = 100
number_of_generations = [50, 500, 5000]
mutation_rate = 0.02
tornument_size = 4
plot = False

costs = []
scores = []
for number in number_of_generations:
    sol = g.genetic(pr, population_size, number, mutation_rate, tornument_size,
                    plot)
    costs.append(sol.get('cost'))
    scores.append(sol.get('score'))
    print('state = {} , score = {} , cost = {} '.format(
        sol.get('state'), sol.get('score'), sol.get('cost')))

fig = plt.figure()
plt.plot(number_of_generations, costs, label='cost')
plt.plot(number_of_generations, scores, label='fitness')
fig.suptitle('Impact of increasing number of generations', fontsize=12)
plt.xlabel('number of generations', fontsize=8)
plt.ylabel('value', fontsize=8)
fig.savefig('3_genetic_a')
plt.legend()
plt.show()
コード例 #4
0
from OptimizationAlgorithms import genetic as g
from problem2 import problem as p

pr = p.Problem()

population_size = 100
number_of_generations = 20
mutation_rate = 0.02
tornument_size = 4
sol = g.genetic(pr, population_size, number_of_generations, mutation_rate, tornument_size)

print('state = {} , score = {} , cost = {} '.format(sol.get('state'), sol.get('score'), sol.get('cost')))