Motorcycle speedway: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>HoldenV8
en>HoldenV8
 
Line 1: Line 1:
{{Redirect|Floyd's algorithm|cycle detection|Floyd's cycle-finding algorithm|computer graphics|Floyd–Steinberg dithering}}
Historically people, mainly women have had a tendency to believe which the second they begin to lift weights, or make progress in the weights they are lifting which they might become muscle-bound plus bulky. This couldn't be farther from the truth. In purchase to place on fat, whether it be muscle or fat, you require to take in more calories than what you're burning.<br><br>Real [http://safedietplans.com diets that work] when it comes to losing fat plus having an attractive figure include those espoused by experts including dietitians, doctors and nutritionists among others. In making preparations for charting a diet, elements like age, preference inside food, gender, function so forth are to be considered. The diets being planned for the chart may be varied for every meal. For instance, you are able to have some fruit because a snack while we can have some vegetables along with pasta for lunch, because these have low degrees of fat. The same is said for your breakfast and the dinner you'll be having. Foods like fruits plus greens are a fairly sustainable source of power. In time, you can develop a reduced liking to something like fast food.<br><br>These meals arrive because single servings thus you eat just the appropriate amount to stay inside the calorie count. All you must do is warm the meal inside the microwave plus enjoy. Along with removing temptation, diet plans additionally remove the difficulty associated with meal planning and buying whenever you go on a diet. Forget all the complicated stuff. Simply order the meals that appeal to you plus they will arrive at the door. If you don't wish To pick plus choose your meals you are able to even let the company choose the food for we so you have a balanced diet.<br><br>Here are two sample menus: Menu 1 Breakfast: Oatmeal, soy milk, one apple along with a cup of tea. Lunch: Green salad, tomato salad, grated carrots, and a glass of almond milk. The mid-afternoon snack is a strawberry and banana smoothie. Supper: Vegetable soup, vegetable couscous, plus kiwis for dessert.<br><br>There are a amount of popular diets which just never function alone. So, it happens to be important to join a gym to have a backup plan. Although a decrease inside total calories may aid we lose fat or slow the weight gain, exercise can help we burn calories plus heighten the fat reduction. Your ultimate goal must be to change your lifestyle thus that you consume less calories than you burn.<br><br>There are numerous different kinds of diet plan programs. The first is the fixed-menu program inside which they can provide we the list of the foods that you can eat. This is easy to follow still, there is a limited selection of foods to choose, and therefore there are bored by them. Nevertheless, should you are creative or using such a common meal plan, you are able to find various dishes online which may suit the taste.<br><br>One that has severe restrictions on what you can eat, or 1 that understands which you're human plus live in the real planet, plus consequently, enables we to cheat a little?
{{Infobox Algorithm
|class=[[All-pairs shortest path problem]] (for weighted graphs)
|image=
|caption =
|data=[[Graph (data structure)|Graph]]
|time=<math>O(|V|^3)</math>
|best-time=<math>\Omega (|V|^3)</math>
|space=<math>\Theta(|V|^2)</math>
}}
 
{{Tree search algorithm}}
In [[computer science]], the '''Floyd–Warshall algorithm''' (also known as '''Floyd's algorithm''', '''Roy–Warshall algorithm''', '''Roy–Floyd algorithm''', or the '''WFI algorithm''') is a [[graph (mathematics)|graph]] analysis [[algorithm]] for finding [[shortest path problem|shortest paths]] in a [[weighted graph]]  with positive or negative edge weights (but with no negative cycles, see below) and also for finding [[transitive closure]] of a relation <math>R</math>. A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between ''all'' pairs of vertices, though it does not return details of the paths themselves.
 
The Floyd-Warshall algorithm was published in its currently recognized form by [[Robert Floyd]] in 1962.  However, it is essentially the same as algorithms previously published by [[Bernard Roy]] in 1959 and also by [[Stephen Warshall]] in 1962 for finding the transitive closure of a graph.<ref>{{cite web | url = http://mathworld.wolfram.com/Floyd-WarshallAlgorithm.html | title = Floyd-Warshall Algorithm | work = [[Wolfram MathWorld]] | first = Eric | last = Weisstein | authorlink = Eric W. Weisstein | accessdate = 13 November 2009}}</ref> The modern formulation of Warshall's algorithm as three nested for-loops was first described by Peter Ingerman, also in 1962.
 
The algorithm is an example of [[dynamic programming]].
 
==Algorithm==
The Floyd–Warshall algorithm compares all possible paths through the graph between each pair of vertices.  It is able to do this with Θ(|''V''|<sup>3</sup>) comparisons in a graph.  This is remarkable considering that there may be up to Ω(|''V''|<sup>2</sup>) edges in the graph, and every combination of edges is tested. It does so by incrementally improving an estimate on the shortest path between two vertices, until the estimate is optimal.
 
Consider a graph ''G'' with vertices ''V'' numbered 1 through&nbsp;''N''. Further consider a function shortestPath(''i'',&nbsp;''j'',&nbsp;''k'') that returns the shortest possible path from ''i'' to ''j'' using vertices only from the set {1,2,...,''k''} as intermediate points along the way.  Now, given this function, our goal is to find the shortest path from each ''i'' to each ''j'' using only vertices 1 to&nbsp;''k''&nbsp;+&nbsp;1.
 
For each of these pairs of vertices, the true shortest path could be either (1) a path that only uses vertices in the set {1,&nbsp;...,&nbsp;''k''} or (2) a path that goes from ''i'' to ''k''&nbsp;+&nbsp;1 and then from ''k''&nbsp;+&nbsp;1 to ''j''.  We know that the best path from ''i'' to ''j'' that only uses vertices 1 through ''k'' is defined by shortestPath(''i'',&nbsp;''j'',&nbsp;''k''), and it is clear that if there were a better path from ''i'' to ''k''&nbsp;+&nbsp;1 to ''j'', then the length of this path would be the concatenation of the shortest path from ''i'' to ''k''&nbsp;+&nbsp;1 (using vertices in {1,&nbsp;...,&nbsp;''k''}) and the shortest path from ''k''&nbsp;+&nbsp;1 to ''j'' (also using vertices in&nbsp;{1,&nbsp;...,&nbsp;''k''}).
 
If <math>w(i, j)</math> is the weight of the edge between vertices ''i'' and ''j'', we can define shortestPath(''i'',&nbsp;''j'',&nbsp;''k'' + 1) in terms of the following [[Recursion|recursive]] formula: the base case is
: <math>\textrm{shortestPath}(i, j, 0) = w(i, j)</math>
and the recursive case is
: <math>\textrm{shortestPath}(i,j,k+1) = \min(\textrm{shortestPath}(i,j,k),\,\textrm{shortestPath}(i,k+1,k) + \textrm{shortestPath}(k+1,j,k))</math>
 
This formula is the heart of the Floyd–Warshall algorithm. The algorithm works by first computing shortestPath(''i'',&nbsp;''j'',&nbsp;''k'') for all (''i'',&nbsp;''j'') pairs for ''k''&nbsp;=&nbsp;1, then ''k''&nbsp;=&nbsp;2, etc.  This process continues until ''k''&nbsp;=&nbsp;''n'', and we have found the shortest path for all (''i'',&nbsp;''j'') pairs using any intermediate vertices. Pseudocode for this basic version follows:
 
1 '''let''' dist be a |V| × |V| array of minimum distances initialized to ∞ (infinity)
2 '''for each''' vertex ''v''
3    dist[''v''][''v''] &larr; 0
4 '''for each''' edge (''u'',''v'')
5    dist[''u''][''v''] &larr; w(''u'',''v'')  ''// the weight of the edge (''u'',''v'')
6 '''for''' ''k'' '''from''' 1 '''to''' |V|
7    '''for''' ''i'' '''from''' 1 '''to''' |V|
8      '''for''' ''j'' '''from''' 1 '''to''' |V|
9          '''if''' dist[''i''][''j''] > dist[''i''][''k''] + dist[''k''][''j'']
10            dist[''i''][''j''] &larr; dist[''i''][''k''] + dist[''k''][''j'']
11        '''end if'''
 
==Example==
The algorithm above is executed on the graph on the left below:
 
[[File:Floyd-Warshall example.svg|600px]]
 
Prior to the first iteration of the outer loop, labeled ''k''=0 above, the only known paths correspond to the single edges in the graph. At k=1, paths that go through the vertex 1 are found: in particular, the path 2→1→3 is found, replacing the path 2→3 which has fewer edges but is longer. At k=2, paths going through the vertices {1,2} are found. The red and blue boxes show how the path 4→2→1→3 is assembled from the two known paths 4→2 and 2→1→3 encountered in previous iterations, with 2 in the intersection. The path 4→2→3 is not considered, because 2→1→3 is the shortest path encountered so far from 2 to 3. At k=3, paths going through the vertices {1,2,3} are found. Finally, at k=4, all shortest paths are found.
 
==Behavior with negative cycles==
 
A negative cycle is a cycle whose edges sum to a negative value.  There is no shortest path between any pair of vertices i, j which form part of a negative cycle,  because path-lengths from i to j can be arbitrarily small (negative).  For numerically meaningful output, the Floyd–Warshall algorithm assumes that there are no negative cycles. Nevertheless, if there are negative cycles, the Floyd–Warshall algorithm can be used to detect them.  The intuition is as follows:
 
* The Floyd–Warshall algorithm iteratively revises path lengths between all pairs of vertices (''i'',&nbsp;''j''), including where ''i''&nbsp;=&nbsp;''j'';
* Initially, the length of the path (''i'',''i'') is zero;
* A path {(''i'',''k''), (''k'',''i'')} can only improve upon this if it has length less than zero, i.e. denotes a negative cycle;
* Thus, after the algorithm, (''i'',''i'') will be negative if there exists a negative-length path from ''i'' back to ''i''.
 
Hence, to detect negative [[Cycle (graph theory)|cycles]] using the Floyd–Warshall algorithm, one can inspect the diagonal of the path matrix, and the presence of a negative number indicates that the graph contains at least one negative cycle.<ref>{{cite web | url = http://www.ieor.berkeley.edu/~ieor266/Lecture12.pdf | title = Lecture 12: Shortest paths (continued) | work = Network Flows and Graphs | date = 7 October 2008 | format = [[PDF]] | publisher = Department of Industrial Engineering and Operations Research, [[University of California, Berkeley]]}}</ref> Obviously, in an undirected graph a negative edge creates a negative cycle <!-- "Cycle" might imply no repeated edges --> (i.e., a closed walk) involving its incident vertices.
 
==Path reconstruction==
 
The Floyd–Warshall algorithm typically only provides the lengths of the paths between all pairs of vertices. With simple modifications, it is possible to create a method to reconstruct the actual path between any two endpoint vertices. While one may be inclined to store the actual path from each vertex to each other vertex, this is not necessary, and in fact, is very costly in terms of memory. For each vertex, one need only store the information about the highest index intermediate vertex one must pass through if one wishes to arrive at any given vertex. Therefore, information to reconstruct all paths can be stored in a single |V| × |V| matrix ''next'' where next[''i''][''j''] represents the highest index vertex one must travel through if one intends to take the shortest path from ''i'' to ''j''.
 
To implement this, when a new shortest path is found between two vertices, the matrix containing the paths is updated. The ''next'' matrix is updated along with the matrix of minimum distances ''dist'', so at completion both tables are complete and accurate, and any entries which are infinite in the ''dist'' table will be null in the ''next'' table. The path from ''i'' to ''j'' is the path from ''i'' to next[''i''][''j''], followed by the path from next[''i''][''j''] to ''j''. These two shorter paths are determined recursively. This modified algorithm runs with the same time and space complexity as the unmodified algorithm.
 
'''let''' dist be a |V| × |V| array of minimum distances initialized to ∞ (infinity)
'''let''' next be a |V| × |V| array of vertex indices initialized to '''null'''
'''procedure''' ''FloydWarshallWithPathReconstruction'' ()
    '''for each''' vertex v
      dist[v][v] &larr; 0
    '''for each''' edge (u,v)
      dist[u][v] &larr; w(u,v)  ''// the weight of the edge (u,v)
    '''for''' k '''from''' 1 '''to''' |V|
      '''for''' i '''from''' 1 '''to''' |V|
          '''for''' j '''from''' 1 '''to''' |V|
            '''if''' dist[i][k] + dist[k][j] < dist[i][j] '''then'''
                dist[i][j] &larr; dist[i][k] + dist[k][j]
                next[i][j] &larr; k
'''function''' ''Path'' (i, j)
    '''if''' dist[i][j] = ∞ '''then'''
      '''return''' "no path"
    '''var''' intermediate &larr; next[i][j]
    '''if''' intermediate = '''null''' '''then'''
      '''return''' " "  ''// the direct edge from i to j gives the shortest path''
    '''else'''
      '''return''' Path(i, intermediate) + intermediate + Path(intermediate, j)
 
==Analysis==
Let ''n'' be |V|, the number of vertices. To find all ''n''<sup>2</sup> of shortestPath(''i'',''j'',''k'') (for all ''i'' and ''j'') from those of shortestPath(''i'',''j'',''k''−1) requires 2''n''<sup>2</sup> operations. Since we begin with shortestPath(''i'',''j'',0)&nbsp;=&nbsp;edgeCost(''i'',''j'') and compute the sequence of ''n'' matrices shortestPath(''i'',''j'',1), shortestPath(''i'',''j'',2), …, shortestPath(''i'',''j'',''n''), the total number of operations used is ''n'' · 2''n''<sup>2</sup>&nbsp;=&nbsp;2''n''<sup>3</sup>. Therefore, the [[Computational complexity theory|complexity]] of the algorithm is [[big theta|Θ(''n''<sup>3</sup>)]].
 
==Applications and generalizations==
The Floyd–Warshall algorithm can be used to solve the following problems, among others:
* Shortest paths in directed graphs (Floyd's algorithm).
* [[Transitive closure]] of directed graphs (Warshall's algorithm). In Warshall's original formulation of the algorithm, the graph is unweighted and represented by a Boolean adjacency matrix. Then the addition operation is replaced by [[logical conjunction]] (AND) and the minimum operation by [[logical disjunction]] (OR).
* Finding a [[regular expression]] denoting the [[regular language]] accepted by a [[finite automaton]] (Kleene's algorithm)
* [[invertible matrix|Inversion]] of [[real number|real]] [[matrix (mathematics)|matrices]] ([[Gauss&ndash;Jordan elimination|Gauss&ndash;Jordan algorithm]]) <ref>{{cite web | url = http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.71.7650 | title = Algebraic Structures for Transitive Closure | first = Rafael | last = Penaloza}}</ref>
* Optimal routing. In this application one is interested in finding the path with the maximum flow between two vertices. This means that, rather than taking minima as in the pseudocode above, one instead takes maxima. The edge weights represent fixed constraints on flow. Path weights represent bottlenecks; so the addition operation above is replaced by the minimum operation.
* Fast computation of [[Pathfinder network]]s.
* [[Widest path problem|Widest paths/Maximum bandwidth paths]]
 
==Implementations==
Implementations are available for many [[programming language]]s.
* For [[C++]], in the [http://www.boost.org/libs/graph/doc/ boost::graph] library
* For [[C Sharp (programming language)|C#]], at [http://www.codeplex.com/quickgraph QuickGraph]
* For [[Java (programming language)|Java]], in the [http://commons.apache.org/sandbox/commons-graph/ Apache Commons Graph] library
* For [[JavaScript]], at [http://www.turb0js.com/a/Floyd%E2%80%93Warshall_algorithm Turb0JS]
* For [[MATLAB]], in the [http://www.mathworks.com/matlabcentral/fileexchange/10922 Matlab_bgl] package
* For [[Perl]], in the [https://metacpan.org/module/Graph Graph] module
* For [[PHP]], on [http://www.microshell.com/programming/computing-degrees-of-separation-in-social-networking/2/ page] and [[PL/pgSQL]], on [http://www.microshell.com/programming/floyd-warshal-algorithm-in-postgresql-plpgsql/3/ page] at Microshell
* For [[Python (programming language)|Python]], in the [[NetworkX]] library
* For [[R programming language|R]], in package [http://cran.r-project.org/web/packages/e1071/index.html e1071]
* For [[Ruby (programming language)|Ruby]], in [https://github.com/chollier/ruby-floyd script]
 
==See also==
* [[Dijkstra's algorithm]], an algorithm for finding single-source shortest paths in a more restrictive class of inputs, graphs in which all edge weights are non-negative
* [[Johnson's algorithm]], an algorithm for solving the same problem as the Floyd–Warshall algorithm, all pairs shortest paths in graphs with some edge weights negative. Compared to the Floyd–Warshall algorithm, Johnson's algorithm is more efficient for [[sparse graph]]s.
 
==References==
{{Reflist}}
 
* {{Introduction to Algorithms|1}}
** Section 26.2, "The Floyd–Warshall algorithm", pp.&nbsp;558–565;
** Section 26.4, "A general framework for solving path problems in directed graphs", pp.&nbsp;570–576.
* {{cite journal | first = Robert W. | last = Floyd | authorlink = Robert W. Floyd | title = Algorithm 97: Shortest Path | journal = [[Communications of the ACM]] | volume = 5 | issue = 6 | page = 345 | date=  June 1962 | doi = 10.1145/367766.368168 }}
* {{cite journal | first = Peter Z. | last = Ingerman | title = Algorithm 141: Path Matrix | journal = {{Communications of the ACM}} | volume = 5 | number = 11 | page = 556 | date = November 1962 | doi = 10.1145/368996.369016 }}
* {{cite book | authorlink = Stephen Cole Kleene | first = S. C. | last = Kleene | chapter = Representation of events in nerve nets and finite automata | title = Automata Studies | editor = [[Claude Elwood Shannon|C. E. Shannon]] and [[John McCarthy (computer scientist)|J. McCarthy]] | pages = 3–42 | publisher = Princeton University Press | year=  1956 }}
* {{cite journal | first = Stephen | last = Warshall | title = A theorem on Boolean matrices | journal = [[Journal of the ACM]] | volume = 9 | issue = 1 | pages = 11–12 | date=  January 1962 | doi = 10.1145/321105.321107 }}
* {{cite book | author=Kenneth H. Rosen | title=Discrete Mathematics and Its Applications, 5th Edition | publisher = Addison Wesley | year=2003 | isbn=0-07-119881-4<!-- (ISE)--> | id= | ISBN status=May be invalid - please double check }}
* {{cite journal | first = Bernard | last = Roy | title = Transitivité et connexité. | journal = [[C. R. Acad. Sci. Paris]] | volume = 249 | pages = 216–218 | year=  1959 }}
 
==External links==
* [http://www.pms.informatik.uni-muenchen.de/lehre/compgeometry/Gosper/shortest_path/shortest_path.html#visualization Interactive animation of the Floyd–Warshall algorithm]
* [http://quickgraph.codeplex.com/ The Floyd–Warshall algorithm in C#, as part of QuickGraph]
* [http://students.ceid.upatras.gr/~papagel/english/java_docs/allmin.htm Visualization of Floyd's algorithm]
 
{{DEFAULTSORT:Floyd-Warshall algorithm}}
[[Category:Graph algorithms]]
[[Category:Routing algorithms]]
[[Category:Polynomial-time problems]]
[[Category:Articles with example pseudocode]]
[[Category:Dynamic programming]]

Latest revision as of 15:37, 8 December 2014

Historically people, mainly women have had a tendency to believe which the second they begin to lift weights, or make progress in the weights they are lifting which they might become muscle-bound plus bulky. This couldn't be farther from the truth. In purchase to place on fat, whether it be muscle or fat, you require to take in more calories than what you're burning.

Real diets that work when it comes to losing fat plus having an attractive figure include those espoused by experts including dietitians, doctors and nutritionists among others. In making preparations for charting a diet, elements like age, preference inside food, gender, function so forth are to be considered. The diets being planned for the chart may be varied for every meal. For instance, you are able to have some fruit because a snack while we can have some vegetables along with pasta for lunch, because these have low degrees of fat. The same is said for your breakfast and the dinner you'll be having. Foods like fruits plus greens are a fairly sustainable source of power. In time, you can develop a reduced liking to something like fast food.

These meals arrive because single servings thus you eat just the appropriate amount to stay inside the calorie count. All you must do is warm the meal inside the microwave plus enjoy. Along with removing temptation, diet plans additionally remove the difficulty associated with meal planning and buying whenever you go on a diet. Forget all the complicated stuff. Simply order the meals that appeal to you plus they will arrive at the door. If you don't wish To pick plus choose your meals you are able to even let the company choose the food for we so you have a balanced diet.

Here are two sample menus: Menu 1 Breakfast: Oatmeal, soy milk, one apple along with a cup of tea. Lunch: Green salad, tomato salad, grated carrots, and a glass of almond milk. The mid-afternoon snack is a strawberry and banana smoothie. Supper: Vegetable soup, vegetable couscous, plus kiwis for dessert.

There are a amount of popular diets which just never function alone. So, it happens to be important to join a gym to have a backup plan. Although a decrease inside total calories may aid we lose fat or slow the weight gain, exercise can help we burn calories plus heighten the fat reduction. Your ultimate goal must be to change your lifestyle thus that you consume less calories than you burn.

There are numerous different kinds of diet plan programs. The first is the fixed-menu program inside which they can provide we the list of the foods that you can eat. This is easy to follow still, there is a limited selection of foods to choose, and therefore there are bored by them. Nevertheless, should you are creative or using such a common meal plan, you are able to find various dishes online which may suit the taste.

One that has severe restrictions on what you can eat, or 1 that understands which you're human plus live in the real planet, plus consequently, enables we to cheat a little?