本文整理汇总了Java中org.graphstream.graph.Node.hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Node.hasAttribute方法的具体用法?Java Node.hasAttribute怎么用?Java Node.hasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.graphstream.graph.Node
的用法示例。
在下文中一共展示了Node.hasAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例5: getIntersectionNodes
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public List<Node> getIntersectionNodes(Node v, Integer partitionIndex) throws PartitionOutOfBoundException {
checkIndex(partitionIndex);
Iterator<Node> vNeigh = v.getNeighborNodeIterator();
List<Node> intersection = new ArrayList<Node>(1);
while (vNeigh.hasNext()) {
Node u = vNeigh.next();
if (!u.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) continue;
if (Integer.parseInt(u.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) == (partitionIndex)) {
intersection.add(u);
}
}
return intersection;
}
示例6: getIntersectionValue
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIntersectionValue(Node v, Integer partitionIndex) throws PartitionOutOfBoundException {
checkIndex(partitionIndex);
Iterator<Node> vNeigh = v.getNeighborNodeIterator();
int intersection = 0;
while (vNeigh.hasNext()) {
Node u = vNeigh.next();
if (!u.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) continue;
if (Integer.parseInt(u.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) == (partitionIndex)) {
intersection ++;
}
}
return intersection;
}
示例7: getBalancedSetupLabel
import org.graphstream.graph.Node; //导入方法依赖的package包/类
private int getBalancedSetupLabel(Node u,PartitionMap map)
{
if(u.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))
{
if(map.getPartition(Integer.parseInt(u.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))).size() >= map.getC())
{
return -1;
}else
return Integer.parseInt(u.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
}else
return 0;
}
示例8: getDistance
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@Override
public Integer getDistance(Node s, Node t, Node u, Node v) {
if(!v.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) return 1;
Integer i=Integer.parseInt(v.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
Integer j=Integer.parseInt(s.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)?s.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE):"-1");
Integer k=Integer.parseInt(t.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)?t.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE):"-1");
if(i==j && k==i) return 1;
if(j!=-1 || k!=-1 ) return 0;
return -1;
}
示例9: buttonReleased
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@Override
/* (non-Javadoc)
* @see org.graphstream.ui.view.ViewerListener#buttonReleased(java.lang.String)
*/
public void buttonReleased(String id) {
Node node = graphDisplay.getNode(id);
// If node color is black or node color is red, change the color to purple and display
// Closeness Centrality.
if (!node.hasAttribute("ui.style") || node.getAttribute("ui.style")
.toString().equals("fill-color: black;") || node.getAttribute("ui.style")
.toString().equals("fill-color: red;")) {
// Round the Closeness Centrality to two decimals.
String closeness = df.format(graph.closeness(new Vertex(Integer.parseInt(id))));
node.addAttribute("ui.style", "fill-color: purple;");
node.addAttribute("ui.label", closeness);
// else if the node color is purple (already clicked node) and its original color is
// black and change its color to black.
}else if (node.getAttribute("ui.style").toString().equals("fill-color: purple;")
&& !node.hasAttribute("ui.class")){
node.changeAttribute("ui.style", "fill-color: black;");
node.changeAttribute("ui.label", id);
// else (if the node is purple and its original color is red) then change node
// color to red and label it with its ID.
}else{
node.changeAttribute("ui.style", "fill-color: red;");
node.changeAttribute("ui.label", id);
}
}
示例10: setCustomAttribute
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void setCustomAttribute(VFUnit selectedVF, Node curr) {
JPanel panel = new JPanel(new GridLayout(0, 2));
JTextField attributeName = new JTextField("");
JTextField attributeValue = new JTextField("");
panel.add(attributeName);
panel.add(new JLabel("Attribute: "));
panel.add(attributeValue);
panel.add(new JLabel("Attribute value: "));
int result = JOptionPane.showConfirmDialog(null, panel, "Setting custom attribute", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
Map<String, String> hmCustAttr = new HashMap<>();
// Get actual customized attributes
Set set = selectedVF.getHmCustAttr().entrySet();
Iterator i = set.iterator();
String attributeString = "";
if(curr.hasAttribute(nodeAttributesString))
{
attributeString += curr.getAttribute(nodeAttributesString) + "<br>";
curr.removeAttribute(nodeAttributesString);
}
else
attributeString += "";
// Display elements
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
hmCustAttr.put((String) me.getKey(), (String) me.getValue());
}
if ((attributeName.getText().length() > 0) && (attributeValue.getText().length() > 0)) {
try {
hmCustAttr.put(attributeName.getText(), attributeValue.getText());
selectedVF.setHmCustAttr(hmCustAttr);
ArrayList<VFUnit> units = new ArrayList<>();
units.add(selectedVF);
attributeString += attributeName.getText() + ":" + attributeValue.getText();
curr.setAttribute(nodeAttributesString, attributeString);
curr.addAttribute("ui.color", Color.red.getRGB());
} catch (Exception e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(new JPanel(), "Please make sure all fields are correctly filled out", "Warning", JOptionPane.WARNING_MESSAGE);
}
}
}
示例11: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
Integer c = partitionMap.getC();
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<>(partitionMap.getK());
for (int i = 1; i <= partitionMap.getK(); i++) {
if(partitionMap.getPartition(i).size() >= c)
{
continue;
}
int y=0;
for (int j = 1; j <= partitionMap.getK(); j++) {
int tmp=partitionMap.getIntersectionValue(n,j);
if(j!=i) y+=tmp;
}
int x=partitionMap.getIntersectionValue(n, i);
int score=-x+y;//-partitionMap.getIntersectionValue(n, i);
Iterator<Node> pOFn=n.getNeighborNodeIterator();
Node p=null;
while(pOFn.hasNext())
{
p=pOFn.next();
if(!p.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))
score+=phiNeighbor(partitionMap, n, p, i);
}
partitionsScores.put(i, (double)score);
// System.out.println(n+" = "+partitionsScores);
}
if (partitionsScores.isEmpty()) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
Stream<Entry<Integer, Double>> strScore = partitionsScores.entrySet().stream();
if (parallel) {
strScore = strScore.parallel();
}
Integer maxPart = strScore
.min(new Comparator<Entry<Integer, Double>>() {
public int compare(Entry<Integer, Double> e1, Entry<Integer, Double> e2) {
Integer size1 = partitionMap.getPartitionSize(e1.getKey());
Integer size2 = partitionMap.getPartitionSize(e2.getKey());
Double score1 = getWeight((double)size1, c) *(e1.getValue());
Double score2 = getWeight((double)size2, c)*(e2.getValue());
if (score1 > score2) {
return 1;
} else if (score1 < score2) {
return -1;
} else {
return size1 >= size2 ? 1 : -1;
}
}
}).get().getKey();
return maxPart;
}
示例12: getDistance
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getDistance(Node s, Node t, Node u, Node v) {
SimpleDistanceFunction dist=new SimpleDistanceFunction();
if(!v.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)) return DIST_POS;
Integer i=Integer.parseInt(v.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
Integer j=Integer.parseInt(s.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)?s.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE):"0");
Integer k=Integer.parseInt(t.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE)?t.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE):"0");
if(i==j && j==k) return DIST_NEG;
if(j!=i || k!=i) return DIST_POS;
return dist.getDistance(s, t, u, v);
}
示例13: getIndexWithDispersionWithPredictionNeighbors
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public final Integer getIndexWithDispersionWithPredictionNeighbors(PartitionMap partitionMap, Node n) {
Integer c = partitionMap.getC();
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<>(partitionMap.getK());
for (int i = 1; i <= partitionMap.getK(); i++) {
if(partitionMap.getPartition(i).size() >= c)
{
continue;
}
int y=0;
for (int j = 1; j <= partitionMap.getK(); j++) {
int tmp=partitionMap.getIntersectionValue(n,j);
if(j!=i) y+=tmp;
}
int x=partitionMap.getIntersectionValue(n, i);
int score=-x+y;//-partitionMap.getIntersectionValue(n, i);
Iterator<Node> pOFn=n.getNeighborNodeIterator();
Node p=null;
while(pOFn.hasNext())
{
p=pOFn.next();
if(!p.hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))
score+=phiNeighbor(partitionMap, n, p, i);
}
partitionsScores.put(i, (double)score);
// System.out.println(n+" = "+partitionsScores);
}
if (partitionsScores.isEmpty()) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
Stream<Entry<Integer, Double>> strScore = partitionsScores.entrySet().stream();
if (parallel) {
strScore = strScore.parallel();
}
Integer maxPart = strScore
.min(new Comparator<Entry<Integer, Double>>() {
public int compare(Entry<Integer, Double> e1, Entry<Integer, Double> e2) {
// Integer intersection1 = partitionMap.getIntersectionValue(n, e1.getKey());
// Integer intersection2 = partitionMap.getIntersectionValue(n, e2.getKey());
Integer size1 = partitionMap.getPartitionSize(e1.getKey());
Integer size2 = partitionMap.getPartitionSize(e2.getKey());
//System.out.println("Score "+e1.getKey()+" "+e1.getValue());
Double score1 = getWeight((double)size1, c) *(e1.getValue());
Double score2 = getWeight((double)size2, c)*(e2.getValue());
if (score1 > score2) {
return 1;
} else if (score1 < score2) {
return -1;
} else {
return size1 >= size2 ? 1 : -1;
}
}
}).get().getKey();
// System.out.println(n+"->"+maxPart);
return maxPart;
}
示例14: mouseReleased
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@Override
public void mouseReleased(MouseEvent e) {
boolean isShiftPressed = e.isShiftDown();
if(!isShiftPressed) {
if (curElement != null) {
mouseButtonReleaseOffElement(curElement, e);
curElement = null;
}
return;
}
if (curElement != null) {
mouseButtonReleaseOffElement(curElement, e);
curElement = null;
} else {
float x2 = e.getX();
float y2 = e.getY();
float t;
if (x1 > x2) {
t = x1;
x1 = x2;
x2 = t;
}
if (y1 > y2) {
t = y1;
y1 = y2;
y2 = t;
}
mouseButtonRelease(e, view.allNodesOrSpritesIn(x1, y1, x2, y2));
view.endSelectionAt(x2, y2);
}
boolean nodesWereSelected = false;
System.out.println("## Selection of Nodes is ...");
HashMap<String, Integer> freq = new HashMap<>();
for(Node node : graph) {
if(node.hasAttribute("ui.selected")) {
nodesWereSelected = true;
String nodeId = node.toString();
if(displayedGraph != null) {
SourceLineNode lineNode = displayedGraph.getNode(Integer.parseInt(nodeId));
String sourceLine = lineNode.toString();
if(!freq.containsKey(sourceLine)) {
freq.put(sourceLine, 0);
}
int f = freq.get(sourceLine);
freq.put(sourceLine, f + 1);
// System.out.println(sourceLine);
} else {
System.out.println(nodeId);
}
}
}
for(String line : freq.keySet()) {
System.out.println(line + " " + freq.get(line));
}
if(!nodesWereSelected) {
System.out.println("EMPTY.");
}
}