Without trying to manually sketch out a graph on paper, is there a simple way I could get the arcs between nodes in this problem? I am using R and it seems there must be an elegant way of doing so but I'm at a loss. I'm going to need to be passing this into getShortestPathTree()
from optrees
, which takes a matrix with the list of arcs of the graph. Each row represents one arc. The first two columns contain the two endpoints of each arc and the third column contains their weights.
By going through with a pen and paper and sketching the graph I was able to create this matrix but I'm just looking for a simpler solution.
head = c(1,1,1, 2, 3, 4,4,4, 6, 7, 9)
tail = c(2,6,9, 3, 7, 5,8,10, 7, 4, 10)
weight = c(90,90,90, 15, 5, 20,20,20, 21, 25, 30)
arcs = cbind(head, tail, weight)
head(arcs)
head tail weight
[1,] 1 2 90
[2,] 1 6 90
[3,] 1 9 90
[4,] 2 3 15
[5,] 3 7 5
[6,] 4 5 20
arc
. The far right column needs to correspond to the task # inhead
, these are the weights of the arcs that go from Thehead
totail
I should have clarified that the numbers inhead
refer to tasks, so1
is task A,2
is task B and so on. $\endgroup$