c++ - Finding edge in weighted graph -


I have a graph with four nodes, each node represents a position and they are like two dimensional grids is kept. Each node has connections (one edge) for everyone (according to the condition) adjacent nodes. There is also the weight of each edge.

Nodes are represented by the weight of A, B, C, D and edges, which are represented by numbers:

  A 100 B 120 220 C 150 D  

I want to create a container and an algorithm that shares the nodes with the highest weight. Then reset the weight of that edge, for example, the above processing, the highest load is on the side of the beady, so we switch them on, the node (position) can be switched more than once. Since any node can be switched more than once, so all the edges involved in either B or D are reset. <120> <120> The weight is only on the edge, switching can give us the final layout: C, D, A, B.

I am currently running a terrible implementation of this. I store a long list of edges, which are connected to the nodes (potential), keep a value for its weight and four values ​​for the position of the node. Every time anything is requested, through the entire list I loop.

I am writing this in C ++, can some parts of STL increase this speed? Also, how to avoid duplication of data? The position of a node is currently in five objects, it is the node and it is a sign of connection to its four nodes.

In short, I want help from:

  • Can it be structured in a way so that there is no duplication of data?
  • Identify the problem? If there is a name for any of these, then let me know that I can do Google for more information on this topic.
  • Fast algorithms are always good.

For names, this is a top armor problem Optimal top bracket NP-hard refine The approximation is with the solution, but your problem is simple. You are looking at a pseudo-maximization under the hard edge selection criteria. Specifically, after selecting one edge, each connecting edge is removed (white paper can be swapped, representing the removal).

For example, here is a standard greedy approach:

0) Sort the edges; Keep proximity information - while staying in the edges: 1) Select the highest edge. 2) Remove all adjacent edges from the list
above.

The edges of the edges The list selected gives you the meridian to swap. The complexity of time is o (sorting of the serus + linear pass in the corner), which will normally boil o (sorting corner), which o (v * log (v))

The method of keeping the attachment information depends on the graph properties; Feel free to start with your adjacent matrix for simplicity to see your friendly local algorithms text.

Along with the imminent information, most other speed improvements will best apply to the graph of a specific size, but come with time along with the complexity of time.

For example, the statement of your problem indicates that the vertical ones are kept in a square pattern, so that we can get many interesting properties. For example, that system is very easily parallelly. In addition, the proximate information should be highly regular, but most of the sparse graphs on large sizes (most of the meridians are not connected to each other). This gives the proximity matrix a higher upper part; Instead, you can store the impulse in an array of 4-topless instead, because it will maintain fast access, but will almost completely eliminate the overhead.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -