-
Notifications
You must be signed in to change notification settings - Fork 1
/
runGA_multi.py
38 lines (29 loc) · 961 Bytes
/
runGA_multi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from mpi4py import MPI
from common import Output
from multi import Environment
from fitness.test import localglobal
from fitness.test import quadratic
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
graphics = True # plots matplotlib graphs
problem_name = 'quadratic'
# Objectives
objectives = ['objective1']
# GA settings
size=3 #population size
num_cycles=1 # number of GA cycles
cross_rate = 1.0
mutation_rate = 0.03
# Convergence criteria
max_gen=2 # Maximum number of generations
# Names and Ranges of Variables
var_ranges = {
'X1': [-10, 10],\
}
function = quadratic.Fitness(problem_name, objectives, comm=comm, size=size)
if rank==0:
output = Output.Output(problem_name, objectives, var_ranges, max_gen, size, cross_rate, mutation_rate, graphics)
env = Environment.VEGAEnvironment(objectives, var_ranges, size, max_gen, cross_rate, mutation_rate, num_cycles,function, output)
env.run()
else:
function.slaves_work()