Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
playing the labelled graphs for now
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpc5 committed Mar 8, 2018
1 parent 3f07264 commit 4661b86
Showing 1 changed file with 101 additions and 34 deletions.
135 changes: 101 additions & 34 deletions src/sage/graphs/bliss.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -327,33 +327,89 @@ def canonical_form(G, partition=None, return_graph=False, certificate=False):
# constucting the canonical form from a list of edges
#####################################################

#cdef Digraph *bliss_digraph_from_edges(int Vnr, list edges, list partition):
# r"""
# Return a bliss copy of a digraph G
cdef Digraph *bliss_digraph_from_labelled_edges(int Vnr, int Lnr, list Vout, list Vin, list labels, list partition, bint verbose=False):
r"""
Return a bliss copy of a digraph G
INPUT:
- ``Vnr`` (number of vertices such that the vertices are 0 ... Vnr-1)
# INPUT:
- ``Lnr`` (number of labels such that the labels are 0 ... Lnr-1)
# - ``Vnr`` (the number of vertices such that the vertices are 0 ... Vnr-1)
- ``Vout`` (the list of vertices of outgoing edges)
# - ``edges`` (a list of edges)
- ``Vin`` (the list of vertices of ingoing edges)
# - ``partition`` -- a partition of the vertex set.
# """
# cdef Digraph *g = new Digraph(Vnr)
# cdef int x,y
- ``labels`` (the list of edge labels)
- ``partition`` -- a partition of the vertex set
"""
cdef Py_ssize_t i, j
cdef int logLnr
cdef str binrep
cdef str ind

cdef Digraph *g
cdef int x,y, lab

if Lnr == 1:
g = new Digraph(Vnr)
if g == NULL:
raise MemoryError("Allocation Failed")
else:
logLnr = len(numpy.binary_repr(Lnr))
g = new Digraph(Vnr*logLnr)
if g == NULL:
raise MemoryError("Allocation Failed")
for i from 0 <= i < Vnr:
for j from 1 <= j < logLnr:
g.add_edge((j-1)*Vnr+i,j*Vnr+i)
if verbose:
print "edge init", ((j-1)*Vnr+i,j*Vnr+i)

cdef int Enr = len(Vout)

for i from 0 <= i < Enr:
x = Vout[i]
y = Vin[i]
if Lnr == 1:
lab = 0
else:
lab = labels[i]

# if g == NULL:
# raise MemoryError("Allocation Failed")
if lab != 0:
lab = lab+1
binrep = numpy.binary_repr(lab)

# for x,y in edges:
# g.add_edge(x,y)
for j from 0 <= j < logLnr:
ind = binrep[j]
if ind == "1":
g.add_edge((logLnr-1-j)*Vnr+x,(logLnr-1-j)*Vnr+y)
if verbose:
print "edge", ((logLnr-1-j)*Vnr+x,(logLnr-1-j)*Vnr+y)
else:
g.add_edge(x,y)
if verbose:
print "edge unlab", (x,y)

# for i from 1 <= i < len(partition):
# for v in partition[i]:
# g.change_color(v, i)
# return g
if partition == []:
partition = [list(range(Vnr))]
cdef Pnr = len(partition)
for i from 0 <= i < Pnr:
for v in partition[i]:
if Lnr == 1:
g.change_color(v, i)
if verbose:
print "color",(v, i)
else:
for j from 0 <= j < logLnr:
g.change_color(j*Vnr+v, j*Pnr+i)
if verbose:
print "color",(j*Vnr+v, j*Pnr+i)
return g

cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, list Vout, list Vin, list labels, list partition):
cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, list Vout, list Vin, list labels, list partition, bint verbose=False):
r"""
Return a bliss copy of a digraph G
Expand Down Expand Up @@ -391,10 +447,11 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, list Vout, list Vi
for i from 0 <= i < Vnr:
for j from 1 <= j < logLnr:
g.add_edge((j-1)*Vnr+i,j*Vnr+i)
print "edge init", ((j-1)*Vnr+i,j*Vnr+i)
if verbose:
print "edge init", ((j-1)*Vnr+i,j*Vnr+i)

cdef int Enr = len(Vout)

for i from 0 <= i < Enr:
x = Vout[i]
y = Vin[i]
Expand All @@ -411,25 +468,27 @@ cdef Graph *bliss_graph_from_labelled_edges(int Vnr, int Lnr, list Vout, list Vi
ind = binrep[j]
if ind == "1":
g.add_edge((logLnr-1-j)*Vnr+x,(logLnr-1-j)*Vnr+y)
print "edge", ((logLnr-1-j)*Vnr+x,(logLnr-1-j)*Vnr+y)
if verbose:
print "edge", ((logLnr-1-j)*Vnr+x,(logLnr-1-j)*Vnr+y)
else:
g.add_edge(x,y)
print "edge unlab", (x,y)
if verbose:
print "edge unlab", (x,y)

if partition == []:
partition = [list(range(Vnr))]
print "XXX",partition
cdef Pnr = len(partition)
for i from 0 <= i < Pnr:
for v in partition[i]:
print "YYY",v
if Lnr == 1:
g.change_color(v, i)
print "color",(v, i)
if verbose:
print "color",(v, i)
else:
for j from 0 <= j < logLnr:
g.change_color(j*Vnr+v, j*Pnr+i)
print "color",(j*Vnr+v, j*Pnr+i)
if verbose:
print "color",(j*Vnr+v, j*Pnr+i)
return g

cpdef canonical_form_from_edge_list(int Vnr, list Vout, list Vin, int Lnr=1, list labels=[], list partition=[], bint directed=False, bint certificate=False):
Expand All @@ -447,13 +506,21 @@ cpdef canonical_form_from_edge_list(int Vnr, list Vout, list Vin, int Lnr=1, lis
cdef long e, f

if directed:
pass
# d = bliss_digraph_from_edges(Vnr, edges, partition)
# aut = d.canonical_form(s, empty_hook, NULL)
# for x,y in edges:
# e,f = aut[x], aut[y]
# new_edges.append( (e,f) )
# del d
d = bliss_digraph_from_labelled_edges(Vnr, Lnr, Vout, Vin, labels, partition)
aut = d.canonical_form(s, empty_hook, NULL)
for i from 0 <= i < len(Vout):
x = Vout[i]
y = Vin[i]
e = aut[x]
f = aut[y]
if Lnr == 1:
new_edges.append( (e,f) )
else:
lab = labels[i]
new_edges.append( (e,f,lab) )
if certificate:
relabel = {v: <long>aut[v] for v in range(Vnr)}
del d
else:
g = bliss_graph_from_labelled_edges(Vnr, Lnr, Vout, Vin, labels, partition)
aut = g.canonical_form(s, empty_hook, NULL)
Expand Down

0 comments on commit 4661b86

Please sign in to comment.