{"algorithm":"bellman-ford","about":["Bellman-Ford starts like Dijkstra, with 0 at the start and infinity everywhere else, but it doesn't take vertices in order of distance. It goes through every edge, and when an edge gives its end a shorter distance, it lowers that distance. It repeats this pass one time fewer than there are vertices. A shortest path that doesn't repeat a vertex has at most that many edges, so after the last pass every distance is final.","Then it makes one more pass. If an edge can still shorten a distance, the start can reach a cycle whose weights add up to less than zero. Such a graph has no shortest path, since each trip around the cycle makes the path shorter, and path.BellmanFordPaths returns ErrNegativeWeightCycle. It needs a directed, weighted graph and costs O(V·E). path.NegativeCycle then returns one such cycle. It searches the whole graph rather than what one start reaches, so on a graph with more than one it can return a cycle other than the one the start runs into.","When there is no negative cycle, Distance and PathTo on the result give each distance and the route there, start first, and report false for a vertex out of reach. Of two routes that are equally short, PathTo returns the one with the fewest edges.","Use it when some weights are negative, such as refunds, rewards or the negative logarithms of exchange rates, where a negative cycle is a chance for arbitrage. When no weight is negative, Dijkstra gives the same distances faster."],"template":{"id":"fx-arbitrage","name":"Arbitrage loop","description":"Eight currencies, where the quotes between GBP and JPY lag behind the others. Each edge is a trade, and its weight is minus the natural log of the exchange rate. Trading USD for GBP, GBP for JPY and JPY back to USD ends with about 0.2% more dollars than it started with, so that loop has a negative total weight. The rates are illustrative and close to market rates.","family":"currency","directed":true,"weighted":true,"acyclic":false,"vertices":[{"id":"AUD","x":674,"y":604},{"id":"CAD","x":110,"y":414},{"id":"CHF","x":187,"y":177},{"id":"EUR","x":500,"y":72},{"id":"GBP","x":813,"y":177},{"id":"JPY","x":890,"y":414},{"id":"NZD","x":326,"y":604},{"id":"USD","x":500,"y":352}],"edges":[{"from":"AUD","to":"USD","weight":0.41701657},{"from":"AUD","to":"JPY","weight":-4.592115341},{"from":"AUD","to":"NZD","weight":-0.093308177},{"from":"CAD","to":"USD","weight":0.319819664},{"from":"CAD","to":"CHF","weight":0.481331549},{"from":"CHF","to":"USD","weight":-0.156490797},{"from":"CHF","to":"EUR","weight":-0.065225785},{"from":"CHF","to":"CAD","weight":-0.473310655},{"from":"EUR","to":"USD","weight":-0.094309679},{"from":"EUR","to":"CHF","weight":0.069210752},{"from":"GBP","to":"USD","weight":-0.260901657},{"from":"GBP","to":"JPY","weight":-5.277451174},{"from":"JPY","to":"USD","weight":5.011635794},{"from":"JPY","to":"GBP","weight":5.285480118},{"from":"JPY","to":"AUD","weight":4.598095272},{"from":"NZD","to":"USD","weight":0.513328754},{"from":"NZD","to":"AUD","weight":0.097315188},{"from":"USD","to":"EUR","weight":0.096312682},{"from":"USD","to":"GBP","weight":0.263861385},{"from":"USD","to":"JPY","weight":-5.009634794},{"from":"USD","to":"CHF","weight":0.168537002},{"from":"USD","to":"CAD","weight":-0.309834877},{"from":"USD","to":"AUD","weight":-0.414028339},{"from":"USD","to":"NZD","weight":-0.508322494}],"details":{"vertices":8,"edges":24,"directed":true,"weighted":true,"acyclic":false,"weightMin":-5.277451174,"weightMax":5.285480118,"negativeWeights":true,"density":0.42857142857142855,"inDegree":{"min":2,"avg":3,"max":7},"outDegree":{"min":2,"avg":3,"max":7},"selfLoops":0,"components":1}},"problem":"How much of each currency can a dollar buy at the best rate, and is there a loop of trades that ends with more dollars than it started with?","params":{"start":"USD"},"result":{"kind":"error","name":"path.ErrNegativeWeightCycle","message":"graph contains negative weight cycle","cycle":["GBP","JPY","USD"]},"answer":"There is no best rate. USD can reach a loop of trades that ends with more than it started with, so path.BellmanFordPaths returns path.ErrNegativeWeightCycle. path.NegativeCycle finds the loop GBP, JPY, USD, GBP, which turns 1 GBP into 1.002 GBP.","legend":{"vertex":[{"id":"idle","label":"Not reached","color":"#64748B","shape":"hollow"},{"id":"waiting","label":"Changed in this pass","color":"#E69F00","shape":"dashed-square"},{"id":"current","label":"Latest change","color":"#56B4E9","shape":"ring"},{"id":"done","label":"Reached","color":"#009E73","shape":"filled"}],"edge":[{"id":"idle","label":"Edge","color":"#475569","shape":"line"},{"id":"tree","label":"Best way in so far","color":"#009E73","shape":"thick"},{"id":"error","label":"Negative cycle","color":"#D55E00","shape":"dashed"}],"panels":[{"id":"dist","title":"Distances","kind":"table"},{"id":"changed","title":"Changed in this pass","kind":"list"}]},"steps":[{"say":"Every distance starts at ∞, except USD, which is 0. Bellman-Ford checks all 24 edges in each of 7 passes, one fewer than the 8 vertices, then once more to look for a negative cycle.","ops":[{"v":"USD","state":"done"},{"panel":"dist","set":{"AUD":"∞"}},{"panel":"dist","set":{"CAD":"∞"}},{"panel":"dist","set":{"CHF":"∞"}},{"panel":"dist","set":{"EUR":"∞"}},{"panel":"dist","set":{"GBP":"∞"}},{"panel":"dist","set":{"JPY":"∞"}},{"panel":"dist","set":{"NZD":"∞"}},{"panel":"dist","set":{"USD":"0"}}]},{"say":"Pass 1. USD to EUR at 0.90818: 0 + 0.0963 = 0.0963, so EUR's distance becomes 0.0963: 1 USD buys 0.90818 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0963"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"}]}]},{"say":"Pass 1. USD to GBP at 0.76808: 0 + 0.2639 = 0.2639, so GBP's distance becomes 0.2639: 1 USD buys 0.76808 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.2639"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 1. USD to JPY at 149.85: 0 - 5.0096 = -5.0096, so JPY's distance becomes -5.0096: 1 USD buys 149.85 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["USD","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0096"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"},{"key":"JPY","note":"-5.0096"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 1. USD to CHF at 0.8449: 0 + 0.1685 = 0.1685, so CHF's distance becomes 0.1685: 1 USD buys 0.8449 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["USD","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1685"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"},{"key":"JPY","note":"-5.0096"},{"key":"CHF","note":"0.1685"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 1. USD to CAD at 1.3632: 0 - 0.3098 = -0.3098, so CAD's distance becomes -0.3098: 1 USD buys 1.3632 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3098"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"},{"key":"JPY","note":"-5.0096"},{"key":"CHF","note":"0.1685"},{"key":"CAD","note":"-0.3098"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 1. USD to AUD at 1.5129: 0 - 0.414 = -0.414, so AUD's distance becomes -0.414: 1 USD buys 1.5129 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.414"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"},{"key":"JPY","note":"-5.0096"},{"key":"CHF","note":"0.1685"},{"key":"CAD","note":"-0.3098"},{"key":"AUD","note":"-0.414"}]},{"v":"CAD","state":"waiting"}]},{"say":"Pass 1. USD to NZD at 1.6625: 0 - 0.5083 = -0.5083, so NZD's distance becomes -0.5083: 1 USD buys 1.6625 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5083"}},{"panel":"changed","list":[{"key":"EUR","note":"0.0963"},{"key":"GBP","note":"0.2639"},{"key":"JPY","note":"-5.0096"},{"key":"CHF","note":"0.1685"},{"key":"CAD","note":"-0.3098"},{"key":"AUD","note":"-0.414"},{"key":"NZD","note":"-0.5083"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 1 done. 7 distances changed.","ops":[{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"JPY","state":"done"},{"v":"CHF","state":"done"},{"v":"CAD","state":"done"},{"v":"AUD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 2. EUR to CHF at 0.93313: 0.0963 + 0.0692 = 0.1655, shorter than 0.1685, so CHF's distance becomes 0.1655: 1 USD buys 0.84745 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1655"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"}]},{"e":["USD","CHF"],"state":"idle"}]},{"say":"Pass 2. GBP to JPY at 195.87: 0.2639 - 5.2775 = -5.0136, shorter than -5.0096, so JPY's distance becomes -5.0136: 1 USD buys 150.44 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0136"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"}]},{"e":["USD","JPY"],"state":"idle"},{"v":"CHF","state":"waiting"}]},{"say":"Pass 2. JPY to USD at 0.00666: -5.0136 + 5.0116 = -0.002, shorter than 0, so USD's distance becomes -0.002: 1 USD buys 1.002 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.002"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 2. JPY to AUD at 0.010071: -5.0136 + 4.5981 = -0.4155, shorter than -0.414, so AUD's distance becomes -0.4155: 1 USD buys 1.5151 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4155"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.4155"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 2. USD to EUR at 0.90818: -0.002 + 0.0963 = 0.0944, shorter than 0.0963, so EUR's distance becomes 0.0944: 1 USD buys 0.90996 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0944"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.4155"},{"key":"EUR","note":"0.0944"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 2. USD to GBP at 0.76808: -0.002 + 0.2639 = 0.2619, shorter than 0.2639, so GBP's distance becomes 0.2619: 1 USD buys 0.76958 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.2619"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.4155"},{"key":"EUR","note":"0.0944"},{"key":"GBP","note":"0.2619"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 2. USD to CAD at 1.3632: -0.002 - 0.3098 = -0.3118, shorter than -0.3098, so CAD's distance becomes -0.3118: 1 USD buys 1.3659 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3118"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.4155"},{"key":"EUR","note":"0.0944"},{"key":"GBP","note":"0.2619"},{"key":"CAD","note":"-0.3118"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 2. USD to AUD at 1.5129: -0.002 - 0.414 = -0.416, shorter than -0.4155, so AUD's distance becomes -0.416: 1 USD buys 1.5159 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.416"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.416"},{"key":"EUR","note":"0.0944"},{"key":"GBP","note":"0.2619"},{"key":"CAD","note":"-0.3118"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 2. USD to NZD at 1.6625: -0.002 - 0.5083 = -0.5103, shorter than -0.5083, so NZD's distance becomes -0.5103: 1 USD buys 1.6658 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5103"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1655"},{"key":"JPY","note":"-5.0136"},{"key":"USD","note":"-0.002"},{"key":"AUD","note":"-0.416"},{"key":"EUR","note":"0.0944"},{"key":"GBP","note":"0.2619"},{"key":"CAD","note":"-0.3118"},{"key":"NZD","note":"-0.5103"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 2 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 3. EUR to CHF at 0.93313: 0.0944 + 0.0692 = 0.1636, shorter than 0.1655, so CHF's distance becomes 0.1636: 1 USD buys 0.84911 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1636"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"}]}]},{"say":"Pass 3. GBP to JPY at 195.87: 0.2619 - 5.2775 = -5.0155, shorter than -5.0136, so JPY's distance becomes -5.0155: 1 USD buys 150.74 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0155"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 3. JPY to USD at 0.00666: -5.0155 + 5.0116 = -0.0039, shorter than -0.002, so USD's distance becomes -0.0039: 1 USD buys 1.0039 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.0039"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 3. JPY to AUD at 0.010071: -5.0155 + 4.5981 = -0.4174, shorter than -0.416, so AUD's distance becomes -0.4174: 1 USD buys 1.5181 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4174"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4174"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 3. USD to EUR at 0.90818: -0.0039 + 0.0963 = 0.0924, shorter than 0.0944, so EUR's distance becomes 0.0924: 1 USD buys 0.91174 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0924"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4174"},{"key":"EUR","note":"0.0924"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 3. USD to GBP at 0.76808: -0.0039 + 0.2639 = 0.26, shorter than 0.2619, so GBP's distance becomes 0.26: 1 USD buys 0.77109 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.26"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4174"},{"key":"EUR","note":"0.0924"},{"key":"GBP","note":"0.26"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 3. USD to CAD at 1.3632: -0.0039 - 0.3098 = -0.3137, shorter than -0.3118, so CAD's distance becomes -0.3137: 1 USD buys 1.3685 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3137"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4174"},{"key":"EUR","note":"0.0924"},{"key":"GBP","note":"0.26"},{"key":"CAD","note":"-0.3137"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 3. USD to AUD at 1.5129: -0.0039 - 0.414 = -0.4179, shorter than -0.4174, so AUD's distance becomes -0.4179: 1 USD buys 1.5188 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4179"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4179"},{"key":"EUR","note":"0.0924"},{"key":"GBP","note":"0.26"},{"key":"CAD","note":"-0.3137"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 3. USD to NZD at 1.6625: -0.0039 - 0.5083 = -0.5122, shorter than -0.5103, so NZD's distance becomes -0.5122: 1 USD buys 1.669 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5122"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1636"},{"key":"JPY","note":"-5.0155"},{"key":"USD","note":"-0.0039"},{"key":"AUD","note":"-0.4179"},{"key":"EUR","note":"0.0924"},{"key":"GBP","note":"0.26"},{"key":"CAD","note":"-0.3137"},{"key":"NZD","note":"-0.5122"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 3 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 4. EUR to CHF at 0.93313: 0.0924 + 0.0692 = 0.1616, shorter than 0.1636, so CHF's distance becomes 0.1616: 1 USD buys 0.85077 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1616"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"}]}]},{"say":"Pass 4. GBP to JPY at 195.87: 0.26 - 5.2775 = -5.0175, shorter than -5.0155, so JPY's distance becomes -5.0175: 1 USD buys 151.03 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0175"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 4. JPY to USD at 0.00666: -5.0175 + 5.0116 = -0.0059, shorter than -0.0039, so USD's distance becomes -0.0059: 1 USD buys 1.0059 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.0059"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 4. JPY to AUD at 0.010071: -5.0175 + 4.5981 = -0.4194, shorter than -0.4179, so AUD's distance becomes -0.4194: 1 USD buys 1.5211 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4194"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4194"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 4. USD to EUR at 0.90818: -0.0059 + 0.0963 = 0.0905, shorter than 0.0924, so EUR's distance becomes 0.0905: 1 USD buys 0.91352 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0905"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4194"},{"key":"EUR","note":"0.0905"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 4. USD to GBP at 0.76808: -0.0059 + 0.2639 = 0.258, shorter than 0.26, so GBP's distance becomes 0.258: 1 USD buys 0.7726 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.258"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4194"},{"key":"EUR","note":"0.0905"},{"key":"GBP","note":"0.258"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 4. USD to CAD at 1.3632: -0.0059 - 0.3098 = -0.3157, shorter than -0.3137, so CAD's distance becomes -0.3157: 1 USD buys 1.3712 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3157"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4194"},{"key":"EUR","note":"0.0905"},{"key":"GBP","note":"0.258"},{"key":"CAD","note":"-0.3157"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 4. USD to AUD at 1.5129: -0.0059 - 0.414 = -0.4199, shorter than -0.4194, so AUD's distance becomes -0.4199: 1 USD buys 1.5218 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4199"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4199"},{"key":"EUR","note":"0.0905"},{"key":"GBP","note":"0.258"},{"key":"CAD","note":"-0.3157"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 4. USD to NZD at 1.6625: -0.0059 - 0.5083 = -0.5142, shorter than -0.5122, so NZD's distance becomes -0.5142: 1 USD buys 1.6723 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5142"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1616"},{"key":"JPY","note":"-5.0175"},{"key":"USD","note":"-0.0059"},{"key":"AUD","note":"-0.4199"},{"key":"EUR","note":"0.0905"},{"key":"GBP","note":"0.258"},{"key":"CAD","note":"-0.3157"},{"key":"NZD","note":"-0.5142"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 4 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 5. EUR to CHF at 0.93313: 0.0905 + 0.0692 = 0.1597, shorter than 0.1616, so CHF's distance becomes 0.1597: 1 USD buys 0.85243 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1597"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"}]}]},{"say":"Pass 5. GBP to JPY at 195.87: 0.258 - 5.2775 = -5.0195, shorter than -5.0175, so JPY's distance becomes -5.0195: 1 USD buys 151.33 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0195"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 5. JPY to USD at 0.00666: -5.0195 + 5.0116 = -0.0078, shorter than -0.0059, so USD's distance becomes -0.0078: 1 USD buys 1.0078 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.0078"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 5. JPY to AUD at 0.010071: -5.0195 + 4.5981 = -0.4214, shorter than -0.4199, so AUD's distance becomes -0.4214: 1 USD buys 1.524 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4214"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4214"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 5. USD to EUR at 0.90818: -0.0078 + 0.0963 = 0.0885, shorter than 0.0905, so EUR's distance becomes 0.0885: 1 USD buys 0.91531 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0885"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4214"},{"key":"EUR","note":"0.0885"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 5. USD to GBP at 0.76808: -0.0078 + 0.2639 = 0.256, shorter than 0.258, so GBP's distance becomes 0.256: 1 USD buys 0.77411 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.256"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4214"},{"key":"EUR","note":"0.0885"},{"key":"GBP","note":"0.256"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 5. USD to CAD at 1.3632: -0.0078 - 0.3098 = -0.3177, shorter than -0.3157, so CAD's distance becomes -0.3177: 1 USD buys 1.3739 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3177"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4214"},{"key":"EUR","note":"0.0885"},{"key":"GBP","note":"0.256"},{"key":"CAD","note":"-0.3177"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 5. USD to AUD at 1.5129: -0.0078 - 0.414 = -0.4218, shorter than -0.4214, so AUD's distance becomes -0.4218: 1 USD buys 1.5248 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4218"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4218"},{"key":"EUR","note":"0.0885"},{"key":"GBP","note":"0.256"},{"key":"CAD","note":"-0.3177"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 5. USD to NZD at 1.6625: -0.0078 - 0.5083 = -0.5161, shorter than -0.5142, so NZD's distance becomes -0.5161: 1 USD buys 1.6755 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5161"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1597"},{"key":"JPY","note":"-5.0195"},{"key":"USD","note":"-0.0078"},{"key":"AUD","note":"-0.4218"},{"key":"EUR","note":"0.0885"},{"key":"GBP","note":"0.256"},{"key":"CAD","note":"-0.3177"},{"key":"NZD","note":"-0.5161"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 5 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 6. EUR to CHF at 0.93313: 0.0885 + 0.0692 = 0.1577, shorter than 0.1597, so CHF's distance becomes 0.1577: 1 USD buys 0.8541 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1577"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"}]}]},{"say":"Pass 6. GBP to JPY at 195.87: 0.256 - 5.2775 = -5.0214, shorter than -5.0195, so JPY's distance becomes -5.0214: 1 USD buys 151.62 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0214"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 6. JPY to USD at 0.00666: -5.0214 + 5.0116 = -0.0098, shorter than -0.0078, so USD's distance becomes -0.0098: 1 USD buys 1.0098 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.0098"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 6. JPY to AUD at 0.010071: -5.0214 + 4.5981 = -0.4233, shorter than -0.4218, so AUD's distance becomes -0.4233: 1 USD buys 1.527 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4233"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4233"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 6. USD to EUR at 0.90818: -0.0098 + 0.0963 = 0.0865, shorter than 0.0885, so EUR's distance becomes 0.0865: 1 USD buys 0.9171 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0865"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4233"},{"key":"EUR","note":"0.0865"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 6. USD to GBP at 0.76808: -0.0098 + 0.2639 = 0.2541, shorter than 0.256, so GBP's distance becomes 0.2541: 1 USD buys 0.77562 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.2541"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4233"},{"key":"EUR","note":"0.0865"},{"key":"GBP","note":"0.2541"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 6. USD to CAD at 1.3632: -0.0098 - 0.3098 = -0.3196, shorter than -0.3177, so CAD's distance becomes -0.3196: 1 USD buys 1.3766 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3196"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4233"},{"key":"EUR","note":"0.0865"},{"key":"GBP","note":"0.2541"},{"key":"CAD","note":"-0.3196"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 6. USD to AUD at 1.5129: -0.0098 - 0.414 = -0.4238, shorter than -0.4233, so AUD's distance becomes -0.4238: 1 USD buys 1.5278 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4238"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4238"},{"key":"EUR","note":"0.0865"},{"key":"GBP","note":"0.2541"},{"key":"CAD","note":"-0.3196"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 6. USD to NZD at 1.6625: -0.0098 - 0.5083 = -0.5181, shorter than -0.5161, so NZD's distance becomes -0.5181: 1 USD buys 1.6788 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.5181"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1577"},{"key":"JPY","note":"-5.0214"},{"key":"USD","note":"-0.0098"},{"key":"AUD","note":"-0.4238"},{"key":"EUR","note":"0.0865"},{"key":"GBP","note":"0.2541"},{"key":"CAD","note":"-0.3196"},{"key":"NZD","note":"-0.5181"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 6 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Pass 7. EUR to CHF at 0.93313: 0.0865 + 0.0692 = 0.1558, shorter than 0.1577, so CHF's distance becomes 0.1558: 1 USD buys 0.85577 CHF this way.","ops":[{"v":"CHF","state":"current"},{"e":["EUR","CHF"],"state":"tree"},{"panel":"dist","set":{"CHF":"0.1558"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"}]}]},{"say":"Pass 7. GBP to JPY at 195.87: 0.2541 - 5.2775 = -5.0234, shorter than -5.0214, so JPY's distance becomes -5.0234: 1 USD buys 151.92 JPY this way.","ops":[{"v":"JPY","state":"current"},{"e":["GBP","JPY"],"state":"tree"},{"panel":"dist","set":{"JPY":"-5.0234"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"}]},{"v":"CHF","state":"waiting"}]},{"say":"Pass 7. JPY to USD at 0.00666: -5.0234 + 5.0116 = -0.0117, shorter than -0.0098, so USD's distance becomes -0.0117: 1 USD buys 1.0118 USD this way, more than it started with.","ops":[{"v":"USD","state":"current"},{"e":["JPY","USD"],"state":"tree"},{"panel":"dist","set":{"USD":"-0.0117"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"}]},{"v":"JPY","state":"waiting"}]},{"say":"Pass 7. JPY to AUD at 0.010071: -5.0234 + 4.5981 = -0.4253, shorter than -0.4238, so AUD's distance becomes -0.4253: 1 USD buys 1.53 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["JPY","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4253"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4253"}]},{"e":["USD","AUD"],"state":"idle"},{"v":"USD","state":"waiting"}]},{"say":"Pass 7. USD to EUR at 0.90818: -0.0117 + 0.0963 = 0.0846, shorter than 0.0865, so EUR's distance becomes 0.0846: 1 USD buys 0.91889 EUR this way.","ops":[{"v":"EUR","state":"current"},{"e":["USD","EUR"],"state":"tree"},{"panel":"dist","set":{"EUR":"0.0846"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4253"},{"key":"EUR","note":"0.0846"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 7. USD to GBP at 0.76808: -0.0117 + 0.2639 = 0.2521, shorter than 0.2541, so GBP's distance becomes 0.2521: 1 USD buys 0.77714 GBP this way.","ops":[{"v":"GBP","state":"current"},{"e":["USD","GBP"],"state":"tree"},{"panel":"dist","set":{"GBP":"0.2521"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4253"},{"key":"EUR","note":"0.0846"},{"key":"GBP","note":"0.2521"}]},{"v":"EUR","state":"waiting"}]},{"say":"Pass 7. USD to CAD at 1.3632: -0.0117 - 0.3098 = -0.3216, shorter than -0.3196, so CAD's distance becomes -0.3216: 1 USD buys 1.3793 CAD this way.","ops":[{"v":"CAD","state":"current"},{"e":["USD","CAD"],"state":"tree"},{"panel":"dist","set":{"CAD":"-0.3216"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4253"},{"key":"EUR","note":"0.0846"},{"key":"GBP","note":"0.2521"},{"key":"CAD","note":"-0.3216"}]},{"v":"GBP","state":"waiting"}]},{"say":"Pass 7. USD to AUD at 1.5129: -0.0117 - 0.414 = -0.4258, shorter than -0.4253, so AUD's distance becomes -0.4258: 1 USD buys 1.5307 AUD this way.","ops":[{"v":"AUD","state":"current"},{"e":["USD","AUD"],"state":"tree"},{"panel":"dist","set":{"AUD":"-0.4258"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4258"},{"key":"EUR","note":"0.0846"},{"key":"GBP","note":"0.2521"},{"key":"CAD","note":"-0.3216"}]},{"e":["JPY","AUD"],"state":"idle"},{"v":"CAD","state":"waiting"}]},{"say":"Pass 7. USD to NZD at 1.6625: -0.0117 - 0.5083 = -0.52, shorter than -0.5181, so NZD's distance becomes -0.52: 1 USD buys 1.6821 NZD this way.","ops":[{"v":"NZD","state":"current"},{"e":["USD","NZD"],"state":"tree"},{"panel":"dist","set":{"NZD":"-0.52"}},{"panel":"changed","list":[{"key":"CHF","note":"0.1558"},{"key":"JPY","note":"-5.0234"},{"key":"USD","note":"-0.0117"},{"key":"AUD","note":"-0.4258"},{"key":"EUR","note":"0.0846"},{"key":"GBP","note":"0.2521"},{"key":"CAD","note":"-0.3216"},{"key":"NZD","note":"-0.52"}]},{"v":"AUD","state":"waiting"}]},{"say":"Pass 7 done. 8 distances changed.","ops":[{"v":"CHF","state":"done"},{"v":"JPY","state":"done"},{"v":"USD","state":"done"},{"v":"AUD","state":"done"},{"v":"EUR","state":"done"},{"v":"GBP","state":"done"},{"v":"CAD","state":"done"},{"v":"NZD","state":"done"}]},{"say":"Extra pass. EUR to CHF at 0.93313: 0.0846 + 0.0692 = 0.1538, still shorter than 0.1558, so the distances never settle. The loop USD, GBP, JPY, USD turns 1 USD into 1.002 USD, and each lap lowers them again. gograph stops and returns path.ErrNegativeWeightCycle.","ops":[{"e":["USD","GBP"],"state":"error"},{"e":["GBP","JPY"],"state":"error"},{"e":["JPY","USD"],"state":"error"}]}],"traceNote":"","verification":"The steps come from a step-by-step copy of the algorithm. Its distances and the route it draws to each vertex are checked against Distance and PathTo of path.BellmanFordPaths on every start. Of two routes that are equally short, BellmanFordPaths takes the one with the fewest edges, and the steps keep the last edge that lowered each distance, so the drawn route can be another one as short. On a negative cycle, path.NegativeCycle searches the whole graph, so the check takes any loop whose weights add up to less than zero.","snippet":"paths, err := path.BellmanFordPaths(g, \"USD\")\nif errors.Is(err, path.ErrNegativeWeightCycle) {\n\tloop, _ := path.NegativeCycle(g)\n\tfor _, v := range loop {\n\t\tfmt.Println(v.Label())\n\t}\n\treturn err\n}\nif err != nil {\n\treturn err\n}\ndist, ok := paths.Distance(\"NZD\")\nif !ok {\n\treturn nil // out of reach\n}\nroute, _ := paths.PathTo(\"NZD\")\nfmt.Println(dist)\nfor _, v := range route {\n\tfmt.Println(v.Label())\n}"}
