コード例 #1
0
 def templateTestColoringNegativeConnections(self, filename, solver_type = solve_type.FAST):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):        
         graph = read_graph(filename);
         syncgcolor_network = syncgcolor(graph.data, 0, -1);
         
         analyser = syncgcolor_network.process(solution = solver_type);
         
         map_coloring = analyser.allocate_map_coloring(0.05);
         
         # Check number of colors
         assigned_colors = set(map_coloring);
         
         # Check validity of color numbers
         for color_number in range(0, len(assigned_colors), 1):
             if (color_number not in assigned_colors):
                 continue;
             
         # 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");
             if (map_coloring[index_node] in color_neighbors):
                 continue;
         
         result_testing = True;
             
     assert result_testing;
コード例 #2
0
def template_graph_coloring(positive_weight, negative_weight, filename, reduction = None, title = None):
    if (title is None): title = filename;
    print("\nGraph Coloring: ", title);
    
    graph = read_graph(filename);
    network = syncgcolor(graph.data, positive_weight, negative_weight, reduction);
    
    analyser = network.process(order = 0.999, solution = solve_type.FAST, collect_dynamic = True);
    sync.sync_visualizer.show_output_dynamic(analyser);

    clusters = analyser.allocate_color_clusters();
    
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
        
    coloring_map = analyser.allocate_map_coloring();
    print("Number colors: ", max(coloring_map));
    
    draw_graph(graph, coloring_map);
    
    # Check validity of colors
    for index_node in range(len(graph.data)):
        color_neighbors = [ coloring_map[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");
        
        if (coloring_map[index_node] in color_neighbors):
            print("Warining: Incorrect coloring");
            return;
コード例 #3
0
ファイル: sync_tests.py プロジェクト: annoviko/pyclustering
 def templateTestColoringNegativeConnections(self, filename, solver_type = solve_type.FAST):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):        
         graph = read_graph(filename);
         syncgcolor_network = syncgcolor(graph.data, 0, -1);
         
         analyser = syncgcolor_network.process(solution = solver_type);
         
         map_coloring = analyser.allocate_map_coloring(0.05);
         
         # Check number of colors
         assigned_colors = set(map_coloring);
         
         # Check validity of color numbers
         for color_number in range(0, len(assigned_colors), 1):
             if (color_number not in assigned_colors):
                 continue;
             
         # 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");
             if (map_coloring[index_node] in color_neighbors):
                 continue;
         
         result_testing = True;
             
     assert result_testing;
コード例 #4
0
def template_graph_coloring(filename,
                            alpha,
                            eps,
                            steps,
                            time,
                            title=None,
                            tolerance=0.1,
                            threshold_steps=10):
    if (title is None): title = filename

    graph = read_graph(filename)
    network = hysteresisgcolor(graph.data, alpha, eps)

    output_dynamic = network.simulate(steps, time)
    draw_dynamics(output_dynamic.time,
                  output_dynamic.output,
                  x_title="Time",
                  y_title="State")

    clusters = output_dynamic.allocate_clusters(tolerance, threshold_steps)
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index])

    coloring_map = output_dynamic.allocate_map_coloring(
        tolerance, threshold_steps)
    draw_graph(graph, coloring_map)
コード例 #5
0
ファイル: sync_examples.py プロジェクト: Gudui/pyclustering
def template_graph_coloring(positive_weight, negative_weight, filename, reduction = None, title = None):
    if (title is None): title = filename;
    print("\nGraph Coloring: ", title);
    
    graph = read_graph(filename);
    network = syncgcolor(graph.data, positive_weight, negative_weight, reduction);
    
    analyser = network.process(order = 0.999, solution = solve_type.FAST, collect_dynamic = True);
    sync.sync_visualizer.show_output_dynamic(analyser);

    clusters = analyser.allocate_color_clusters();
    
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
        
    coloring_map = analyser.allocate_map_coloring();
    print("Number colors: ", max(coloring_map));
    
    draw_graph(graph, coloring_map);
    
    # Check validity of colors
    for index_node in range(len(graph.data)):
        color_neighbors = [ coloring_map[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");
        
        if (coloring_map[index_node] in color_neighbors):
            print("Warining: Incorrect coloring");
            return;
コード例 #6
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)
コード例 #7
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);
コード例 #8
0
def template_graph_coloring(filename, alpha, eps, steps, time, title = None, tolerance = 0.1):
    if (title is None): title = filename;
    
    graph = read_graph(filename);
    network = hysteresisgcolor(graph.data, alpha, eps);
    
    (t, dyn) = network.simulate(steps, time);
    draw_dynamics(t, dyn, x_title = "Time", y_title = "State");
    
    clusters = network.get_clusters(tolerance);
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
    
    coloring_map = network.get_map_coloring(tolerance);
    draw_graph(graph, coloring_map);
コード例 #9
0
def template_graph_coloring(filename, alpha, eps, steps, time, title = None, tolerance = 0.1, threshold_steps = 10):
    if (title is None): title = filename;
    
    graph = read_graph(filename);
    network = hysteresisgcolor(graph.data, alpha, eps);
    
    output_dynamic = network.simulate(steps, time);
    draw_dynamics(output_dynamic.time, output_dynamic.output, x_title = "Time", y_title = "State");
    
    clusters = output_dynamic.allocate_clusters(tolerance, threshold_steps);
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index]);
    
    coloring_map = output_dynamic.allocate_map_coloring(tolerance, threshold_steps);
    draw_graph(graph, coloring_map);
コード例 #10
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;
コード例 #11
0
 def templateTestColoring(self, filename, alpha, eps, steps, time):
     graph = read_graph(filename);
     network = hysteresisgcolor(graph.data, alpha, eps);
     
     output_analyser = network.process(steps, time);
     map_coloring = output_analyser.allocate_map_coloring(0.05, 20);
     
     # Check number of colors
     assigned_colors = set(map_coloring);
     
     # Check validity of color numbers
     for color_number in range(0, len(assigned_colors), 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;
コード例 #12
0
ファイル: dsatur_tests.py プロジェクト: annoviko/pyclustering
 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;
コード例 #13
0
def template_graph_coloring(filename,
                            alpha,
                            eps,
                            steps,
                            time,
                            title=None,
                            tolerance=0.1):
    if (title is None): title = filename

    graph = read_graph(filename)
    network = hysteresisgcolor(graph.data, alpha, eps)

    (t, dyn) = network.simulate(steps, time)
    draw_dynamics(t, dyn, x_title="Time", y_title="State")

    clusters = network.get_clusters(tolerance)
    for index in range(0, len(clusters)):
        print("Color #", index, ": ", clusters[index])

    coloring_map = network.get_map_coloring(tolerance)
    draw_graph(graph, coloring_map)
コード例 #14
0
    def templateTestColoring(self, filename, alpha, eps, steps, time):
        graph = read_graph(filename)
        network = hysteresisgcolor(graph.data, alpha, eps)

        (t, dyn) = network.simulate(steps, time)
        map_coloring = network.get_map_coloring(0.05)

        # Check number of colors
        assigned_colors = set(map_coloring)

        # Check validity of color numbers
        for color_number in range(0, len(assigned_colors), 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