comparison defical-sharp/libsemtd/label.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 namespace libsemtd
2 {
3 partial class Semtd
4 {
5 private void labelReset()
6 {
7 this.labelVer = new int[this.numVerMain];
8 this.labelEdges = new int[this.numVerMain, this.numVerMain];
9 this.labelEdgeAbsoluteMax = 2 * this.numVerTotal - 1;
10 this.labelEdgesUsed = new int[this.labelEdgeAbsoluteMax + 1];
11 //this.scoreCache = -1;
12 }
13 private int labelRangeEdge()
14 {
15 labelRefreshEdgeMinMax();
16 return this.labelEdgeMax - this.labelEdgeMin + 1;
17 }
18 private void labelRefreshEdgeMinMax()
19 {
20 for (int i = 1; i <= this.labelEdgeAbsoluteMax; i++)
21 {
22 if (this.labelEdgesUsed[i] > 0)
23 {
24 this.labelEdgeMin = i;
25 break;
26 }
27 }
28 for (int i = this.labelEdgeAbsoluteMax; i >= 1; i--)
29 {
30 if (this.labelEdgesUsed[i] > 0)
31 {
32 this.labelEdgeMax = i;
33 break;
34 }
35 }
36 }
37 private void labelRemoveVer(int posVer)
38 {
39 if (this.labelVer[posVer] > 0)
40 {
41 this.labelVer[posVer] = 0;
42 labelRemoveEdges(posVer);
43 }
44 }
45 private void labelRemoveEdges(int posVer)
46 {
47 for (int i = 0; i < this.numVerMain; i++)
48 {
49 if (this.labelVer[i] > 0 && i != posVer && this.graphConn[posVer, i])
50 {
51 int labelOld = this.labelEdges[i, posVer];
52 this.labelEdgesUsed[labelOld]--;
53 this.labelEdges[i, posVer] = this.labelEdges[posVer, i] = 0;
54 }
55 }
56 }
57 private void labelSetVer(int posVer, int labelVer)
58 {
59 if (this.labelVer[posVer] > 0) { labelRemoveVer(posVer); }
60 this.labelVer[posVer] = labelVer;
61 labelSetEdges(posVer);
62 }
63 private void labelSetEdges(int posVer)
64 {
65 int labelNew;
66 for (int i = 0; i < this.numVerMain; i++)
67 if (i != posVer &&
68 this.graphConn[posVer, i] &&
69 this.labelVer[i] > 0)
70 {
71 labelNew = this.labelVer[posVer] + this.labelVer[i];
72 this.labelEdges[i, posVer] = this.labelEdges[posVer, i] = labelNew;
73 this.labelEdgesUsed[labelNew]++;
74 }
75 }
76 private bool isValidToLabel(int posVer, int labelVer)
77 {
78 for (int i = 0; i < this.numVerMain; i++)
79 {
80 if (this.graphConn[i, posVer] &&
81 this.labelVer[i] > 0 &&
82 this.labelEdgesUsed[this.labelVer[i] + labelVer] == 1)
83 {
84 return false;
85 }
86 }
87 return true;
88 }
89 private bool isSemt()
90 {
91 if (labelRangeEdge() == numEdges)
92 {
93 for (int i = this.labelEdgeMin; i <= this.labelEdgeMax; i++)
94 {
95 if (this.labelEdgesUsed[i] != 1)
96 {
97 return false;
98 }
99 }
100 return true;
101 }
102 return false;
103 }
104 private int minDef()
105 {
106 int ret = 0;
107 switch (this.graphType)
108 {
109 case "wheel": //source: dissertation[1]
110 switch (this.numVerMain)
111 {
112 case 3 | 4 | 6 | 7:
113 ret = 1;
114 break;
115 default:
116 ret = 2;
117 break;
118 }
119 break;
120 case "fan": //source: dissertation[1]
121 if (this.numVerMain <= 7)
122 ret = 0;
123 else
124 ret = 1;
125 break;
126 case "doublefan": //source: dissertation[1]
127 ret = (this.numVerMain - 1) / 2;
128 break;
129 default:
130 // ret = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(this.numEdges / 2))) + 2 - this.numVertices;
131 //break;
132 ret = -1;
133 break;
134 }
135 return ret;
136 }
137 }
138 }