Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Graph coloring problem
#1
I'm using networkx to implement the edge coloring algorithm. Each edge should have a set of colors.
Here i'm creating the graph:

G = nx.Graph()
G.add_nodes_from ([1,2,3,4,5])

G.add_edge(1,2)
G.add_edge(1,4)
G.add_edge(1,5)
G.add_edge(2,3)
G.add_edge(4,2)
G.add_edge(3,1)
G.add_edge(5,4)
G.add_edge(3,5)

# list of nodes
U = list(G.nodes)

# variable with number of edges
K = G.number_of_edges()
Z = []

# creating a set of available colors. We assume that K = {0, 1, . . . , K − 1}and K ≤ |E|
def nrofCol():
Z.clear()
z = 0
while z < K - 1:
    Z.append(z)
    z = z+1
return Z
The set of colors is z=[0,1,2,3,4,5,6]. Each edge should have all the available colors as follows:

G[u][v][z] = 1,2,0
G[u][v][z] = 1,2,1
G[u][v][z] = 1,2,2
G[u][v][z] = 1,2,3
G[u][v][z] = 1,2,4
G[u][v][z] = 1,2,5
G[u][v][z] = 1,2,6
G[u][v][z] = 1,4,0
G[u][v][z] = 1,4,1
......
where u and v are nodes and z is the color


i tried with:

for u,v in G.edges():
for z in Z:
    G[u][v]['color'] = z


but only one color to each edge is added (the last one of the list. A better solution?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Plot multiple csv into one graph problem with visualize linkxxx86 1 5,720 Oct-14-2019, 05:54 PM
Last Post: linkxxx86
  coloring cells in a row with openpyxl curranjohn46 3 7,109 Oct-08-2019, 11:46 AM
Last Post: curranjohn46
  PyEDA-IPython Problem [Graph] embash 5 4,523 Jun-02-2018, 06:40 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020