本文整理汇总了Java中org.jgrapht.graph.DefaultEdge类的典型用法代码示例。如果您正苦于以下问题:Java DefaultEdge类的具体用法?Java DefaultEdge怎么用?Java DefaultEdge使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultEdge类属于org.jgrapht.graph包,在下文中一共展示了DefaultEdge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addEdgesForEquivalenceClass
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private void addEdgesForEquivalenceClass(String constant, FormulaVariable variable, String operator,
IFormula formula, UndirectedGraph<FormulaGraphVertex, DefaultEdge> graph, Map<FormulaVariable, FormulaGraphVertex> vertexMap) {
VariableEquivalenceClass equivalenceClass = DependencyUtility.findEquivalenceClassForVariable(variable, formula.getLocalVariableEquivalenceClasses());
if (logger.isDebugEnabled()) logger.debug("Adding edges for equivalence class " + equivalenceClass);
for (FormulaVariable otherVariable : equivalenceClass.getVariables()) {
if (otherVariable.equals(variable)) {
continue;
}
if (existComparison(otherVariable, constant, formula)) {
continue;
}
Expression expression = new Expression(otherVariable.getId() + operator + constant);
ComparisonAtom virtualComparisonAtom = new ComparisonAtom(formula, expression, otherVariable.getId(), null, null, constant, operator);
virtualComparisonAtom.addVariable(otherVariable);
FormulaGraphVertex virtualComparisonVertex = new FormulaGraphVertex(virtualComparisonAtom);
virtualComparisonVertex.setVirtual(true);
graph.addVertex(virtualComparisonVertex);
FormulaGraphVertex variableVertex = vertexMap.get(otherVariable);
graph.addEdge(virtualComparisonVertex, variableVertex);
createConstantVertex(constant, virtualComparisonVertex, graph);
}
}
示例2: testAllMissingEntitiesAreExpected
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private boolean testAllMissingEntitiesAreExpected(final DefinitionModel definition, final Consumer<ErrorModel> errorListner,
final Map<String, ExpectedModel> missing, final DirectedGraph<BaseInstanceModel, DefaultEdge> entityGraph) {
//check computed expected are actually expected
boolean errored = false;
List<String> expectedMissing = definition.getExpectedDefinitions().stream().map(em -> em.getIdentity())
.collect(Collectors.toList());
for (ExpectedModel expected : missing.values()) {
if (!expectedMissing.contains(expected.getIdentity())) {
List<AbstractModel> dependsOnMissing = Stream.concat(
Stream.of(definition),
entityGraph.incomingEdgesOf(expected).stream().map(edge -> entityGraph.getEdgeSource(edge))
.filter(m -> m.getSourceElement().isPresent()))
.collect(Collectors.toList());
errored = true;
errorListner.accept(new ErrorModel(ErrorType.MISSING_BEAN_DEFINITIONS, Arrays.asList(expected), dependsOnMissing));
} else {
definition.addComputedExpected(expected);
}
}
return errored;
}
示例3: pathsToParents
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
@Override
public Collection<Call> pathsToParents(MethodGraph element) {
Collection<Call> paths = new HashSet<>();
logger.debug("Finding path to parents for: {} ", element);
if (!directedGraph.containsVertex(element)) {
logger.warn("Graph does not contain vertex: {} . Returning empty collection.", element);
return paths;
}
Set<DefaultEdge> incomingEdges = directedGraph.incomingEdgesOf(element);
if (incomingEdges.isEmpty()) {
Call lonelyCall = new Call(element, null);
paths.add(lonelyCall);
return paths;
}
for (DefaultEdge incomingEdge : incomingEdges) {
MethodGraph father = directedGraph.getEdgeSource(incomingEdge);
logger.debug("Finding path to parents, element={}, father={} . About to find paths from father", element, father);
Call call = new Call(father, element);
paths.add(call);
paths.addAll(pathsToParents(father));
}
return paths;
}
示例4: nonPlanarRandomGraphStructure
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
/**
* Creates a naive, random, not necessarily planar graph
*/
@Deprecated
public static UndirectedGraph<RegionSetup, DefaultEdge> nonPlanarRandomGraphStructure(
final double populationPerRegionMean,
final double populationStandardDeviation,
UniformDistributionRNG rng,
IntegerInterval numberOfRegionsInterval,
IntegerInterval averageAdjacenciesPerRegionInterval
) {
int numberOfRegions = rng.nextInt(numberOfRegionsInterval);
int numberOfAdjacencies = rng.nextInt(averageAdjacenciesPerRegionInterval) * numberOfRegions;
RandomGraphGenerator<RegionSetup, DefaultEdge> randomGraphGenerator = new RandomGraphGenerator<>(
numberOfRegions, numberOfAdjacencies, rng.nextLong());
SimpleGraph<RegionSetup, DefaultEdge> targetGraph = new SimpleGraph<>(DefaultEdge.class);
VertexFactory<RegionSetup> vertexFactory = () -> new RegionSetup(populationPerRegionMean, populationStandardDeviation, "randomly created");
randomGraphGenerator.generateGraph(targetGraph, vertexFactory, null);
return targetGraph;
}
示例5: deserialize
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
@Override
public UnmodifiableUndirectedGraph<MRVMRegionsMap.Region, DefaultEdge> deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonArray jsonArray = json.getAsJsonArray();
Set<SerializedRegion> serializedRegions = new HashSet<>();
Map<Integer, MRVMRegionsMap.Region> regionsById = new HashMap<>();
SimpleGraph<MRVMRegionsMap.Region, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
for (int i = 0; i < jsonArray.size(); i++) {
JsonElement regionElement = jsonArray.get(i);
SerializedRegion r = context.deserialize(regionElement, SerializedRegion.class);
serializedRegions.add(r);
regionsById.put(r.getNode().getId(), r.getNode());
graph.addVertex(r.getNode());
}
for (SerializedRegion serializedRegion : serializedRegions) {
Set<Integer> neighbors = serializedRegion.getNeighbors();
for (Integer neighborId : neighbors) {
graph.addEdge(serializedRegion.getNode(), regionsById.get(neighborId));
}
}
return new UnmodifiableUndirectedGraph<>(graph);
}
示例6: getConnectedTo
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
@Override
public Object[] getConnectedTo(Object entity) {
if (entity instanceof PgStatement){
DirectedGraph<PgStatement, DefaultEdge> currentGraph = depRes.getOldGraph();
if (currentGraph != null){
List<PgStatement> connected = new ArrayList<>();
for (DefaultEdge e : currentGraph.outgoingEdgesOf((PgStatement)entity)){
PgStatement connectedVertex = currentGraph.getEdgeTarget(e);
if (!(connectedVertex instanceof PgColumn)) {
connected.add(connectedVertex);
}
}
return connected.toArray();
}
}
return null;
}
示例7: handleChanges
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private MutableList<ExecuteChangeCommand> handleChanges(MutableCollection<Change> fromSourceList) {
final MutableList<ExecuteChangeCommand> commands = Lists.mutable.empty();
DirectedGraph<Change, DefaultEdge> graph = enricher.createDependencyGraph(fromSourceList, false);
if (graph != null) {
ConnectivityInspector<Change, DefaultEdge> connectivityInspector
= new ConnectivityInspector<Change, DefaultEdge>(graph);
for (Set<Change> connectedSet : connectivityInspector.connectedSets()) {
// once we have a connectedSet, sort within those changes to ensure that we still sort them in the
// right order (i.e. via topological sort)
ImmutableList<Change> fullChanges = sorter.sortChanges(graph, SetAdapter.adapt(connectedSet), SortableDependency.GRAPH_SORTER_COMPARATOR);
commands.add(changeCommandFactory.createDeployCommand(new GroupChange(fullChanges)));
}
}
return commands;
}
示例8: sortChanges
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
/**
* Sorts the graph to provide a consistent topological ordering.
*
* @param graph The input graph
* @param subsetVertices The subset vertices of the graph we want to sort
* @param comparator The comparator on which to order the vertices to guarantee a consistent topological ordering
*/
public <T> ImmutableList<T> sortChanges(DirectedGraph<T, DefaultEdge> graph, RichIterable<T> subsetVertices, Comparator<? super T> comparator) {
if (subsetVertices.toSet().size() != subsetVertices.size()) {
throw new IllegalStateException("Unexpected state - have some dupe elements here: " + subsetVertices);
}
DirectedGraph<T, DefaultEdge> subsetGraph = new DirectedSubgraph<T, DefaultEdge>(
graph, subsetVertices.toSet(), null);
// At one point, we _thought_ that the DirectedSubGraph was dropping vertices that don't have edges, so we
// manually add them back to the graph to ensure that we can still order them.
// However, that no longer seems to be the case. We add a check here just in case this comes up again.
if (subsetVertices.size() != subsetGraph.vertexSet().size()) {
throw new IllegalArgumentException("This case should never happen! [subsetVertices: " + subsetVertices + ", subsetGraphVertices: " + subsetGraph.vertexSet());
}
return sortChanges(subsetGraph, comparator);
}
示例9: testSchemaObjectDependencies
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
/**
* The test data in this class is all written w/ case-sensitivy as the default.
* If we pass caseInsensitive == true, then we enable that mode in the graph enricher and tweak the object names
* a bit so that we can verify that the resolution works either way.
*/
public void testSchemaObjectDependencies(boolean caseInsensitive) {
this.enricher = new GraphEnricherImpl(caseInsensitive ? StringFunctions.toUpperCase() : Functions.getStringPassThru());
SortableDependencyGroup sch1Obj1 = newChange(schema1, type1, "obj1", Sets.immutable.with("obj3", schema2 + ".obj2"));
SortableDependencyGroup sch1Obj2 = newChange(schema1, type2, "obj2", Sets.immutable.<String>with());
// change the case of the object name to ensure others can still point to it
SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, caseInsensitive ? "obj3".toUpperCase() : "obj3", Sets.immutable.with("obj2"));
// change the case of the dependency name to ensure that it can point to others
SortableDependencyGroup sch2Obj1 = newChange(schema2, type1, "obj1", Sets.immutable.with(caseInsensitive ? "obj2".toUpperCase() : "obj2"));
SortableDependencyGroup sch2Obj2 = newChange(schema2, type2, "obj2", Sets.immutable.with(schema1 + ".obj3"));
DirectedGraph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
sch1Obj1, sch1Obj2, sch1Obj3, sch2Obj1, sch2Obj2), false);
validateChange(sortGraph, sch1Obj1, Sets.immutable.with(sch1Obj3, sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
validateChange(sortGraph, sch1Obj2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sch1Obj3));
validateChange(sortGraph, sch1Obj3, Sets.immutable.with(sch1Obj2), Sets.immutable.with(sch1Obj1, sch2Obj2));
validateChange(sortGraph, sch2Obj1, Sets.immutable.with(sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
validateChange(sortGraph, sch2Obj2, Sets.immutable.with(sch1Obj3), Sets.immutable.with(sch1Obj1, sch2Obj1));
}
示例10: testGetChangesCaseInsensitive
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
@Test
public void testGetChangesCaseInsensitive() {
this.enricher = new GraphEnricherImpl(StringFunctions.toUpperCase());
String schema1 = "schema1";
String schema2 = "schema2";
String type1 = "type1";
SortableDependencyGroup sp1 = newChange(schema1, type1, "SP1", "n/a", 0, Sets.immutable.with("sp2"));
SortableDependencyGroup sp2 = newChange(schema1, type1, "SP2", Sets.immutable.<String>with());
SortableDependencyGroup sp3 = newChange(schema1, type1, "SP3", Sets.immutable.with("sp1", "sp2"));
SortableDependencyGroup spA = newChange(schema1, type1, "SPA", Sets.immutable.with("sp3"));
SortableDependencyGroup sp1Schema2 = newChange(schema2, type1, "sp1", "n/a", 0, Sets.immutable.with("sp2", schema1 + ".sp3"));
SortableDependencyGroup sp2Schema2 = newChange(schema2, type1, "sP2", "n/a", 0, Sets.immutable.<String>with());
DirectedGraph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
sp1, sp2, sp3, spA, sp1Schema2, sp2Schema2), false);
validateChange(sortGraph, sp1, Sets.immutable.with(sp2), Sets.immutable.with(sp3));
validateChange(sortGraph, sp2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1, sp3));
validateChange(sortGraph, sp3, Sets.immutable.with(sp1, sp2), Sets.immutable.with(spA, sp1Schema2));
validateChange(sortGraph, spA, Sets.immutable.with(sp3), Sets.immutable.<SortableDependencyGroup>with());
validateChange(sortGraph, sp1Schema2, Sets.immutable.with(sp2Schema2, sp3), Sets.immutable.<SortableDependencyGroup>with());
validateChange(sortGraph, sp2Schema2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1Schema2));
}
示例11: assertHasSingleCronRoot
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private void assertHasSingleCronRoot(DirectedAcyclicGraph<NameAndGroup, DefaultEdge> graph) {
Iterator<NameAndGroup> itr = graph.iterator();
NameAndGroup root = null;
while (itr.hasNext()) {
NameAndGroup cur = itr.next();
if(!isRoot(graph, cur)) {
continue;
}
if(root != null) {
throw new CronyxException(String.format("Graph has at least 2 roots: %s, %s", root, cur));
}
if(!isCron(cur)) {
throw new CronyxException("Found a root that is not a cron trigger: " + cur);
}
root = cur;
}
if(root == null) {
throw new CronyxException("Didn't find a root in the graph!");
}
}
示例12: modify
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void modify(JCas jcas) throws AnalysisEngineProcessException {
Collection<CandidateAnswerVariant> cavs = TypeUtil.getCandidateAnswerVariants(jcas);
UndirectedGraph<Object, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
cavs.forEach(cav -> {
graph.addVertex(cav);
for (String name : TypeUtil.getCandidateAnswerVariantNames(cav)) {
graph.addVertex(name);
graph.addEdge(cav, name);
}
} );
ConnectivityInspector<Object, DefaultEdge> ci = new ConnectivityInspector<>(graph);
ci.connectedSets().stream().map(subgraph -> {
List<CandidateAnswerVariant> subCavs = subgraph.stream()
.filter(CandidateAnswerVariant.class::isInstance)
.map(CandidateAnswerVariant.class::cast).collect(toList());
return TypeFactory.createAnswer(jcas, TypeConstants.SCORE_UNKNOWN, subCavs);
} ).forEach(Answer::addToIndexes);
}
示例13: addVertexAndEdge
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private void addVertexAndEdge(Intent<? extends Resolution> fromIntent,
Intent<? extends Resolution> toIntent,
DirectedAcyclicGraph<Handler<? extends Intent<? extends Resolution>>, DefaultEdge> dag)
{
Handler<? extends Intent<? extends Resolution>> toHandler = handlerFactory.build(toIntent);
dag.addVertex(toHandler);
try
{
dag.addDagEdge(handlerFactory.build(fromIntent), toHandler);
}
catch (CycleFoundException e)
{
throw new RuntimeException("Cycle found building allegedly acyclical graph", e);
}
}
示例14: findParentNodes
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
public List<String> findParentNodes(String nodeID){
List<String> parentNodes = new LinkedList<>();
//Get incoming edges of given service
Set<DefaultEdge> incomingEdges = graphComposition.incomingEdgesOf(nodeID);
//Put the source nodes of the incomingEdges in the list of parentNodes
Iterator it = incomingEdges.iterator();
while (it.hasNext()) {
String sourceNode = graphComposition.getEdgeSource((DefaultEdge) it.next());
parentNodes.add(sourceNode);
}
return parentNodes;
}
示例15: getParameterOrdering
import org.jgrapht.graph.DefaultEdge; //导入依赖的package包/类
private List<Field> getParameterOrdering(DirectedGraph<Field, DefaultEdge> dependencyGraph) {
CycleDetector<Field, DefaultEdge> cycleDetector = new CycleDetector<Field, DefaultEdge>(dependencyGraph);
if (cycleDetector.detectCycles()) {
throw new RuntimeException("Cyclic dependency detected!");
} else {
TopologicalOrderIterator<Field, DefaultEdge> orderIterator;
Field f;
orderIterator = new TopologicalOrderIterator<Field, DefaultEdge>(dependencyGraph);
List<Field> output = new ArrayList<>(dependencyGraph.vertexSet().size());
while (orderIterator.hasNext()) {
f = orderIterator.next();
output.add(f);
}
return output;
}
}