org.jgrapht.graph.SimpleDirectedGraph Java Examples
The following examples show how to use
org.jgrapht.graph.SimpleDirectedGraph.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelAssembler.java From gama with GNU General Public License v3.0 | 6 votes |
private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDescription model) { final DirectedGraph<SpeciesDescription, Object> hierarchy = new SimpleDirectedGraph<>(Object.class); final DescriptionVisitor visitor = desc -> { if (desc instanceof ModelDescription) { return true; } final SpeciesDescription sd = ((SpeciesDescription) desc).getParent(); if (sd == null || sd == desc) { return false; } hierarchy.addVertex((SpeciesDescription) desc); if (!sd.isBuiltIn()) { hierarchy.addVertex(sd); hierarchy.addEdge(sd, (SpeciesDescription) desc); } return true; }; model.visitAllSpecies(visitor); return () -> new TopologicalOrderIterator<>(hierarchy); }
Example #2
Source File: RoleUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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; }
Example #3
Source File: RoleUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * * @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; } }
Example #4
Source File: AdminRoleUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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; } }
Example #5
Source File: AdminRoleUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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; }
Example #6
Source File: UsoUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * * @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; } }
Example #7
Source File: PsoUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * @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; } }
Example #8
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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 ) { 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; }
Example #9
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * Utility function returns a set of all children (direct descendant) names. * * @param vertex contains the position of the cursor for traversal of graph. * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @return value contains the vertex of current position. */ static Set<String> getChildren( String vertex, SimpleDirectedGraph<String, Relationship> graph ) { Set<String> descendants = new HashSet<>(); if ( graph == null ) { return null; } LOG.debug( "getChildren [{}]", vertex ); Set<Relationship> edges; try { edges = graph.incomingEdgesOf( vertex ); } catch ( java.lang.IllegalArgumentException iae ) { // vertex is leaf. return null; } for ( Relationship edge : edges ) { descendants.add( edge.getChild() ); } return descendants; }
Example #10
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Utility function recursively traverses a given digraph to build a set of all descendants names. * * @param vertex contains the position of the cursor for traversal of graph. * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param descendants contains the result set of names of all descendants of node. * @return value contains the vertex of current position. */ private static String getDescendants( Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> descendants ) { String v = vertex.get( VERTEX ); if ( v == null ) { return null; } else if ( graph == null ) { return null; } LOG.debug( "getDescendants [{}]", v); Set<Relationship> edges; try { edges = graph.incomingEdgesOf( v ); } catch ( java.lang.IllegalArgumentException iae ) { // vertex is leaf. return null; } for ( Relationship edge : edges ) { vertex.put( VERTEX, edge.getChild() ); descendants.add( edge.getChild() ); v = getDescendants( vertex, graph, descendants ); } return v; }
Example #11
Source File: AdminMgrConsole.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * @param hier * @return * @throws org.apache.directory.fortress.core.SecurityException * */ public static SimpleDirectedGraph<String, Relationship> toGraphNotUsed(Hier hier) { LOG.info("toGraphX"); SimpleDirectedGraph<String, Relationship> graph = new SimpleDirectedGraph<>(Relationship.class); //List<String> roles = hier.getRoles(); //if (roles != null) //{ // for (String role : roles) // { // graph.addVertex(role); // } //} List<Relationship> edges = hier.getRelationships(); if (edges != null && edges.size() > 0) { for (Relationship edge : edges) { String child = edge.getChild(); String parent = edge.getParent(); graph.addVertex(child); graph.addVertex(parent); graph.addEdge(child, parent, edge); if (LOG.isDebugEnabled()) LOG.debug("toGraphX child=" + child + " parent=" + parent); } } return graph; }
Example #12
Source File: UsoUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * 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 user ou hierarchies. */ private synchronized SimpleDirectedGraph<String, Relationship> loadGraph( String contextId ) { Hier inHier = new Hier( Hier.Type.ROLE ); inHier.setContextId( contextId ); LOG.info( "loadGraph initializing USO context [{}]", inHier.getContextId() ); List<Graphable> descendants = null; try { OrgUnit orgUnit = new OrgUnit(); orgUnit.setType( OrgUnit.Type.USER ); orgUnit.setContextId( contextId ); descendants = orgUnitP.getAllDescendants( orgUnit ); } catch ( SecurityException se ) { LOG.info( "loadGraph caught SecurityException={}", se ); } Hier hier = HierUtil.loadHier( contextId, descendants ); SimpleDirectedGraph<String, Relationship> graph; graph = HierUtil.buildGraph( hier ); usoCache.put( getKey( contextId ), graph ); return graph; }
Example #13
Source File: PsoUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * 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 perm ou hierarchies. */ private synchronized SimpleDirectedGraph<String, Relationship> loadGraph( String contextId ) { Hier inHier = new Hier( Hier.Type.ROLE ); inHier.setContextId( contextId ); LOG.info( "loadGraph initializing PSO context [{}]", inHier.getContextId() ); List<Graphable> descendants = null; try { OrgUnit orgUnit = new OrgUnit(); orgUnit.setType( OrgUnit.Type.PERM ); orgUnit.setContextId( contextId ); descendants = orgUnitP.getAllDescendants( orgUnit ); } catch ( SecurityException se ) { LOG.info( "loadGraph caught SecurityException={}", se ); } Hier hier = HierUtil.loadHier( contextId, descendants ); SimpleDirectedGraph<String, Relationship> graph; graph = HierUtil.buildGraph( hier ); psoCache.put( getKey( contextId ), graph ); return graph; }
Example #14
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * 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 is success" ); return graph; }
Example #15
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * This api allows synchronized access to allow updates to hierarchical relationships. * Method will update the hierarchical data set and reload the JGraphT simple digraph with latest. * * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param relationship contains parent-child relationship targeted for addition. * @param op used to pass the ldap op {@link Hier.Op#ADD}, {@link Hier.Op#MOD}, {@link org.apache.directory.fortress.core.model.Hier.Op#REM} * @throws org.apache.directory.fortress.core.SecurityException in the event of a system error. */ static void updateHier( SimpleDirectedGraph<String, Relationship> graph, Relationship relationship, Hier.Op op ) throws SecurityException { if ( op == Hier.Op.ADD ) HierUtil.addEdge( graph, relationship ); else if ( op == Hier.Op.REM ) HierUtil.removeEdge( graph, relationship ); else throw new SecurityException( GlobalErrIds.HIER_CANNOT_PERFORM, CLS_NM + "updateHier Cannot perform hierarchical operation" ); }
Example #16
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Recursively traverse the hierarchical graph and return all of the ascendants of a given node. * * @param childName maps to vertex to determine parentage. * @param parentName points to top most ascendant where traversal must stop. * @param isInclusive if set to true will include the parentName in the result set. False will not return specified parentName. * @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> getAscendants( String childName, String parentName, boolean isInclusive, SimpleDirectedGraph<String, Relationship> graph ) { Map<String, String> vx = new HashMap<>(); // TreeSet will return in sorted order with case insensitive comparator: Set<String> parents = new TreeSet<>( String.CASE_INSENSITIVE_ORDER ); vx.put( VERTEX, childName.toUpperCase() ); getAscendants( vx, graph, parents, parentName, isInclusive ); return parents; }
Example #17
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Recursively traverse the hierarchical graph and determine if parent node contains a given child as one of its descendants. * * @param childName maps to vertex to determine parentage. * @param parentName maps to vertex to determine parentage. * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @return Set of names that are children of given parent. */ private static boolean isDescedant( String childName, String parentName, SimpleDirectedGraph<String, Relationship> graph ) { boolean isDescendant = false; Set<String> descendants = getDescendants( parentName, graph ); if ( descendants.contains( childName ) ) { isDescendant = true; } return isDescendant; }
Example #18
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Recursively traverse the hierarchical graph and return all of the descendants for a given node. * * @param parentName maps to vertex to determine parentage. * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @return Set of names that are children of given parent. */ static Set<String> getDescendants( String parentName, SimpleDirectedGraph<String, Relationship> graph ) { Map<String, String> vx = new HashMap<>(); // TreeSet will return in sorted order with case insensitive comparator: Set<String> children = new TreeSet<>( String.CASE_INSENSITIVE_ORDER ); vx.put( VERTEX, parentName.toUpperCase() ); getDescendants( vx, graph, children ); return children; }
Example #19
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Utility function recursively traverses a given digraph to build a set of all ascendant names. * * @param vertex contains the position of the cursor for traversal of graph. * @param graph contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param ascendants contains the result set of ascendant names. * @return value contains the vertex of current position. */ private static String getAscendants( Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> ascendants ) { String v = vertex.get( VERTEX ); if ( v == null ) { return null; } else if ( graph == null ) { return null; } LOG.debug( "getAscendants [{}]", v); Set<Relationship> edges; try { edges = graph.outgoingEdgesOf( v ); } catch ( java.lang.IllegalArgumentException iae ) { // vertex is leaf. return null; } for ( Relationship edge : edges ) { vertex.put( VERTEX, edge.getParent() ); ascendants.add( edge.getParent() ); v = getAscendants( vertex, graph, ascendants ); } return v; }
Example #20
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Recursively traverse the hierarchical graph and return all of the ascendants of a given node. * * @param childName maps to vertex to determine parentage. * @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> getAscendants( String childName, SimpleDirectedGraph<String, Relationship> graph ) { Map<String, String> vx = new HashMap<>(); // TreeSet will return in sorted order with case insensitive comparator: Set<String> parents = new TreeSet<>( String.CASE_INSENSITIVE_ORDER ); vx.put( VERTEX, childName.toUpperCase() ); getAscendants( vx, graph, parents ); return parents; }
Example #21
Source File: SubtourSeparatorDemo.java From jorlib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Example on directed graph */ public static void example2(){ //Define a new Directed Graph. For simplicity we'll use a simple, unweighted graph. Graph<Integer, DefaultEdge> directedGraph=new SimpleDirectedGraph<Integer, DefaultEdge>(DefaultEdge.class); Graphs.addAllVertices(directedGraph, Arrays.asList(1,2,3,4,5,6)); directedGraph.addEdge(1, 2); directedGraph.addEdge(2, 3); directedGraph.addEdge(3, 4); directedGraph.addEdge(4, 1); directedGraph.addEdge(1, 4); directedGraph.addEdge(1, 5); directedGraph.addEdge(5, 1); directedGraph.addEdge(4, 5); directedGraph.addEdge(5, 4); directedGraph.addEdge(6, 2); directedGraph.addEdge(3, 6); //Define the x_e values for every edge e\in E Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>(); edgeValueMap.put(directedGraph.getEdge(1,2), 0.0); edgeValueMap.put(directedGraph.getEdge(2,3), 1.0); edgeValueMap.put(directedGraph.getEdge(3,4), 0.0); edgeValueMap.put(directedGraph.getEdge(4,1), 0.5); edgeValueMap.put(directedGraph.getEdge(1,4), 0.5); edgeValueMap.put(directedGraph.getEdge(1,5), 0.5); edgeValueMap.put(directedGraph.getEdge(5,1), 0.5); edgeValueMap.put(directedGraph.getEdge(4,5), 0.5); edgeValueMap.put(directedGraph.getEdge(5,4), 0.5); edgeValueMap.put(directedGraph.getEdge(6,2), 1.0); edgeValueMap.put(directedGraph.getEdge(3,6), 1.0); //Invoke the separator SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(directedGraph); separator.separateSubtour(edgeValueMap); System.out.println("Has found a violated subtour: "+separator.hasSubtour()); System.out.println("Cut value: "+separator.getCutValue()); System.out.println("Cut set: "+separator.getCutSet()); //The returned cut set is: {2,3,6}. This leads to the cut: \sum_{e\in \delta{2,3,6}} x_e >=2 }
Example #22
Source File: SubtourSeparatorTest.java From jorlib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Test 3 - Directed, incomplete graph without a subtour. */ public void testDirectedGraphWithSubtour(){ //Define a new Directed Graph. For simplicity we'll use a simple, unweighted graph. Graph<Integer, DefaultEdge> directedGraph=new SimpleDirectedGraph<Integer, DefaultEdge>(DefaultEdge.class); Graphs.addAllVertices(directedGraph, Arrays.asList(1,2,3,4,5,6)); directedGraph.addEdge(1, 2); directedGraph.addEdge(2, 3); directedGraph.addEdge(3, 4); directedGraph.addEdge(4, 1); directedGraph.addEdge(1, 4); directedGraph.addEdge(1, 5); directedGraph.addEdge(5, 1); directedGraph.addEdge(4, 5); directedGraph.addEdge(5, 4); directedGraph.addEdge(6, 2); directedGraph.addEdge(3, 6); //Define the x_e values for every edge e\in E Map<DefaultEdge, Double> edgeValueMap=new HashMap<DefaultEdge, Double>(); edgeValueMap.put(directedGraph.getEdge(1,2), 0.0); edgeValueMap.put(directedGraph.getEdge(2,3), 1.0); edgeValueMap.put(directedGraph.getEdge(3,4), 0.0); edgeValueMap.put(directedGraph.getEdge(4,1), 0.5); edgeValueMap.put(directedGraph.getEdge(1,4), 0.5); edgeValueMap.put(directedGraph.getEdge(1,5), 0.5); edgeValueMap.put(directedGraph.getEdge(5,1), 0.5); edgeValueMap.put(directedGraph.getEdge(4,5), 0.5); edgeValueMap.put(directedGraph.getEdge(5,4), 0.5); edgeValueMap.put(directedGraph.getEdge(6,2), 1.0); edgeValueMap.put(directedGraph.getEdge(3,6), 1.0); //Invoke the separator SubtourSeparator<Integer, DefaultEdge> separator=new SubtourSeparator<Integer, DefaultEdge>(directedGraph); separator.separateSubtour(edgeValueMap); assertTrue(separator.hasSubtour()); assertEquals(0, separator.getCutValue(), PRECISION); assertEquals(new HashSet<Integer>(Arrays.asList(2,3,6)), separator.getCutSet()); }
Example #23
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * This method is synchronized and removes an edge from a simple directed graph stored in static memory of this process. * * @param graph synchronized parameter contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param relation contains parent-child relationship targeted for removal. * @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 void removeEdge( SimpleDirectedGraph<String, Relationship> graph, Relationship relation ) { LOG.debug( "removeEdge" ); synchronized ( graph ) { graph.removeEdge( relation ); } }
Example #24
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * This method is synchronized and adds an edge and its associated vertices to simple directed graph stored in static memory of this process. * * @param graph synchronized parameter contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}. * @param relation contains parent-child relationship targeted for addition. * @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 void addEdge( SimpleDirectedGraph<String, Relationship> graph, Relationship relation ) { LOG.debug( "addEdge" ); synchronized ( graph ) { graph.addVertex( relation.getChild().toUpperCase() ); graph.addVertex( relation.getParent().toUpperCase() ); graph.addEdge( relation.getChild().toUpperCase(), relation.getParent().toUpperCase(), relation ); } }
Example #25
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * 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; }
Example #26
Source File: TrajectoryEnvelopeCoordinator.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
private SimpleDirectedGraph<Integer,Dependency> depsToGraph(HashSet<Dependency> deps) { SimpleDirectedGraph<Integer,Dependency> g = new SimpleDirectedGraph<Integer,Dependency>(Dependency.class); for (Dependency dep : deps) { g.addVertex(dep.getWaitingRobotID()); g.addVertex(dep.getDrivingRobotID()); if (!g.addEdge(dep.getWaitingRobotID(), dep.getDrivingRobotID(), dep)) metaCSPLogger.severe("<<<<<<<<< Add dependency fails (13). Dep: " + dep); } return g; }
Example #27
Source File: JBossModuleLoader.java From Nicobar with Apache License 2.0 | 5 votes |
/** * Construct the Module dependency graph of a module loader where each vertex is the module name * @return a mutable snapshot of the underlying dependency */ public DirectedGraph<ModuleId, DefaultEdge> getModuleNameGraph() { SimpleDirectedGraph<ModuleId, DefaultEdge> graph = new SimpleDirectedGraph<ModuleId, DefaultEdge>(DefaultEdge.class); Map<ModuleId, ModuleIdentifier> moduleIdentifiers = getLatestRevisionIds(); GraphUtils.addAllVertices(graph, moduleIdentifiers.keySet()); for (Entry<ModuleId, ModuleIdentifier> entry : moduleIdentifiers.entrySet()) { ModuleId scriptModuleId = entry.getKey(); ModuleIdentifier revisionID = entry.getValue(); ModuleSpec moduleSpec = moduleSpecs.get(revisionID); Set<ModuleId> dependencyNames = getDependencyScriptModuleIds(moduleSpec); GraphUtils.addOutgoingEdges(graph, scriptModuleId, dependencyNames); } return graph; }
Example #28
Source File: HierUtil.java From directory-fortress-core with Apache License 2.0 | 4 votes |
/** * Private utility to recursively traverse the hierarchical graph and return all of the 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}. * @param parents contains the result set of parent nodes. * @param stopName contains the name of node where traversal ends. * @param isInclusive if set to true will include the parentName in the result set. False will not return specified parentName. * @return Set of names that are parents of given child. */ private static String getAscendants( Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> parents, String stopName, boolean isInclusive ) { String v = vertex.get( VERTEX ); if ( v == null ) { return null; } else if ( graph == null ) { return null; } LOG.debug( "getAscendants [{}]", v); Set<Relationship> edges; try { edges = graph.outgoingEdgesOf( v ); } catch ( java.lang.IllegalArgumentException iae ) { // vertex is leaf. return null; } for ( Relationship edge : edges ) { if ( edge.getParent().equalsIgnoreCase( stopName ) ) { if ( isInclusive ) { parents.add( edge.getParent() ); } break; } else { vertex.put( VERTEX, edge.getParent() ); parents.add( edge.getParent() ); v = getAscendants( vertex, graph, parents, stopName, isInclusive ); } } return v; }
Example #29
Source File: GamlResourceIndexer.java From gama with GNU General Public License v3.0 | 4 votes |
public static void eraseIndex() { // DEBUG.OUT("Erasing GAML indexer index"); index = new SimpleDirectedGraph(Edge.class); }
Example #30
Source File: AdminMgrConsole.java From directory-fortress-core with Apache License 2.0 | 4 votes |
/** * @param g */ private static String getParents(Map vertex, SimpleDirectedGraph<String, Relationship> g, List<String> parents) { String v; //ReaderUtil.clearScreen(); //System.out.println("addJGraph"); //String vertex = "Max"; v = (String) vertex.get("Vertex"); if (g == null) { System.out.println("getAscendants simple directed graph is null"); return null; } if (v == null) { System.out.println("getAscendants simple directed graph is null"); return null; } System.out.println("getAscendants V [" + v + "]"); Set<Relationship> edges = g.outgoingEdgesOf(v); for (Relationship edge : edges) { if (v == null) return null; else { System.out.println("Edge:" + edge); //parents.add(edge.toString()); v = edge.toString(); //Max : Super //getAscendants V <Super)> int indx = v.indexOf(GlobalIds.PROP_SEP); int indx2 = v.indexOf(')'); if (indx >= 0) { v = v.substring(indx + 2, indx2); } //String parent = vertex.put("Vertex", v); if (!v.equalsIgnoreCase("Root")) parents.add(v); v = getParents(vertex, g, parents); } } return v; }