use of org.jgrapht.graph.DefaultEdge in project graal by graphik-team.
the class GraphPositionDependencies method initFiniteRank.
public void initFiniteRank() {
if (this.isFiniteRank == null) {
this.isFiniteRank = new TreeSet<PredicatePosition>();
StrongConnectivityAlgorithm<PredicatePosition, DefaultEdge> sccInspector = new KosarajuStrongConnectivityInspector<PredicatePosition, DefaultEdge>(graph);
List<Set<PredicatePosition>> sccList = sccInspector.stronglyConnectedSets();
for (Set<PredicatePosition> scc : sccList) {
boolean componentIsFiniteRank = true;
for (PredicatePosition p1 : scc) {
for (PredicatePosition p2 : scc) {
for (DefaultEdge edge : graph.getAllEdges(p1, p2)) {
if (edge instanceof SpecialEdge) {
componentIsFiniteRank = false;
}
}
}
}
// store information
if (componentIsFiniteRank) {
for (PredicatePosition p : scc) {
this.isFiniteRank.add(p);
}
}
}
}
}
use of org.jgrapht.graph.DefaultEdge in project midpoint by Evolveum.
the class AbstractOrgClosureTest method checkChildrenSets.
private void checkChildrenSets(Set<String> oidsToCheck) {
try (Session session = openSession()) {
// noinspection unchecked
SimpleDirectedGraph<String, DefaultEdge> tc = (SimpleDirectedGraph<String, DefaultEdge>) orgGraph.clone();
TransitiveClosure.INSTANCE.closeSimpleDirectedGraph(tc);
for (String subroot : oidsToCheck) {
logger.info("Checking descendants of {}", subroot);
Set<String> expectedChildren = new HashSet<>();
for (DefaultEdge edge : tc.incomingEdgesOf(subroot)) {
expectedChildren.add(tc.getEdgeSource(edge));
}
expectedChildren.add(subroot);
logger.trace("Expected children: {}", expectedChildren);
Set<String> actualChildren = getActualChildrenOf(subroot, session);
logger.trace("Actual children: {}", actualChildren);
Set<String> expectedMinusActual = new HashSet<>(expectedChildren);
expectedMinusActual.removeAll(actualChildren);
if (!expectedMinusActual.isEmpty()) {
System.out.println("Expected-Actual = " + expectedMinusActual);
}
Set<String> actualMinusExpected = new HashSet<>(actualChildren);
actualMinusExpected.removeAll(expectedChildren);
if (!actualMinusExpected.isEmpty()) {
System.out.println("Actual-Expected = " + actualMinusExpected);
}
assertEquals("Incorrect children for " + subroot, expectedChildren, actualChildren);
}
}
}
use of org.jgrapht.graph.DefaultEdge in project midpoint by Evolveum.
the class AbstractOrgClosureTest method checkOrgGraph.
// checks org graph w.r.t. real org/parentref situation in repo
protected void checkOrgGraph() throws SchemaException {
OperationResult result = new OperationResult("temp");
int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, null, null, result);
info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size());
Assertions.assertThat(orgGraph.vertexSet()).withFailMessage("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")").hasSize(numberOfOrgsInRepo);
for (String oid : orgGraph.vertexSet()) {
// info("Checking " + oid);
OrgType orgType;
try {
orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable();
} catch (ObjectNotFoundException | SchemaException e) {
throw new AssertionError("Couldn't fetch " + oid, e);
}
assertTrue(orgGraph.vertexSet().contains(orgType.getOid()));
Set<String> parentOidsInRepo = new HashSet<>();
for (ObjectReferenceType ort : orgType.getParentOrgRef()) {
if (orgGraph.vertexSet().contains(ort.getOid())) {
// i.e. the parent does exist
parentOidsInRepo.add(ort.getOid());
}
}
Set<String> parentOidsInGraph = new HashSet<>();
for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) {
parentOidsInGraph.add(orgGraph.getEdgeTarget(edge));
}
assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo);
}
info("Graph is OK w.r.t. repo");
}
use of org.jgrapht.graph.DefaultEdge in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method loadModuleExtension.
private void loadModuleExtension(ExtensionDeclarer declarer, URL resource, Document moduleDocument, Set<ExtensionModel> extensions, boolean comesFromTNS) {
final ComponentModel moduleModel = getModuleComponentModel(resource, moduleDocument);
if (!moduleModel.getIdentifier().equals(MODULE_IDENTIFIER)) {
throw new MuleRuntimeException(createStaticMessage(format("The root element of a module must be '%s', but found '%s'", MODULE_IDENTIFIER.toString(), moduleModel.getIdentifier().toString())));
}
final String name = moduleModel.getParameters().get(MODULE_NAME);
// TODO(fernandezlautaro): MULE-11010 remove version from ExtensionModel
final String version = "4.0.0";
final String category = moduleModel.getParameters().get(CATEGORY);
final String vendor = moduleModel.getParameters().get(VENDOR);
final XmlDslModel xmlDslModel = getXmlDslModel(moduleModel, name, version);
final String description = getDescription(moduleModel);
final String xmlnsTnsValue = moduleModel.getParameters().get(XMLNS_TNS);
if (xmlnsTnsValue != null && !xmlDslModel.getNamespace().equals(xmlnsTnsValue)) {
throw new MuleRuntimeException(createStaticMessage(format("The %s attribute value of the module must be '%s', but found '%s'", XMLNS_TNS, xmlDslModel.getNamespace(), xmlnsTnsValue)));
}
fillDeclarer(declarer, name, version, category, vendor, xmlDslModel, description);
declarer.withModelProperty(getXmlExtensionModelProperty(moduleModel, xmlDslModel));
DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
// loading public operations
final Optional<ConfigurationDeclarer> configurationDeclarer = loadPropertiesFrom(declarer, moduleModel, extensions);
final HasOperationDeclarer hasOperationDeclarer = configurationDeclarer.isPresent() ? configurationDeclarer.get() : declarer;
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PUBLIC);
// loading private operations
if (comesFromTNS) {
// when parsing for the TNS, we need the <operation/>s to be part of the extension model to validate the XML properly
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
} else {
// when parsing for the macro expansion, the <operation/>s will be left in the PrivateOperationsModelProperty model property
final ExtensionDeclarer temporalDeclarer = new ExtensionDeclarer();
fillDeclarer(temporalDeclarer, name, version, category, vendor, xmlDslModel, description);
loadOperationsFrom(temporalDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
final ExtensionModel result = createExtensionModel(temporalDeclarer);
declarer.withModelProperty(new PrivateOperationsModelProperty(result.getOperationModels()));
}
final CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(directedGraph);
final Set<String> cycles = cycleDetector.findCycles();
if (!cycles.isEmpty()) {
throw new MuleRuntimeException(createStaticMessage(format(CYCLIC_OPERATIONS_ERROR, new TreeSet(cycles))));
}
}
use of org.jgrapht.graph.DefaultEdge in project presto by prestodb.
the class PhasedExecutionSchedule method extractPhases.
@VisibleForTesting
static List<Set<PlanFragmentId>> extractPhases(Collection<PlanFragment> fragments) {
// Build a graph where the plan fragments are vertexes and the edges represent
// a before -> after relationship. For example, a join hash build has an edge
// to the join probe.
DirectedGraph<PlanFragmentId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
fragments.forEach(fragment -> graph.addVertex(fragment.getId()));
Visitor visitor = new Visitor(fragments, graph);
for (PlanFragment fragment : fragments) {
visitor.processFragment(fragment.getId());
}
// Computes all the strongly connected components of the directed graph.
// These are the "phases" which hold the set of fragments that must be started
// at the same time to avoid deadlock.
List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
Map<PlanFragmentId, Set<PlanFragmentId>> componentMembership = new HashMap<>();
for (Set<PlanFragmentId> component : components) {
for (PlanFragmentId planFragmentId : component) {
componentMembership.put(planFragmentId, component);
}
}
// build graph of components (phases)
DirectedGraph<Set<PlanFragmentId>, DefaultEdge> componentGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
components.forEach(componentGraph::addVertex);
for (DefaultEdge edge : graph.edgeSet()) {
PlanFragmentId source = graph.getEdgeSource(edge);
PlanFragmentId target = graph.getEdgeTarget(edge);
Set<PlanFragmentId> from = componentMembership.get(source);
Set<PlanFragmentId> to = componentMembership.get(target);
if (!from.equals(to)) {
// the topological order iterator below doesn't include vertices that have self-edges, so don't add them
componentGraph.addEdge(from, to);
}
}
List<Set<PlanFragmentId>> schedulePhases = ImmutableList.copyOf(new TopologicalOrderIterator<>(componentGraph));
return schedulePhases;
}
Aggregations