Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scheduling algorithm - only first visit paid

I need to know whether the following problem has been studied before:

Let's have a directed acyclic graph G. The graph is connected, it has exactly one source vertex (no incomming nodes) and exactly one sink vertex (no outgoing nodes).

Each vertex has been assigned a nonnegative price in dollars and also a color.

The goal is to find a walk from the start to the sink which maximizes the sum of prices of visited edges.

The catch is, that the price is received only when a vertex of particular color is visited for the first time. For example when we wisit red vertex with price $1, then blue one with $2 and then red with $30 the total price is $3.

The approximate size of my particular problem: 50000 vertices, 3000 colors, typical walk length from start to sink about 200 edges.

             ------>[B red $1]---                   ---->[E red $1]----
            /                    \                 /                   \
[A black $0]                      ==>[D black $0]==                     ==>[G black $0]
            \                    /                 \                   /
             ---->[C green $2]---                   ->[F green $1000]--
like image 677
danatel Avatar asked Nov 05 '22 09:11

danatel


1 Answers

This is a nice variant of the shortest path problem that considers dynamic graphs, i.e. graphs that change over time (as you get farther from the source, edge weights change). Dijkstra's algorithm will solve it since the weights of edges are calculated as you go, so the fact that edge weights are different based on where you've been doesn't matter. Here's wikipedia's description with considerations for the the color variation problem in bold:

Let the node at which we are starting be called the initial node. Let the distance of node Y be the distance from the initial node to Y. Dijkstra's algorithm will assign some initial distance values and will try to improve them step by step.

  1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes.

  2. Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited nodes called the unvisited set consisting of all the nodes except the initial node.

  3. For the current node, consider all of its unvisited neighbors and calculate their tentative distances. This now depends upon the chosen path up to this point. For example, if the current node A is marked with a distance of 6, and the edge connecting it with a neighbor B has length 2 based on the colored weight, then the distance to B through the path so far will be 6+2=8. If this distance is less than the previously recorded distance, then overwrite that distance. Even though a neighbor has been examined, it is not marked as visited at this time, and it remains in the unvisited set.

  4. When we are done considering all of the neighbors of the current node, mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again; its distance recorded now is final and minimal.

  5. If the destination node has been marked visited, then stop. The algorithm has finished.

  6. Set the unvisited node marked with the smallest tentative distance as the next "current node" and go back to step 3.

Nannicini and Liberti have a nice survey on Shortest paths on dynamic graphs.

like image 197
PengOne Avatar answered Nov 09 '22 16:11

PengOne