/
StructuralChromosome.cs
58 lines (37 loc) · 1.35 KB
/
StructuralChromosome.cs
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
53
54
55
56
57
58
using Frixel.Core.Analysis;
using GeneticSharp.Domain.Chromosomes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frixel.Optimizer {
public class StructuralChromosome : ChromosomeBase {
// Change the argument value passed to base construtor to change the length
// of your chromosome.
int _numPixels;
public AnalysisResults Results { get; set; }
public StructuralChromosome(int numPixels)
: base(numPixels) {
_numPixels = numPixels;
//int s = RandomizationProvider.Current.GetInt(0, 1);
Random rand = new Random();
for (int i = 0; i < numPixels; i++) {
PixSwitch piswi = new PixSwitch();
bool s = rand.Next(0, 2) == 0;
piswi.Switch = s;
ReplaceGene(i, new Gene(piswi));
}
}
public override Gene GenerateGene(int geneIndex) {
Random rand = new Random();
PixSwitch piswi = new PixSwitch();
bool s = rand.Next(0, 2) == 0;
piswi.Switch = s;//s == 0 ? false : true;
return new Gene(piswi);
}
public override IChromosome CreateNew() {
return new StructuralChromosome(_numPixels);
}
}
}