Mercurial > defical
annotate defical-sharp/libsemtd/graph.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 |
rev | line source |
---|---|
0
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
1 namespace libsemtd |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
2 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
3 public partial class Semtd |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
4 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
5 private void draw(string graphType, int start, int end, params int[] ver_others) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
6 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
7 if (end < start) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
8 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
9 int temp = start; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
10 start = end; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
11 end = temp; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
12 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
13 switch (graphType) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
14 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
15 case "path": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
16 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
17 for (int i = start; i < end; i++) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
18 connectVertices(i, i + 1); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
19 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
20 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
21 case "cycle": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
22 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
23 draw("path", start, end); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
24 connectVertices(start, end); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
25 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
26 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
27 case "completebipartite": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
28 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
29 for (int i = start; i <= end; i++) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
30 foreach (int other in ver_others) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
31 connectVertices(i, other); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
32 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
33 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
34 case "wheel": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
35 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
36 draw("cycle", start + 1, end); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
37 draw("completebipartite", start + 1, end, start); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
38 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
39 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
40 case "fan": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
41 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
42 draw("path", start + 1, end); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
43 draw("completebipartite", start + 1, end, start); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
44 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
45 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
46 case "doublefan": |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
47 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
48 draw("path", start + 2, end); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
49 draw("completebipartite", start + 2, end, start, start + 1); |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
50 break; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
51 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
52 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
53 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
54 private void connectVertices(int a, int b) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
55 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
56 if (!this.graphConn[a, b]) |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
57 { |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
58 this.graphConn[a, b] = this.graphConn[b, a] = true; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
59 this.numEdges++; |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
60 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
61 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
62 } |
ebed2bd0d300
Initial import from svn. History be damned.
Edho P. Arief <me@myconan.net>
parents:
diff
changeset
|
63 } |