Like this document? Why not share!

4,334

-1

-1

Published on

e.r diagram on hspital management

No Downloads

Total Views

4,334

On Slideshare

0

From Embeds

0

Number of Embeds

0

Shares

0

Downloads

23

Comments

0

Likes

2

No embeds

No notes for slide

- 1. Capital expenditures (CAPEX or capex) are expenditures creating future benefits. A capital expenditure is incurred when a business spends money either to buy fixed assets or to add to the value of an existing fixed asset with a useful life that extends beyond the taxable year. Included in capital expenditures are amounts spent on: 1. acquiring fixed assets 2. fixing problems with an asset that existed prior to acquisition 3. preparing an asset to be used in business 4. legal costs of establishing or maintaining one's right of ownership in a piece of property 5. restoring property or adapting it to a new or different use 6. starting a new business For tax purposes, capital expenditures are costs that cannot be deducted in the year in which they are paid or incurred, and must be capitalized. An operating expense, operating expenditure, operational expense, operational expenditure or OPEX is an on-going cost for running a product, business, or systemFor example, the purchase of a photocopier is the CAPEX, and the annual paper and toner cost is the OPEXOn an income statement, quot;operating expensesquot; is the sum of a business's operating expenses for a period of time, such as a month or year.
- 2. Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1959, [1] is a graph search algorithm that solves the single- source shortest path problem for a graph with nonnegative edge path costs, producing a shortest path tree. This algorithm is often used in routing. For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First). Contents [hide] 1 Algorithm • 2 Description of the algorithm • 3 Pseudocode • 4 Running time • 5 Python implementation • 6 Related problems and algorithms • 7 See also • 8 Notes • 9 References • 10 External links • [edit] Algorithm
- 3. Let's call the node we are starting with an initial node. Let a distance of a node X be the distance from the initial node to it. Dijkstra's algorithm will assign some initial distance values and will try to improve them step-by-step. 1. Assign to every node a distance value. Set it to zero for our initial node and to infinity for all other nodes. 2. Mark all nodes as unvisited. Set initial node as current. 3. For current node, consider all its unvisited neighbours and calculate their distance (from the initial node). For example, if current node (A) has distance of 6, and an edge connecting it with another node (B) is 2, the distance to B through A will be 6+2=8. If this distance is less than the previously recorded distance (infinity in the beginning, zero for the initial node), overwrite the distance. 4. When we are done considering all neighbours of the current node, mark it as visited. A visited node will not be checked ever again; its distance recorded now is final and minimal. 5. Set the unvisited node with the smallest distance (from the initial node) as the next quot;current nodequot; and continue from step 3 [edit] Description of the algorithm Suppose you create a knotted web of strings, with each knot corresponding to a node, and the strings corresponding to the edges of the web: the length of each string is proportional to the weight of each edge. Now you compress the web into a small pile without making any knots or tangles in it. You then grab your starting knot and pull straight up. As new knots start to come up with the original, you can measure the straight up-down distance to these knots: this must be the shortest distance from the starting node to the destination node. The acts of quot;pulling upquot; and quot;measuringquot; must be abstracted for the computer, but the general idea of the algorithm is the same: you have two sets, one of knots that are on the table, and another of knots that are in the air. Every step of the algorithm, you take the closest knot from the table and pull it into the air, and mark it with its length. If any knots are left on the table when you're done, you mark them with the distance infinity. Or, using a street map, suppose you're marking over the streets (tracing the street with a marker) in a certain order, until you have a route marked in from the starting point to the destination. The order is conceptually simple: from all the street intersections of the already marked routes, find the closest unmarked intersection - closest to the starting point (the quot;greedyquot; part). It's the whole marked route to the intersection, plus the street to the new, unmarked intersection. Mark that street to that intersection, draw an arrow with the direction, then repeat. Never mark to any intersection twice. When you get to the destination, follow the arrows backwards. There will be only one path back against the arrows, the shortest one. [edit] Pseudocode
- 4. In the following algorithm, the code u := node in Q with smallest dist[], searches for the vertex u in the vertex set Q that has the least dist[u] value. That vertex is removed from the set Q and returned to the user. dist_between(u, v) calculates the length between the two neighbor-nodes u and v. alt on line 11 is the length of the path from the root node to the neighbor node v if it were to go through u. If this path is shorter than the current shortest path recorded for v, that current path is replaced with this alt path. The previous array is populated with a pointer to the quot;next-hopquot; node on the source graph to get the shortest route to the source. 1 function Dijkstra(Graph, source): 2 for each vertex v in Graph: // Initializations 3 dist[v] := infinity // Unknown distance function from source to v 4 previous[v] := undefined // Previous node in optimal path from source 5 dist[source] := 0 // Distance from source to source 6 Q := the set of all nodes in Graph // All nodes in the graph are unoptimized - thus are in Q 7 while Q is not empty: // The main loop 8 u := vertex in Q with smallest dist[] 9 remove u from Q 10 for each neighbor v of u: // where v has not yet been removed from Q. 11 alt := dist[u] + dist_between(u, v) // be careful in 1st step - dist[u] is infinity yet 12 if alt < dist[v] // Relax (u,v,a) 13 dist[v] := alt 14 previous[v] := u 15 return previous[] If we are only interested in a shortest path between vertices source and target, we can terminate the search at line 10 if u = target. Now we can read the shortest path from source to target by iteration: 1 S := empty sequence 2 u := target 3 while defined previous[u] 4 insert u at the beginning of S 5 u := previous[u] Now sequence S is the list of vertices constituting one of the shortest paths from target to source, or the empty sequence if no path exists. A more general problem would be to find all the shortest paths between source and target (there might be several different ones of the same length). Then instead of storing only a single node in each entry of previous[] we would store all nodes satisfying the relaxation condition. For example, if both r and source connect to target and both of them lie on different shortest paths through target (because the edge cost is the same in both cases), then we would add both r and source to previous[target]. When the algorithm completes, previous[] data structure will actually describe a graph that is a subset of the original graph
- 5. with some edges removed. Its key property will be that if the algorithm was run with some starting node, then every path from that node to any other node in the new graph will be the shortest path between those nodes in the original graph, and all paths of that length from the original graph will be present in the new graph. Then to actually find all these short paths between two given nodes we would use a path finding algorithm on the new graph, such as depth-first search. [edit] Running time An upper bound of the running time of Dijkstra's algorithm on a graph with edges E and vertices V can be expressed as a function of |E| and |V| using the Big-O notation. For any implementation of set Q the running time is O(|E|*decrease_key_in_Q + |V| *extract_minimum_in_Q), where decrease_key_in_Q and extract_minimum_in_Q are times needed to perform that operation in set Q. The simplest implementation of the Dijkstra's algorithm stores vertices of set Q in an ordinary linked list or array, and operation Extract-Min(Q) is simply a linear search through all vertices in Q. In this case, the running time is O(|V|2+|E|)=O(|V|2). For sparse graphs, that is, graphs with fewer than |V|2 edges, Dijkstra's algorithm can be implemented more efficiently by storing the graph in the form of adjacency lists and using a binary heap, pairing heap, or Fibonacci heap as a priority queue to implement the Extract- Min function efficiently. With a binary heap, the algorithm requires O((|E|+|V|) log |V|) time (which is dominated by O(|E| log |V|) assuming every vertex is connected, that is, |E| ≥ |V| - 1), and the Fibonacci heap improves this to O( | E | + | V | log | V | ). [edit] Python implementation import heapq from collections import defaultdict class Edge(object): def __init__(self, start, end, weight): self.start, self.end, self.weight = start, end, weight # For heapq. def __cmp__(self, other): return cmp(self.weight, other.weight) class Graph(object): def __init__(self): # The adjacency list. self.adj = defaultdict(list) def add_e(self, start, end, weight = 0): self.adj[start].append(Edge(start, end, weight)) def s_path(self, src): quot;quot;quot;
- 6. Returns the distance to every vertex from the source and the array representing, at index i, the node visited before visiting node i. This is in the form (dist, previous). quot;quot;quot; dist, visited, previous, queue = {src: 0}, {}, {}, [] heapq.heappush(queue, (dist[src],src)) while len(queue) > 0: distance, current = heapq.heappop(queue) if current in visited: continue visited[current] = True for edge in self.adj[current]: relaxed = dist[current] + edge.weight end = edge.end if end not in dist or relaxed < dist[end]: previous[end], dist[end] = current, relaxed heapq.heappush(queue, (dist[end],end)) return dist, previous For the example graph in the Applet by Carla Laffra of Pace University we do: g = Graph() g.add_e(1,2,4) g.add_e(1,4,1) g.add_e(2,1,74) g.add_e(2,3,2) g.add_e(2,5,12) g.add_e(3,2,12) g.add_e(3,10,12) g.add_e(3,6,74) g.add_e(4,7,22) g.add_e(4,5,32) g.add_e(5,8,33) g.add_e(5,4,66) g.add_e(5,6,76) g.add_e(6,10,21) g.add_e(6,9,11) g.add_e(7,3,12) g.add_e(7,8,10) g.add_e(8,7,2) g.add_e(8,9,72) g.add_e(9,10,7) g.add_e(9,6,31) g.add_e(9,8,18) g.add_e(10,6,8) # Find a shortest path from vertex 'a' (1) to 'j' (10). dist, prev = g.s_path(1) # Trace the path back using the prev array. path, current, end = [], 10, 10 while current in prev: path.insert(0, prev[current]) current = prev[current]
- 7. print path print dist[end] Output: [1, 2, 3] (namely a, b, c) 18 [edit] Related problems and algorithms The functionality of Dijkstra's original algorithm can be extended with a variety of modifications. For example, sometimes it is desirable to present solutions which are less than mathematically optimal. To obtain a ranked list of less-than-optimal solutions, the optimal solution is first calculated. A single edge appearing in the optimal solution is removed from the graph, and the optimum solution to this new graph is calculated. Each edge of the original solution is suppressed in turn and a new shortest-path calculated. The secondary solutions are then ranked and presented after the first optimal solution. Dijkstra's algorithm is usually the working principle behind link-state routing protocols, OSPF and IS-IS being the most common ones. Unlike Dijkstra's algorithm, the Bellman-Ford algorithm can be used on graphs with negative edge weights, as long as the graph contains no negative cycle reachable from the source vertex s. (The presence of such cycles means there is no shortest path, since the total weight becomes lower each time the cycle is traversed.) The A* algorithm is a generalization of Dijkstra's algorithm that cuts down on the size of the subgraph that must be explored, if additional information is available that provides a lower-bound on the quot;distancequot; to the target. The process that underlies Dijkstra's algorithm is similar to the greedy process used in Prim's algorithm. Prim's purpose is to find a minimum spanning tree for a graph. For the solution of nonconvex cost trees (typical for real-world costs exhibiting economies of scale) one solution allowing application of this algorithm is to successively divide the problem into convex subtrees (using bounding linear costs) and to pursue subsequent divisions using branch and bound methods. Such methods have been superseded by more efficient direct methods[citation needed].
- 8. Graph search algorithms Search A* • B* • Bellman-Ford • algorithm Best-first search • quot;Floyd's algorithmquot; redirects here. For Bidirectional search • cycle detection, see Floyd's cycle-finding algorithm. Breadth-first search • D* • In computer science, the Floyd–Warshall algorithm Depth-first search • Depth-limited (sometimes known as the WFI Algorithm or Roy–Floyd • search algorithm, since Bernard Roy described this algorithm in Dijkstra's algorithm • 1959) is a graph analysis algorithm for finding shortest paths Floyd–Warshall • in a weighted, directed graph. A single execution of the algorithm algorithm will find the shortest paths between all pairs of Hill climbing • vertices. The Floyd–Warshall algorithm is an example of Iterative deepening • dynamic programming. depth-first search Johnson's algorithm • Contents Uniform-cost • [hide] search 1 Algorithm • 2 Pseudocode • 3 Behaviour with negative cycles • 4 Analysis • 5 Applications and generalizations • 6 Implementations • 7 References • 8 See also • 9 External links • [edit] Algorithm The Floyd-Warshall algorithm compares all possible paths through the graph between each pair of vertices. It is able to do this with only V3 comparisons. This is remarkable considering that there may be up to V2 edges in the graph, and every combination of edges
- 9. is tested. It does so by incrementally improving an estimate on the shortest path between two vertices, until the estimate is known to be optimal. Consider a graph G with vertices V, each numbered 1 through N. Further consider a function shortestPath(i,j,k) that returns the shortest possible path from i to j using only vertices 1 through 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 nodes 1 through k + 1. There are two candidates for this path: either the true shortest path only uses nodes in the set (1...k); or there exists some path that goes from i to k + 1, then from k + 1 to j that is better. We know that the best path from i to j that only uses nodes 1 through k is defined by shortestPath(i,j,k), and it is clear that if there were a better path from i to k + 1 to j, then the length of this path would be the concatenation of the shortest path from i to k + 1 (using vertices in (1...k)) and the shortest path from k + 1 to j (also using vertices in (1...k)). Therefore, we can define shortestPath(i,j,k) in terms of the following recursive formula: This formula is the heart of Floyd Warshall. The algorithm works by first computing shortestPath(i,j,1) for all (i,j) pairs, then using that to find shortestPath(i,j,2) for all (i,j) pairs, etc. This process continues until k=n, and we have found the shortest path for all (i,j) pairs using any intermediate vertices. [edit] Pseudocode Conveniently, when calculating the kth case, one can overwrite the information saved from the computation of k − 1. This means the algorithm uses quadratic memory. Be careful to note the initialization conditions: 1 /* Assume a function edgeCost(i,j) which returns the cost of the edge from i to j 2 (infinity if there is none). 3 Also assume that n is the number of vertices and edgeCost(i,i)=0 4 */ 5 6 int path[][]; 7 /* A 2-dimensional matrix. At each step in the algorithm, path[i][j] is the shortest path 8 from i to j using intermediate vertices (1..k-1). Each path[i] [j] is initialized to 9 edgeCost(i,j) or infinity if there is no edge between i and j. 10 */ 11 12 procedure FloydWarshall () 13 for k: = 1 to n 14 for each (i,j) in {1,..,n}2 15 path[i][j] = min ( path[i][j], path[i][k]+path[k][j] ); [edit] Behaviour with negative cycles
- 10. For numerically meaningful output, Floyd-Warshall assumes that there are no negative cycles (in fact, between any pair of vertices which form part of a negative cycle, the shortest path is not well-defined because the path can be arbitrarily negative). Nevertheless, if there are negative cycles, Floyd–Warshall can be used to detect them. A negative cycle can be detected if the path matrix contains a negative number along the diagonal. If path[i] [i] is negative for some vertex i, then this vertex belongs to at least one negative cycle. Please help improve this section by expanding it. Further information might be found on the talk page. (June 2008) [edit] Analysis To find all n2 of from those of requires 2n2 bit operations. Since we begin with and compute the sequence of n zero-one matrices , , ..., , the total number of bit operations used is . Therefore, the complexity of the algorithm is Θ(n3) and can be solved by a deterministic machine in polynomial time. [edit] 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) Inversion of real matrices (Gauss-Jordan algorithm). • 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. Testing whether an undirected graph is bipartite. • Fast computation of Pathfinder Networks. • Maximum Bandwidth Paths in Flow Networks • [edit] Implementations A Perl implementation is available in the Graph module • A Javascript implementation is available at Alex Le's Blog • A Python implementation is available in the NetworkX package • A C implementation is available at ece.rice.edu •
- 11. A C++ implementation is available in the boost::graph library • A Java implementation is in the Apache commons graph library. • A Java implementation is on Algowiki • A C# implementation is in QuickGraph • A PHP implementation and PL/pgSQL implementation are available at Microshell. • [edit] References Cormen, Thomas H.; Leiserson, Charles E., Rivest, Ronald L. (1990). Introduction • to Algorithms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8. o Section 26.2, quot;The Floyd–Warshall algorithmquot;, pp. 558–565; o Section 26.4, quot;A general framework for solving path problems in directed graphsquot;, pp. 570–576. Floyd, Robert W. (June 1962). quot;Algorithm 97: Shortest Pathquot;. Communications of • the ACM 5 (6): 345. doi:10.1145/367766.368168. Kleene, S. C. (1956). quot;Representation of events in nerve nets and finite automataquot;. • in C. E. Shannon and J. McCarthy. Automata Studies. Princeton University Press. pp. 3–42. Warshall, Stephen (January 1962). quot;A theorem on Boolean matricesquot;. Journal of • the ACM 9 (1): 11–12. doi:10.1145/321105.321107. Kenneth H. Rosen (2003). Discrete Mathematics and Its Applications, 5th Edition. • Addison Wesley. ISBN 0-07-119881-4 (ISE). [edit] See also Robert Floyd • Stephen Warshall • Dijkstra's algorithm • Johnson's algorithm (in a sparse graph) • [edit] External links Analyze Floyd's algorithm in an online Javascript IDE • Interactive animation of Floyd–Warshall algorithm • Retrieved from quot;http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithmquot;
- 12. Dijkstra' s algorithm We now study path problems for graphs with edge weights, which we call costs. For convenience we also call a (slightly modied) weighted adjacency matrix of a graph (or digraph) simply a cost matrix. Although the shortest path problem seems much harder with edge-weights than without, Dijkstra has invented an algorithm that computes the shortest distances from a vertex s to all other vertices in time . This is only slightly slower than the time which is needed for our method maxDistances. We assume below that the `cost' between two vertices without an edge (arc) is some suciently large number (representing 1 in the cost matrix). algorithm Dijkstra (digraph , cost matrix , vertex ) 1 W = {s} and d[s] = 0 2 for each &#;` {s} do d[ ] = 3 while do find d[x] = min(d[y] | y W)
- 13. W=W 4 for all &#;` W do d[y] = min(d[y], d[x] + ) endwhile 5 return shortest distance vector d[ ] end The idea behind Dijkstra's algorithm is to start with a set of vertices W (initially ) reachable by some total cost C and all other vertices will require higher cost than C. We gradually increase the value of C until all vertices are reachable from the start vertex . The increment to C is calculated by taking the smallest cost edge between vertices of and vertices of V &#;` W. Line 4 in the algorithm updates these distances after a new vertex is added to W. The while loop on line 3 is repeated times. Thus, one can check that the total time of the algorithm is . A priority queue can be used to efficiently pick the next closest vertex x. Example 29. An application of Dijkstra's algorithm on the second digraph of Example 26 is given below for every starting vertex. This example illustrates that the distance vector is updated at most times (only before a new vertex is selected and added to Thus we could have omitted the lines with above.

No public clipboards found for this slide

Be the first to comment