本文整理匯總了Java中org.jgrapht.Graph.containsVertex方法的典型用法代碼示例。如果您正苦於以下問題:Java Graph.containsVertex方法的具體用法?Java Graph.containsVertex怎麽用?Java Graph.containsVertex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jgrapht.Graph
的用法示例。
在下文中一共展示了Graph.containsVertex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Dijkstra
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* Creates and executes a new DijkstraShortestPath algorithm instance. An
* instance is only good for a single search; after construction, it can be
* accessed to retrieve information about the path found.
*
* @param graph the graph to be searched
* @param startVertex the vertex at which the path should start
* @param endVertex the vertex at which the path should end
* @param radius limit on path length, or Double.POSITIVE_INFINITY for
* unbounded search
*/
public Dijkstra(
Graph<V, E> graph,
V startVertex,
V endVertex,
double radius)
{
if (!graph.containsVertex(endVertex)) {
throw new IllegalArgumentException(
"graph must contain the end vertex");
}
ClosestFirstIterator<V, E> iter =
new ClosestFirstIterator<V, E>(graph, startVertex, radius);
while (iter.hasNext()) {
V vertex = iter.next();
if (vertex.equals(endVertex)) {
createEdgeList(graph, iter, startVertex, endVertex);
return;
}
}
path = null;
}
示例2: CrossComponentIteratorModified
import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
* Creates a new iterator for the specified graph. Iteration will start at
* the specified start vertex. If the specified start vertex is <code>
* null</code>, Iteration will start at an arbitrary graph vertex.
*
* @param g the graph to be iterated.
* @param startVertex the vertex iteration to be started.
*
* @throws IllegalArgumentException if <code>g==null</code> or does not
* contain <code>startVertex</code>
*/
public CrossComponentIteratorModified(Graph<V, E> g, V startVertex)
{
super();
if (g == null) {
throw new IllegalArgumentException("graph must not be null");
}
graph = g;
specifics = createGraphSpecifics(g);
vertexIterator = g.vertexSet().iterator();
while (vertexIterator.hasNext()){
}
setCrossComponentTraversal(startVertex == null);
reusableEdgeEvent = new FlyweightEdgeEvent<V, E>(this, null);
reusableVertexEvent = new FlyweightVertexEvent<V>(this, null);
if (startVertex == null) {
// pick a start vertex if graph not empty
if (vertexIterator.hasNext()) {
this.startVertex = vertexIterator.next();
} else {
this.startVertex = null;
}
} else if (g.containsVertex(startVertex)) {
this.startVertex = startVertex;
} else {
throw new IllegalArgumentException(
"graph must contain the start vertex");
}
}
示例3: getGraph
import org.jgrapht.Graph; //導入方法依賴的package包/類
public static Graph<Figure, DefaultWeightedEdge> getGraph(JCas jcas, String viewName)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException, CASException {
JCas graphView = jcas.getView(viewName);
Map<Integer, Figure> figureMap = new HashMap<Integer, Figure>();
for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
figureMap.put(figure.getBegin(), figure);
}
if (!JCasUtil.exists(graphView, GraphMetaData.class))
return null;
GraphMetaData gmd = JCasUtil.selectSingle(graphView, GraphMetaData.class);
Class<?> cl = Class.forName(gmd.getGraphClassName());
@SuppressWarnings("unchecked")
Graph<Figure, DefaultWeightedEdge> graph = (Graph<Figure, DefaultWeightedEdge>) cl.getConstructor(Class.class)
.newInstance(DefaultWeightedEdge.class);
boolean weighted = false;
if (graph instanceof WeightedGraph) {
weighted = true;
}
// SimpleWeightedGraph<Figure, DefaultWeightedEdge> graph =
// new SimpleWeightedGraph<Figure, DefaultWeightedEdge>(
// DefaultWeightedEdge.class);
Pattern pattern;
if (weighted)
pattern = Pattern.compile("(-?\\d+) (-?\\d+) (\\d+.\\d+)");
else
pattern = Pattern.compile("(-?\\d+) (-?\\d+)");
for (String line : graphView.getDocumentText().split("\n")) {
Matcher m = pattern.matcher(line);
if (m.find()) {
int sId = Integer.valueOf(m.group(1));
int tId = Integer.valueOf(m.group(2));
Figure sFigure = figureMap.get(sId);
Figure tFigure = figureMap.get(tId);
if (!graph.containsVertex(sFigure))
graph.addVertex(sFigure);
if (!graph.containsVertex(tFigure))
graph.addVertex(tFigure);
Object edge = graph.addEdge(sFigure, tFigure);
if (weighted) {
double w = Double.valueOf(m.group(3));
if (edge != null)
((WeightedGraph<Figure, DefaultWeightedEdge>) graph).setEdgeWeight((DefaultWeightedEdge) edge,
w);
}
}
}
return graph;
}