-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitArrayFit.hs
More file actions
34 lines (28 loc) · 767 Bytes
/
BitArrayFit.hs
File metadata and controls
34 lines (28 loc) · 767 Bytes
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
-- CPSC 312 - 2018 - Genetic Algorithm Library
-- done by Junsu Shin
module BitArrayFit(
fit,
Fit) where
import BitArrayChromosome
type Fit = Chromosome -> Int
temptarget = chromosome2lst (mkData [1,1,1,1,1,1])
-- Fitness function. From a Chromosome it must return a Num regarding how good this Chromosome is
-- <Test Case>
{-
d1 = mkData [0,0,1,0,0,0]
d3 = mkData [0,1,0,1,0,1]
d4 = mkData [1,0,1,0,1,1]
d6 = mkData [1,1,1,1,1,1]
fit d1
fit d3
fit d4
fit d6
-}
fit::Chromosome -> Int
fit chromosome = targetCompare temptarget (chromosome2lst chromosome)
targetCompare:: (Eq a) => [a] -> [a] -> Int
targetCompare _ [] = 0
targetCompare [] _ = 0
targetCompare (h1:t1) (h2:t2)
| h1 == h2 = 1 + targetCompare t1 t2
| otherwise = targetCompare t1 t2