Example usage for org.apache.hadoop.io LongWritable get

List of usage examples for org.apache.hadoop.io LongWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io LongWritable get.

Prototype

public long get() 

Source Link

Document

Return the value of this LongWritable.

Usage

From source file:in.dream_lab.goffish.sample.ConnectedComponents.java

License:Apache License

@Override
public void compute(Collection<IMessage<LongWritable, LongWritable>> messages) {

    if (getSuperStep() == 0) {
        minSubgraphID = getSubgraph().getSubgraphID().get();
        for (IRemoteVertex<LongWritable, LongWritable, LongWritable, LongWritable, LongWritable> vertex : getSubgraph()
                .getRemoteVertices()) {/*from   w w  w.  j av a 2 s  .  com*/
            if (minSubgraphID > vertex.getSubgraphID().get()) {
                minSubgraphID = vertex.getSubgraphID().get();
            }
        }
        LongWritable msg = new LongWritable(minSubgraphID);
        sendToNeighbors(msg);
        getSubgraph().setValue(new LongWritable(minSubgraphID));
    } else {
        boolean updated = false;
        for (IMessage<LongWritable, LongWritable> msg : messages) {
            long subgraphID = msg.getMessage().get();
            if (minSubgraphID > subgraphID) {
                minSubgraphID = subgraphID;
                updated = true;
            }
        }
        if (updated) {
            getSubgraph().setValue(new LongWritable(minSubgraphID));
            LongWritable msg = new LongWritable(minSubgraphID);
            sendToNeighbors(msg);
        }
        // System.out.println("Superstep "+ getSuperStep() + " Subgraph " +
        // getSubgraph().getSubgraphID() + " value " + getSubgraph().getValue());
    }
    // System.out.println("Subgraph " + getSubgraph().getSubgraphID() + " in
    // superstep " + getSuperStep() + " value " + getSubgraph().getValue());
    voteToHalt();
}

From source file:io.apigee.lembos.mapreduce.converters.input.LongWritableConverter.java

License:Apache License

/**
 * Takes in a {@link LongWritable} and returns a {@link Long}.
 *
 * @param scope the JavaScript scope//from   w  w w.  j av  a2 s  .  c om
 * @param writable the value to convert
 *
 * @return the {@link Long} equivalent
 */
@Override
public Object toJavaScript(final Scriptable scope, final LongWritable writable) {
    return writable.get();
}

From source file:it.polito.dbdmg.searum.utils.ParallelCountingReducer.java

License:Apache License

@Override
protected void reduce(Text key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long sum = 0;
    for (LongWritable value : values) {
        // context.setStatus("Parallel Counting Reducer :" + key);
        sum += value.get();
    }//w w w  .j  a  va 2 s  .  c om
    // context.setStatus("Parallel Counting Reducer: " + key + " => " +
    // sum);
    context.write(key, new LongWritable(sum));

}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.densesubgraph.direct.DenseSubgraphDirectMasterCompute.java

License:Apache License

