Just ran across this problem, I'm wondering if any of you math and algorithm types have seen it addressed anywhere... There's a directed acyclical graph. Each node has two values: a duration (suppose integers) and a profit (which can be negative). The profit value changes over time. Is there a polynomial or near-linear algorithm for finding the most profitable path? ''(p.s. simpler version: suppose the profit always starts negative and increases linearly)'' My situation is project scheduling, the graph is the project PERT chart, the duration is the number of days or weeks to complete a feature, profit = (gained revenue - development cost) for any particular feature, and the gained revenue is time-varying because later generally means less profit; missing some key date can make it catastrophic; sometimes there is no cash advantage to early. The book SoftwareByNumbers describes a heuristic, but it seemed to me that maybe there could be an algorithm based on working backwards from the end date, using induction to add one earlier node at a time and always keeping score of the cost profile from each new starting node. If this worked, then the cost of adding a new node to the front would be O(projectLength) or O(edges) and the whole thing could be at worst O(projectLength*edges*nodes) or similar instead of factorial or exponential. Does this graph problem sound familiar to anyone? -- AlistairCockburn Let me see if I understand this. You have '''(V,E)''' a directed acyclic graph. We have functions '''d(V,t)''' and '''p(V,t)''' which for a given value of '''t''' give a "duration" and "profit" for each vertex. Given a path '''v_0, v_1, v_2, v_3 ... v_n''' we compute '''t_0, t_1, t_2 ... t_n''' by setting '''t_0=0''' and '''t_i''' to be the sum of the '''d(v_j,t_j)''' for '''j (1, 0) -> (1, 0) -> (1, 30 + 9t) The time value for profit calculations is then the number of nodes that have been already been traversed in the graph. We're ''close'' to being able to apply DijkstrasAlgorithm here, since you could just assign a cost to each node that's the negative of the profit (or alternatively, take the max profit instead of min cost). But there's a problem, because the profit depends on where the node is placed, so I think the "relaxation" process that DijkstrasAlgorithm uses would need to back up all the way to beginning and compute costs for everything. This leads to the combinatorial explosion Doug was talking about. I think any similar method would have the same problem: any intermediate results are potentially invalidated by the changing profit, so you can't use DynamicProgramming techniques or break the problem up into subproblems. I'll give this a bit more thought overnight. My gut intuition is it can't be done in polynomial time. But it's summer/winter vacation, I've got nothing else to do, and it's a neat challenge. Plus, this problem is an isomorphism of how to play Civilization 3 so that you get key scientific advances as fast as possible, a far more applicable problem for me. ;) -- JonathanTang ''Yeah, now you're talking! That's an '''important''' problem. Please post your results ASAP! ;-)'' ''Being JustaStudent may be an advantage here; math is still fresh in your mind, you have fewer preconceptions, your memory is better, you have the speed/reflexes of youth...Perhaps you'll discover that P = NP. Could happen. Never know.'' Now the Civilization 3 tech tree would be a MUCH harder problem. Should you spend time increasing city size (more taxes to science) or increasing production (more units = more cities = more science, also more libraries/universities = more science, also building science wonders)? Should you go directly for a technology or is it faster to research universities and research labs and science wonders to help you there? The mind boggles. ''Although, the way you phrased it was static...just at a point in time. Surely a single matrix inversion (or pseudo-inversion) will solve '''that'''. :-)'' How many features/nodes would be on graph? i.e. is the number of nodes too big to make brute force too slow? You can presumably cache the contribution from early features added if just looking at swapping orders of late feature, swapping earliest feature clearly potentially changes all others as you have stated. You might also consider what it means if the profit does change complexly with order. You already have one example, the demo, which has a step function shape. You may be able to find other sets of profit functions, then some Sets of functions may be considered before others to give a solution (although you need a way to decide which to look at first). -- JamesKeogh I'd like to make the problem a bit harder: In reality we don't know the durations/costs for sure, but have to either make conservative estimates or else work with probability distributions which is my proposal. Note: Summing over probability distributions is done by folding and can be simplified to a few additions if one constrains oneself to a set of simple cases like gauss or poisson distributions. -- GunnarZarncke ---- CategoryAlgorithm