本文整理汇总了Java中org.graphstream.graph.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.graphstream.graph包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findParentWithHighestLevel
import org.graphstream.graph.Node; //导入依赖的package包/类
/**
* Determine the parent of a node that has the highest level set.
* @param node
* @return parent node that has the highest level assigned
*/
static Node findParentWithHighestLevel(Node node) {
int inDegreeOfNode = node.getInDegree();
Node parent = null;
Iterator<Edge> nodeIterator = node.getEachEnteringEdge().iterator();
if(inDegreeOfNode == 1)
parent = nodeIterator.next().getOpposite(node);
else if (inDegreeOfNode > 1) {
parent = nodeIterator.next().getOpposite(node);
while (nodeIterator.hasNext()) {
Node temp = nodeIterator.next().getOpposite(node);
if (temp.hasAttribute("layoutLayer") && (int) temp.getAttribute("layoutLayer") > (int) parent.getAttribute("layoutLayer")) {
parent = temp;
}
}
}
if(parent != null && !parent.hasAttribute("layouted")) {
parent.setAttribute("layouted", "true");
positionNode(parent);
}
return parent;
}
示例2: positionNode
import org.graphstream.graph.Node; //导入依赖的package包/类
/**
* Assign the coordinates to the node in the graph.
* @param node
*/
private static void positionNode(Node node) {
Node parent = findParentWithHighestLevel(node);
if(parent == null)
return;
double[] positionOfParent = Toolkit.nodePosition(parent);
int outDegreeOfParent = parent.getOutDegree();
if (outDegreeOfParent == 1) {
node.setAttribute("xyz", positionOfParent[0], positionOfParent[1] - spacingY, 0.0);
} else {
if(node.hasAttribute("directionResolver")) {
double x = positionOfParent[0] + ((int) node.getAttribute("directionResolver") * spacingX);
double y = positionOfParent[1] - spacingY;
node.setAttribute("xyz", x, y, 0.0);
} else {
node.setAttribute("xyz", positionOfParent[0], positionOfParent[1] - spacingY, 0.0);
}
}
}
示例3: filterGraphNodes
import org.graphstream.graph.Node; //导入依赖的package包/类
/**
* Filters and highlights the graph by setting the {@code uiClassForFilteredNodes} class on the filtered nodes based on the boolean value {@code selection} and also pans the view to the last filtered node based on the value of {@code panToNode}.
* @param nodes - nodes to be filtered
* @param selection - flag to determine whether the nodes have to be highlighted
* @param panToNode - flag to determine whether to pan the graph to the last filtered node
* @param uiClassForFilteredNodes - class name to be set on filtered nodes, defaults to <b>filter</b> if the passed in value is null
* @author Shashank B S
*/
private void filterGraphNodes(List<VFNode> nodes, boolean selection, boolean panToNode, String uiClassForFilteredNodes) {
boolean panned = false;
if (uiClassForFilteredNodes == null) {
uiClassForFilteredNodes = "filter";
}
Iterable<? extends Node> graphNodes = graph.getEachNode();
for (Node node : graphNodes) {
if (node.hasAttribute("ui.class")) {
node.removeAttribute("ui.class");
}
for (VFNode vfNode : nodes) {
if (node.getAttribute("unit").toString().contentEquals(vfNode.getUnit().toString())) {
if (selection) {
node.removeAttribute("ui.color");
node.addAttribute("ui.class", uiClassForFilteredNodes);
}
if (!panned && panToNode) {
this.panToNode(node.getId());
panned = true;
}
}
}
}
}
示例4: createGraphMethodNode
import org.graphstream.graph.Node; //导入依赖的package包/类
/**
* Creates the graph method node and sets the label, methodName, methodSignature, methodBody and nodeMethod attributes on the node.
*
* @param src
* @author Shashank B S
*/
private void createGraphMethodNode(VFMethod src) {
if (graph.getNode(src.getId() + "") == null) {
Node createdNode = graph.addNode(src.getId() + "");
String methodName = src.getSootMethod().getName();
String escapedMethodName = StringEscapeUtils.escapeHtml(methodName);
String escapedMethodSignature = StringEscapeUtils.escapeHtml(src.getSootMethod().getSignature());
createdNode.setAttribute("ui.label", methodName);
createdNode.setAttribute("nodeData.methodName", escapedMethodName);
createdNode.setAttribute("nodeData.methodSignature", escapedMethodSignature);
String methodBody = src.getBody().toString();
methodBody = Pattern.compile("^[ ]{4}", Pattern.MULTILINE).matcher(methodBody).replaceAll(""); // remove indentation at line start
methodBody = methodBody.replaceAll("\n{2,}", "\n"); // replace empty lines
String escapedMethodBody = StringEscapeUtils.escapeHtml(methodBody);
String hexColor = getCodeBackgroundColor();
createdNode.setAttribute("nodeData.methodBody", "<code><pre style=\"color: #000000; background-color: #"+hexColor+"\">" + escapedMethodBody + "</pre></code>");
createdNode.setAttribute("nodeMethod", src);
}
}
示例5: SetPartitionMap
import org.graphstream.graph.Node; //导入依赖的package包/类
public SetPartitionMap(Integer k, Integer capacity) {
this.K = k;
chm = new ConcurrentHashMap<Integer, Collection<Node>>(k);
partitionsSize = new ConcurrentHashMap<Integer, Integer>(k);
degreeMap = new ConcurrentHashMap<Integer,Integer>();
if (capacity <= 0) {
throw new InvalidCapacity("Capacity must be greater than 0");
}
this.C = capacity;
for (int i = 1; i <= k; i++) {
chm.put(i, new HashSet<Node>(capacity/2));
}
for (int i = 1; i <= k; i++) {
partitionsSize.put(i, 0);
}
}
示例6: assignToPartition
import org.graphstream.graph.Node; //导入依赖的package包/类
public Node assignToPartition(Node v, Integer ind) throws PartitionOutOfBoundException {
checkIndex(ind);
Collection<Node> s = chm.get(ind);
if (s.size() > C) throw new PartitionOutOfBoundException("Partition " + ind + " is already full");
s.add(v);
//update size
partitionsSize.put(ind, partitionsSize.get(ind) + 1);
size++;
//add to degreeMap
if (degreeMap.containsKey(v.getDegree())) {
degreeMap.put(v.getDegree(), degreeMap.get(v.getDegree()) +1);
} else {
degreeMap.put(v.getDegree(), 1);
}
//end update size
return v;
}
示例7: getTrianglesValue
import org.graphstream.graph.Node; //导入依赖的package包/类
public double getTrianglesValue(Node n, Integer partitionIndex) {
int totalEdges = 0;
List<Node> gammaNIntersect = getIntersectionNodes(n, partitionIndex);
for (int i = 0; i < gammaNIntersect.size(); i++) {
for (int j = i+1; j < gammaNIntersect.size(); j++) {
if (gammaNIntersect.get(i).hasEdgeBetween(gammaNIntersect.get(j))) {
totalEdges ++;
}
}
}
Integer N = gammaNIntersect.size();
Integer binCoeff = N == 1 || N == 0 ? 0 : N*(N-1)>>1; //>>1 = /2
if (binCoeff == 0) { //hardcoded 0.0 because totalEdges must be 0 too. check it out
return 0.0;
}
return (double)totalEdges/binCoeff; //safe to calculate because binCoeff != 0
}
示例8: getCuttingEdgesCount
import org.graphstream.graph.Node; //导入依赖的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;
}
示例9: checkSTCproperty
import org.graphstream.graph.Node; //导入依赖的package包/类
private boolean checkSTCproperty(Node n,List<Node> neighborsOnI) {
for(Node u:neighborsOnI)
{
for(Node v: neighborsOnI)
{
Edge e1 = u.getEdgeBetween(v);
Edge e2 = n.getEdgeBetween(v);
Edge e3 = n.getEdgeBetween(u);
if(u!=v && e1==null && ((boolean)e2.getAttribute("stc") && (boolean)e3.getAttribute("stc")))
{
return false;
}
}
}
return true;
}
示例10: bufferNodes
import org.graphstream.graph.Node; //导入依赖的package包/类
@SuppressWarnings("unused")
private synchronized void bufferNodes(int nodeId1, int nodeId2) {
buffer.add(nodeId1);
buffer.add(nodeId2);
while(buffer.size() > BUFFER_LIMIT) {
int oldestNode = buffer.first();
buffer.remove(oldestNode);
removeNode(String.valueOf(oldestNode));
}
for(Node node : graph.getEachNode()) {
if(node.getEdgeSet().size() == 0) {
buffer.remove(Integer.parseInt(node.getId()));
graph.removeNode(node);
}
}
}
示例11: process
import org.graphstream.graph.Node; //导入依赖的package包/类
@Override
protected void process() {
while (graph.getNodeCount() <= getSize()) {
gen.nextEvents();
}
//gerar as partições
Random rand = new Random();
Node n1 = graph.getNode(rand.nextInt(graph.getNodeCount()));
Node n2 = null;
for (Edge edge : n1.getEachEdge()) {
n2 = edge.getOpposite(n1);
}
graph.removeNode(n1);
graph.removeNode(n2);
}
示例12: getIndex
import org.graphstream.graph.Node; //导入依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
Map<Integer, Collection<Node>> partitions = partitionMap.getPartitions();
int c = partitionMap.getC();
Stream<Entry<Integer, Collection<Node>>> str = partitions.entrySet().stream();
if (parallel) {
str = str.parallel();
}
Integer minimumSizeIndex = str
.filter(p -> p.getValue().size() <= c)
.min(new Comparator<Entry<Integer,Collection<Node>>>() {
public int compare(Entry<Integer, Collection<Node>> p1,Entry<Integer, Collection<Node>> p2) {
Integer part1size = p1.getValue().size();
Integer part2size = p2.getValue().size();
Integer sizeDiff = part1size - part2size;
if (sizeDiff == 0) {
return 1;
} else {
return sizeDiff;
}
}
}).get().getKey();
return minimumSizeIndex;
}
示例13: writeFile
import org.graphstream.graph.Node; //导入依赖的package包/类
private void writeFile() {
nodesTrav.remove(0);
for (Node node : nodesTrav) {
String s = "";
if (node.getDegree() == 0) {
s = " ";
} else {
Iterator<Node> nNeigh = node.getNeighborNodeIterator();
while(nNeigh.hasNext()) {
Node u = nNeigh.next();
s += " " + mapNode.get(u);
}
}
printerOut.print('\n' + s);
}
}
示例14: initGraphicGraph
import org.graphstream.graph.Node; //导入依赖的package包/类
public void initGraphicGraph() {
int uniqId = 0;
for(Cell<Integer, Integer, Integer> edge : flowGraph.getEdges()) {
double weight = edge.getValue();
System.out.format("%s %s %s\n", edge.getRowKey(), edge.getColumnKey(), weight);
String fromId = String.valueOf(edge.getRowKey());
String toId = String.valueOf(edge.getColumnKey());
Node from = this.addNode(fromId);
Node to = this.addNode(toId);
int id = uniqId++;
addEdge(from, to, id);
}
weighEdges();
}
示例15: handleEvent
import org.graphstream.graph.Node; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void handleEvent(Event event) {
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_MODEL_CHANGED)) {
renderICFG((ICFGStructure) event.getProperty("icfg"));
}
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_SELECTION)) {
VFMethod selectedMethod = (VFMethod) event.getProperty("selectedMethod");
boolean panToNode = (boolean) event.getProperty("panToNode");
try {
renderMethodCFG(selectedMethod.getControlFlowGraph(), panToNode);
} catch (Exception e) {
e.printStackTrace();
}
}
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_FILTER_GRAPH)) {
filterGraphNodes((List<VFNode>) event.getProperty("nodesToFilter"), (boolean) event.getProperty("selection"),
(boolean) event.getProperty("panToNode"), (String) event.getProperty("uiClassName"));
}
if (event.getTopic().equals(DataModel.EA_TOPIC_DATA_UNIT_CHANGED)) {
VFUnit unit = (VFUnit) event.getProperty("unit");
for (Edge edge : graph.getEdgeSet()) {
Node src = edge.getSourceNode();
VFNode vfNode = src.getAttribute("nodeUnit");
if (vfNode != null) {
VFUnit currentUnit = vfNode.getVFUnit();
if (unit.getFullyQualifiedName().equals(currentUnit.getFullyQualifiedName())) {
String outset = Optional.fromNullable(unit.getOutSet()).or("").toString();
edge.setAttribute("ui.label", outset);
edge.setAttribute("edgeData.outSet", outset);
src.addAttribute("nodeData.inSet", unit.getInSet());
src.addAttribute("nodeData.outSet", unit.getOutSet());
}
}
}
}
}