Skip to content

Commit

Permalink
Update graph coloring algorithm [gcolor.syncgcolor] and examples for …
Browse files Browse the repository at this point in the history
…it. Created examples of graphs
  • Loading branch information
annoviko committed Mar 18, 2014
1 parent 6bee700 commit 39a708d
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 96 deletions.
124 changes: 29 additions & 95 deletions gcolor/syncgcolor/examples.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from gcolor.syncgcolor import syncgcolor;
from nnet.sync import net, conn_type, solve_type, draw_dynamics;

def template_graph_coloring(strength, graph_matrix_repr, title = "Sample"):
from nnet.sync import draw_dynamics, solve_type;

from support import read_sample;

from samples.definitions import GRAPH_SIMPLE_SAMPLES;


def template_graph_coloring(positive_weight, negative_weight, filename, reduction = None, title = "Sample"):
print("\nGraph Coloring: ", title);
network = syncgcolor(graph_matrix_repr, strength);

(t, dyn) = network.process(collect_dynamic = True);
graph_matrix_repr = read_sample(filename);
network = syncgcolor(graph_matrix_repr, positive_weight, negative_weight, reduction);

(t, dyn) = network.process(order = 0.999, solution = solve_type.FAST, collect_dynamic = True);
draw_dynamics(t, dyn);

clusters = network.get_clusters();
Expand All @@ -15,117 +23,43 @@ def template_graph_coloring(strength, graph_matrix_repr, title = "Sample"):


