-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (48 loc) · 1.12 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 13 15:08:51 2017
@author: luowen
"""
import numpy as np
import GeneticOperator as GO
import LocalSearch as LS
import Initialize as Initial
import Update as Update
import matplotlib.pyplot as plt
N=4
Ns=1
dt=0.1
data=Initial.generate_data(N,Ns,dt)
Gm=100
Sp=200
Spool=Sp/2
Stour=2
Pc=0.8
Pm=0.2
population=Initial.initial_pop(N,Sp)
dimension=N*(N+2)
Bestpop=np.zeros([Gm,dimension])
t=0
maxfitness=[]
while t<Gm:
parents=GO.selection(population,data,Spool,Stour)
children=GO.Cross_Mutate(parents,Pc,Pm)
Bestchild=LS.Findbest(children,data)
Islocal=False
#localsearch operator
# while not Islocal:
# L=neighbor
# if
#
# else:
# Islocal=True
population=Update.updatePopulation(population,data,children,Bestchild)
print 'generation %d'%t
maxfitness.append(GO.fitness(data,population[0]))
Bestpop[t]=population[0]
t+=1
plt.figure()
plt.plot(maxfitness)
plt.show()
finalbest=LS.Findbest(Bestpop,data)
print 'the minist energy is :',GO.fitness(data,finalbest)