@Override
public void compute() {

    long superstep = getSuperstep();
    long totVertices = this.getTotalNumVertices();

    if (superstep > 3) {

        LongWritable removedEdges = this.getAggregatedValue(REMOVEDEDGES);//superstep precedente

        LongWritable removedVertexInS = this.getAggregatedValue(REMOVEDVERTICIESINS);//superstep precedente       
        LongWritable removedVertexInT = this.getAggregatedValue(REMOVEDVERTICIESINT);//superstep precedente

        if (isEven(superstep)) {//2,4....

            Long edges = this.getTotalNumEdges() - removedEdges.get();
            Long verticesInS = totVertices - removedVertexInS.get();
            Long verticesInT = totVertices - removedVertexInT.get();

            Boolean IsNextPartitionS = (verticesInS.doubleValue() / verticesInT.doubleValue()) >= c;
            Boolean SamePreviuosStepPartition = IsNextPartitionS.equals(isPreviousPartitionS);

            //con rimozione effettiva dei vertici ci vogliono 2 step per startup
            Boolean noChangePreviousStep = prevStepRemovedEdges.equals(removedEdges.get())
                    && SamePreviuosStepPartition;
            if ((noChangePreviousStep && superstep > 4) || edges == 0) {
                LOG.info("edge rimasti\t" + edges);
                LOG.info("vertici in partizione S\t" + verticesInS);
                LOG.info("vertici in partizione T\t" + verticesInT);
                LOG.info("NO CHANGES or NO more Edges - HALT COMPUTATION");
                LOG.info("BEST DENSITY\t" + bestlDensity + " at " + bestDensitySuperstep);
                this.haltComputation();
                return;
            }//  w w  w  . jav a2 s  .  com

            //Aggiorno variabile vertici rimossi per check nel step successivo
            prevStepRemovedEdges = removedEdges.get();
            isPreviousPartitionS = IsNextPartitionS;

            //EpSpSPp --> |E(S, T )| = |E  (ST)|
            Long EpSTp = this.getTotalNumEdges() - removedEdges.get();
            LOG.info("EpSTp\t" + this.getTotalNumEdges() + "\t" + removedEdges.get());

            //DENSITY DIRECT  ?(S, T ) =  |E(S, T )| /  sqrt (|S||T |)
            Double currDensity = EpSTp.doubleValue()
                    / Math.sqrt(verticesInS.doubleValue() * verticesInT.doubleValue());
            LOG.info("currDesity" + "\t" + verticesInS.doubleValue() + "\t" + verticesInT.doubleValue());

            if (currDensity > bestlDensity && superstep > 2) {
                bestlDensity = currDensity;
                bestDensitySuperstep = superstep - 2; //Densit calcolata sul supertep pari precedente
                this.getConf().setLong(OPTIMALSUPERSTEP, superstep);
            }

            //soglia dipende della partizione
            Double soglia;
            if (IsNextPartitionS) {
                //S                
                LOG.info("partizione S");
                LOG.info(edges + "\t" + verticesInS);
                this.getContext().getConfiguration().setStrings(PARTITIONTOPROCESS, "S");
                this.setComputation(DenseSubgraphDirectPartitionS.class);

                // soglia = (1 + epsilon) * (|E(S, T)| / |S| )
                soglia = (1 + epsilon) * ((EpSTp.doubleValue()) / verticesInS.doubleValue());

            } else {
                //T
                LOG.info("partizione T");
                LOG.info(edges + "\t" + verticesInT);
                this.getContext().getConfiguration().setStrings(PARTITIONTOPROCESS, "T");
                this.setComputation(DenseSubgraphDirectPartitionT.class);

                // soglia = (1 + epsilon) * (|E(S, T)| / |T| )
                soglia = (1 + epsilon) * ((EpSTp.doubleValue()) / verticesInT.doubleValue());
                ;
            }

            LOG.info("superstep\t" + superstep + "\t\tdensity\t" + currDensity);
            LOG.info("soglia = " + soglia);

            this.getContext().getConfiguration().setDouble(SOGLIA, soglia);

        }
        //        else {//3,5...
        //
        //        }
    }
}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.densesubgraph.direct.DenseSubgraphDirectPartitionS.java

@Override
public void compute(Vertex<LongWritable, DenseSubgraphDirectVertexValue, NullWritable> vertex,
        Iterable<LongWritable> messages) throws IOException {
    Long superstep = this.getSuperstep();

    if (superstep > 1) {

        //Partition S
        if (this.isEven(superstep)) {
            //2, 4, 6 ..
            if (vertex.getValue().getPartitionS().IsActive()) {

                int outDegree = vertex.getNumEdges() - vertex.getValue().getPartitionS().getEdgeRemoved();
                Double soglia = this.getContext().getConfiguration().getDouble(SOGLIA,
                        Double.NEGATIVE_INFINITY);

                if (outDegree <= soglia) {
                    //elimino vertice dalla partizione S
                    vertex.getValue().getPartitionS().deactivate();
                    vertex.getValue().getPartitionS().setDeletedSuperstep(superstep);

                    this.aggregate(REMOVEDVERTICIESINS, new LongWritable(1));

                    //invio messaggi a vertici in Partizione T che diminueranno il loro inDegree
                    this.sendMessageToAllEdges(vertex, vertex.getId());
                    this.aggregate(REMOVEDEDGES, new LongWritable(outDegree));
                }//  www . j a v  a2  s.c  om
            }
        } else {
            //3,5,7 ..
            //vertici nella partizione T

            //elimino da lista incoming edge
            if (vertex.getValue().getPartitionT().IsActive()) {
                for (LongWritable msg : messages) {
                    vertex.getValue().getIncomingEdge().remove(msg.get());
                }
            }
        }

    } else {
        //INIT - Superstep 0 e 1 creano lista incoming edge 
        if (superstep == 0) {
            this.sendMessageToAllEdges(vertex, vertex.getId());
        }
        if (superstep == 1) {
            for (LongWritable msg : messages) {
                vertex.getValue().getIncomingEdge().add(msg.get());
            }
        }
    }

}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.densesubgraph.undirect.longwritable.DenseSubgraphUndirectMasterCompute.java

License:Apache License

