Directed acyclic graph profit sorting

In summary: S x is still a positive node, but y is a negative node and we've increased the profit of S by deleting it. If Lvl is not empty then continue to the next level
  • #1
mXSCNT
315
1
Suppose we have a directed acyclic graph. The nodes are labeled with integers (which may be negative). Imagine that the labels represent payoffs or costs of taking an action associated with each node. In order to perform an action you must perform prerequisite actions indicated by the graph.

The question is whether there is a topological sort on this graph, such that at some point during the ordering, the sum of the labels on all the nodes up to that point becomes positive. This would represent a net profit from taking all actions up to that point.

Example:

[PLAIN]http://img535.imageshack.us/img535/5395/graph1f.png

If we have the topological sort ABCED, the labels on ABCE sum to a positive number (1). So this graph does meet the criteria for being profitable - if you take actions A B C E in that order, you make a profit of 1. Note that if you also took action D, the sum would be -6, so you should stop after E. ABCED is a "profitable topological sort" because it has the prefix ABCE which is profitable. ABCDE is an example of a non-profitable topological sort.

The problem is to find an algorithm to determine whether a directed acyclic graph in general has a profitable topological sort.
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Here's what I think may be a solution. I haven't figured out a proof of correctness, but it does work at least for simple examples, and it has some ideas.

First, when seeking to maximize the profit in the graph, we only need to consider including or excluding positive nodes; we only want to include the negative nodes that are prerequisites for our positive nodes. Including extra negative nodes beyond that would only decrease the profit.

So we maintain a set S of positive nodes and all their negative prerequisites, and consider a positive node x in S. If we remove x from S, then we also remove:
- The set of all nodes y in S with a path x -> y (call this set Descendents(x,S)). If we take out x then anything that x is a prerequisite for has to go as well.
- The set of all negative nodes z in S with a path z -> x, and no path from z to any other positive node w in S, unless w is in Descendents(x,S). Call this set Support(x,S). If we take out x, then we get to greedily remove the negative "support" for x that we aren't using elsewhere.

Define Family(x,S) = {x} u Support(x,S) u Descendents(x,S).

Define Level(x,S) for positive nodes to be 0 if Descendents(x,S) = {}, and otherwise Level(x,S) is one plus the highest level of any positive node y with a path x -> y. Level(x,S) measures how "deep" x is away from the front of the set. Level(x,S) is infinite for negative nodes.

Here is a graph to illustrate these definitions.

[PLAIN]http://img687.imageshack.us/img687/2971/graph2an.png

If S is the entire graph, then:
The nodes at level 0 are H, E, and F
The only node at level 1 is B
Family(E,S) = {E} u Support(E,S) = {E} - doesn't include C because C supports F
Family(F,S) = {F} u Support(F,S) = {F, D}
Family(H) = {H}
Family(B,S) = {B} u Support(B,S) u Descendents(B,S) = {B} u {A} u {E, C, D, F} = {A, B, C, D, E, F} - omitting G because G supports H

Also define LabelSum(A) to be the sum of the labels of each node in a set A.

The idea is to start with a set S that includes all positive nodes and their negative prerequisites, and greedily delete positive nodes and their families from S to increase the profit. Note that LabelSum(Family(F,S)) = -1 < 0 in the example, and since F is level 0 we can remove it and increase the profit for S (or in this case just decreasing the loss).

We want to work backwards trying to delete nodes with level 0 first, then level 1, etc. This is because, suppose you have a level 1 node x, and y is a positive level 0 descendent of x where LabelSum(Support(y,S)) < 0. Now perhaps LabelSum(Family(x,S)) is also less than 0. We don't want to delete x right away, because if we try deleting y first, it would change the evaluation of LabelSum(Family(x,S)) and we might end up not deleting x after all.

So here is the algorithm.
Code:
Initialize S to include all positive nodes and their negative prerequisites
Done = False
while not Done:
  for L = 0 to infinity:
    Lvl = {x in S: Level(x,S) = L}
    If Lvl = {} then Done = True and exit the for loop
    If there are any nodes x in Lvl where LabelSum(Family(x,S)) < 0:
      Delete Family(x,S) from S
      Exit the for loop