def one_circle1():
graph_matrix_repr = [ [0, 1, 0, 0, 1],
[1, 0, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 1],
[1, 0, 0, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Circle 1");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_ONE_CIRCLE1, None, "Circle 1");


def one_circle2():
graph_matrix_repr = [ [0, 1, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0],
[0, 0, 1, 0, 1, 0],
[0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Circle 2");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_ONE_CIRCLE2, None, "Circle 2");


def one_circle3():
graph_matrix_repr = [ [0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0],
[0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Circle 3");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_ONE_CIRCLE3, None, "Circle 3");


def broken_circle1():
graph_matrix_repr = [ [0, 1, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 1],
[0, 0, 1, 0, 1, 0],
[0, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Broken Circle 1");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_BROKEN_CIRCLE1, None, "Broken Circle 1");


def broken_circle2():
graph_matrix_repr = [ [0, 1, 0, 0, 1],
[1, 0, 1, 0, 0],
[0, 1, 0, 1, 1],
[0, 0, 1, 0, 1],
[1, 0, 1, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Broken Circle 2");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_BROKEN_CIRCLE2, None, "Broken Circle 2");


def one_star():
graph_matrix_repr = [ [0, 0, 0, 0, 1],
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 1],
[1, 1, 1, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "One Star");
def one_crossroad():
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_ONE_CROSSROAD, None, "One Crossroad");


def five_pointed_star():
graph_matrix_repr = [ [0, 0, 1, 1, 0],
[0, 0, 0, 1, 1],
[1, 0, 0, 0, 1],
[1, 1, 0, 0, 0],
[0, 1, 1, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "Five Pointed Star");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_FIVE_POINTED_STAR, None, "Five Pointed Star");


def one_line():
graph_matrix_repr = [ [0, 1, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 1],
[0, 0, 0, 1, 0] ];

template_graph_coloring(1, graph_matrix_repr, "One Line");


def two_interconnected_stars():
graph_matrix_repr = [ [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 0] ];

template_graph_coloring(2, graph_matrix_repr, "Two Interconnected Stars");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_ONE_LINE, None, "One Line");


def two_crossroads():
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_TWO_CROSSROADS, None, "Two Interconnected Stars");


def five_pointed_frame_star():
graph_matrix_repr = [ [0, 1, 0, 0, 1, 1, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0, 1, 0],
[1, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1, 1, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 1, 0, 0, 1, 0, 0, 0, 1],
[0, 0, 0, 1, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1, 1, 0, 0] ];

template_graph_coloring(2, graph_matrix_repr, "Five Pointed Star With Frame");
template_graph_coloring(0, -1, GRAPH_SIMPLE_SAMPLES.GRAPH_FIVE_POINTED_FRAME_STAR, None, "Five Pointed Star With Frame");


one_line();
Expand All @@ -134,7 +68,7 @@ def five_pointed_frame_star():
one_circle3();
broken_circle1();
broken_circle2();
one_star();
one_crossroad();
two_crossroads();
five_pointed_star();
five_pointed_frame_star();
two_interconnected_stars();
five_pointed_frame_star();
2 changes: 1 addition & 1 deletion nnet/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def cluster(self, value):
self._cluster = value;


def __init__(self, num_osc, weight, frequency = False, type_conn = conn_type.ALL_TO_ALL, conn_represent = conn_represent.MATRIX, initial_phases = initial_type.RANDOM_GAUSSIAN):
def __init__(self, num_osc, weight = 1, frequency = False, type_conn = conn_type.ALL_TO_ALL, conn_represent = conn_represent.MATRIX, initial_phases = initial_type.RANDOM_GAUSSIAN):
self._num_osc = num_osc;
self._weight = weight;

Expand Down
12 changes: 12 additions & 0 deletions samples/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ class FCPS_SAMPLES:
SAMPLE_TETRA = samples.__path__[0] + "\\SampleTetra.txt";
SAMPLE_TWO_DIAMONDS = samples.__path__[0] + "\\SampleTwoDiamonds.txt";
SAMPLE_WING_NUT = samples.__path__[0] + "\\SampleWingNut.txt";

class GRAPH_SIMPLE_SAMPLES:
GRAPH_BROKEN_CIRCLE1 = samples.__path__[0] + "\\graphs\\GraphBrokenCircle1.txt";
GRAPH_BROKEN_CIRCLE2 = samples.__path__[0] + "\\graphs\\GraphBrokenCircle2.txt";
GRAPH_FIVE_POINTED_FRAME_STAR = samples.__path__[0] + "\\graphs\\GraphFivePointedFrameStar.txt";
GRAPH_FIVE_POINTED_STAR = samples.__path__[0] + "\\graphs\\GraphFivePointedStar.txt";
GRAPH_ONE_CIRCLE1 = samples.__path__[0] + "\\graphs\\GraphOneCircle1.txt";
GRAPH_ONE_CIRCLE2 = samples.__path__[0] + "\\graphs\\GraphOneCircle2.txt";
GRAPH_ONE_CIRCLE3 = samples.__path__[0] + "\\graphs\\GraphOneCircle3.txt";
GRAPH_ONE_CROSSROAD = samples.__path__[0] + "\\graphs\\GraphOneCrossroad.txt";
GRAPH_ONE_LINE = samples.__path__[0] + "\\graphs\\GraphOneLine.txt";
GRAPH_TWO_CROSSROADS = samples.__path__[0] + "\\graphs\\GraphTwoCrossroads.txt";
6 changes: 6 additions & 0 deletions samples/graphs/GraphBrokenCircle1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0 1 0 0 0 1
1 0 1 0 0 0
0 1 0 1 0 1
0 0 1 0 1 0
0 0 0 1 0 1
1 0 1 0 1 0
5 changes: 5 additions & 0 deletions samples/graphs/GraphBrokenCircle2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 1 0 0 1
1 0 1 0 0
0 1 0 1 1
0 0 1 0 1
1 0 1 1 0
10 changes: 10 additions & 0 deletions samples/graphs/GraphFivePointedFrameStar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0 1 0 0 1 1 0 0 0 0
1 0 1 0 0 0 1 0 0 0
0 1 0 1 0 0 0 1 0 0
0 0 1 0 1 0 0 0 1 0
1 0 0 1 0 0 0 0 0 1
1 0 0 0 0 0 0 1 1 0
0 1 0 0 0 0 0 0 1 1
0 0 1 0 0 1 0 0 0 1
0 0 0 1 0 1 1 0 0 0
0 0 0 0 1 0 1 1 0 0
5 changes: 5 additions & 0 deletions samples/graphs/GraphFivePointedStar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 0 1 1 0
0 0 0 1 1
1 0 0 0 1
1 1 0 0 0
0 1 1 1 0
5 changes: 5 additions & 0 deletions samples/graphs/GraphOneCircle1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 1 0 0 1
1 0 1 0 0
0 1 0 1 0
0 0 1 0 1
1 0 0 1 0
6 changes: 6 additions & 0 deletions samples/graphs/GraphOneCircle2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0 1 0 0 0 1
1 0 1 0 0 0
0 1 0 1 0 0
0 0 1 0 1 0
0 0 0 1 0 1
1 0 0 0 1 0
7 changes: 7 additions & 0 deletions samples/graphs/GraphOneCircle3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0 1 0 0 0 0 1
1 0 1 0 0 0 0
0 1 0 1 0 0 0
0 0 1 0 1 0 0
0 0 0 1 0 1 0
0 0 0 0 1 0 1
1 0 0 0 0 1 0
5 changes: 5 additions & 0 deletions samples/graphs/GraphOneCrossroad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
1 1 1 1 0
5 changes: 5 additions & 0 deletions samples/graphs/GraphOneLine.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0 1 0 0 0
1 0 1 0 0
0 1 0 1 0
0 0 1 0 1
0 0 0 1 0
10 changes: 10 additions & 0 deletions samples/graphs/GraphTwoCrossroads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 1 1 1 1 1 0

0 comments on commit 39a708d

Please sign in to comment.