@Override
public void compute() {

    long superstep = getSuperstep();
    LongWritable removedEdges = this.getAggregatedValue(REMOVEDEDGES);//superstep precedente
    LongWritable removedVertex = this.getAggregatedValue(REMOVEDVERTICIES);//superstep precedente

    if (isEven(superstep)) {//0,2,4....

        LOG.info("confronto \t" + prevStepRemovedVertex + "\t" + removedEdges);

        //con rimozione effettiva dei vertici ci vogliono 2 step per startup
        if ((prevStepRemovedVertex.equals(removedEdges.get())) && superstep > 2) {
            LOG.info("NO CHANGES - HALT COMPUTATION");
            LOG.info("BEST DENSITY\t" + bestlDensity + " at " + bestDensitySuperstep);
            this.haltComputation();
            return;
        }//from  w  w w.  j a v a  2 s .  c om

        //Aggiorno variabile vertici rimossi per step successivo
        prevStepRemovedVertex = removedEdges.get();

        //DENSITY UNDIRECT ?(S) = (|E(S)| / 2 ) / |S|
        // |E(S)| / 2 perch giraph rappresenta edge non diretto con 2 edge diretti
        Long edges = this.getTotalNumEdges() - removedEdges.get();
        Long vertices = this.getTotalNumVertices() - removedVertex.get();
        Double currDensity = (edges.doubleValue() / 2) / vertices.doubleValue();

        LOG.info("superstep\t" + superstep + "\tedge\t" + edges + "\tvertices\t" + vertices + "\tdensity\t"
                + currDensity);

        if (currDensity > bestlDensity) {
            bestlDensity = currDensity;
            bestDensitySuperstep = superstep - 2;//Densit calcolata sul supertep pari precedente
            this.getConf().setLong(OPTIMALSUPERSTEP, superstep);
        }

        //soglia = 2(1 + epsilon) ?(S)
        Double soglia = 2 * (1 + epsilon) * currDensity;
        LOG.info("soglia = " + soglia);

        this.getContext().getConfiguration().setDouble(SOGLIA, soglia);

    }
    //        else {//1,3,5...
    //
    //        }

}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.ksimplecycle.CustomMessageWithPathPlusPlus.java

@Override
public void write(DataOutput out) throws IOException {

    out.writeInt(visitedVertex.size());/*from   ww w . jav a 2  s  . c  o  m*/
    for (LongWritable item : visitedVertex) {
        out.writeLong(item.get());
    }
    out.writeLong(this.id.get());
    out.writeLong(this.value.get());
}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.sssp.longwritable.SimpleShortestPathsComputationTextValue.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, LongWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {

    if (getSuperstep() == 0) {
        vertex.setValue(new LongWritable(Long.MAX_VALUE));
    }//w ww .  ja  v  a  2 s .  c o  m
    long minDist = isSource(vertex) ? 0 : Long.MAX_VALUE;
    for (LongWritable message : messages) {
        minDist = Math.min(minDist, message.get());
    }
    if (LOG.isDebugEnabled()) {
        System.out.println("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = "
                + vertex.getValue());
    }
    if (minDist < new Long(vertex.getValue().toString())) {
        vertex.setValue(new LongWritable(minDist));
        for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {

            //                long distance = minDist + edge.getValue().get();
            long distance = minDist + 1;

            if (LOG.isDebugEnabled()) {
                System.out.println(
                        "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance);
            }
            sendMessage(edge.getTargetVertexId(), new LongWritable(distance));
        }
    }
    vertex.voteToHalt();
}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.trianglecount.longwritable.TriangleCount.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {

    Iterable<Edge<LongWritable, NullWritable>> edges = vertex.getEdges();

    if (getSuperstep() == 0) {

        for (Edge<LongWritable, NullWritable> edge : edges) {
            this.sendMessageToAllEdges(vertex, edge.getTargetVertexId());
        }/*from ww w. j  a  va  2s  .co m*/

    } else if (getSuperstep() == 1) {

        Double T = 0.0;
        Set<Long> edgeMap = Sets.<Long>newHashSet();

        for (Edge<LongWritable, NullWritable> edge : edges) {
            edgeMap.add(edge.getTargetVertexId().get());
        }
        for (LongWritable message : messages) {
            if (edgeMap.contains(message.get())) {
                T++;
            }
        }

        T = T / 6;

        vertex.setValue(new DoubleWritable(T));
        vertex.voteToHalt();

        aggregate(SOMMA + getSuperstep(), new DoubleWritable(T));

    }

}

From source file:it.uniroma1.bdc.tesi.piccioli.giraphstandalone.trianglecount.longwritable.TriangleCountPlusPlusPhase2.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, LongWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {

    Iterable<Edge<LongWritable, NullWritable>> edges = vertex.getEdges();

    if (getSuperstep() == 2) {
        //triangle count
        for (Edge<LongWritable, NullWritable> edge : edges) {
            this.sendMessageToAllEdges(vertex, edge.getTargetVertexId());
        }/*from ww  w .  j  a  va  2s.c  o m*/
    }
    if (getSuperstep() == 3) {
        Integer T = 0;
        Set<Long> edgeMap = Sets.<Long>newHashSet();

        for (Edge<LongWritable, NullWritable> edge : edges) {
            edgeMap.add(edge.getTargetVertexId().get());
        }

        for (LongWritable message : messages) {
            if (edgeMap.contains(message.get())) {
                T++;
            }
        }
        vertex.setValue(new LongWritable(T));
        aggregate(SOMMA + getSuperstep(), new LongWritable(T));
        vertex.voteToHalt();
    }
}