diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/defical-sharp/libsemtd/graph.cs	Fri Apr 02 23:11:57 2010 +0700
@@ -0,0 +1,63 @@
+namespace libsemtd
+{
+    public partial class Semtd
+    {
+        private void draw(string graphType, int start, int end, params int[] ver_others)
+        {
+            if (end < start)
+            {
+                int temp = start;
+                start = end;
+                end = temp;
+            }
+            switch (graphType)
+            {
+                case "path":
+                    {
+                        for (int i = start; i < end; i++)
+                            connectVertices(i, i + 1);
+                        break;
+                    }
+                case "cycle":
+                    {
+                        draw("path", start, end);
+                        connectVertices(start, end);
+                        break;
+                    }
+                case "completebipartite":
+                    {
+                        for (int i = start; i <= end; i++)
+                            foreach (int other in ver_others)
+                                connectVertices(i, other);
+                        break;
+                    }
+                case "wheel":
+                    {
+                        draw("cycle", start + 1, end);
+                        draw("completebipartite", start + 1, end, start);
+                        break;
+                    }
+                case "fan":
+                    {
+                        draw("path", start + 1, end);
+                        draw("completebipartite", start + 1, end, start);
+                        break;
+                    }
+                case "doublefan":
+                    {
+                        draw("path", start + 2, end);
+                        draw("completebipartite", start + 2, end, start, start + 1);
+                        break;
+                    }
+            }
+        }
+        private void connectVertices(int a, int b)
+        {
+            if (!this.graphConn[a, b])
+            {
+                this.graphConn[a, b] = this.graphConn[b, a] = true;
+                this.numEdges++;
+            }
+        }
+    }
+}