pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
graph.py
1class 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]
existing_connex
Definition graph.py:7
rename_connex(self, past, future)
Definition graph.py:41
add_edge(self, first, second, orientation=0)
Definition graph.py:22
new_connex(self, idx)
Definition graph.py:33
add_node(self, q=None, new_connex=False)
Definition graph.py:9
connexIndexes(self, connex)
Definition graph.py:52