static void Main(string[] args) { var gl = new GraphLoader(); var graph = gl.LoadFromCsvFile("../../../Datasets/KarateClub/KarateClub.csv"); var kl = new KernighanLin(); var clusteredGraph = kl.Cluster(graph); var exporter = new GraphExporter(); exporter.ExportToCsv(clusteredGraph, "../../../Datasets/KarateClub/KarateClubClustered.csv"); }
public void StartPartition_Test() { Graph graph = new Graph(); Vertex vertexA = graph.FindNode(1, true); Vertex vertexB = graph.FindNode(2, true); Vertex vertexC = graph.FindNode(3, true); graph.CreateLink(vertexA, vertexB, 2); graph.CreateLink(vertexA, vertexC, 6); graph.CreateLink(vertexB, vertexC, 5); graph.CommunityCount = 2; //arrange GraphList expected = new GraphList() { new Graph() { Vertices = new List <Vertex>() { vertexA, vertexB } }, new Graph() { Vertices = new List <Vertex>() { vertexC } } }; KernighanLin kernighanLin = new KernighanLin(); kernighanLin.SetGraph(graph); //act GraphList actual = kernighanLin.StartPartition(graph); //assert for (int i = 0; i < expected.Count; i++) { for (int j = 0; j < expected[i].Vertices.Count; j++) { Assert.AreEqual(expected[i].Vertices[j].Label, actual[i].Vertices[j].Label); } } }
public ActionResult Solve(FormCollection fc) { AbstractAlgorithm algorithm = null; switch (fc.GetValue("Algorithm").AttemptedValue) { case "KernighanLin": GraphProblemDb.CurrentProblem.Algorithm = Algorithm.KernighanLin; algorithm = new KernighanLin(); GraphProblemDb.CurrentProblem = algorithm.FindCommunityStructure(GraphProblemDb.CurrentProblem.Graph); break; case "GirvanNewman": GraphProblemDb.CurrentProblem.Algorithm = Algorithm.GirvanNewman; algorithm = new GirvanNewman(); GraphProblemDb.CurrentProblem = algorithm.FindCommunityStructure(GraphProblemDb.CurrentProblem.Graph); break; } return(RedirectToAction("GraphListResult", "GraphListResult", GraphProblemDb.CurrentProblem)); }