def template_graph_coloring(filename):
    graph = read_graph(filename);
    
    dsatur_instance = dsatur(graph.data);
    dsatur_instance.process();
    coloring = dsatur_instance.get_colors();
    
    print("Number colors: ", max(coloring));
    
    draw_graph(graph, coloring);
示例#2
0
def template_graph_coloring(filename):
    graph = read_graph(filename)

    dsatur_instance = dsatur(graph.data)
    dsatur_instance.process()
    coloring = dsatur_instance.get_colors()

    print("Number colors: ", max(coloring))

    draw_graph(graph, coloring)
示例#3
0
 def templateTestColoring(self, filename):
     graph = read_graph(filename);
     
     dsatur_intance = dsatur(graph.data);
     dsatur_intance.process();
     map_coloring = dsatur_intance.get_colors();
     
     # Check number of colors
     assigned_colors = set(map_coloring);
     
     # Check validity of color numbers
     for color_number in range(1, len(assigned_colors) + 1, 1):
         assert color_number in assigned_colors;
         
     # Check validity of colors
     for index_node in range(len(graph.data)):
         color_neighbors = [ map_coloring[index] for index in range(len(graph.data[index_node])) if graph.data[index_node][index] != 0 and index_node != index];
         #print(index_node, map_coloring[index_node], color_neighbors, assigned_colors, map_coloring, "\n\n");
         assert map_coloring[index_node] not in color_neighbors;
示例#4
0
 def templateTestColoring(self, filename):
     graph = read_graph(filename);
     
     dsatur_intance = dsatur(graph.data);
     dsatur_intance.process();
     map_coloring = dsatur_intance.get_colors();
     
     # Check number of colors
     assigned_colors = set(map_coloring);
     
     # Check validity of color numbers
     for color_number in range(1, len(assigned_colors) + 1, 1):
         assert color_number in assigned_colors;
         
     # Check validity of colors
     for index_node in range(len(graph.data)):
         color_neighbors = [ map_coloring[index] for index in range(len(graph.data[index_node])) if graph.data[index_node][index] != 0 and index_node != index];
         #print(index_node, map_coloring[index_node], color_neighbors, assigned_colors, map_coloring, "\n\n");
         assert map_coloring[index_node] not in color_neighbors;
示例#5
0
def _get_LB(sol: "AngularGraphSolution", solution_type):
    graph = sol.graph
    if solution_type == "local_min_sum":
        try:
            return _get_LB.local_min_sum_lbs[graph.id]
        except KeyError:
            lb = max(get_lower_bounds(graph))
            _get_LB.local_min_sum_lbs[graph.id] = lb
            return lb
    if solution_type == "min_sum":
        try:
            return _get_LB.min_sum_lbs[graph.id]
        except KeyError:
            lb = sum(get_lower_bounds(graph))
            _get_LB.min_sum_lbs[graph.id] = lb
            return lb
    if solution_type == "makespan":
        try:
            lb = _get_LB.makespan_lbs[graph.id]
        except KeyError:
            from solver.coloring_solver import Coloring_CP_Solver
            from pyclustering.gcolor.dsatur import dsatur
            if graph.edge_amount < 40:
                solver = Coloring_CP_Solver()
                colors = solver.solve(graph)
            else:
                dsatur_instance = dsatur(graph.ad_matrix)
                dsatur_instance.process()
                colors = dsatur_instance.get_colors()

            lb = ((math.ceil(math.log2(max(colors))) - 2) / 2) * 90
            _get_LB.makespan_lbs[graph.id] = lb
        if sol.makespan and lb > sol.makespan:

            log_c_number = math.ceil(sol.makespan * 2 / 90) + 2
            lb2 = ((math.ceil(log_c_number) - 2) / 2) * 90
            if lb > lb2:
                _get_LB.makespan_lbs[graph.id] = lb2
                lb = lb2
        return lb
示例#6
0
def optim_and_save(keys, mat, overwrite):
    if len(mat) == 0:
        print("No course in this training programme!")
        return
    opti = dsatur(mat)
    opti.process()
    color_indices = opti.get_colors()
    print(color_indices, max(color_indices))
    color_set = get_color_set(
        os.path.join(settings.BASE_DIR, 'misc', 'colors.json'),
        max(color_indices))
    for mi in range(len(keys)):
        cbg = color_set[color_indices[mi] - 1]
        try:
            mod_disp = ModuleDisplay.objects.get(module=keys[mi])
            if overwrite:
                mod_disp.color_bg = cbg
                mod_disp.color_txt = compute_luminance(cbg)
                mod_disp.save()
        except ObjectDoesNotExist:
            mod_disp = ModuleDisplay(module=keys[mi],
                                     color_bg=cbg,
                                     color_txt=compute_luminance(cbg))
            mod_disp.save()
def solve_dsatur(graph: Graph):
    dsatur_instance = dsatur(graph.ad_matrix)
    dsatur_instance.process()
    coloring = dsatur_instance.get_colors()
    return coloring