In [1]:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import os

from IPython.display import SVG
from IPython.display import HTML

In [2]:
pwd()


Out[2]:
'C:\\Users\\chaithcock\\Documents\\repos\\RushHour\\RushHourPy\\analysis_prototypes\\Numpy Experiments'

In [3]:
os.chdir('../..')

In [4]:
pwd()


Out[4]:
'C:\\Users\\chaithcock\\Documents\\repos\\RushHour\\RushHourPy'

In [5]:
%run numpy_constants.py
%run numpy_utilities.py
%run numpy_components.py
%run numpy_neighbors.py
%run numpy_display.py

In [6]:
cards = np.zeros((40,1,3),dtype='ulonglong')

In [7]:
cards[6,0]


Out[7]:
array([0, 0, 0], dtype=uint64)

In [8]:
# Card 18 - Itermediate
v18 = np.zeros((6,6),dtype=int)
v18[0,:2] = hcar
v18[1,:2] = hcar
v18[2,1:3] = hcar
v18[:2,2] = vcar
v18[:3,3] = vtruck
v18[2:5,0] = vtruck
v18[3,1:4] = htruck
v18[4,1:3] = hcar
v18[5,:3] = htruck

i1,i2 = split_int(board_to_int(v18))
cards[18] = [i1,i2,2]

HTML(svg_from_state(board_to_int(v18),2))


Out[8]:
XLKJHZWRT

In [9]:
cards[18]


Out[9]:
array([[15362435066293568, 13506451033292288,                 2]], dtype=uint64)

In [10]:
HTML(svg_from_state(combine_ints(cards[18,0,0],cards[18,0,1]),2))


Out[10]:
XLKJHZWRT

In [11]:
board_to_int(v18),split_int(board_to_int(v18))


Out[11]:
(276745027360252628944933584371200, (15362435066293568, 13506451033292288))

In [97]:
# Card 28 - Advanced

i = 28

v = np.zeros((6,6),dtype=int)
v[0,:3] = htruck
v[2,:2] = hcar
v[5,:2] = hcar
v[5,2:4] = hcar
v[1,4:6] = hcar
v[3,3:5] = hcar
v[4,2:5] = htruck


v[3:5,0] = vcar
v[3:5,1] = vcar
v[:2,3] = vcar
v[1:4,2] = vtruck
v[3:6,5] = vtruck


i1,i2 = split_int(board_to_int(v))
cards[i] = [i1,i2,2]

HTML(svg_from_state(board_to_int(v),1))


Out[97]:
XLKJHGFEZWRT

In [119]:
# Card 14 - intermediate

i = 14
red_col = 3

v = np.zeros((6,6),dtype=int)
v[0,:2] = hcar
v[1,4:] = hcar
v[2,2:4] = hcar
v[3,2:4] = hcar
v[4,4:] = hcar
v[5,:2] = hcar

v[2:4,0] = vcar
v[2:4,1] = vcar
v[2:4,4] = vcar
v[2:4,5] = vcar
v[4:,2] = vcar
v[:2,2] = vcar

i1,i2 = split_int(board_to_int(v))
cards[i] = [i1,i2,2]

HTML(svg_from_state(board_to_int(v),red_col))


Out[119]:
XLKJHGFEDCBA

In [132]:
# Card 37 - intermediate

i = 37
red_col = 2

v = np.zeros((6,6),dtype=int)
v[0,:2] = hcar
v[1,:2] = hcar
v[2,1:3] = hcar
v[3,1:4] = htruck
v[5,:2] = hcar
v[0,4:] = hcar
v[4,4:] = hcar
v[5,4:] = hcar

v[2:5,0] = vtruck
v[1:4,4] = vtruck
v[1:4,5] = vtruck
v[4:,3] = vcar
v[:2,2] = vcar

i1,i2 = split_int(board_to_int(v))
cards[i] = [i1,i2,2]

HTML(svg_from_state(board_to_int(v),red_col))


Out[132]:
XLKJHGFEDZWRT

In [98]:
comps = components([(board_to_int(v),int(1))])

In [99]:
comps


