8000 update GA · mohuishou/go-algorithm@6198788 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6198788

Browse files
committed
update GA
1 parent 9cc8d10 commit 6198788

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

GA/GA.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package GA
2+
3+
var (
4+
groupSize int //种群大小
5+
selectRand int //轮盘选择概率
6+
crossRand int //交叉概率
7+
mutationRand int //变异概率
8+
)
9+
10+
//Person 个体
11+
type Person struct {
12+
chromosomes []int //染色体
13+
}
14+
15+
//Init 初始化函数
16+
//初始化设置种群大小、轮盘选择概率、交叉概率已经变异的概率
17+
func Init(GroupSize, SelectRand, CrossRand, MutationRand int) {
18+
groupSize = GroupSize
19+
crossRand = CrossRand
20+
selectRand = SelectRand
21+
mutationRand = MutationRand
22+
}
23+
24+
//InitGroup 初始化种群
25+
//根据种群大小随机产生一些个体填充
26+
func InitGroup() {
27+
28+
}
29+
30+
//Fitness 计算适应值
31+
func Fitness() {
32+
33+
}
34+
35+
//Select 选择
36+
func Select() {
37+
38+
}
39+
40+
//Cross 交叉
41+
func Cross() {
42+
43+
}
44+
45+
//Mutation 变异
46+
func Mutation() {
47+
48+
}
49+
50+
//GA 遗传算法
51+
func GA() {
52+
53+
}

GA/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//Package GA 遗传算法的Golang实现
2+
//遗传算法的计算流程 编码->获得初始群体->计算适应值->产生新的群体(选择、交叉、变异等)->满足要求->解码- B906 >获得近似解
3+
//例子:求解函数 f(x) = x + 10*sin(5*x) + 7*cos(4*x) 在区间[0,9]的最大值。
4+
package GA

GA/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 遗传算法
2+

ShortestPath/SPFA/SPFA.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func Init(g Graph.Graph, S Graph.VextexType, Dist []Graph.EdgeType, Path []Graph
5151

5252
//DFS spfa算法dfs实现
5353
func DFS(u Graph.VextexType) error {
54+
if isInit != true {
55+
return errors.New("请先执行SPFA.Init方法")
56+
}
5457
visited[u] = true
5558
e := graph.G[u].FisrtEdge
5659
for e != nil {

0 commit comments

Comments
 (0)
0