本文整理汇总了Java中edu.uci.ics.jung.graph.SparseMultigraph类的典型用法代码示例。如果您正苦于以下问题:Java SparseMultigraph类的具体用法?Java SparseMultigraph怎么用?Java SparseMultigraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SparseMultigraph类属于edu.uci.ics.jung.graph包,在下文中一共展示了SparseMultigraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveLayer
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
@Test
public void testRemoveLayer(){
Graph<String, String> graph = new SparseMultigraph<>();
graph.addVertex("v1");
graph.addVertex("v2");
graph.addVertex("v3");
graph.addEdge("e1", "v1", "v2", EdgeType.DIRECTED);
graph.addEdge("e2", "v2", "v1", EdgeType.DIRECTED);
graph.addEdge("e3", "v3", "v2", EdgeType.DIRECTED);
DependencyGraph.removeLayer(graph);
assertEquals(2, graph.getVertexCount());
assertEquals(2, graph.getEdgeCount());
assertTrue(graph.getVertices().contains("v1"));
assertTrue(graph.getVertices().contains("v2"));
assertTrue(graph.getEdges().contains("e1"));
assertTrue(graph.getEdges().contains("e2"));
}
示例2: testJUNG2
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
@Test
public void testJUNG2() throws Exception {
Graph<String, String> graph = new SparseMultigraph<String, String>();
graph.addVertex("state 1");
graph.addVertex("state 2");
graph.addVertex("state 3");
graph.addVertex("state 4");
graph.addVertex("state 5");
graph.addVertex("state 6");
graph.addEdge("edge 1", "state 1", "state 2", EdgeType.DIRECTED);
graph.addEdge("edge 2", "state 1", "state 3", EdgeType.DIRECTED);
graph.addEdge("edge 3", "state 1", "state 4", EdgeType.DIRECTED);
graph.addEdge("edge 4", "state 3", "state 4", EdgeType.DIRECTED);
CircleLayout<String, String> layout = new CircleLayout<String, String>(graph);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<String, String> visualization = new BasicVisualizationServer<String, String>(layout);
visualization.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
visualization.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());
visualization.setPreferredSize(new Dimension(350, 350));
JOptionPane.showMessageDialog(null, visualization);
}
示例3: groupCluster
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
private void groupCluster(AggregateLayout<Number,Number> layout, Set<Number> vertices) {
if(vertices.size() < layout.getGraph().getVertexCount()) {
Point2D center = layout.transform(vertices.iterator().next());
Graph<Number,Number> subGraph = SparseMultigraph.<Number,Number>getFactory().create();
for(Number v : vertices) {
subGraph.addVertex(v);
}
Layout<Number,Number> subLayout =
new CircleLayout<Number,Number>(subGraph);
subLayout.setInitializer(vv.getGraphLayout());
subLayout.setSize(new Dimension(40,40));
layout.put(subLayout,center);
vv.repaint();
}
}
示例4: createDependencyGraph
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
private Graph<AnalysisEngine, Integer> createDependencyGraph(List<AnalysisEngine> analysisEngines){
Graph<AnalysisEngine, Integer> graph = new SparseMultigraph<>();
//First, add all annotators onto the graph
for(AnalysisEngine ae : analysisEngines)
graph.addVertex(ae);
//Now add dependencies between annotators
for(AnalysisEngine ae1 : analysisEngines){
for(AnalysisEngine ae2 : analysisEngines){
if(ae1 == ae2)
continue;
addAnnotatorDependencies(graph, ae1, ae2);
}
}
return graph;
}
示例5: testRemoveLoops
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
@Test
public void testRemoveLoops(){
Graph<String, String> graph = new SparseMultigraph<>();
graph.addVertex("v1");
graph.addVertex("v2");
graph.addVertex("v3");
graph.addEdge("e1", "v1", "v2", EdgeType.DIRECTED);
graph.addEdge("e2", "v2", "v1", EdgeType.DIRECTED);
graph.addEdge("e3", "v1", "v3", EdgeType.DIRECTED);
DependencyGraph.removeLoops(graph);
assertEquals(3, graph.getVertexCount());
assertEquals(2, graph.getEdgeCount());
assertTrue(graph.getEdges().contains("e1"));
assertTrue(graph.getEdges().contains("e3"));
}
示例6: RoleGraphViewer
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
/** Creates a new instance of SimpleGraphView */
public RoleGraphViewer() {
// Graph<V, E> where V is the type of the vertices and E is the type of
// the edges
g = new SparseMultigraph<Integer, String>();
nodeCount = 0;
edgeCount = 0;
vertexFactory = new Factory<Integer>() { // My vertex factory
public Integer create() {
return nodeCount++;
}
};
edgeFactory = new Factory<String>() { // My edge factory
public String create() {
return "E" + edgeCount++;
}
};
}
示例7: main
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
GraphPartitioningVisualization cd = new GraphPartitioningVisualization() {
private static final long serialVersionUID = 1L;
@Override
public Graph<NodeWrapper, EdgeWrapper> getGraph() {
return new SparseMultigraph<NodeWrapper, EdgeWrapper>();
}
@Override
public String getIteracao() {
return "2";// any
}
@Override
public int getCut() {
return 0;
}
};
cd.executeView(2);
}
示例8: getEntitiesGraph
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
public static Graph<NamedEntity, Edge> getEntitiesGraph(Map<Long, List<NamedEntity>> entitiesPerStatus) {
Graph<NamedEntity, Edge> graph = new SparseMultigraph<NamedEntity, Edge>();
for(Entry<Long, List<NamedEntity>> entry : entitiesPerStatus.entrySet()) {
List<NamedEntity> eColl = entry.getValue();
for(int i=0; i<eColl.size(); i++) {
for(int j=i+1; j<eColl.size(); j++) {
NamedEntity e1 = eColl.get(i);
NamedEntity e2 = eColl.get(j);
graph.addVertex(e1);
graph.addVertex(e2);
Edge edge = graph.findEdge(e1, e2);
if(edge == null) {
edge = new Edge();
graph.addEdge(edge, e1, e2);
}
else {
edge.incFrequency();
}
}
}
}
return graph;
}
示例9: getSmallGraph
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
/**
* Returns a small graph with directed and undirected edges, and parallel edges.
*/
public static Graph<String, Number> getSmallGraph() {
Graph<String, Number> graph =
new SparseMultigraph<String, Number>();
String[] v = new String[3];
for (int i = 0; i < 3; i++) {
v[i] = String.valueOf(i);
graph.addVertex(v[i]);
}
graph.addEdge(new Double(0), v[0], v[1], EdgeType.DIRECTED);
graph.addEdge(new Double(.1), v[0], v[1], EdgeType.DIRECTED);
graph.addEdge(new Double(.2), v[0], v[1], EdgeType.DIRECTED);
graph.addEdge(new Double(.3), v[1], v[0], EdgeType.DIRECTED);
graph.addEdge(new Double(.4), v[1], v[0], EdgeType.DIRECTED);
graph.addEdge(new Double(.5), v[1], v[2]);
graph.addEdge(new Double(.6), v[1], v[2]);
return graph;
}
示例10: generateVertexGrid
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
private Graph<String,Number> generateVertexGrid(Map<String,Point2D> map,
Dimension d, int interval) {
int count = d.width/interval * d.height/interval;
Graph<String,Number> graph = new SparseMultigraph<String,Number>();
String[] v = new String[count];
for(int i=0; i<count; i++) {
int x = interval*i;
int y = x / d.width * interval;
x %= d.width;
Point2D location = new Point2D.Float(x, y);
v[i] = ""+i;
map.put(v[i], location);
graph.addVertex(v[i]);
}
return graph;
}
示例11: MapperEngine
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
public MapperEngine() {
graph = new SparseMultigraph<Room, Exit>();
mapperLayout = new MapperLayout( graph );
mapperLayout.setSize( new Dimension( 500, 500 ) ); //????
vv = new VisualizationViewer<Room, Exit>( mapperLayout );
pickedState = vv.getPickedVertexState();
pickedState.addItemListener( this );
vv.setPreferredSize( new Dimension( 500, 500 ) ); //????
RenderContext<Room, Exit> rc = vv.getRenderContext();
rc.setEdgeLabelTransformer( new ToStringLabeller<Exit>() );
rc.setEdgeLabelRenderer( new ExitLabelRenderer() );
rc.setEdgeShapeTransformer( new EdgeShape.QuadCurve<Room, Exit>() );
rc.setEdgeShapeTransformer( new EdgeShape.Wedge<Room, Exit>( 30 ) );
rc.setEdgeFillPaintTransformer( new ExitPaintTransformer( vv ) );
rc.setVertexShapeTransformer( new RoomShape( graph ) );
rc.setVertexIconTransformer( new RoomIconTransformer() );
vv.getRenderContext().setLabelOffset( 5 );
PluggableGraphMouse pgm = new PluggableGraphMouse();
pgm.add( new MapperPickingGraphMousePlugin<Room, Exit>( MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON3_MASK ) );
pgm.add( new TranslatingGraphMousePlugin( MouseEvent.BUTTON1_MASK ) );
scaler = new ScalingGraphMousePlugin( new CrossoverScalingControl(), 0, 1 / 1.1f, 1.1f );
pgm.add( scaler );
mousePlugin = new MapperEditingGraphMousePlugin( this );
pgm.add( mousePlugin );
vv.setGraphMouse( pgm );
panel = new MapperPanel( this );
}
示例12: makeSaveObject
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
private static AreaSaveObject makeSaveObject( String basedir, SparseMultigraph<Room, Exit> graph, Layout<Room, Exit> layout ) throws IOException {
AreaSaveObject saveObject = new AreaSaveObject();
saveObject.setGraph( graph );
Map<Room, Point2D> locations = saveObject.getLocations();
for (Room room : graph.getVertices()) {
Point2D coord = layout.transform( room );
locations.put( room, coord );
}
saveObject.setFileName( getFileNameFrom( basedir, graph.getVertices().iterator().next().getArea().getName() ) );
// System.out.println("\n\n+nsaveobjectdone\n\n\n"+saveObject.getFileName());
return saveObject;
}
示例13: addLinks
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
public synchronized void addLinks(List<Link> links) {
if(links == null || links.isEmpty()) {
LOG.debug("In addLinks: No link added as links is null or empty.");
return;
}
if(networkGraph == null) {
networkGraph = new SparseMultigraph<>();
}
for(Link link : links) {
if(linkAlreadyAdded(link)) {
continue;
}
NodeId sourceNodeId = link.getSource().getSourceNode();
NodeId destinationNodeId = link.getDestination().getDestNode();
networkGraph.addVertex(sourceNodeId);
networkGraph.addVertex(destinationNodeId);
networkGraph.addEdge(link, sourceNodeId, destinationNodeId, EdgeType.UNDIRECTED);
}
LOG.info("Created topology graph {} ", networkGraph);
if(shortestPath == null) {
shortestPath = new DijkstraShortestPath<>(networkGraph);
} else {
shortestPath.reset();
}
LOG.info("Shortest paths {} ", shortestPath);
}
示例14: groupCluster
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
private void groupCluster(AggregateLayout<NodeWrapper, EdgeWrapper> layout, Set<NodeWrapper> vertices,
boolean circleClusters) {
Point2D center = layout.transform(vertices.iterator().next());
Graph<NodeWrapper, EdgeWrapper> subGraph = SparseMultigraph.<NodeWrapper, EdgeWrapper> getFactory().create();
for (NodeWrapper v : vertices) {
subGraph.addVertex(v);
}
Layout<NodeWrapper, EdgeWrapper> subLayout = null;
if (circleClusters) {
CircleLayout<NodeWrapper, EdgeWrapper> circleLayout = new CircleLayout<NodeWrapper, EdgeWrapper>(subGraph);
circleLayout.setRadius(getGraph().getVertexCount() * 4);
circleLayout.setSize(new Dimension(200, 400));
circleLayout.setVertexOrder(new Comparator<NodeWrapper>() {
@Override
public int compare(NodeWrapper o1, NodeWrapper o2) {
return o1.getId() < o2.getId() ? -1 : 1;
}
});
subLayout = circleLayout;
} else {
subLayout = new KKLayout<NodeWrapper, EdgeWrapper>(subGraph);
// UTIL: verificar o algoritmo e uso dessa classe: VoltageClusterer
// subLayout = new VoltageClusterer<NodeWrapper,
// EdgeWrapper>(subGraph, 2);
// subLayout = new FRLayout2<NodeWrapper,
// EdgeWrapper>(subGraph); //esse layout dá erro
}
subLayout.setInitializer(vv.getGraphLayout());
subLayout.setSize(new Dimension((int) getSize().getWidth() / 2, (int) getSize().getHeight() / 2));
layout.put(subLayout, center);
vv.repaint();
}
示例15: SimpleGraphView
import edu.uci.ics.jung.graph.SparseMultigraph; //导入依赖的package包/类
/** Creates a new instance of SimpleGraphView */
public SimpleGraphView( File f ) {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
g = new SparseMultigraph<Integer, String>();
// Add some vertices. From above we defined these to be type Integer.
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)3);
// Note that the default is for undirected edges, our Edges are Strings.
g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
g.addEdge("Edge-B", 2, 3);
g.addEdge("Edge-C", 1, 3);
}