org.jgrapht.alg.shortestpath.BellmanFordShortestPath Java Examples
The following examples show how to use
org.jgrapht.alg.shortestpath.BellmanFordShortestPath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NatureRecognitor.java From cocolian-nlp with Apache License 2.0 | 5 votes |
/** * 进行最佳词性查找,引用赋值.所以不需要有返回值 */ @Override protected void recognize(TermGraph graph) { NatureTermGraph natureGraph = new NatureTermGraph(); NatureTerm start = null; NatureTerm end = null; for (POSTerm term : graph.vertexSet()){ boolean hasNature = false; //该Term是否有nature; for (Nature nature : term.getTermNatures().natures()) { NatureTerm item = new NatureTerm(term, nature, term.getTermNatures().getFrequency(nature)); if (graph.getStartVertex().equals(term)) { item.score = 0; start = item; } else if (graph.getEndVertex().equals(term)) { end = item; } natureGraph.addVertex(item); hasNature = true; } if(!hasNature) natureGraph.addVertex(new NatureTerm(term, Nature.valueOf("n"), 0)); //默认的设置为名词 } for (NatureTerm from : natureGraph.vertexSet()) for (NatureTerm to : natureGraph.vertexSet()) { if (graph.getEdge(from.term, to.term) != null) { natureGraph.addEdge(from, to); } } List<NatureTermEdge> edges = BellmanFordShortestPath.findPathBetween(natureGraph, start, end).getEdgeList(); for (NatureTermEdge edge : edges) { NatureTerm nt = natureGraph.getEdgeTarget(edge); nt.term.setNature(nt.nature); } }
Example #2
Source File: BellmanFordPointRouterFactory.java From openAGV with Apache License 2.0 | 4 votes |
@Override protected ShortestPathAlgorithm<String, ModelEdge> createShortestPathAlgorithm( Graph<String, ModelEdge> graph) { return new BellmanFordShortestPath<>(graph); }
Example #3
Source File: ShortestPathTest.java From JQF with BSD 2-Clause "Simplified" License | 4 votes |
@Fuzz public void bellmanFord(@GraphModel(nodes=10, weighted=true) Graph graph) { new BellmanFordShortestPath<>(graph).getPaths(1); }
Example #4
Source File: DirectedGraphUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenDirectedGraph_whenGetBellmanFordShortestPath_thenGetNotNullPath() { BellmanFordShortestPath bellmanFordShortestPath = new BellmanFordShortestPath(directedGraph); List<String> shortestPath = bellmanFordShortestPath.getPath("v1", "v4").getVertexList(); assertNotNull(shortestPath); }
Example #5
Source File: AbstractRecognitor.java From cocolian-nlp with Apache License 2.0 | 2 votes |
/** * 获取graph中的最短路径; * @param graph * @return */ protected TermPath findShortestPath(TermGraph graph) { List<TermEdge> edges = BellmanFordShortestPath.findPathBetween(graph, graph.getStartVertex(), graph.getEndVertex()).getEdgeList(); return graph.createPath(edges); }