comparison defical-sharp/libsemtd/ga.cs @ 0:ebed2bd0d300

Initial import from svn. History be damned.
author Edho P. Arief <me@myconan.net>
date Fri, 02 Apr 2010 23:11:57 +0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ebed2bd0d300
1 /*using System;
2
3 namespace libsemtd
4 {
5 public partial class Semtd
6 {
7 private void ga_LabelRemoveVer(int posVer) { this.labelVer[posVer] = 0; }
8 private void ga_LabelSetVer(int posVer, int labelVer) { this.labelVer[posVer] = labelVer; }
9 private double ga_ScoreAlgorithm(int start, int end, params int[] numbers)
10 {
11 //STANDARD DEVIATION
12 double mean = 0;
13 double nstdev = 0;
14 int numData = end - start + 1;
15 foreach (double num in numbers)
16 {
17 mean += num;
18 }
19 mean /= numData;
20 for (int i = start; i <= end; i++)
21 {
22 nstdev += Math.Pow((numbers[i] - mean), 2);
23 }
24 return Math.Sqrt(nstdev / numData);
25 }
26 private double ga_SemtScore()
27 {
28 if (this.scoreCache > -1) { return scoreCache; }
29 if (this.IsSemt()) { return 0; }
30 int rangeDelta = this.numEdges - this.labelRangeEdge();
31 int upperBound = this.labelEdgeAbsoluteMax;
32 int edgeTempMax = this.labelEdgeMax;
33 int edgeTempMin = this.labelEdgeMin;
34 int[] edgeTempLabels = new int[upperBound + 1];
35 if (rangeDelta > 0)
36 {
37 if ((edgeTempMax + rangeDelta) > upperBound)
38 {
39 edgeTempMax = upperBound;
40 edgeTempMin -= upperBound - edgeTempMax;
41 }
42 else
43 {
44 edgeTempMax += rangeDelta;
45 }
46 }
47 for (int i = 0; i < upperBound; i++)
48 {
49 edgeTempLabels[i] = this.labelEdgesUsed[i];
50 }
51 this.scoreCache = ga_ScoreAlgorithm(edgeTempMin, edgeTempMax, edgeTempLabels);
52 return scoreCache;
53 }
54 private void ga_FixLabel()
55 {
56 bool[] labelVerUsed = new bool[this.numVerTotal+ 1];
57 bool[] verPassed = new bool[this.numVerMain + 1];
58 for (int i = 0; i < this.numVerMain; i++)
59 {
60 if (!labelVerUsed[this.labelVer[i]])
61 {
62 labelVerUsed[this.labelVer[i]] = true;
63 verPassed[i] = true;
64 }
65 }
66 for (int i = 0; i < this.numVerMain; i++)
67 {
68 if (!verPassed[i])
69 {
70 for (int nextLabel = 0; nextLabel < this.numVerMain; nextLabel++)
71 {
72 if (!labelVerUsed[nextLabel])
73 {
74 this.labelVer[i] = nextLabel;
75 verPassed[i] = true;
76 labelVerUsed[nextLabel] = true;
77 break;
78 }
79 }
80 }
81 }
82 }
83 private void ga_SwapLabel()
84 {
85 Random random = new Random();
86 int verA, verB, labelVerTemp;
87 verA = random.Next(this.numVerMain);
88 verB = verA;
89 while (verA == verB)
90 {
91 verB = random.Next(1, this.numVerMain);
92 }
93 labelVerTemp = this.labelVer[verA];
94 this.labelSetVer(verA, this.labelVer[verB]);
95 this.labelSetVer(verB, labelVerTemp);
96 }
97 private bool ga_IsSemt()
98 {
99 int[] labelVerTemp = new int[this.numVerMain];
100 for(int i=0;i<this.numVerMain;i++)
101 labelVerTemp[i] = this.labelVer[i];
102 labelReset();
103 for (int i = 0; i < this.numVerMain; i++)
104 labelSetVer(i, labelVerTemp[i]);
105 return isSemt();
106 }
107 }
108 }*/