graph.py
Go to the documentation of this file.
1 class Graph:
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: # noqa: E722
50  pass
51 
52  def connexIndexes(self, connex):
53  """
54  Return the list of all node indexes belonging to connex component <connex>.
55  """
56  return [i for i, c in enumerate(self.connex) if c == connex]
graph.Graph.connexIndexes
def connexIndexes(self, connex)
Definition: graph.py:52
graph.Graph.nconnex
nconnex
Definition: graph.py:6
graph.Graph.connex
connex
Definition: graph.py:5
graph.Graph
Definition: graph.py:1
graph.Graph.add_edge
def add_edge(self, first, second, orientation=0)
Definition: graph.py:22
graph.Graph.new_connex
def new_connex(self, idx)
Definition: graph.py:33
graph.Graph.rename_connex
def rename_connex(self, past, future)
Definition: graph.py:41
graph.Graph.add_node
def add_node(self, q=None, new_connex=False)
Definition: graph.py:9
graph.Graph.children
children
Definition: graph.py:3
boost::fusion::append
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:32
graph.Graph.q
q
Definition: graph.py:4
graph.Graph.existing_connex
existing_connex
Definition: graph.py:7
graph.Graph.__init__
def __init__(self)
Definition: graph.py:2


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:09