# Path Tracing Algorithm Help

Page 1 of 1

## 1 Replies - 1329 Views - Last Post: 15 May 2013 - 08:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=321014&amp;s=f36ae33d82dc177f8498f08b47c66b4b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 blueguitar

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 14-May 13

# Path Tracing Algorithm Help

Posted 14 May 2013 - 12:53 AM

I have a graph with a int label and int cost associated with each edge. The graph is represented as an adjacency list. Given an int array, find a path through the graph that traces the values of the ints in the array while at the same time minimizing the cost acrued during the trace. That is, the first edge in the path should have a label that matches the array[0], and the second edge in the path should have a label that matches array[1], etc.... Any node may be the start. Parallel edges are allowed. An edge may be traversed more than once.

Specifically: what is the fastest algorithm to both trace the given path and minimize the cost of the path? How should the labels and costs be represented in the adjacency list?

Right now, I have basically a BFS, where the potential paths are kept in a priority list sorted by the total cost. Only edges that have labels that match the current index of the array (ie, the current path-label) are considered in the BFS. However, this seems rather slow as I'm optimizing for speed?

Is This A Good Question/Topic? 0

## Replies To: Path Tracing Algorithm Help

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12316
• Posts: 45,416
• Joined: 27-December 08

## Re: Path Tracing Algorithm Help

Posted 15 May 2013 - 08:07 PM

Take a look at Dijkstra's algorithm.
Was This Post Helpful? 2

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }