本文整理汇总了Java中org.graphstream.graph.Graph类的典型用法代码示例。如果您正苦于以下问题:Java Graph类的具体用法?Java Graph怎么用?Java Graph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于org.graphstream.graph包,在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCuttingEdgesCount
import org.graphstream.graph.Graph; //导入依赖的package包/类
public Integer getCuttingEdgesCount(Graph gr) {
Integer cuttingEdges = 0;
Collection<Edge> edges = gr.getEdgeSet();
for (Edge edge : edges) {
Node n0 = edge.getNode0();
Node n1 = edge.getNode1();
if (n0.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE) &&
n1.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) {
if (!n0.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE).equals(
n1.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))) {
cuttingEdges++;
}
}
}
return cuttingEdges;
}
示例2: save
import org.graphstream.graph.Graph; //导入依赖的package包/类
public void save(final File file) throws IOException {
//noinspection ResultOfMethodCallIgnored
file.getParentFile().mkdirs();
final FileSinkImages fsi = new FileSinkImages();
fsi.setLayoutPolicy(LayoutPolicy.NO_LAYOUT);
fsi.setQuality(Quality.HIGH);
fsi.setResolution(Resolutions.HD720);
final Graph graph = getGraph();
graph.clearSinks();
graph.addSink(fsi);
fsi.writeAll(graph, file.getCanonicalPath());
}
示例3: generateGraph
import org.graphstream.graph.Graph; //导入依赖的package包/类
/**
* Random seed taken for simulator: for each seed the same barabasi network
* is generated with getMaxLinkPerNode and getNumUsers nodes
*/
public static Graph generateGraph(long seedNetwork, int maxLinkPerNode, int nodes) {
System.setProperty("org.graphstream.ui.renderer",
"org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph graph = new SingleGraph("Social network");
String path = (new File(BTSim.getProperty("graphStylePath"))).getAbsolutePath();
graph.addAttribute("ui.stylesheet", "url('" + path + "')"); //style of graph
// Between 1 and maxLinkPerNode new links per node added.
Generator gen = new BarabasiAlbertGenerator(maxLinkPerNode);
// Generate numUsers nodes:
((BaseGenerator) gen).setRandomSeed(seedNetwork);
gen.addSink(graph);
gen.begin();
for (int i = 0; i < nodes - 2; i++) {//barabasi starts with 2 agents
gen.nextEvents();
}
//gen.end(); //to add more nodes
return graph;
// graphGenerator = gen;
}
示例4: getImportantNodes
import org.graphstream.graph.Graph; //导入依赖的package包/类
/**
* Calls igraph to obtain the n nodes most important
* @param g
* @param centrality: b, c, or d for betwenness, closeness or degree, respectively. r for random is also possible
* @param numberOfNodes
* @return
*/
public static String[] getImportantNodes(Graph g, String centrality, int numberOfNodes) {
//export temporal graph
GraphTools.graphToGraphML(g, BTSim.getProperty("tempgraph"));
//execute R code
RCaller caller = new RCaller();
RCode code = new RCode();
caller.setRscriptExecutable(BTSim.getProperty("rpath"));
code.addRCode("source('"+ BTSim.getProperty("rcode") +"')");
String command = "nodes<- getNMostImportantNodes(\"" + BTSim.getProperty("tempgraph") + ("\", \"") + centrality + ("\", ") + numberOfNodes + ")";
LOG.fine("R command for getting important nodes: " + command);
code.addRCode(command);
caller.setRCode(code);
caller.runAndReturnResult("nodes");
String[] r = caller.getParser().getAsStringArray("nodes");
LOG.fine("Important nodes found " + Arrays.toString(r));
return r;
}
示例5: addBeaconTowards
import org.graphstream.graph.Graph; //导入依赖的package包/类
/**
* Add a beacon connected to the agent indexes
* @param agentsIndexes
*/
public void addBeaconTowards(List<Integer> agentsIndexes){
Graph g=getBt().getSpreadModel().getGraph();
this.beacons++;
int nodes= g.getNodeCount();
//create node and edge
String idNode= Integer.toString(nodes);
g.addNode(idNode);
for(Integer i: agentsIndexes){
g.addEdge(idNode + g.getNode(i).getId() , idNode, g.getNode(i).getId());
}
//create agent
UserAgent a = createAgent(nodes,this);
a.setState(State.BEACONOFF.toString());
getBt().setNumUsers(getBt().getNumUsers()+1);
}
示例6: getCuttingEdgesCount
import org.graphstream.graph.Graph; //导入依赖的package包/类
public Integer getCuttingEdgesCount(Graph gr) {
Integer cuttingEdges = 0;
Collection<Edge> edges = gr.getEdgeSet();
Stream<Edge> parallelEdges = edges.stream();
cuttingEdges = (int) parallelEdges.filter(EdgePredicates.isCuttingEdge()).count();
return cuttingEdges;
}
示例7: getTotalPartitionedEdges
import org.graphstream.graph.Graph; //导入依赖的package包/类
public Long getTotalPartitionedEdges(Graph gr, SGPHeuristic h) {
Collection<Edge> edges = gr.getEdgeSet();
return edges.parallelStream()
.filter(p -> p.getNode0().hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)
&& p.getNode1().hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))
.count();
}
示例8: setupNodes
import org.graphstream.graph.Graph; //导入依赖的package包/类
private void setupNodes(Graph g, PartitionMap map)
{
for(Node u : g.getNodeSet())
{
u.setAttribute("label",""+getBalancedSetupLabel(u,map));
u.setAttribute("tmplabel",""+u.getAttribute("label"));
}
}
示例9: setupNodes
import org.graphstream.graph.Graph; //导入依赖的package包/类
private void setupNodes(Graph g, PartitionMap map)
{
for(Node u : g.getNodeSet())
{
u.setAttribute("label",getBalancedSetupLabel(u,map));
u.setAttribute("tmplabel",u.getAttribute("label"));
}
}
示例10: EventHandler
import org.graphstream.graph.Graph; //导入依赖的package包/类
public EventHandler(Viewer v, Graph gs, CapGraph g){
// Assign variables
graphDisplay = gs;
viewer = v;
graph = g;
// Add key listener.
viewer.getDefaultView().addKeyListener(this);
}
示例11: configureNodes
import org.graphstream.graph.Graph; //导入依赖的package包/类
public void configureNodes(Graph graph) {
for (Data data : nodes) {
if (data.side == 0) {
countImportant++;
// System.out.println("node " + data.id + " is important.");
graph.getNode(data.id).addAttribute("ui.class", "important");
}
}
// for (Data data : nodes) {
// System.out.println("id: " + data.id + " degree: " + data.degree());
// }
System.out.println("countImportant: " + countImportant);
}
示例12: exportGraph
import org.graphstream.graph.Graph; //导入依赖的package包/类
@Override
protected void exportGraph(Graph graph) {
long timeId = 0;
try {
output.write("" + graph.getNodeCount() + " " + graph.getEdgeCount() + "\n");
output.write("#atributes:" + "\n");
for (String key : graph.getAttributeKeySet()){
output.write("#" + key + ": " + graph.getAttribute(key) + "\n");
}
for (Node node : graph) {
String nodeId = node.getId();
Collection<Edge> edges = node.getEdgeSet();
for (Edge edge : edges) {
if(edge.getSourceNode().getId() == nodeId) {
output.write(edge.getTargetNode().getId() + " ");
} else {
output.write(edge.getSourceNode().getId() + " ");
}
}
output.write("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: configureNodes
import org.graphstream.graph.Graph; //导入依赖的package包/类
public void configureNodes(Graph graph) {
for (Data data : nodes) {
if(data.side) {
countImportant++;
// System.out.println("node " + data.id + " is important.");
graph.getNode(data.id).addAttribute("ui.class", "important");
}
}
System.out.println("countImportant: " + countImportant);
}
示例14: graphToGexf
import org.graphstream.graph.Graph; //导入依赖的package包/类
public static void graphToGexf(Graph g, String filename) {
FileSinkGEXF out = new FileSinkGEXF();
try {
PrintStream ps = new PrintStream(new File(filename));
out.writeAll(g, ps);
ps.close();
} catch (IOException ex) {
Logger.getLogger(AdvancedTab.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例15: graphToGraphML
import org.graphstream.graph.Graph; //导入依赖的package包/类
public static void graphToGraphML(Graph g, String filename) {
FileSinkGraphML out = new FileSinkGraphML();
try {
PrintStream ps = new PrintStream(new File(filename));
out.writeAll(g, ps);
ps.close();
} catch (IOException ex) {
Logger.getLogger(AdvancedTab.class.getName()).log(Level.SEVERE, null, ex);
}
}