本文整理汇总了Java中org.graphstream.graph.Node.getDegree方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getDegree方法的具体用法?Java Node.getDegree怎么用?Java Node.getDegree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.graphstream.graph.Node
的用法示例。
在下文中一共展示了Node.getDegree方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
if (Double.max((double) n.getDegree(), partitionMap.getDegreeAverage()) == (double)n.getDegree()) {
return new BalancedHeuristic(parallel).getIndex(partitionMap,n);
} else {
return new LinearNormalizedWeightedDispersionBased(parallel).getIndex(partitionMap, n);
}
}
示例3: getPredictionIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public final Integer getPredictionIndex(PartitionMap partitionMap, Node p)
{
int max=Integer.MIN_VALUE;
int partid=-1;
HashMap<Integer,Integer> maxs=new HashMap<Integer,Integer>();
for (int i = 1; i <= partitionMap.getK(); i++) {
Collection<Node> part=partitionMap.getPartition(i);
if(part.size() >= partitionMap.getC()) continue;
for(Node vp: part)
{
if(vp.hasEdgeBetween(p))
{
maxs.put(i,maxs.get(i)==null?1:maxs.get(i)+1);
if(maxs.get(i) > max)
{
max=maxs.get(i);
partid=i;
}
}
}
}
if (p.getDegree()/2.0 < max){
return partid;
}
else
return -1;
}
示例4: cuvCalculator
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public static List<Node> cuvCalculator(final Node u, Node v) {
List<Node> cuv = new ArrayList<>(u.getDegree());
Iterator<Node> uIterator = u.getNeighborNodeIterator();
while (uIterator.hasNext()) {
Node w = uIterator.next();
if (v.hasEdgeBetween(w)) {
cuv.add(w);
}
}
return cuv;
}
示例5: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
if (Double.max((double) n.getDegree(), partitionMap.getDegreeAverage()) == (double)n.getDegree()) {
return new BalancedHeuristic(parallel).getIndex(partitionMap,n);
} else {
return new LinearWeightedDeterministicGreedy(parallel).getIndex(partitionMap, n);
}
}
示例6: compare
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public int compare(Node o1, Node o2) {
return o2.getDegree() - o1.getDegree();
}
示例7: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public final Integer getIndex(PartitionMap partitionMap, Node n) {
Integer c = partitionMap.getC();
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
List<Node> nNeighbours = new ArrayList<Node>(n.getDegree());
n.getNeighborNodeIterator().forEachRemaining(p -> nNeighbours.add(p));
Map<Node, Double> xNodes = getDispersion(nNeighbours, n);
Map<Integer, Double> partitionsScore = new ConcurrentHashMap<>(partitionMap.getK());
Stream<Entry<Node,Double>> str = xNodes.entrySet().stream();
if (parallel) {
str = str.parallel();
}
str
.filter(p -> p.getKey().hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE) &&
partitionMap.getPartitionSize(Integer.parseInt(p.getKey().getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))) <= c)
.forEach(new Consumer<Entry<Node,Double>>() {
public void accept(Entry<Node, Double> t) {
Node v = t.getKey();
Integer partitionIndex = Integer.parseInt(v.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
Integer partitionSize = partitionMap.getPartitionSize(partitionIndex);
if (partitionsScore.containsKey(partitionIndex)) {
partitionsScore.put(partitionIndex, (partitionsScore.get(partitionIndex)) +
t.getValue() * getWeight((double) partitionSize,c));
} else {
partitionsScore.put(partitionIndex,
t.getValue() * getWeight((double) partitionSize,c));
}
}
});
if (partitionsScore.isEmpty()) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
Stream<Entry<Integer,Double>> scoreStr = partitionsScore.entrySet().stream();
if (parallel) {
scoreStr = scoreStr.parallel();
}
Integer maxPartIndex = scoreStr
.max(new Comparator<Entry<Integer, Double>>() {
public int compare(Entry<Integer, Double> o1, Entry<Integer, Double> o2) {
Double p1score = o1.getValue();
Double p2score = o2.getValue();
if (p1score > p2score) {
return 1;
} else if (p1score < p2score) {
return -1;
} else {
return partitionMap.getPartition(o1.getKey()).size() >=
partitionMap.getPartition(o2.getKey()).size() ? -1 : 1;
}
}
}).get().getKey();
return maxPartIndex;
}
开发者ID:isislab-unisa,项目名称:streaminggraphpartitioning,代码行数:64,代码来源:AbstractRecursiveDispersionBased.java
示例8: getDispersion
import org.graphstream.graph.Node; //导入方法依赖的package包/类
private Map<Node,Double> getDispersion(List<Node> uNeighbour, Node n) {
Map<Node, Double> xNodes = new ConcurrentHashMap<>(n.getDegree());
Map<Node, List<Node>> cuvs = new ConcurrentHashMap<>(n.getDegree());
for (int iteration = ITERATION_TIME; iteration-- > 0;) {
Stream<Node> str = uNeighbour.stream();
if (parallel) {
str = str.parallel();
}
str
.forEach(new Consumer<Node>() {
public void accept(Node v) {
//cuv contains all uv common neighbour
List<Node> cuv = null;
if (cuvs.containsKey(v)) {
cuv = cuvs.get(v);
} else {
cuv = Dispersion.cuvCalculator(v, n);
cuvs.put(v, cuv);
}
//calculate pt.1
Double pt1 = 0.0;
for (Node w : cuv) {
if (xNodes.containsKey(w)) {
pt1 += xNodes.get(w)*xNodes.get(w);
} else {
pt1 += 1.0;
xNodes.put(w, 1.0);
}
}
//calculate pt.2
Double pt2 = 0.0;
int size = cuv.size();
for (int i = 0; i < size; i++) {
for (int j = i+1; j < size; j++) {
Node s = cuv.get(i);
Node t = cuv.get(j);
double xs = 1.0;
if (xNodes.containsKey(s)) {
xs = xNodes.get(s);
} else{
xNodes.put(s, 1.0);
}
double xt = 1.0;
if (xNodes.containsKey(s)) {
xt = xNodes.get(t);
} else{
xNodes.put(t, 1.0);
}
pt2 += (dist.getDistance(cuv.get(i), cuv.get(i), n, v) * xs * xt);
}
}
//calculate all
double xv = (pt1 + 2*pt2)/cuv.size();
xNodes.put(v, xv);
}
});
}
return xNodes;
}
开发者ID:isislab-unisa,项目名称:streaminggraphpartitioning,代码行数:65,代码来源:AbstractRecursiveDispersionBased.java
示例9: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
double alpha=1,beta=2;
Integer c = partitionMap.getC();
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<Integer, Double>(partitionMap.getK());
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
for (int i = 1; i <= partitionMap.getK(); i++) {
if(partitionMap.getPartition(i).size() >= c) continue;
List<Node> neighborsOnI=partitionMap.getIntersectionNodes(n,i);
labelEdgesSTC(partitionMap, n, neighborsOnI);
double scorei=0.0;
for(Node p: neighborsOnI)
{
scorei+=((boolean)n.getEdgeBetween(p).getAttribute("stc"))?alpha:beta;
}
partitionsScores.put(i, scorei);
}
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
.max(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;
}
示例10: 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;
}
示例11: getIndex
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getIndex(PartitionMap partitionMap, Node n) {
Double T=(double)++count/(double)(partitionMap.getC()*partitionMap.getK());
dist = new SimpleDistanceFunction();
Integer c = partitionMap.getC();
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
//score for each neighbour
Map<Node, Double> nodeScores = new HashMap<Node, Double>(n.getDegree());
Iterator<Node> nNeighIt = n.getNeighborNodeIterator();
nNeighIt.forEachRemaining(p -> {
List<Node> cuv = Dispersion.cuvCalculator(n, p);
double emb=(double)cuv.size();
double disp=(double)Dispersion.getDispersion(n, p, dist,cuv);
double ndisp=emb==0?0:Math.min(1,disp/emb);
double beta=1-T;
nodeScores.put(p, T + beta*(1-ndisp));
});
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<>(partitionMap.getK());
Stream<Entry<Node,Double>> nodeStream = nodeScores.entrySet().stream();
if (parallel) {
nodeStream = nodeStream.parallel();
}
nodeStream.filter(p -> p.getKey().hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE) &&
partitionMap.getPartitionSize(Integer.parseInt(p.getKey().getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))) < c)
.forEach(new Consumer<Entry<Node,Double>>() {
public void accept(Entry<Node, Double> t) {
Node v = t.getKey();
Integer partitionIndex = Integer.parseInt(v.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
if (partitionsScores.containsKey(partitionIndex)){
partitionsScores.put(partitionIndex,
((partitionsScores.get(partitionIndex)) + t.getValue()) );
} else {
partitionsScores.put(partitionIndex, (double) t.getValue());
}
}
});
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
.max(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: 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(true).getIndex(partitionMap, n);
}
//score for each neighbour
Map<Node, Integer> nodeScores = new HashMap<Node, Integer>(n.getDegree());
Iterator<Node> nNeighIt = n.getNeighborNodeIterator();
Map<Node, Integer> nNeighNeigh = new ConcurrentHashMap<>();
//1 + disp(u,v) in order to mix DG with ADB
nNeighIt.forEachRemaining(p -> nodeScores.put(p, 1+ Dispersion.getDispersion(p, n, dist)));
nodeScores.keySet().parallelStream()
.forEach(p -> p.getNeighborNodeIterator()
.forEachRemaining(q -> nNeighNeigh.put(q, Dispersion.getDispersion(q, n, dist))));
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<>(partitionMap.getK());
nodeScores.entrySet().parallelStream()
.filter(p -> p.getKey().hasAttribute(GraphPartitionator.PARTITION_ATTRIBUTE) &&
partitionMap.getPartitionSize(Integer.parseInt(p.getKey().getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE))) <= c)
.forEach(new Consumer<Entry<Node,Integer>>() {
public void accept(Entry<Node, Integer> t) {
Node v = t.getKey();
Integer partitionIndex = Integer.parseInt(v.getAttribute(GraphPartitionator.PARTITION_ATTRIBUTE));
Integer partitionSize = partitionMap.getPartitionSize(partitionIndex);
if (partitionsScores.containsKey(partitionIndex)){
//x1*w+x2*w+...+xn*w = w*(x1+x2+..+xn)
partitionsScores.put(partitionIndex, (partitionsScores.get(partitionIndex)) + t.getValue()
* getWeight((double)partitionSize, c));
} else {
partitionsScores.put(partitionIndex, (double) t.getValue() *
getWeight((double) partitionSize, c));
}
}
});
if (partitionsScores.isEmpty()) {
return new BalancedHeuristic(true).getIndex(partitionMap, n);
}
Integer maxPart = partitionsScores.entrySet().parallelStream()
.max(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 = e1.getValue();
Double score2 = e2.getValue();
if (Double.max(score1, score2) == score1) {
return 1;
} else if (Double.max(score1, score2) == score2) {
return -1;
} else { //inverse tie break
return size2 - size1;
}
}
}).get().getKey();
return maxPart;
}
开发者ID:isislab-unisa,项目名称:streaminggraphpartitioning,代码行数:64,代码来源:AbstractCompleteAbsDispersionBased.java
示例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: getIndexWithSTC
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public final Integer getIndexWithSTC(PartitionMap partitionMap, Node n) {
double alpha=1,beta=2;
Integer c = partitionMap.getC();
Map<Integer, Double> partitionsScores = new ConcurrentHashMap<Integer, Double>(partitionMap.getK());
if (n.getDegree() == 0) {
return new BalancedHeuristic(parallel).getIndex(partitionMap, n);
}
for (int i = 1; i <= partitionMap.getK(); i++) {
if(partitionMap.getPartition(i).size() >= c) continue;
List<Node> neighborsOnI=partitionMap.getIntersectionNodes(n,i);
labelEdgesSTC(partitionMap, n, neighborsOnI);
double scorei=0.0;
for(Node p: neighborsOnI)
{
scorei+=((boolean)n.getEdgeBetween(p).getAttribute("stc"))?alpha:beta;
//System.out.println(n.getEdgeBetween(p)+" ->"+((boolean)n.getEdgeBetween(p).getAttribute("stc")));
}
partitionsScores.put(i, scorei);
//System.out.println(i+ " "+ scorei);
}
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
.max(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("\t"+n +" -> "+maxPart);
return maxPart;
}