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