forked from dogefuzz/dogefuzz
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bc0b60
commit 93200dd
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package genetic_operators | ||
|
||
// metodos a serem testados podem ter mais de um parametro de entrada | ||
// uma seed representa uma lista de paramentros de entrada | ||
func Crossover(seed1, seed2 []string) ([]string, []string) { | ||
var crossoverSeed1 []string | ||
var crossoverSeed2 []string | ||
|
||
if len(seed1) == len(seed2) { | ||
for i := range seed1 { | ||
smallest := smallestSize(seed1[i], seed2[i]) | ||
// analisar a necessidade desta verificacao | ||
if smallest == 0 { | ||
crossoverSeed1 = seed1 | ||
crossoverSeed2 = seed2 | ||
// funcionando como esperado | ||
} else if smallest == 1 { | ||
var tempSeed1 string | ||
var tempSeed2 string | ||
for j := 0; j < smallest; j++ { | ||
tempSeed1 = seed1[i][j:j+1] + seed2[i][j:j+1] | ||
tempSeed2 = seed2[i][j:j+1] + seed1[i][j:j+1] | ||
} | ||
crossoverSeed1 = append(crossoverSeed1, tempSeed1) | ||
crossoverSeed2 = append(crossoverSeed2, tempSeed2) | ||
} else { | ||
var tempSeed1 string | ||
var tempSeed2 string | ||
for j := 0; j < smallest; j++ { | ||
|
||
if j%2 == 0 { | ||
tempSeed1 += seed2[i][j : j+1] | ||
tempSeed2 += seed1[i][j : j+1] | ||
} else { | ||
tempSeed1 += seed1[i][j : j+1] | ||
tempSeed2 += seed2[i][j : j+1] | ||
} | ||
} | ||
crossoverSeed1 = append(crossoverSeed1, tempSeed1) | ||
crossoverSeed2 = append(crossoverSeed2, tempSeed2) | ||
} | ||
} | ||
} | ||
|
||
return crossoverSeed1, crossoverSeed2 | ||
} | ||
|
||
func smallestSize(seed1, seed2 string) int { | ||
if len(seed1) >= len(seed2) { | ||
return len(seed2) | ||
} | ||
|
||
return len(seed1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package genetic_operators | ||
|
||
import "github.com/dogefuzz/dogefuzz/pkg/common" | ||
|
||
const MUTATION_CHANCE = 0.1 | ||
|
||
func Mutation(mutationFunction []func()) { | ||
rnd := common.RandomFloat64() | ||
|
||
if rnd < MUTATION_CHANCE { | ||
mutationFunction := common.RandomChoice(mutationFunction) | ||
mutationFunction() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package genetic_operators | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/dogefuzz/dogefuzz/pkg/common" | ||
) | ||
|
||
// consts to define chances to select some seeds | ||
const FIRST_LIMIT = 0.5 | ||
const SECOND_LIMIT = 0.8 | ||
|
||
// consts to define what range interval will used to prioritize some seeds | ||
const FIRST_RANGE = 0.4 | ||
const SECOND_RANGE = 0.7 | ||
|
||
func Selection(seedsList [][]string) []string { | ||
rnd := common.RandomFloat64() | ||
lengthList := len(seedsList) | ||
var seedsSlice [][]string | ||
|
||
if rnd < FIRST_LIMIT { | ||
seedsSlice = seedsList[0:maxIndex(lengthList, FIRST_RANGE)] | ||
} else if rnd < SECOND_LIMIT { | ||
seedsSlice = seedsList[minIndex(lengthList, FIRST_RANGE):maxIndex(lengthList, SECOND_RANGE)] | ||
} else { | ||
// [minIndex:len(seedsList)] | ||
seedsSlice = seedsList[minIndex(lengthList, SECOND_RANGE):] | ||
} | ||
|
||
return common.RandomChoice(seedsSlice) | ||
} | ||
|
||
func maxIndex(length int, factor float64) int { | ||
return int(math.Ceil(float64(length) * factor)) | ||
} | ||
|
||
func minIndex(length int, factor float64) int { | ||
return int(math.Floor(float64(length) * factor)) | ||
} |