本文整理汇总了Java中org.jgrapht.DirectedGraph.containsVertex方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedGraph.containsVertex方法的具体用法?Java DirectedGraph.containsVertex怎么用?Java DirectedGraph.containsVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.DirectedGraph
的用法示例。
在下文中一共展示了DirectedGraph.containsVertex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractMentionNetwork
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
protected DirectedGraph<Figure, DefaultEdge> extractMentionNetwork(JCas jcas) {
DirectedGraph<Figure, DefaultEdge> graph = new DirectedPseudograph<Figure, DefaultEdge>(DefaultEdge.class);
for (Utterance utterance : JCasUtil.select(jcas, Utterance.class)) {
Speaker speaker = DramaUtil.getFirstSpeaker(utterance);
if (speaker != null)
for (FigureMention mention : JCasUtil.selectCovered(jcas, FigureMention.class, utterance)) {
if (speaker.getFigure() != null && mention.getFigure() != null) {
if (!graph.containsVertex(speaker.getFigure()))
graph.addVertex(speaker.getFigure());
if (!graph.containsVertex(mention.getFigure()))
graph.addVertex(mention.getFigure());
graph.addEdge(speaker.getFigure(), mention.getFigure());
}
}
}
return graph;
}
示例2: buildDefinitionGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private void buildDefinitionGraph(Collection<DefinitionModel> definitions,
DirectedGraph<DefinitionModel, DefaultEdge> definitionGraph) {
for (DefinitionModel definition : definitions) {
if (!definitionGraph.containsVertex(definition)) {
definitionGraph.addVertex(definition);
buildDefinitionGraph(definition.getDependencies(), definitionGraph);
for (DefinitionModel dependency : definition.getDependencies()) {
definitionGraph.addEdge(definition, dependency);
}
}
}
}
示例3: detectCyclesInEntityGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
/**
* Inspects the instance graph for cycles, any cycle is printed as an error. The nameToEntity parameter doesn't list expected
* instances, any instances that are not found in the nameToInstances map (they are looked for because they are referenced as a
* dependency by an instance in the map) and are not found by name in the definition's expectedInstances are treated as errors
* as well.
*
* @param definition definition being processed. Will uses it's expected list, any instances references as dependencies but
* not found, not listed as expected in this DefinitionModel, will be treated as errors.
* @param nameToEntity name to unique instanceModels, verified before call.
* @param errorListner accepts and displays all errors produced by analyzing the models
* @return true if an error occurred, false otherwise
*/
private boolean detectCyclesInEntityGraph(final DefinitionModel definition, final Map<String, InstanceModel> nameToEntity,
final Consumer<ErrorModel> errorListener) {
final Map<String, ExpectedModel> missing = new HashMap<>();
final DirectedGraph<BaseInstanceModel, DefaultEdge> entityGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
for (BaseInstanceModel entity : nameToEntity.values()) {
if (!entityGraph.containsVertex(entity)) {
entityGraph.addVertex(entity);
}
if (InstanceModel.class.isAssignableFrom(entity.getClass())) {
InstanceModel instanceModel = (InstanceModel) entity;
for (InstanceDependencyModel instanceDependency : instanceModel.getDependencies()) {
BaseInstanceModel dependency = nameToEntity.get(instanceDependency.getIdentity());
if (dependency == null) {
dependency = missing.computeIfAbsent(instanceDependency.getIdentity(), s -> new ExpectedModel(s));
missing.get(instanceDependency.getIdentity())
.addDefinitionReferenceToType(instanceModel.getIdentity(), instanceDependency.getType());
}
if (!entityGraph.containsVertex(dependency)) {
entityGraph.addVertex(dependency);
}
entityGraph.addEdge(entity, dependency);
}
}
}
boolean errored = errorsForCycles(errorListener, entityGraph);
errored = testAllMissingEntitiesAreExpected(definition, errorListener, missing, entityGraph) || errored;
errored = errorUnusedExpectedsOnDefinition(definition, errorListener, missing) || errored;
return errored;
}
示例4: addEdge
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
protected static <Y, Z> void addEdge(DirectedGraph<Y, Z> t, Y source, Y target) {
if (!t.containsVertex(source)) {
t.addVertex(source);
}
if (!t.containsVertex(target)) {
t.addVertex(target);
}
t.addEdge(source, target);
}
示例5: scheduleTypeDependencyCheck
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
/**
* array[a..b] of c..d: e:
*
* {a,b, c,d} would be "to", e would be "from"
* @param scopeType
* @param from
* @param toType
* @throws MiniBrassParseException
*/
public void scheduleTypeDependencyCheck(PVSType scopeType, String from, MiniZincVarType toType) throws MiniBrassParseException {
DirectedGraph<String, DefaultEdge> parameterGraph = null;
if(!parameterDependencies.containsKey(scopeType.getName())) {
parameterGraph = new DirectedAcyclicGraph<>(DefaultEdge.class);
parameterDependencies.put(scopeType.getName(), parameterGraph);
} else {
parameterGraph = parameterDependencies.get(scopeType.getName());
}
if(toType instanceof IntervalType) {
IntervalType safeTo = (IntervalType) toType;
for(String to : safeTo.getReferencedParameters()) {
try{
if(!parameterGraph.containsVertex(from))
parameterGraph.addVertex(from);
if(!parameterGraph.containsVertex(to))
parameterGraph.addVertex(to);
parameterGraph.addEdge(from, to);
} catch(IllegalArgumentException ce) {
throw new MiniBrassParseException("Detected cyclic dependency when adding parameter dependency: "+from + " -> "+ to);
}
}
}
}
示例6: isReachable
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private boolean isReachable(AttributeRef attribute, Set<AttributeRef> initialAttributes, DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
for (AttributeRef initialAttribute : initialAttributes) {
if (logger.isTraceEnabled()) logger.trace("Checking reachability of " + attribute + " from " + initialAttribute);
if (!dependencyGraph.containsVertex(initialAttribute)) {
continue;
}
List path = DijkstraShortestPath.findPathBetween(dependencyGraph, initialAttribute, attribute);
if (path != null) {
if (logger.isTraceEnabled()) logger.trace("Found!");
return true;
}
}
return false;
}
示例7: createFromFile
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
public static TrafficLocationGraph createFromFile(File file)
{
TrafficLocationGraph tlg = new TrafficLocationGraph();
try {
BufferedReader brPoffsets = new BufferedReader(new FileReader(file));
String line = null;
DirectedGraph<Integer, LocationEdge> graph = tlg.graph;
while ((line = brPoffsets.readLine()) != null) {
if ((!line.startsWith("#")) && (!line.equals(""))) {
String[] tmp = line.split(";");
if (tmp[2].equals(""))
continue;
int loc0 = Integer.parseInt(tmp[2]);
if (!graph.containsVertex(loc0))
graph.addVertex(loc0);
for(int i = 3; i< tmp.length; i++)
{
if (tmp[i].equals(""))
continue;
int loc1 = Integer.parseInt(tmp[i]);
if (!graph.containsVertex(loc1))
graph.addVertex(loc1);
graph.addEdge(loc0, loc1);
}
}
}
brPoffsets.close();
} catch (NumberFormatException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//tlg.getShortestPath(36716, 52807);
return tlg;
}
示例8: testGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
/**
* Compares the given graph with the expected graph. Returns true only if both<br>
* graphs are identical.
* @param graph
*/
private void testGraph(DirectedGraph<Integer,DefaultEdge> graph){
//make sure all vertices are there
for(int i=1;i<16;i++){
if(!graph.containsVertex(i)) {
fail("Graph does not contain vertex " + i);
}
}
if(!graph.containsVertex(30)) {
fail("Graph does not contain vertex " + 200);
}
if(!graph.containsVertex(200)) {
fail("Graph does not contain vertex " + 200);
}
//make sure there are no supplemental vertices
assertEquals(17, graph.vertexSet().size());
//make sure all edges are there
if(!graph.containsEdge(1,200)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(1,2)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(1,4)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(1,3)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(1,5)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(3,6)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(4,9)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(5,8)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(6,9)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(6,8)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(6,7)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(7,11)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(7,10)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(8,15)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(8,13)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(8,14)) {
fail("Graph does not contain edge");
}
if(!graph.containsEdge(8,12)) {
fail("Graph does not contain edge");
}
//make sure there no supplemental edges
assertEquals(17, graph.edgeSet().size());
}
示例9: cacheRegex
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private static void cacheRegex(String regex) {
String r = expandRegex(regex);
Automaton automaton = new RegExp(r, RegExp.NONE).toAutomaton();
automaton.expandSingleton();
// We convert this to a graph without self-loops in order to determine the topological order
DirectedGraph<State, DefaultEdge> regexGraph = new DefaultDirectedGraph<State, DefaultEdge>(
DefaultEdge.class);
Set<State> visitedStates = new HashSet<State>();
Queue<State> states = new LinkedList<State>();
State initialState = automaton.getInitialState();
states.add(initialState);
while (!states.isEmpty()) {
State currentState = states.poll();
if (visitedStates.contains(currentState))
continue;
if (!regexGraph.containsVertex(currentState))
regexGraph.addVertex(currentState);
for (Transition t : currentState.getTransitions()) {
// Need to get rid of back edges, otherwise there is no topological order!
if (!t.getDest().equals(currentState)) {
regexGraph.addVertex(t.getDest());
regexGraph.addEdge(currentState, t.getDest());
states.add(t.getDest());
CycleDetector<State, DefaultEdge> det = new CycleDetector<State, DefaultEdge>(
regexGraph);
if (det.detectCycles()) {
regexGraph.removeEdge(currentState, t.getDest());
}
}
}
visitedStates.add(currentState);
}
TopologicalOrderIterator<State, DefaultEdge> iterator = new TopologicalOrderIterator<State, DefaultEdge>(
regexGraph);
List<State> topologicalOrder = new ArrayList<State>();
while (iterator.hasNext()) {
topologicalOrder.add(iterator.next());
}
regexStateCache.put(regex, topologicalOrder);
regexAutomatonCache.put(regex, automaton);
}