# Description

Converts an arborescence to an adjacency matrix. The arborescence stores only the parents' index for each node, and needs the original adjacency matrix to retrieve the costs of each edge.

# Synopse

• par: The arborescence.
• labels: The original adjacency matrix.
2     """
3     Parameters:
4         par: the parents of each node
5         A: the adjacency matrix to get the costs from
6
7     >>> from numpy import array
8     >>> A = array([[10,  8,  9,  4,  6,  8],[ 8,  1,  6, 10,  4,  8],[ 9,  6, 10, 10,  3,  6],[ 4, 10, 10,  7,  4,  5],[ 6,  4,  3,  4,  2,  6],[ 8,  8,  6,  5,  6,  9]])
9     >>> parents = [3, 4, 4, 3, 4, 3]
11     [[0 0 0 4 0 0]
12      [0 0 0 0 4 0]
13      [0 0 0 0 3 0]
14      [4 0 0 0 0 5]
15      [0 4 3 0 0 0]
16      [0 0 0 5 0 0]]
17     """
18     from numpy import ones
19
20     n = len(par)
21     B = ones((n,n))*float("inf")
22     for v in range(n):
23         p = par[v]
24         if p != v:
25             B[p,v] = A[p,v]
26
27     return B

# Examples

2 from numpy import array
3 A = array([[10,  8,  9,  4,  6,  8],
4            [ 8,  1,  6, 10,  4,  8],
5            [ 9,  6, 10, 10,  3,  6],
6            [ 4, 10, 10,  7,  4,  5],
7            [ 6,  4,  3,  4,  2,  6],
8            [ 8,  8,  6,  5,  6,  9]])
9 parents =  [3, 4, 4, 3, 4, 3]