List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable
public DoubleWritable(double value)
From source file:org.apache.giraph.comm.messages.primitives.LongDoubleMessageStore.java
License:Apache License
@Override public Iterable<DoubleWritable> getVertexMessages(LongWritable vertexId) throws IOException { Long2DoubleOpenHashMap partitionMap = getPartitionMap(vertexId); if (!partitionMap.containsKey(vertexId.get())) { return EmptyIterable.get(); } else {/*w w w .j ava 2 s . co m*/ return Collections.singleton(new DoubleWritable(partitionMap.get(vertexId.get()))); } }
From source file:org.apache.giraph.comm.messages.TestLongDoublePrimitiveMessageStores.java
License:Apache License
private static void insertLongDoubleMessages(MessageStore<LongWritable, DoubleWritable> messageStore) throws IOException { ByteArrayVertexIdMessages<LongWritable, DoubleWritable> messages = createLongDoubleMessages(); messages.add(new LongWritable(0), new DoubleWritable(1)); messages.add(new LongWritable(2), new DoubleWritable(3)); messages.add(new LongWritable(0), new DoubleWritable(4)); messageStore.addPartitionMessages(0, messages); messages = createLongDoubleMessages(); messages.add(new LongWritable(1), new DoubleWritable(1)); messages.add(new LongWritable(1), new DoubleWritable(3)); messages.add(new LongWritable(1), new DoubleWritable(4)); messageStore.addPartitionMessages(1, messages); messages = createLongDoubleMessages(); messages.add(new LongWritable(0), new DoubleWritable(5)); messageStore.addPartitionMessages(0, messages); }
From source file:org.apache.giraph.debugger.examples.instrumented.BuggySimpleShortestPathsDebugComputationModified.java
License:Apache License
@Override public void compute(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { // We do a dummy read of the aggregator below because for now we only // intercept an aggregator // if at least one vertex reads it. LongWritable aggregatedValue = getAggregatedValue( SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR); if (aggregatedValue != null) { System.out.print("NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR: " + aggregatedValue.get() + "\n"); }//from w w w. ja v a 2s . c o m if (getSuperstep() == 0) { vertex.setValue(new DoubleWritable(isSource(vertex) ? 0d : Double.MAX_VALUE)); } double previousValue = vertex.getValue().get(); double minDist = previousValue; for (DoubleWritable message : messages) { minDist = Math.min(minDist, message.get()); } if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = " + vertex.getValue()); } if (minDist < vertex.getValue().get() || getSuperstep() == 0 && minDist == 0) { vertex.setValue(new DoubleWritable(minDist)); for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) { double distance = minDist + edge.getValue().get(); if (LOG.isDebugEnabled()) { LOG.debug( "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance); } // INTENTIONAL BUG:Instead of sending the distance (i.e. by adding edge // values), // we send the vertex value. sendMessage(edge.getTargetVertexId(), new DoubleWritable(minDist)); } } if (previousValue > 3 && minDist <= 3) { aggregate(SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR, new LongWritable(1)); } vertex.voteToHalt(); }
From source file:org.apache.giraph.debugger.examples.pagerank.SimplePageRankComputation.java
License:Apache License
@Override public void compute(Vertex<LongWritable, DoubleWritable, NullWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { if (getSuperstep() >= 1) { double sum = 0; for (DoubleWritable message : messages) { sum += message.get();//from ww w. j ava2 s.com } DoubleWritable vertexValue = new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum); vertex.setValue(vertexValue); aggregate(MAX_AGG, vertexValue); aggregate(MIN_AGG, vertexValue); aggregate(SUM_AGG, new LongWritable(1)); // LOG.info(vertex.getId() + ": PageRank=" + vertexValue + " max=" + // getAggregatedValue(MAX_AGG) + " min=" + getAggregatedValue(MIN_AGG)); } if (getSuperstep() < MAX_SUPERSTEPS) { long edges = vertex.getNumEdges(); sendMessageToAllEdges(vertex, new DoubleWritable(vertex.getValue().get() / edges)); } else { vertex.voteToHalt(); } }
From source file:org.apache.giraph.debugger.examples.simpledebug.BuggySimpleShortestPathsComputation.java
License:Apache License
@Override public void compute(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { // We do a dummy read of the aggregator below because for now we only // intercept an aggregator // if at least one vertex reads it. LongWritable aggregatedValue = getAggregatedValue( SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR); if (aggregatedValue != null) { System.out.print("NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR: " + aggregatedValue.get() + "\n"); }/* www.j a v a 2 s . c o m*/ if (getSuperstep() == 0) { vertex.setValue(new DoubleWritable(isSource(vertex) ? 0d : Double.MAX_VALUE)); } double previousValue = vertex.getValue().get(); double minDist = previousValue; for (DoubleWritable message : messages) { minDist = Math.min(minDist, message.get()); } if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = " + vertex.getValue()); } if (minDist < vertex.getValue().get() || getSuperstep() == 0 && minDist == 0) { vertex.setValue(new DoubleWritable(minDist)); for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) { double distance = minDist + edge.getValue().get(); if (LOG.isDebugEnabled()) { LOG.debug( "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance); } // INTENTIONAL BUG:Instead of sending the distance (i.e. by adding edge // values), // we send minDist, which is the vertex value. sendMessage(edge.getTargetVertexId(), new DoubleWritable(minDist)); } } if (previousValue > 3 && minDist <= 3) { aggregate(SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR, new LongWritable(1)); } vertex.voteToHalt(); }
From source file:org.apache.giraph.debugger.instrumenter.test.basecompute.DerivedComputation.java
License:Apache License
@Override protected void collect(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages) { if (getSuperstep() == 0) { vertex.setValue(new DoubleWritable(Double.MAX_VALUE)); }/*from ww w . j ava 2s . c om*/ if (getSuperstep() == 8) { throw new RuntimeException("bug"); } minDist = isSource(vertex) ? 0d : Double.MAX_VALUE; for (DoubleWritable message : messages) { minDist = Math.min(minDist, message.get()); } if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = " + vertex.getValue()); } }
From source file:org.apache.giraph.debugger.instrumenter.test.basecompute.DerivedComputation.java
License:Apache License
@Override protected void signal(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages) { if (minDist < vertex.getValue().get()) { vertex.setValue(new DoubleWritable(minDist)); for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) { double distance = minDist + edge.getValue().get(); if (LOG.isDebugEnabled()) { LOG.debug(// w w w. jav a 2 s . co m "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance); } // INTENTIONAL BUG:Instead of sending the distance (i.e. by // adding edge values), we send the vertex value. sendMessage(edge.getTargetVertexId(), new DoubleWritable(minDist)); } } }
From source file:org.apache.giraph.debugger.mock.TestGraphGenerator.java
License:Apache License
/** * Constructs a {@link Writable} object with the appropriate type that * contains the specified content. For example, type can be LongWritable, * and content can be 100L, and this method would return a new * {@link LongWritable} that has value 100. * @param contents contetns of the writable. * @param type type of the writable.// www. j a v a2s. c o m * @return a {@link Writable} object of appropriate type, whose value contains * the given contents. */ private Writable convertToSuitableType(String contents, WritableType type) { switch (type) { case NULL: return NullWritable.get(); case LONG: return new LongWritable(Long.valueOf(contents)); case DOUBLE: return new DoubleWritable(Double.valueOf(contents)); default: throw new IllegalStateException("Unknown type!"); } }
From source file:org.apache.giraph.edge.TestMultiGraphEdges.java
License:Apache License
private void testParallelEdgesClass(Class<? extends OutEdges> edgesClass) { OutEdges<LongWritable, DoubleWritable> edges = instantiateOutEdges(edgesClass); // Initial edges list contains parallel edges. List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList( EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)), EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)), EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)), EdgeFactory.create(new LongWritable(2), new DoubleWritable(20))); edges.initialize(initialEdges);/*from w w w .j a va 2s.c o m*/ // The parallel edges should still be there. assertEquals(4, edges.size()); // Adding a parallel edge should increase the number of edges. edges.add(EdgeFactory.create(new LongWritable(3), new DoubleWritable(30))); assertEquals(5, edges.size()); // Removing edges pointing to a given vertex should remove all parallel // edges. edges.remove(new LongWritable(2)); assertEquals(3, edges.size()); }
From source file:org.apache.giraph.edge.TestMultiRandomAccessEdges.java
License:Apache License
private void testParallelEdgesClass(Class<? extends MultiRandomAccessOutEdges> edgesClass) { MultiRandomAccessOutEdges<LongWritable, DoubleWritable> edges = (MultiRandomAccessOutEdges<LongWritable, DoubleWritable>) instantiateOutEdges( edgesClass);//from www. j av a 2 s . com // Initial edges list contains parallel edges. List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList( EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)), EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)), EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)), EdgeFactory.create(new LongWritable(2), new DoubleWritable(20))); edges.initialize(initialEdges); assertEquals(2, Iterables.size(edges.getAllEdgeValues(new LongWritable(2)))); assertEquals(1, Iterables.size(edges.getAllEdgeValues(new LongWritable(1)))); assertEquals(0, Iterables.size(edges.getAllEdgeValues(new LongWritable(42)))); }