VII. Applications: sciences, economics and optimization
52. Graphs, networks and logistics
Problems on graphs and networks are on the home screen in the "Applications" section, field Logistics and networks: the shortest path (Dijkstra's, Bellman–Ford and Floyd–Warshall algorithms), the minimum spanning tree (Kruskal, Prim), the maximum flow and minimum cut, currency arbitrage as a search for a negative cycle and a project's critical path (CPM, PERT).
You enter the graph in a multi-line field, one edge per line – A-B 4 is an undirected edge of weight 4, A->B 4 a directed one, for a flow A->B 3/7 a given flow and capacity; without a number an edge has weight 1. Instead of the edges you can paste a matrix of weights row by row (-, ∞ or 0 means no edge), optionally with a line of the node names above it. Nodes can be named by a letter or a word (PHA, Boston). A project's activities are given by their name, duration and predecessors (D 5 B C), for PERT with three estimates (B 3/4/11 A).
For an arbitrage you can choose today's rate table of the ČNB or the ECB instead of your own rates – just list the currencies (CZK EUR USD GBP). With one table an arbitrage never comes out (the steps show why); with both tables at once each pair of currencies takes the better rate and a cycle above 1 can come out. The “Fill in the rates to edit” button puts one table's rates into the Exchange rates field – edit them, for example, by an exchange office's buying and selling rates.
The steps show a table of the iterations as in textbooks – Dijkstra's permanent and temporary labels, the Bellman–Ford passes, the Floyd–Warshall matrix after each node, Kruskal's sorted edges, the augmenting paths of a flow, the CPM forward and backward pass. Below the result is the graph, which you go through step by step with the arrows: red is the step's change, blue what is already decided, green the result.
Examples
shortestpath(A-B 4; A-C 2; B-C 1; B-D 5; C-D 8; C-E 10; D-E 2; D-F 6; E-F 2; from=A; to=F; method=dijkstra)


shortestpath(S->A 4; S->B 5; B->A -2; A->C 3; C->D 2; B->D 6; from=S; to=D; method=bellmanford)


shortestpath(A->B 3; B->C -1; A->C 4; C->A 2; C->D 2; D->B 1; method=floyd)


spanningtree(A-B 7; A-D 5; B-C 8; B-D 9; B-E 7; C-E 5; D-E 15; D-F 6; E-F 8; E-G 9; F-G 11; method=kruskal)


spanningtree(PHA-PLZ 93; PHA-LBC 110; PHA-HK 115; PHA-JI 128; PHA-BRN 205; LBC-HK 100; HK-OL 140; JI-BRN 88; BRN-OL 78; OL-OVA 100; BRN-OVA 170; PLZ-JI 210; start=PHA; method=prim)


maxflow(S->A 16; S->B 13; B->A 4; A->C 12; C->B 9; B->D 14; D->C 7; C->T 20; D->T 4; from=S; to=T)


arbitrage(USD->EUR 0.9; EUR->GBP 0.8; GBP->USD 1.4; EUR->USD 1.1; GBP->EUR 1.24; USD->GBP 0.7)


arbitrage(CZK EUR USD; 1 0.04 0.0432; 25 1 1.08; 23.148148 0.925926 1)


arbitrage(source=cnb; CZK EUR USD GBP)


arbitrage(source=cnb+ecb; CZK EUR USD GBP CHF)


cpm(A 3; B 4 A; C 2 A; D 5 B C; E 3 C; F 2 D E)


cpm(A 2/3/4; B 3/4/11 A; C 1/2/3 A; D 4/5/6 B C; T=15)


Known limitations
- A graph may have at most 30 nodes and 200 edges; the Floyd–Warshall matrices node by node are shown up to 6 nodes, for larger graphs only the final matrix.
- The arbitrage search finds one profitable cycle (not necessarily the most profitable one); differences below 0.0001 % count as rounding of the rates.
- The ČNB and the ECB publish only mid (reference) rates, which nobody trades at; the “gain” from both tables at once is in hundredths of a percent and can't be had in practice.
- With both tables only the currencies both banks publish (neither publishes the Russian rouble).
- Vehicle routing, the knapsack problem, inventory and queues are coming; linear programming, transportation and assignment have a chapter of their own.