public void Test3() { var graph = new Graph(); var algo = new SmallestFirst(); graph.Vertices.Add(new Vertex(0)); graph.Vertices.Add(new Vertex(1)); graph.Vertices.Add(new Vertex(2)); graph.Vertices[2].Neighbors.Add(graph.Vertices[0]); graph.Vertices[2].Neighbors.Add(graph.Vertices[1]); Assert.Equal(1, algo.GetFreeColorGreedily(graph.Vertices[2])); }
static void Main(string[] args) { string cwd = Directory.GetCurrentDirectory(); DirectoryInfo graphDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(cwd).FullName).FullName).GetDirectories("Graphs").FirstOrDefault(); singleGraphs = graphDir.GetDirectories("Single").FirstOrDefault(); listsGraphs = graphDir.GetDirectories("Lists").FirstOrDefault(); if (singleGraphs == default || listsGraphs == default) { throw new Exception("Failed to load the Single and Lists graphs directories!"); } var graphFactory = new GraphFactory(); var graphs = new List <Graph>(); // one graph with 208 vertices //graphs.Add(graphFactory.GraphFromAdjacencyList(GetSingleGraphPath("graph_41669.lst"))); // simple test graph graphs.Add(graphFactory.GraphFromAdjacencyList(GetSingleGraphPath("graph_844.lst"))); // 170 big graphs, over 240 vertices //graphs.AddRange(graphFactory.GraphsFromAdjacencyLists(GetGraphListsPath("list_170_graphs.lst"))); // 22 graphs with different sizes and bounds calculation //graphs.AddRange(graphFactory.GraphsFromAdjacencyLists(GetGraphListsPath("chidx_22_graphs.lst"))); var smallestFirst = new SmallestFirst(); var dSatur = new ModifiedDSatur(); var sums = new List <Tuple <int, int> >(); foreach (var graph in graphs) { //graph.PrintVerticesAndEdges(); graph.PrintGraphProperties(); var sumSF = smallestFirst.ApproximateChromaticSum(graph); graph.ResetColors(); var sumDS = dSatur.ApproximateChromaticSum(graph); sums.Add(new Tuple <int, int>(sumSF, sumDS)); if (graph.HasDefinedBounds) { Console.WriteLine($"Chromoctic sum bounds: [{graph.ChromaticSumLowerBound},{graph.ChromaticSumUpperBound}]"); } Console.WriteLine($"SmallestFirst chromatic sum : {sumSF}"); Console.WriteLine($"ModifiedDSatur chromatic sum : {sumDS}"); Console.WriteLine(); graph.PrintVerticesWithColors(); } }
public void Test4() { var graph = new Graph(); var algo = new SmallestFirst(); graph.Vertices.Add(new Vertex(0)); graph.Vertices.Add(new Vertex(1)); graph.Vertices.Add(new Vertex(2)); Assert.Equal(graph.Vertices[0].Index, algo.GetMinimalDegreeVertex(graph.Vertices).Index); graph.Vertices[0].Neighbors.Add(graph.Vertices[1]); graph.Vertices[1].Neighbors.Add(graph.Vertices[2]); Assert.Equal(graph.Vertices[2].Index, algo.GetMinimalDegreeVertex(graph.Vertices).Index); graph.Vertices[2].Neighbors.Add(graph.Vertices[0]); Assert.Equal(graph.Vertices[0].Index, algo.GetMinimalDegreeVertex(graph.Vertices).Index); }