Out[99]:
[<networkx.classes.graph.Graph at 0x2926c0b3e80>]

In [100]:
g = comps[0]

In [101]:
g.size()


Out[101]:
8026

In [102]:
len(g.nodes())


Out[102]:
2544

In [18]:
%run numpy_distance_partition.py
partition = distance_partition(g)

In [19]:
len(partition)


Out[19]:
61

In [20]:
partition[60]


Out[20]:
{(276745027360252628944933584371200, 2)}

In [21]:
HTML(svg_from_state(276745027360252628944933584371200, 2))


Out[21]:
XLKJHZWRT

In [22]:
HTML(svg_neighborhood(276745027360252628944933584371200, 2))


Out[22]:
XLKJHZWRTXLKJHZWRTXLKJHZWRTXLKJHZWRT

In [23]:
g


Out[23]:
<networkx.classes.graph.Graph at 0x2926a9bd160>

In [36]:
import copy
h = nx.Graph()
#h.nodes = copy.deepcopy(g.nodes)
h


Out[36]:
<networkx.classes.graph.Graph at 0x2926b529c50>

In [37]:
len(h.nodes())


Out[37]:
0

In [38]:
h.size()


Out[38]:
0

In [39]:
len(g.nodes())


Out[39]:
4318

In [40]:
nodes = list(g.nodes())

In [41]:
nodes[0]


Out[41]:
(276745027360252628944933584371200, 2)

In [42]:
d_0 = [n for n in g.nodes() if n[1] == 5]
len(d_0)


Out[42]:
2644

In [43]:
for n in d_0:
    h.add_node(n)
len(h.nodes())


Out[43]:
2644

In [44]:
g


Out[44]:
{(276745027360252626978457038093824, 2): {},
 (276745027360252628944927242583552, 2): {},
 (276745027360252628944933584142272, 2): {}}

In [45]:
len(g.edges())


Out[45]:
12961

In [46]:
edges = [g.edges()]

In [51]:
type(edges[0])


Out[51]:
list

In [52]:
g.edges()[0]


Out[52]:
((276745027360252628944933584371200, 2),
 (276745027360252628944933584142272, 2))

In [54]:
g.edges()[1]


Out[54]:
((276745027360252628944933584371200, 2),
 (276745027360252626978457038093824, 2))

In [57]:
p_edges = [e for e in g.edges() if abs( e[0][1] - e[1][1] ) == 1]

len(p_edges)


In [58]:
len(p_edges)


Out[58]:
312

In [64]:
g.nodes()[0]


Out[64]:
(276745027360252628944933584371200, 2)

In [65]:
g[(276745027360252628944933584371200, 2)]


Out[65]:
{(276745027360252626978457038093824, 2): {},
 (276745027360252628944927242583552, 2): {},
 (276745027360252628944933584142272, 2): {}}

In [68]:
nbr_depths = {n:set([ x[1] for x in g[n]]) for n in g.nodes()}

In [75]:
buried_nodes = [x for x in nbr_depths.keys() if set(x[1]) == nbr_depths[x]]


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-75-68fa5227f704> in <module>()
----> 1 buried_nodes = [x for x in nbr_depths.keys() if set(x[1]) == nbr_depths[x]]

<ipython-input-75-68fa5227f704> in <listcomp>(.0)
----> 1 buried_nodes = [x for x in nbr_depths.keys() if set(x[1]) == nbr_depths[x]]

TypeError: 'int' object is not iterable

In [83]:
list(nbr_depths.keys())[0][1]


Out[83]:
2

In [82]:
nbr_depths[(276745027360252628944933584371200, 2)]


Out[82]:
{2}

In [84]:
{1.2} == {2}


Out[84]:
False

In [134]:
cards[18],cards[28],cards[14],cards[37]


Out[134]:
(array([[15362435066293568, 13506451033292288,                 2]], dtype=uint64),
 array([[17996807076014592, 10339091161247109,                 2]], dtype=uint64),
 array([[15340386781908388, 10373068125595648,                 2]], dtype=uint64),
 array([[15344155613391917, 13509536243212598,                 2]], dtype=uint64))

In [ ]: