Hi All,
I am MSc student and I try to write an algorithm written in Java using
apache Giraph. But below I have a part of a java code using HashMap in a
way that I can't understan't how can be implemented in Giraph.
I try to implement it to Giraph and for better understanding what actually
the question is, below after the java code I have specific question about
this.
Source code in java:
----------------------------------
public class BucketList{
HashMap<Integer, Node>[] bucketList;
int maxGainPointer;
int minGain;
int maxGain;
public BucketList(int ming, int maxg){
this.minGain = ming;
this.maxGain = maxg;
this.maxGainPointer = -1;
this.bucketList = (HashMap<Integer, Node>[]) new
HashMap[maxGain - minGain + 1];
for(int i = 0; i < this.bucketList.length; i++) // initialize
all buckets
this.bucketList[i] = new HashMap<Integer, Node>();
}
}
// hang this node to the corresponding bucket in realBuckets
*if*(*this*.node_locked[node_id - 1] == *false*){ // only hang unlocked
nodes
*this*.realBuckets.bucketList[(*int*)cur_node.compoundGain - *this*.
realBuckets.minGain].put(node_id, cur_node);
*if*(*this*.realBuckets.maxGainPointer < (*int*) cur_node.compoundGain -
*this*.realBuckets.minGain){
*if*(*this*.realBuckets.maxGainPointer != -1)
assert
this.sybilBuckets.bucketList[this.sybilBuckets.maxGainPointer].values().iterator().next().compoundGain
< cur_node.compoundGain : "Error: current maxGainPionter error!!!";
*this*.realBuckets.maxGainPointer = (*int*) cur_node.compoundGain - *this*.
realBuckets.minGain;
}
}
...
int realBucketsPointer = this.realBuckets.maxGainPointer;
Vector<Node> nodesInRealBuckets = new Vector<Node>();
if(realBucketsPointer >= 0){
nodesInRealBuckets = new
Vector<Node>(this.realBuckets.bucketList[realBucketsPointer].values());
}
// check nodes in the real bucket
if(nodesInRealBuckets.size() > 0){
for(Node rnode : nodesInRealBuckets){
assert this.node_locked[rnode.uid - 1] == false : "Error:
move a locked real user!!";
if(maxExchangeGain < rnode.compoundGain){
maxExchangeGain = rnode.compoundGain;
enode.nid = rnode.uid;
enode.friendGain = rnode.friendGain;
enode.rejectionGain = rnode.rejectionGain;
enode.compoundGain = rnode.compoundGain;
maxGainSet = new ExchangeGains(rnode.friendGain,
rnode.rejectionGain, rnode.compoundGain);
}
}
}
...
}
return maxGainSet;
}
Question:
-----------------
How check nodes in the real bucket in order to get the node with the
maximum compound gain (below in superstep 3)?
Note: The real bucket fill up in superstep 2.
My source code in Giraph:
------------------------------------------
Bucketlist.java
-------------------------
package MyComputation;
import java.util.HashMap;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
public class Bucketlist{
HashMap<LongWritable, DoubleWritable>[] bucketList;
int maxGainPointer;
int maxGain;
public Bucketlist(int maxg){
maxGain = maxg;
maxGainPointer = -1;
bucketList = (HashMap<LongWritable, DoubleWritable>[]) new
HashMap[2*maxGain + 1];
for(int i = 0; i < bucketList.length; i++) // initialize all buckets
bucketList[i] = new HashMap<LongWritable, DoubleWritable>();
}
}
MyComputationAlgo.java
-------------------------------------------------
...
if (getSuperstep()==2 )
{
SybilBuckets= new Bucketlist(SybilMaxRgain);
RealBuckets = new Bucketlist(RealMaxRgain);
if( vertex.getValue().getStatus()==1 &&
vertex.getValue().getLocked()==0 ){
nodesInRealBuckets += 1;
DoubleWritable cgainToLongWritable=new
DoubleWritable ( vertex.getValue().getVertexCompoundGain());
RealBuckets.bucketList[(int) (
vertex.getValue().getVertexCompoundGain() + RealMaxRgain)].put(new
LongWritable(vertex.getId().get()), cgainToLongWritable);
if(RealBuckets.maxGainPointer < (int)
vertex.getValue().getVertexCompoundGain() + RealMaxRgain ){
if(RealBuckets.maxGainPointer != -1)
if(
RealBuckets.bucketList[RealBuckets.maxGainPointer].values().iterator().next().get()
> vertex.getValue().getVertexCompoundGain())
System.out.println("Error:
current maxGainPionter error!!!");
RealBuckets.maxGainPointer = (int)
vertex.getValue().getVertexCompoundGain() + RealBuckets.maxGain;
realBucketsHead=RealBuckets.maxGainPointer;
System.out.println("RealBuckets.maxGainPointer: "+ realBucketsHead+ "
nodesInRealBuckets "+ nodesInRealBuckets + " ID: "+ vertex.getId() + ",
VValue: "+ vertex.getValue());
}
}
} // superstep2
if( getSuperstep()>=2 && getSuperstep()<=3 )
{
aggregate(REAL_MAXP_AGG, new LongWritable
(realBucketsHead));
LongWritable
realMaxPointer=getAggregatedValue(REAL_MAXP_AGG);
LOG.info(vertex.getId() + " realmaxpointer="
+ realMaxPointer);
realMaxPointer_get=(int)realMaxPointer.get();
}
if (getSuperstep()==2 &&
vertex.getValue().getLocked()==0)
{
for (Edge<LongWritable, LongWritable> edge :
vertex.getEdges())
{
MessageValue realEdgeIdAndgain2=
new
MessageValue(vertex.getId().get((long)vertex.getValue().getVertexCompoundGain(),vertex.getValue().getFGain(),vertex.getValue().getRGain(),vertex.getValue().getLocked(),vertex.getValue().getStatus());
sendMessage(edge.getTargetVertexId(),realEdgeIdAndgain2);
System.out.println("sendingToS3.. " +
realEdgeIdAndgain2);
}
}
if(getSuperstep()==3)//Here I get the place of the node/s
in the real bucket with max compound gain (realMaxPointer_get) because it
is aggregator above
{
System.out.println("HERE I THINK THAT SHOULD
FIND/GET THE NODE WITH MAX COMPOUND GAIN ");
}
vertex.voteToHalt();
}
Thank you in advance,
Xenia