%pylab inline
import numpy as np
from conway99 import *
import pickle
We start from an arbitrary vertex and its neighbours. These can necessarily be arranged as 7 blades of a fan; we fix a numbering with vertex 0 the centre, 1-14 its neighbours, and blade edges 1-2, 3-4, 5-6, 7-8, 9-10, 11-12, 13-14
seed15 = np.empty((15,15), dtype='int')
for i in range(15):
for j in range(15):
seed15[i,j] = 0
# 1-14 all nhbrs of 0
for i in range(1,15):
seed15[0,i] = 1
seed15[i,0] =1
# By fixing an ordering, a single representative suffices
for i in [1,3,5,7,9,11,13]:
seed15[i,i+1] = 1
seed15[i+1,i] = 1
# review
print(seed15)
plot_given_edges(seed15)
# Verify some details
assert len(seed15)*len(seed15) == num_known_zeros(seed15) + num_known_ones(seed15) + num_unknowns(seed15)
assert not(has_unknown_values(seed15))
assert lambda_compatible(seed15)
assert mu_compatible(seed15)
assert meets_adjacency_requirements(seed15, debug=True)
assert graph_is_valid(seed15)
(NB, as we started numbering at 0, this is our 16th vertex)
wlog, we let this be a neighbour of vertex 1
# Generate template with an additional vertex, and review
seed16 = get_supermatrix_template(seed15, forced_edges=[(1,15)])
print(seed16)
plot_given_edges(seed16)
# Fill in the template
%time super16 = templates_to_valid_graphs([seed16], verbose=0)
# Reduce to eliminate equivalent graphs
rep16 = reduce_mod_equivalence(super16, verbose=True)
# Turns out, there's only really one way to extend this! Let's take a look
plot_given_edges(rep16[0])
This was expected:
By mu=2 condition, as 15 is not a nhbr of 0, they have 2 mutual nhbrs
Moreover, we could have applied this at the template stage to reduce the search space.
# alternative template
seed16 = get_supermatrix_template(seed15, forced_edges=[(1,15), (15,14)])
print(seed16)
plot_given_edges(seed16)
# Fill in the template
%time super16 = templates_to_valid_graphs([seed16], verbose=0)
# For convenience, can wrap up the templating, search, and reduction steps for a list of seed graphs
%time rep16 = find_valid_supergraphs([seed15], forced_edges=[(1,15), (15,14)])
# confirm this is what we expected from the individual steps:
plot_given_edges(rep16[0])
We know one of the blades centred at vertex 1; namely 1-0-2-1.
We also have part of another, containing vertex 15.
wlog, let vertex 16 be the other vertex of that blade (so we force 1-16, and 15-16)
%time rep17 = find_valid_supergraphs(rep16, forced_edges=[(1,16),(15,16)], verbose=False)
Vertex 17 necessarily starts a new blade, so only forcing 1-17
%time rep18 = find_valid_supergraphs(rep17, forced_edges=[(1,17)], verbose=False)
However, we can then force vertex 18 to be the other vertex of that blade
%time rep19 = find_valid_supergraphs(rep18, forced_edges=[(1,18),(17,18)], verbose=False)
Continue in this fashion until we have all nhbrs of vertex 1, with forced fan pattern 0-2, 15-16, 17-18, 19-20, 21-22, 23-24, 25-26
%time rep20 = find_valid_supergraphs(rep19, forced_edges=[(1,19)], verbose=False)
%time rep21 = find_valid_supergraphs(rep20, forced_edges=[(1,20), (19,20)], verbose=False)
%time rep22 = find_valid_supergraphs(rep21, forced_edges=[(1,21)], verbose=False)
%time rep23 = find_valid_supergraphs(rep22, forced_edges=[(1,22), (21,22)], verbose=False)
%time rep24 = find_valid_supergraphs(rep23, forced_edges=[(1,23)], verbose=False)
%time rep25 = find_valid_supergraphs(rep24, forced_edges=[(1,24), (23,24)], verbose=False)
%time rep26 = find_valid_supergraphs(rep25, forced_edges=[(1,25)], verbose=False)
%time rep27 = find_valid_supergraphs(rep26, forced_edges=[(1,26),(25,26)], verbose=False)
# Review an example
plot_given_edges(rep27[0])
Although we have multiple possible 27-vertex graphs, for each of them we know that vertex 2 has degree 2:
Thus we have precisely one blade centered at vertex 2, 2-0-1-2.
# Confirm our claim:
[vertex_degrees(a)[2] for a in rep27]
We note that vertices 2 and 3 are non-adjacent. Thus, they will have two mutual neighbours.
Vertex 0 is one of these, but they cannot currently have another:
# Confirm our claim:
[mutual_neighbours(2,3,a) for a in rep27]
wlog, we may arrange for vertex 27 to be the second mutual neighbour of vertices 2 and 3. As a non-nhbr of 0, these are their two mutual neighbours, so by mu condition 27 is not a neighbour of any of 4 through 14.
non_edges27 = [(k,27) for k in range(4,15)]
non_edges27
%time rep28 = find_valid_supergraphs(rep27, forced_edges=[(2,27),(3,27)], forced_non_edges=non_edges27, verbose=False)
min([[k for k in range(27) if r[27][k] and k not in [2,3]] for r in rep28])
Similarly, vertices 2 and 4 are non-adajcent, with at least 1 mutual neighbour 0. Do they have any more?
max([len(mutual_neighbours(2,4,a)) for a in rep28])
No, so we introduce their second mutual neighbour now.
Again, it cannot have any additional mutual neighbours with vertex 0, so is not adjacent to 3 or 5 through 14.
non_edges28 = [(k,28) for k in range(15) if k not in [2,4]]
%time rep29 = find_valid_supergraphs(rep28, forced_edges=[(2,28),(4,28)], forced_non_edges=non_edges28, verbose=False)
Similarly for vertex 5, there is only vertex 0 as a mutual neighbour with vertex 2:
max([len(mutual_neighbours(2,5,a)) for a in rep29])
So we add their second mutual neighbour next:
non_edges29 = [(k,29) for k in range(15) if k not in [2,5]]
%time rep30 = find_valid_supergraphs(rep29, forced_edges=[(2,29),(5,29)], forced_non_edges=non_edges29, verbose=False)
Again for vertex 6, there is only vertex 0 as a mutual neighbour with vertex 2:
max([len(mutual_neighbours(2,6,a)) for a in rep30])
non_edges30 = [(k,30) for k in range(15) if k not in [2,6]]
%time rep31 = find_valid_supergraphs(rep30, forced_edges=[(2,30),(6,30)], forced_non_edges=non_edges30, verbose=False)
pickle.dump( rep31, open( "fullsearch-31.p", "wb" ) )
next stage errors out due to insufficient memory
Again for vertex 7, there is only vertex 0 as a mutual neighbour with vertex 2:
max([len(mutual_neighbours(2,7,a)) for a in rep31])
non_edges31 = [(k,31) for k in range(15) if k not in [2,7]]
#%time rep32 = find_valid_supergraphs(rep31, forced_edges=[(2,31),(7,31)], forced_non_edges=non_edges31, verbose=False)