If LabelSum(S) > 0:
  print "The maximum profit to be had from the graph is ", LabelSum(S)
Else:
  print "The graph is not profitable"
 
Last edited by a moderator:
  • #3
mXSCNT said:
if you take actions A B C E in that order, you make a profit of 1.

I don't understand what defines an allowed sequence of actions. The diagram doesn't show a path directly from C to E. Should there be one? If not, to perform ABCE, it looks like to you have to go from C back to B and then to E. However, what's the point of the direction in the graph, if you can do that?
 
  • #4
Stephen Tashi said:
I don't understand what defines an allowed sequence of actions. The diagram doesn't show a path directly from C to E. Should there be one? If not, to perform ABCE, it looks like to you have to go from C back to B and then to E. However, what's the point of the direction in the graph, if you can do that?
The rule is that you can't visit node x until you've visited all nodes y with an edge (y, x). In other words you just have to visit nodes in an order corresponding to some topological sort. It's OK to visit E in the diagram because we already visited B, the only parent of E. A topological sort can jump around, not always following the edges, as long as we don't visit a node before visiting its parents.
 
  • #5


A directed acyclic graph profit sorting problem is an interesting and complex problem that has practical applications in various fields such as project management, scheduling, and optimization. The scenario described in the content involves a directed acyclic graph with nodes labeled with integers representing payoffs or costs of taking an action associated with each node. The goal is to find a topological sort that results in a positive net profit from taking all actions up to a certain point in the ordering.

To tackle this problem, we can use a dynamic programming approach. We can define a function that takes in a node and returns the maximum profit that can be achieved by taking all actions up to that node. This function can be recursively defined as follows:

- If the node has no prerequisites, the profit is simply the label of that node.
- If the node has prerequisites, the profit is the maximum of the label of that node plus the profit of its prerequisites, or just the profit of its prerequisites if it results in a negative value.

By recursively applying this function to all nodes in the graph, we can determine the maximum profit that can be achieved by taking all actions up to each node. If this maximum profit is positive, then a profitable topological sort exists. Otherwise, there is no profitable topological sort.

In the example given, the function would return the following values:

- A: 1
- B: 3
- C: 3
- D: -6
- E: 4

Since the maximum profit for node E is positive, a profitable topological sort exists. The prefix ABCE has a profit of 1, which meets the criteria for a profitable topological sort.

This algorithm can be applied to any directed acyclic graph to determine if a profitable topological sort exists. However, it may not necessarily provide the most optimal topological sort, as it only considers the maximum profit up to each node rather than the overall profit of the entire graph. Therefore, further optimization may be required depending on the specific application of this problem.
 

What is a directed acyclic graph (DAG)?

A directed acyclic graph (DAG) is a type of graph that consists of vertices and directed edges, where the edges point from one vertex to another. It is called "acyclic" because there are no cycles or loops in the graph, meaning you cannot start at a vertex and follow the directed edges to end up back at the same vertex.

What is profit sorting in the context of a DAG?

Profit sorting in the context of a DAG refers to the process of organizing the vertices in the graph based on a certain profit or value associated with each vertex. This allows for efficient and optimized traversal of the DAG to find the path with the highest profit.

How is profit sorting used in real-world applications?

Directed acyclic graph profit sorting is commonly used in various fields such as finance, machine learning, and operations research. It is used to optimize decision-making processes, such as determining the most profitable investment portfolio, finding the shortest path for a delivery route, or selecting the best machine learning algorithm for a given dataset.

What are the benefits of using profit sorting in a DAG?

Using profit sorting in a DAG allows for more efficient and optimized traversal of the graph, reducing the time and resources needed to find the desired path or solution. It also helps in identifying the most profitable or valuable vertices in the graph, providing valuable insights for decision-making processes.

What are some common algorithms used for profit sorting in a DAG?

Some common algorithms used for profit sorting in a DAG include topological sorting, Dijkstra's algorithm, and Bellman-Ford algorithm. These algorithms use different approaches to traverse the DAG and determine the optimal path based on the profit associated with each vertex.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
19
Views
4K
  • Programming and Computer Science
Replies
15
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
1K
  • Linear and Abstract Algebra
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
6
Views
4K
Replies
1
Views
2K
Back
Top