graph.py
Go to the documentation of this file.
1 class Graph(object):
2  def __init__(self):
3  self.children = {} # dictionnary giving the list of childrens for each node.
4  self.q = [] # configuration associated to each node.
5  self.connex = [] # ID of the connex component the node is belonging to.
6  self.nconnex = 0 # number of connex components.
7  self.existing_connex = [] # List of existing connex component ID.
8 
9  def add_node(self, q=None, new_connex=False):
10  '''
11  Create the memory to store a new edge. Initialize all components to None.
12  Create an empty list of children.
13  '''
14  idx = len(self.children)
15  self.children[idx] = []
16  self.q.append(q)
17  self.connex.append(None)
18  if new_connex:
19  self.new_connex(idx)
20  return idx
21 
22  def add_edge(self, first, second, orientation=0):
23  '''
24  Add edge from first to second. Also add edge from second to first if orientation
25  is null.
26  '''
27  assert(first in self.children and second in self.children)
28  if orientation >= 0:
29  self.children[first].append(second)
30  if orientation <= 0:
31  self.children[second].append(first)
32 
33  def new_connex(self, idx):
34  '''
35  Create a new connex component for node <idx>
36  '''
37  self.connex[idx] = self.nconnex
38  self.existing_connex.append(self.nconnex)
39  self.nconnex += 1
40 
41  def rename_connex(self, past, future):
42  '''
43  Change the index of the all the nodes belonging to a connex component.
44  Useful when merging two connex components.
45  '''
46  try:
47  self.existing_connex.remove(past)
48  self.connex = [c if c != past else future for c in self.connex]
49  except:
50  pass
51 
52  def connexIndexes(self, connex):
53  '''Return the list of all node indexes belonging to connex component <connex>.'''
54  return [i for i, c in enumerate(self.connex) if c == connex]
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:24
existing_connex
Definition: graph.py:7
def add_edge(self, first, second, orientation=0)
Definition: graph.py:22
def rename_connex(self, past, future)
Definition: graph.py:41
def new_connex(self, idx)
Definition: graph.py:33
def connexIndexes(self, connex)
Definition: graph.py:52
def __init__(self)
Definition: graph.py:2
children
Definition: graph.py:3
def add_node(self, q=None, new_connex=False)
Definition: graph.py:9


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:03