-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCross.hs
More file actions
46 lines (35 loc) · 1.18 KB
/
Cross.hs
File metadata and controls
46 lines (35 loc) · 1.18 KB
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
-- CPSC 312 - 2018 - Genetic Algorithm Library
module Cross (
cross,
Chromosome
) where
import BitArrayChromosome
-- cross two chromosomes to make a pair of children
{-
dad = mkData [0,0,0,0,0,1]
mom = mkData [0,1,0,0,1,1]
cross dad mom
-}
cross::Chromosome -> Chromosome -> (Chromosome, Chromosome)
cross a b = crossTuple (a, b)
crossTuple::(Chromosome, Chromosome) -> (Chromosome, Chromosome)
crossTuple (parent1, parent2) = (child1, child2) where
child1 = mkChromosome ((getFst parent1)++(getSnd parent2))
child2 = mkChromosome ((getFst parent2)++(getSnd parent1))
{- Old Junsu's Version of CrossAll
crossAll _ _ [] = []
crossAll crossfunc cp population = flattenTupleList (map crossfunc (toTuplelst population))
-}
-- cuts the list of Chromosome into a list of 2 pieces
-- toTuplelst [1,2,3,4,5,6]
-- [[1,2],[3,4],[5,6]]
{-
toTuplelst::[Chromosome] -> [(Chromosome, Chromosome)]
toTuplelst [] = []
toTuplelst (h:t)
| t == [] = error "Uneven number of elements"
| otherwise = (h,head t):(toTuplelst t)
-- make the list of tuple into a big concatonated list
flattenTupleList [] = []
flattenTupleList ((fstelt, sndelt):t) = [fstelt, sndelt]++(flattenTupleList t)
-}