0

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.

Andrea T
  • 15
  • 5
  • 1
    I suggest reading the [tour], the [ask] page and this [help/on-topic] topic to get some ideas on how to hone or rewrite this question in a way that better fits the site guidelines. Typically you want to keep things down to one specific question, that can be answered objectively, and the question is also usually about some code that you've already written. – Random Davis Nov 26 '21 at 16:55
  • What about if you don't know how to start writing the code? How can I learn? How can I ask for hints ? – Andrea T Nov 26 '21 at 21:18
  • 1
    There are other sites that welcome such things, like /r/LearnProgramming on Reddit. I don't really know of all the options out there. They exist, though, for sure. In most cases it's a good idea to design something before you try implementing anything at all; that way once you start coding you'll have a clear end goal in mind. As for getting help to design the program, like I said this site isn't really the place for that, but if you do some searching around I'm sure you'll find a more suitable place. Maybe there's even a Discord server that could help out. Lots of options. – Random Davis Nov 26 '21 at 21:22
  • *"The structure is not as this every time"*: well that is the end of the question then. A question here should be focused, and since you are coding in Python, you should include the sample data structure in Python syntax, add the expected output with some explanation, and add your code attempt (maybe the one based on "travelling salesman"?) and what goes wrong with it. – trincot Nov 27 '21 at 11:51
  • "The structure is not as this every time": Levels are always the same type. the difference starts on last 2 levels. There you could expect more or less nodes depending on the situation. – Andrea T Nov 30 '21 at 09:06

0 Answers0