Shallow say - check points constraints

First the way, this system is based on the basis of the shortest. (Especially SPFA )

Never learned the most shorted look

Single-source shortest path problem

Single-source shortest path = Single Source Shortest Path

I.e. there solving (or non-directed graph) in the drawing to the shortest distance between the point to the other point

Our method is known ...... Dijkstra algorithm

Egg eggs but there are limitations Dijkstra's algorithm! ! !

If the edge weight is negative , Dijkstra algorithm correct?

Solution (single-source shortest path) at the shortest distance from other points A to FIGS.

 

Algorithm steps:

  1. A marker
  2. Dist [C] = 2 smallest mark C,
  3. Dist [B] = 3 minimum, marker B

However, the end ShortestDist [C] = 1

The results of the wrong reasons

Dijkstra's flaw is that it can not handle negative cycles:

Dijkstra for the point labeled no longer be updated, so even if there are negative weights lead to changes in the shortest distance will not recalculate the results had been calculated

We need a new algorithm - Bellman-Ford

About Bellman-Ford I will not go into detail, details see Shortest

Bellman-Ford  further optimization - SPFA algorithm

Is generally considered to be the time complexity O (kE) where k is a constant larger,

Bad estimate, but should be seen SPFA algorithm efficiency is very high

Experience has shown that heap Dijkstra Algorithm faster than SPFA (Dijkstra use or do not use SPFA, some title cards often, card SPFA)

But SPFA faster than ordinary Dijkstra's algorithm.

The SPFA algorithm can deal with the problem of negative rights, but also than the code stack optimized Dijkstra algorithm to be easy to implement, and therefore SPFA is a good algorithm.

Differential restraint system (finally come to the question of)

What is the difference constraint?

Excerpt from Wikipedia

For example: selecting the maximum value of x3-x0

x1-x0<=2      (1)

x2-x0<=7      (2)

x3-x0<=8      (3)

x2-x1<=3      (4)

x3-x2<=2      (5)

Of course, the answer can be obtained by manually deriving x3-x0 <= 7

An inequality can be derived by superimposing x3-x0 <= 7, 7 which is the maximum, we can build a graph comprising four vertices, each xj-xi <= bk, i to j establish a directed edge , a weight of BK .

This figure is obtained by the shortest of x0 to x3 can know and 7, this is a coincidence?

FIG theory can not restraint system reason differential shortest path to solve, because xj-xi <= bk,

It will find the shortest similar triangle inequality d [v] <= d [ u] + w [u, v], i.e., D [V] -d [U] <W = [U, V] .

And obtaining a maximum value of the shortest path algorithm is similar to the process of the relaxation process .

 

Guess you like

Origin www.cnblogs.com/mzyczly/p/11312146.html
Recommended