comparison defical-sharp/libsemtd/print.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 public partial class Semtd
4 {
5 private string sep = " | ";
6 private string print(int mode)
7 {
8 return printBasic() + sep +
9 printMagicNum(mode) + sep +
10 printLabels(mode) + sep +
11 printDef(mode) + sep +
12 printMisc(mode);
13 }
14 private string printBasic()
15 {
16 string ret = "";
17 ret += "graph: " + this.graphType +
18 sep +
19 "edges: " + this.numEdges.ToString() +
20 sep +
21 "vertices: " + this.numVerMain.ToString() +
22 sep +
23 "deficiencies: " + this.numVerDef.ToString();
24 return ret;
25 }
26 private string printMagicNum(int mode)
27 {
28 string ret = "";
29 int edgeWeight, edgeLabel;
30 edgeLabel = edgeWeight = 0;
31 for (int i = 1; i <= this.labelEdgeAbsoluteMax; i++)
32 {
33 if (this.labelEdgesUsed[i] > 0)
34 {
35 edgeWeight = i;
36 edgeLabel = this.numEdges + this.numVerTotal;
37 break;
38 }
39 }
40 if (mode == 1)
41 {
42 edgeWeight = 2 * (this.numVerTotal) + 2 - edgeWeight;
43 edgeLabel = 2 * this.numVerTotal + this.numEdges + 1 - edgeLabel;
44 }
45 ret += "mnum: " + (edgeWeight + edgeLabel).ToString();
46 return ret;
47 }
48 private string printLabels(int mode)
49 {
50 string ret = "";
51 int[] myLabelVer = new int[this.NumVerMain];
52 for (int i = 0; i < this.NumVerMain; i++)
53 {
54 if (mode == 1)
55 {
56 myLabelVer[i] = this.numVerTotal + 1 - this.labelVer[i];
57 }
58 else
59 {
60 myLabelVer[i] = this.labelVer[i];
61 }
62 }
63 if (this.graphType == "doublefan" && myLabelVer[0] > myLabelVer[1])
64 {
65 int temp = myLabelVer[0];
66 myLabelVer[0] = myLabelVer[1];
67 myLabelVer[1] = temp;
68 }
69 int startPath=0;
70 int endPath=0;
71 switch (graphType)
72 {
73 case "fan":
74 {
75 startPath = 1;
76 endPath=this.numVerMain-1;
77 break;
78 }
79 case "doublefan":
80 case "wheel":
81 {
82 startPath = 2;
83 endPath=this.numVerMain-1;
84 break;
85 }
86 }
87 if (startPath > 0 && myLabelVer[startPath] > myLabelVer[endPath])
88 {
89 int a = startPath, b = endPath;
90 while (a < b)
91 {
92 int temp = myLabelVer[a];
93 myLabelVer[a] = myLabelVer[b];
94 myLabelVer[b] = temp;
95 a++; b--;
96 }
97 }
98 for (int i = 0; i < this.numVerMain; i++)
99 {
100 int myLabel=myLabelVer[i];
101 if (i == 0)
102 switch (graphType)
103 {
104 case "wheel":
105 {
106 ret += "c: " + myLabel.ToString()
107 + sep
108 + "l: ";
109 break;
110 }
111 case "fan":
112 {
113 ret += "c: " + myLabel.ToString()
114 + sep
115 + "p: ";
116 break;
117 }
118 case "doublefan":
119 {
120 ret += "c: " + myLabel.ToString() + ",";
121 break;
122 }
123 }
124 else if (i == 1 && this.graphType == "doublefan")
125 {
126 ret += myLabel.ToString()
127 + sep
128 + "p: ";
129 }
130 else if (i == this.numVerMain-1)
131 ret += myLabel.ToString();
132 else
133 ret += myLabel.ToString() + ",";
134 }
135 return ret;
136 }
137 private string printDef(int mode)
138 {
139 string ret = "";
140 if (this.numVerDef > 0)
141 {
142 ret += "def: ";
143 bool[] labelVerUsed = new bool[this.numVerTotal + 1];
144 for (int i = 0; i < this.numVerMain; i++)
145 labelVerUsed[this.labelVer[i]] = true;
146 int amountDef = 0;
147 for (int i = 1; i <= this.numVerTotal; i++)
148 {
149 int myDef;
150 if (!labelVerUsed[i])
151 {
152 if (mode == 1)
153 myDef = this.numVerTotal + 1 - i;
154 else
155 myDef = i;
156 if (amountDef == this.numVerDef - 1)
157 {
158 ret += myDef.ToString();
159 break;
160 }
161 else
162 {
163 ret += myDef.ToString() + ",";
164 amountDef++;
165 }
166 }
167 }
168 }
169 return ret;
170 }
171 private string printMisc(int mode)
172 {
173 string ret = "";
174 if (this.graphType == "wheel" || this.graphType == "fan" || this.graphType == "doublefan")
175 {
176 int startPath, endPath;
177 startPath = 0;
178 switch (this.graphType)
179 {
180 case "fan":
181 {
182 startPath = 1;
183 break;
184 }
185 case "wheel":
186 case "doublefan":
187 {
188 startPath = 2;
189 break;
190 }
191 }
192 endPath = this.numVerMain-1;
193 bool isConstant = true;
194 for (int i = startPath; i < endPath; i++)
195 {
196 if (mode == 0)
197 {
198 if (this.labelVer[i] > this.labelVer[i + 1])
199 {
200 isConstant = false;
201 break;
202 }
203 }
204 else if (mode == 1)
205 {
206 if (this.labelVer[i] < this.labelVer[i + 1])
207 {
208 isConstant = false;
209 break;
210 }
211 }
212 }
213 if (isConstant)
214 ret += "constant";
215 }
216 if (mode == 1)
217 ret += "dual";
218 return ret;
219 }
220 }
221 }