hope everything is fine for all of you in the community.
I got this problem. I have a tree structure as follows, coding in python:
0
├── 0.01
│ └── 0.25
│ └── 0.5
│ ├── 3.5
│ │ └── 7
│ ├── 3.5
│ │ ├── 8
│ │ └── 8
│ ├── 3.5
│ │ ├── 4
│ │ ├── 4
│ │ └── 4
│ ├── 3.5
│ │ └── 8
│ ├── 3.5
│ │ ├── 4
│ │ └── 4
│ └── 3.5
│ └── 2.5
└── 0.01
└── 0.25
└── 0.5
├── 3.5
│ ├── 7
│ ├── 7
│ └── 7
├── 3.5
│ ├── 8
│ └── 8
├── 3.5
│ ├── 4
│ ├── 4
│ └── 4
├── 3.5
│ ├── 4
│ ├── 4
│ └── 4
└── 3.5
├── 2.5
└── 2.5
Each number represents the time in hours that a "task" need to be performed when I reach that node. In order to make the process in the children node I have to had completed the task at related parent node. If two different children node have same parent, I have to complete parent's task only one to run both of them. My goal is to traverse the tree and make all the processes in the minimum time possible with given "numbers of task to do in parallel".
The structure is not as this every time, so I am looking to something scalable depending on the situation. It looks to me something similar to a CPU task scheduler, with I am not that confident to be honest.
I tried to reduce this problem to the well known "problem of the travelling salesman", in which you visit all the cities in the minimum time going back to the initial city. But without success.
I do not expect a proper answer, but If anyone is able to give me hints or suggestions I would be happy.
Thank you!
EDITED
I add my attempt as request. For the moment I am only able to traverse the tree and check if the node has been visited:
totalTime = 0
def addTotalTime(node, totalTime, processTime):
if not node.data.visited:
totalTime += processTime
return totalTime
for lvl1Node in objMain.runTree.children('SimRoot'): # Level 1
node_lvl1 = objMain.runTree.get_node(lvl1Node.identifier)
nodeIDlvl1 = node_lvl1.identifier
processTime = objMain.runTree.nodes[nodeIDlvl1].data.nodeTime
totalTime = addTotalTime(node_lvl1, totalTime, processTime)
# Flagging visited nodes
objMain.runTree.nodes[nodeIDlvl1].data.visited = 1
# Children Single Nodes ALWAYS THE SAME
###################LVL2###################################
node_lvl2 = objMain.runTree.children(nodeIDlvl1)[0]
node_lvl2 = objMain.runTree.get_node(node_lvl2.identifier)
nodIDlvl2 = node_lvl2.identifier
processTime = objMain.runTree.nodes[nodIDlvl2].data.nodeTime
totalTime = addTotalTime(node_lvl2, totalTime, processTime)
# Flagging visited nodes
objMain.runTree.nodes[nodIDlvl2].data.visited = 1
###################LVL3###################################
node_lvl3 = objMain.runTree.children(nodeIDlvl2)[0]
node_lvl3 = objMain.runTree.get_node(node_lvl3.identifier)
nodIDlvl3 = node_lvl3.identifier
processTime = objMain.runTree.nodes[nodIDlvl3].data.nodeTime
totalTime = addTotalTime(node_lvl3, totalTime, processTime)
# Flagging visited nodes
objMain.runTree.nodes[nodIDlvl3].data.visited = 1
for lvl4Node in objMain.runTree.children(nodIDlvl3):
node_lvl4 = objMain.runTree.get_node(lvl4Node.identifier)
nodeIDlvl4 = node_lvl4.identifier
processTime = objMain.runTree.nodes[nodeIDlvl4].data.nodeTime
totalTime = addTotalTime(node_lvl4, totalTime, processTime)
# Flagging visited nodes
objMain.runTree.nodes[nodeIDlvl4].data.visited = 1
for lvl5Node in objMain.runTree.children(nodeIDlvl4):
node_lvl5 = objMain.runTree.get_node(lvl5Node.identifier)
nodeIDlvl5 = node_lvl5.identifier
processTime = objMain.runTree.nodes[nodeIDlvl5].data.nodeTime
totalTime = addTotalTime(node_lvl5, totalTime, processTime)
# Flagging visited nodes
objMain.runTree.nodes[nodeIDlvl5].data.visited = 1
The thing I am missing is how to create a list of consequential processes in order to reach minimum time.