pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
graph.py
1 class Graph(object):
2  def __init__(self):
3  self.childrenchildren = {} # dictionnary giving the list of childrens for each node.
4  self.qq = [] # configuration associated to each node.
5  self.connexconnex = [] # ID of the connex component the node is belonging to.
6  self.nconnexnconnex = 0 # number of connex components.
7  self.existing_connexexisting_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.childrenchildren)
15  self.childrenchildren[idx] = []
16  self.qq.append(q)
17  self.connexconnex.append(None)
18  if new_connex:
19  self.new_connexnew_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.childrenchildren and second in self.childrenchildren
28  if orientation >= 0:
29  self.childrenchildren[first].append(second)
30  if orientation <= 0:
31  self.childrenchildren[second].append(first)
32 
33  def new_connex(self, idx):
34  """
35  Create a new connex component for node <idx>
36  """
37  self.connexconnex[idx] = self.nconnexnconnex
38  self.existing_connexexisting_connex.append(self.nconnexnconnex)
39  self.nconnexnconnex += 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_connexexisting_connex.remove(past)
48  self.connexconnex = [c if c != past else future for c in self.connexconnex]
49  except: # noqa: E722
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.connexconnex) if c == connex]
children
Definition: graph.py:3
existing_connex
Definition: graph.py:7
def connexIndexes(self, connex)
Definition: graph.py:52
def add_node(self, q=None, new_connex=False)
Definition: graph.py:9
def new_connex(self, idx)
Definition: graph.py:33
def add_edge(self, first, second, orientation=0)
Definition: graph.py:22
def rename_connex(self, past, future)
Definition: graph.py:41