public void AddVertexTest() { var db = new OwlerDB(); var v1 = new Vertex(); db.AddVertex(v1); Assert.AreEqual(1, db.VertexCount); }
public void ReadFromEdgeListTest() { var g = new OwlerDB(); var reader = new EdgeListReader(); var stream = File.OpenRead("../../../ToolTests/bin/Debug/graphs/p2p-Gnutella05.txt"); var done = reader.Read(g, stream); Assert.IsTrue(done); Assert.AreEqual(8846, g.VertexCount); Assert.AreEqual(31839, g.EdgeCount); }
public void LinkTest() { var g = new OwlerDB(); var v1 = new Vertex(); var v2 = new Vertex(); g.AddVertex(v1); g.AddVertex(v2); g.AddEdge(new Edge(v1, v2)); //v1 side Assert.AreEqual(v2, v1.OutgoingEdges.First().Target); Assert.AreEqual(v1, v1.OutgoingEdges.First().Source); //v2 side Assert.AreEqual(v1, v2.IncomingEdges.First().Source); Assert.AreEqual(v2, v2.IncomingEdges.First().Target); }
protected IGraph InitGermanyGraph() { #region graph var g = new OwlerDB(); g["name"] = "Germany"; #endregion #region cities var Frankfurt = new Vertex("1", new Dictionary<string, object>() { {"name", "Frankfurt"} }); var Mannheim = new Vertex("2", new Dictionary<string, object>() { {"name", "Mannheim"} }); var Wuerzburg = new Vertex("3", new Dictionary<string, object>() { {"name", "Wuerzburg"} }); var Stuttgart = new Vertex("4", new Dictionary<string, object>() { {"name", "Stuttgart"} }); var Karlsruhe = new Vertex("5", new Dictionary<string, object>() { {"name", "Karlsruhe"} }); var Erfurt = new Vertex("6", new Dictionary<string, object>() { {"name", "Erfurt"} }); var Nuernberg = new Vertex("7", new Dictionary<string, object>() { {"name", "Nuernberg"} }); var Kassel = new Vertex("8", new Dictionary<string, object>() { {"name", "Kassel"} }); var Augsburg = new Vertex("9", new Dictionary<string, object>() { {"name", "Augsburg"} }); var Muenchen = new Vertex("10", new Dictionary<string, object>() { {"name", "Muenchen"} }); g.AddVertex(Frankfurt); g.AddVertex(Mannheim); g.AddVertex(Wuerzburg); g.AddVertex(Stuttgart); g.AddVertex(Karlsruhe); g.AddVertex(Erfurt); g.AddVertex(Nuernberg); g.AddVertex(Kassel); g.AddVertex(Augsburg); g.AddVertex(Muenchen); #endregion #region roads g.AddEdge(new Edge(Frankfurt, Mannheim, new Dictionary<string, object>() { { "s", 85 } })); g.AddEdge(new Edge(Frankfurt, Wuerzburg, new Dictionary<string, object>() { { "s", 127 } })); g.AddEdge(new Edge(Frankfurt, Kassel, new Dictionary<string, object>() { { "s", 172 } })); g.AddEdge(new Edge(Mannheim, Karlsruhe, new Dictionary<string, object>() { { "s", 80 } })); g.AddEdge(new Edge(Wuerzburg, Erfurt, new Dictionary<string, object>() { { "s", 186 } })); g.AddEdge(new Edge(Wuerzburg, Nuernberg, new Dictionary<string, object>() { { "s", 103 } })); g.AddEdge(new Edge(Nuernberg, Stuttgart, new Dictionary<string, object>() { { "s", 183 } })); g.AddEdge(new Edge(Nuernberg, Muenchen, new Dictionary<string, object>() { { "s", 167 } })); g.AddEdge(new Edge(Karlsruhe, Augsburg, new Dictionary<string, object>() { { "s", 250 } })); g.AddEdge(new Edge(Augsburg, Muenchen, new Dictionary<string, object>() { { "s", 84 } })); g.AddEdge(new Edge(Kassel, Muenchen, new Dictionary<string, object>() { { "s", 502 } })); #endregion return g; }
public static void Main(String[] args) { #region graph var g = new OwlerDB(); g["name"] = "Germany"; #endregion #region cities var Frankfurt = new Vertex(new Dictionary<string, object>() { {"name", "Frankfurt"} }); var Mannheim = new Vertex(new Dictionary<string, object>() { {"name", "Mannheim"} }); var Wuerzburg = new Vertex(new Dictionary<string, object>() { {"name", "Wuerzburg"} }); var Stuttgart = new Vertex(new Dictionary<string, object>() { {"name", "Stuttgart"} }); var Karlsruhe = new Vertex(new Dictionary<string, object>() { {"name", "Karlsruhe"} }); var Erfurt = new Vertex(new Dictionary<string, object>() { {"name", "Erfurt"} }); var Nuernberg = new Vertex(new Dictionary<string, object>() { {"name", "Nuernberg"} }); var Kassel = new Vertex(new Dictionary<string, object>() { {"name", "Kassel"} }); var Augsburg = new Vertex(new Dictionary<string, object>() { {"name", "Augsburg"} }); var Muenchen = new Vertex(new Dictionary<string, object>() { {"name", "Muenchen"} }); g.AddVertex(Frankfurt); g.AddVertex(Mannheim); g.AddVertex(Wuerzburg); g.AddVertex(Stuttgart); g.AddVertex(Karlsruhe); g.AddVertex(Erfurt); g.AddVertex(Nuernberg); g.AddVertex(Kassel); g.AddVertex(Augsburg); g.AddVertex(Muenchen); #endregion #region roads g.AddEdge(new Edge(Frankfurt, Mannheim, new Dictionary<string, object>() { { "s", 85 } })); g.AddEdge(new Edge(Frankfurt, Wuerzburg, new Dictionary<string, object>() { { "s", 127 } })); g.AddEdge(new Edge(Frankfurt, Kassel, new Dictionary<string, object>() { { "s", 172 } })); g.AddEdge(new Edge(Mannheim, Karlsruhe, new Dictionary<string, object>() { { "s", 80 } })); g.AddEdge(new Edge(Wuerzburg, Erfurt, new Dictionary<string, object>() { { "s", 186 } })); g.AddEdge(new Edge(Wuerzburg, Nuernberg, new Dictionary<string, object>() { { "s", 103 } })); g.AddEdge(new Edge(Nuernberg, Stuttgart, new Dictionary<string, object>() { { "s", 183 } })); g.AddEdge(new Edge(Nuernberg, Muenchen, new Dictionary<string, object>() { { "s", 167 } })); g.AddEdge(new Edge(Karlsruhe, Augsburg, new Dictionary<string, object>() { { "s", 250 } })); g.AddEdge(new Edge(Augsburg, Muenchen, new Dictionary<string, object>() { { "s", 84 } })); g.AddEdge(new Edge(Kassel, Muenchen, new Dictionary<string, object>() { { "s", 502 } })); #endregion foreach (var edge in Frankfurt.OutgoingEdges) { Console.WriteLine(edge.Target["name"] + " " + edge["s"] + "km"); } Console.WriteLine(g.VertexCount); Console.WriteLine(g.EdgeCount); var path = BreadthFirstSearch.Search(g, Frankfurt, Muenchen); foreach (var v in path) { Console.WriteLine(v["name"]); } Console.ReadKey(true); }
protected IGraph InitGraph(String myGraphName) { var g = new OwlerDB(); var reader = new GraphMLReader(); var stream = File.OpenRead("../../../AlgorithmTests/bin/Debug/graphs/"+myGraphName+".xml"); var done = reader.Read(g, stream); stream.Close(); return (done) ? g : null; }
public static IGraph InitGraph(String myGraphName) { var g = new OwlerDB(); IGraphReader myReader = null; if (myGraphName.EndsWith(".txt")) { myReader = new EdgeListReader(); } else if (myGraphName.EndsWith(".xml")) { myReader = new GraphMLReader(); } if (g == null) { Console.WriteLine("no suitable reader could be detected...exiting"); return null; } else { var stream = File.OpenRead("graphs/" + myGraphName); var done = myReader.Read(g, stream); stream.Close(); return (done) ? g : null; } }