本文整理汇总了Java中org.jgrapht.graph.SimpleDirectedGraph类的典型用法代码示例。如果您正苦于以下问题:Java SimpleDirectedGraph类的具体用法?Java SimpleDirectedGraph怎么用?Java SimpleDirectedGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleDirectedGraph类属于org.jgrapht.graph包,在下文中一共展示了SimpleDirectedGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineAndSolveConflicts
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
protected static void determineAndSolveConflicts(final PathBlockSet resultBlocks) {
// determine conflicts
final PathBlockSet deletedBlocks = new PathBlockSet();
final DirectedGraph<Block, BlockConflict> blockConflictGraph = new SimpleDirectedGraph<>(BlockConflict::of);
for (final Block block : resultBlocks.getBlocks()) {
blockConflictGraph.addVertex(block);
}
for (final Block x : blockConflictGraph.vertexSet()) {
createArcs(blockConflictGraph, resultBlocks, x);
}
// solve conflicts
while (true) {
final Optional<BlockConflict> mostUsefulConflictsFirst =
blockConflictGraph.edgeSet().stream().max(Comparator.comparingInt(BlockConflict::getQuality));
if (!mostUsefulConflictsFirst.isPresent()) {
break;
}
final BlockConflict blockConflict = mostUsefulConflictsFirst.get();
solveConflict(blockConflict, blockConflictGraph, resultBlocks, deletedBlocks);
}
}
示例2: loadGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Read this ldap record,{@code cn=Hierarchies, ou=OS-P} into this entity, {@link Hier}, before loading into this collection class,{@code org.jgrapht.graph.SimpleDirectedGraph}
* using 3rd party lib, <a href="http://www.jgrapht.org/">JGraphT</a>.
*
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing role hierarchies.
*/
private synchronized SimpleDirectedGraph<String, Relationship> loadGraph( String contextId )
{
Hier inHier = new Hier( Hier.Type.ROLE );
inHier.setContextId( contextId );
LOG.info( "loadGraph initializing ROLE context [{}]", inHier.getContextId() );
List<Graphable> descendants = null;
try
{
descendants = roleP.getAllDescendants( inHier.getContextId() );
}
catch ( SecurityException se )
{
LOG.info( "loadGraph caught SecurityException={}", se );
}
Hier hier = HierUtil.loadHier( contextId, descendants );
SimpleDirectedGraph<String, Relationship> graph;
graph = HierUtil.buildGraph( hier );
roleCache.put( getKey( contextId ), graph );
return graph;
}
示例3: getGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
*
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing role hierarchies.
*/
private SimpleDirectedGraph<String, Relationship> getGraph( String contextId )
{
String key = getKey( contextId );
LOG.debug("Getting graph for key " + contextId);
SimpleDirectedGraph<String, Relationship> graph = ( SimpleDirectedGraph<String, Relationship> ) roleCache
.get( key );
if(graph == null){
LOG.debug("Graph was null, creating... " + contextId);
return loadGraph( contextId );
}
else{
LOG.debug("Graph found in cache, returning...");
return graph;
}
}
示例4: toGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* This method converts from physical ldap entity format, {@link Hier} to logical {@code org.jgrapht.graph.SimpleDirectedGraph}.
*
* @param hier contains parent-child relationship in preparation to storing in ldap {@code ftRels} attribute of {@code ftHier} object class.
* @return {@code org.jgrapht.graph.SimpleDirectedGraph} containing the vertices of {@code String}, and edges, as {@link Relationship}s that correspond to relational data.
*/
private static SimpleDirectedGraph<String, Relationship> toGraph( Hier hier )
{
LOG.debug( "toGraph" );
SimpleDirectedGraph<String, Relationship> graph =
new SimpleDirectedGraph<>( Relationship.class );
List<Relationship> edges = hier.getRelationships();
if ( edges != null && edges.size() > 0 )
{
for ( Relationship edge : edges )
{
String child = edge.getChild();
String parent = edge.getParent();
try
{
graph.addVertex( child );
graph.addVertex( parent );
graph.addEdge( child, parent, edge );
}
catch (java.lang.IllegalArgumentException e)
{
String error = "toGraph child: " + child + " parent: " + parent + " caught IllegalArgumentException=" + e;
LOG.error( error );
}
LOG.debug( "toGraph child={}, parent={}", child, parent );
}
}
return graph;
}
示例5: getParents
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Private utility to return the parents (direct ascendants) of a given child node.
*
* @param vertex contains node name and acts as cursor for current location.
* @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
* @return Set of names that are parents of given child.
*/
static Set<String> getParents( String vertex, SimpleDirectedGraph<String, Relationship> graph )
{
Set<String> parents = new HashSet<>();
if ( graph == null )
{
// graph is null
return null;
}
LOG.debug( "getParents [{}]", vertex);
Set<Relationship> edges;
try
{
edges = graph.outgoingEdgesOf( vertex );
}
catch ( java.lang.IllegalArgumentException iae )
{
// vertex is leaf.
return null;
}
for ( Relationship edge : edges )
{
parents.add( edge.getParent() );
}
return parents;
}
示例6: buildGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Method instantiates a new digraph, {@code org.jgrapht.graph.SimpleDirectedGraph}, using data passed in via
* {@link Hier} entity.
*
* @param hier contains the source data for digraph.
* @return reference to {@code org.jgrapht.graph.SimpleDirectedGraph}.
*/
static SimpleDirectedGraph<String, Relationship> buildGraph( Hier hier )
{
SimpleDirectedGraph<String, Relationship> graph;
LOG.debug( "buildGraph is initializing" );
if ( hier == null )
{
String error = "buildGraph detected null hier=";
LOG.error( error );
return null;
}
graph = toGraph( hier );
LOG.debug( "buildGraph success to toGraph" );
LOG.debug( "buildGraph is success" );
return graph;
}
示例7: getGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing perm ou hierarchies.
*/
private SimpleDirectedGraph<String, Relationship> getGraph( String contextId )
{
String key = getKey( contextId );
LOG.debug("Getting graph for key " + contextId);
SimpleDirectedGraph<String, Relationship> graph = ( SimpleDirectedGraph<String, Relationship> ) psoCache
.get( key );
if(graph == null){
LOG.debug("Graph was null, creating... " + contextId);
return loadGraph( contextId );
}
else{
LOG.debug("Graph found in cache, returning...");
return graph;
}
}
示例8: getGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
*
* @return handle to simple digraph containing user ou hierarchies.
*/
private SimpleDirectedGraph<String, Relationship> getGraph( String contextId )
{
String key = getKey( contextId );
LOG.debug("Getting graph for key " + contextId);
SimpleDirectedGraph<String, Relationship> graph = ( SimpleDirectedGraph<String, Relationship> ) usoCache
.get( key );
if(graph == null){
LOG.debug("Graph was null, creating... " + contextId);
return loadGraph( contextId );
}
else{
LOG.debug("Graph found in cache, returning...");
return graph;
}
}
示例9: loadGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Read this ldap record,{@code cn=Hierarchies, ou=OS-P} into this entity, {@link Hier}, before loading into this collection class,{@code org.jgrapht.graph.SimpleDirectedGraph}
* using 3rd party lib, <a href="http://www.jgrapht.org/">JGraphT</a>.
*
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing adminRole hierarchies.
*/
private static synchronized SimpleDirectedGraph<String, Relationship> loadGraph( String contextId )
{
Hier inHier = new Hier( Hier.Type.ROLE );
inHier.setContextId( contextId );
LOG.info( "loadGraph initializing ADMIN ROLE context [{}]", inHier.getContextId() );
List<Graphable> descendants = null;
try
{
descendants = adminRoleP.getAllDescendants( inHier.getContextId() );
}
catch ( SecurityException se )
{
LOG.info( "loadGraph caught SecurityException={}", se );
}
Hier hier = HierUtil.loadHier( contextId, descendants );
SimpleDirectedGraph<String, Relationship> graph;
graph = HierUtil.buildGraph( hier );
adminRoleCache.put( getKey( contextId ), graph );
return graph;
}
示例10: getGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Read this ldap record,{@code cn=Hierarchies, ou=OS-P} into this entity, {@link Hier}, before loading into this collection class,{@code org.jgrapht.graph.SimpleDirectedGraph}
* using 3rd party lib, <a href="http://www.jgrapht.org/">JGraphT</a>.
*
* @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
* @return handle to simple digraph containing adminRole hierarchies.
*/
private static SimpleDirectedGraph<String, Relationship> getGraph( String contextId )
{
String key = getKey( contextId );
LOG.debug("Getting graph for key " + contextId);
SimpleDirectedGraph<String, Relationship> graph = ( SimpleDirectedGraph<String, Relationship> ) adminRoleCache
.get( key );
if(graph == null){
LOG.debug("Graph was null, creating... " + contextId);
return loadGraph( contextId );
}
else{
LOG.debug("Graph found in cache, returning...");
return graph;
}
}
示例11: getSpeciesInHierarchicalOrder
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDescription model) {
final DirectedGraph<SpeciesDescription, Object> hierarchy = new SimpleDirectedGraph<>(Object.class);
final DescriptionVisitor visitor = new DescriptionVisitor<SpeciesDescription>() {
@Override
public boolean visit(final SpeciesDescription desc) {
if (desc instanceof ModelDescription)
return true;
final SpeciesDescription sd = desc.getParent();
if (sd == null || sd == desc)
return false;
hierarchy.addVertex(desc);
if (!sd.isBuiltIn()) {
hierarchy.addVertex(sd);
hierarchy.addEdge(sd, desc);
}
return true;
}
};
model.visitAllSpecies(visitor);
return () -> new TopologicalOrderIterator<>(hierarchy);
}
示例12: sort
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
public List<String> sort(List<Class<?>> classes) throws OrderSortCycleException {
List<String> result = new ArrayList<>();
SimpleDirectedGraph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class);
for (OrderConstraint orderConstraint : getConstraints(classes)) {
graph.addVertex(orderConstraint.getFirst());
graph.addVertex(orderConstraint.getSecond());
graph.addEdge(orderConstraint.getFirst(), orderConstraint.getSecond());
}
CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(graph);
if(!cycleDetector.detectCycles()) {
for (TopologicalOrderIterator<String, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph); iterator.hasNext();) {
result.add(iterator.next());
}
} else {
String cycles = Joiner.on(", ").join(cycleDetector.findCycles());
throw new OrderSortCycleException("The given order constraints contain (at least one) cycle. Cycles can only "
+ "be caused by static references because we have single inherintance only in Java (involved classes: '" + cycles + "').");
}
return result;
}
示例13: checkDependencyCycles
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Check if there are any cycles in the dependencies of the modules.
*/
public void checkDependencyCycles(List<String> errors) {
if (!dependenciesResolved) {
throw new Error("Call resolveDependencies() first");
}
SimpleDirectedGraph<ModuleModel, Edge> g = buildModuleDependencyGraph();
CycleDetector<ModuleModel, Edge> detector = new CycleDetector<>(g);
Set<ModuleModel> cycleModules = detector.findCycles();
if (!cycleModules.isEmpty()) {
errors.add("Found cycle in module dependency graph. Involved modules: "
+ cycleModules);
}
}
示例14: directedGraph
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
/**
* Create a simple directed graph.
*
* @see http://en.wikipedia.org/wiki/Topological_sorting
*/
@SuppressWarnings("boxing")
public static DirectedGraph<Integer, DefaultEdge> directedGraph()
{
final DirectedGraph<Integer, DefaultEdge> g = new SimpleDirectedGraph<>(
DefaultEdge.class);
final Set<Integer> vertices = CollectionUtil.toSet(7, 5, 3, 11, 8, 2, 9, 10);
for (final Integer v : vertices)
{
g.addVertex(v);
}
g.addEdge(7, 8);
g.addEdge(7, 11);
g.addEdge(5, 11);
g.addEdge(3, 8);
g.addEdge(3, 10);
g.addEdge(11, 2);
g.addEdge(11, 9);
g.addEdge(11, 10);
g.addEdge(8, 9);
return g;
}
示例15: checkChildrenSets
import org.jgrapht.graph.SimpleDirectedGraph; //导入依赖的package包/类
private void checkChildrenSets(Set<String> oidsToCheck) {
SimpleDirectedGraph<String,DefaultEdge> tc = (SimpleDirectedGraph) 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);
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);
}
}