private UndirectedGraph ColorGraphRecursion(UndirectedGraph graph) { var notColoredEdges = graph.NotColoredEdges; if (notColoredEdges.Count == 0) { return(graph); } notColoredEdges.Sort((e1, e2) => graph.SortEdgesByColored(e1, e2)); var limitedSortedNotColoredEdges = notColoredEdges.Take(callsLimit); foreach (var e in limitedSortedNotColoredEdges) { var graphPrim = new UndirectedGraph(graph); var minColor = graphPrim.CalculateColor(e); if (minColor == null) { return(null); } graphPrim.ColorEdge(new Edge(e.V1, e.V2, minColor.Value)); var result = ColorGraphRecursion(graphPrim); if (result != null) { return(result); } } return(null); }
private UndirectedGraph ColorGraphRecursion(UndirectedGraph graph) { if (graph.NotColoredEdges.Count == 0) { return(graph); } var graphForMatching = new UndirectedGraph(graph); graphForMatching.Edges = graphForMatching.NotColoredEdges; var matchings = GetGraphMatchings(graphForMatching); foreach (var matching in matchings) { var graphPrim = new UndirectedGraph(graph); bool anyEdgeColored = false; foreach (var edge in matching) { var color = graphPrim.CalculateColor(edge); if (color != null) { graphPrim.ColorEdge(new Edge(edge.V1, edge.V2, color.Value)); anyEdgeColored = true; } else { anyEdgeColored = false; break; } } if (anyEdgeColored) { return(ColorGraphRecursion(graphPrim)); } } return(null); }