def test_0():
  txtblk = """
    A:  F B E 
    B:  F A 
    C:  G F 
    D:  H G 
    E:  A 
    F:  G A B C 
    G:  F C D 
    H:  D 
"""
  od = adjtxtblk2OrderedDict(txtblk)
  assert od == cx.OrderedDict([
    ('A', ['F', 'B', 'E']),
    ('B', ['F', 'A']),
    ('C', ['G', 'F']),
    ('D', ['H', 'G']),
    ('E', ['A']),
    ('F', ['G', 'A', 'B', 'C']), 
    ('G', ['F', 'C', 'D']), 
    ('H', ['D'])])
  # Convert adjacency list in OrderedDict to array of format seen in tinyG.txt
  a, i2v = adjtxtblk2arr_ud(txtblk)
  assert a == [
    8, # V -> Number of vertices
    9, # E -> Number of edges
    (0, 1), (2, 6), (5, 6), (1, 5), (0, 5), (3, 6), (0, 4), (3, 7), (2, 5)] # edges
Ejemplo n.º 2
0
def test_0():
    txtblk = """
    A:  F B E 
    B:  F A 
    C:  G F 
    D:  H G 
    E:  A 
    F:  G A B C 
    G:  F C D 
    H:  D 
"""
    od = adjtxtblk2OrderedDict(txtblk)
    assert od == cx.OrderedDict([('A', ['F', 'B', 'E']), ('B', ['F', 'A']),
                                 ('C', ['G', 'F']), ('D', ['H', 'G']),
                                 ('E', ['A']), ('F', ['G', 'A', 'B', 'C']),
                                 ('G', ['F', 'C', 'D']), ('H', ['D'])])
    # Convert adjacency list in OrderedDict to array of format seen in tinyG.txt
    a, i2v = adjtxtblk2arr_ud(txtblk)
    assert a == [
        8,  # V -> Number of vertices
        9,  # E -> Number of edges
        (0, 1),
        (2, 6),
        (5, 6),
        (1, 5),
        (0, 5),
        (3, 6),
        (0, 4),
        (3, 7),
        (2, 5)
    ]  # edges
Ejemplo n.º 3
0
 def __init__(self, a=None, **kwargs):
   if a is not None:
     if isinstance(a, int):
       self._init_empty(a)
     elif len(a) == 1:
       self._init_empty(a[0])
     else:
       self._init(a)
     self.keys = range(self._V)
   elif 'adjtxt' in kwargs:
     self._adj = adjtxtblk2OrderedDict(kwargs['adjtxt'])
     self._V = len(self._adj)
     self._E = len(set([tuple(sorted([v, w])) for v, ws in self._adj.items() for w in ws]))
     self.keys = self._adj.keys()
Ejemplo n.º 4
0
 def __init__(self, arg=None, **kwargs):
     if arg is not None:
         if isinstance(arg, int):
             self._init_empty(arg)
         elif len(arg) == 1:
             self._init_empty(arg[0])
         else:
             self._init(arg)
         self.keys = range(self.num_nodes)
     elif 'adjtxt' in kwargs:
         self._adj = adjtxtblk2OrderedDict(kwargs['adjtxt'])
         self.num_nodes = len(self._adj)
         self.num_edges = self._init_num_edges()
         self.keys = self._adj.keys()
Ejemplo n.º 5
0
 def __init__(self, a=None, **kwargs):
   if a is not None:
     if isinstance(a, int):
       self._init_empty(a)
     elif len(a) == 1:
       self._init_empty(a[0])
     else:
       self._init(a)
     self.keys = range(self._V)
   elif 'adjtxt' in kwargs:
     self._adj = adjtxtblk2OrderedDict(kwargs['adjtxt'])
     self._V = len(self._adj)
     self._E = len(set([tuple(sorted([v, w])) for v, ws in self._adj.items() for w in ws]))
     self.keys = self._adj.keys()
Ejemplo n.º 6
0
 def __init__(self, arr=None, **kwargs):
     if arr is not None:
         if isinstance(arr, int):
             self._init_empty(arr)
         elif len(arr) == 1:
             self._init_empty(arr[0])
         else:
             self._init(arr)
         self.keys = range(self.num_vertices)
     elif 'adjtxt' in kwargs:
         self._adj = adjtxtblk2OrderedDict(kwargs['adjtxt'])
         self.num_vertices = len(self._adj)
         self.num_edges = len(
             set(
                 tuple(sorted([v, w])) for v, ws in self._adj.items()
                 for w in ws))
         self.keys = self._adj.keys()