Monday, June 1, 2009

Open Brokerga Eaccount Hong Kong

Dijkstra's algorithm

Is a weighted graph G = (V, A), where V is the set of vertices, A the set of arcs and let L [i, j] its adjacency matrix. We calculate the shortest path between a vertex vi taken as origin and each remaining vertex vj in the graph.
The classic Dijkstra algorithm works in stages, where each of them is adding a vertex to the set D represents those vertices is known for its distance from the vertex origin. Initially the set D contains only the origin vertex.
is possible to raise the Dijkstra algorithm in terms of dynamic programming , and thus take advantage of the method design and the benefits this technology offers.
First, note that it is possible to apply the principle of optimal in this case: if the shortest path from vi to vj is a vertex v k as an intermediate, partial roads saw vk and vk to vj must be a minimum turn.
will call D (j) the vector containing the optimal path from the source vertex i = 1 to each vertex vj, 2 <=j <=n, siendo n el número de vértices. Inicialmente D contiene los arcos L(1,j), o bien ∞ si no existe el arco. A continuación, y para cada vértice vk del grafo con k <>  1, repeat:



Thus the algorithm that solves
problem can be implemented as follows:

CONST n = ..., (* number of vertices of the graph *)
TYPE MATRIX = ARRAY [1 .. n], [1 .. n] OF CARDINAL;
BRAND = ARRAY [1 .. n] OF BOOLEAN; (* elements already considered *)
SOLUTION = ARRAY [2 .. n] OF CARDINAL;
Dijkstra
PROCEDURE (VAR L: MATRIX; VAR D: SETTLEMENT )
var i, j, retail, pos, s: CARDINAL; S: BRAND;

BEGIN FOR i: = 2 TO n DO
S [i]: = FALSE;
D [i]: = L [1 , i]
END;
S [1]: = TRUE;
FOR i: = 2 TO n-1 DO
lower: = Menor (D, S, pos);
S [pos]: = TRUE;
FOR j: = 2 TO n DO NOT
IF (S [j]) THEN
D [j]: = Min2 (D [j], D [pos] + L [pos, j]) END
;
END;
Dijkstra
END END;

Minor Role is the calculated minimum
recurrence expression that defines the solution of the problem: Minor

PROCEDURE (VAR D: SETTLEMENT; VAR S: LABEL, VAR pos: CARDINAL)
: CARDINAL;
lower VAR i: CARDINAL ;
lower
BEGIN: = MAX (CARDINAL) pos: = 1;
FOR i: = 2 TO n DO NOT
IF (S [i]) THEN IF
D [i]
lower: = D [i ], pos: = i

END END END
;
less
RETURN END Minor

The time complexity of the algorithm is O (n2), where O (n) space complexity. No substantial gain in efficiency through the use of this technique with the greedy approach algorithm, yet we will win in simplicity of design and implementation of the solution from problem statement.

Seaside Sarong Recipe

El Camino salesman

distances are known from a number of cities. A traveler due from one of them, visiting each city exactly once and return to the starting point having the lowest total travel distance possible.
this problem is to find the path with less weight cycles of a weighted graph through all the vertices and return to the original vertex.


Solution First, we propose the solution of the problem as a series of decisions to verify the principle of optimal. The idea will be to build a search solution by successive minimum runs of size 1, 2, 3, etc.
Representing the problem through a graph G = (V, A), and L is its adjacency matrix, each traveler's journey from vertex v1 is formed by an arc (v1, vk) for some vertex vk belongs to V-{v1} and a path from v1 to vertex vk.
But if the trip is also great to be optimal the path of the vertex v1 vk, as if it were not arrive at a contradiction. If it were not there a better way and including it in the original route would get a better way than the optimum, which is impossible. Thus, it meets the principle of optimal .
then consider recurrence relationship. To this end, we call D (vi, S) to the minimum path length from vertex vi passes through all vertices of set S and returns to the vertex vi. The solution to the traveling salesman problem is given then by D (v1, v1-{V}):



Generalizing to start the tour from any vertex:


Note the difference between the strategy of this algorithm and we try to design the following two techniques greedy (see chapter 4.4 of the previous problem.) In the greedy algorithm has to choose one of the possible options at each step, once taken, or discarded, "and not be seen ever again. Are algorithms which have no "history", and therefore does not always work. However, the dynamic programming solution to the overall problem is constructed in another way: from the optimal solutions for smaller problems.
However, the design here has made a serious drawback: its implementation using a data structure that allows reuse
calculations. This structure should contain the intermediate solutions necessary for the computation of D (v1, v1-{V}), but these are too.
In fact, the table must have n rows and 2n columns, as this is the cardinal part of the set V, which are all possibilities that can take the second parameter of D in its definition.
So yes there is a solution to the traveling salesman problem using dynamic programming, but not only fails to improve the efficiency of the classic version by Turning Back (see next chapter), but also offers an improvement in terms of simplicity implementation.

More information