@@ -0,0 +1,1392 @@
+package org.psjava.example;%0D%0A%0D%0Aimport org.junit.Assert;%0D%0Aimport org.junit.Test;%0D%0Aimport org.psjava.algo.graph.shortestpath.NegativeCycleFinder;%0D%0Aimport org.psjava.algo.graph.shortestpath.NegativeCycleFinderResult;%0D%0Aimport org.psjava.ds.Collection;%0D%0Aimport org.psjava.ds.graph.DirectedWeightedEdge;%0D%0Aimport org.psjava.ds.graph.MutableDirectedWeightedGraph;%0D%0Aimport org.psjava.math.ns.IntegerNumberSystem;%0D%0A%0D%0Apublic class FindingNegativeCycleExample %7B%0D%0A%0D%0A%09@Test%0D%0A%09public void test() %7B%0D%0A%0D%0A%09%09// Let's consturct a simple graph.%0D%0A%0D%0A%09%09MutableDirectedWeightedGraph%3CInteger%3E g = MutableDirectedWeightedGraph.create();%0D%0A%09%09g.insertVertex(%22A%22);%0D%0A%09%09g.insertVertex(%22B%22);%0D%0A%09%09g.insertVertex(%22C%22);%0D%0A%09%09g.addEdge(%22A%22, %22B%22, 100);%0D%0A%09%09g.addEdge(%22B%22, %22C%22, 200);%0D%0A%09%09g.addEdge(%22C%22, %22A%22, -100);%0D%0A%0D%0A%09%09// Now, there is no negative cycles yet.%0D%0A%0D%0A%09%09NegativeCycleFinderResult%3CInteger%3E result1 = NegativeCycleFinder.find(g, IntegerNumberSystem.getInstance());%0D%0A%09%09boolean has1 = result1.hasCycle();%0D%0A%09%09Assert.assertFalse(has1);%0D%0A%0D%0A%09%09// Add another edge to make a cycle.%0D%0A%0D%0A%09%09g.addEdge(%22C%22, %22A%22, -400);%0D%0A%0D%0A%09%09NegativeCycleFinderResult%3CInteger%3E result2 = NegativeCycleFinder.find(g, IntegerNumberSystem.getInstance());%0D%0A%09%09boolean has2 = result2.hasCycle();%0D%0A%09%09Collection%3CDirectedWeightedEdge%3CInteger%3E%3E path = result2.getPath(); // this is the path!%0D%0A%0D%0A%09%09Assert.assertTrue(has2);%0D%0A%09%09Assert.assertEquals(3, path.size());%0D%0A%09%7D%0D%0A%7D%0D%0A

add a example - negative cycle finding.