org.apache.giraph.graph.Vertex Java Examples
The following examples show how to use
org.apache.giraph.graph.Vertex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PageRankAlgorithm.java From rheem with Apache License 2.0 | 6 votes |
@Override public Vertex<LongWritable, DoubleWritable, FloatWritable> getCurrentVertex() throws IOException { Vertex<LongWritable, DoubleWritable, FloatWritable> vertex = getConf().createVertex(); LongWritable vertexId = new LongWritable( (inputSplit.getSplitIndex() * totalRecords) + recordsRead); DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d); long targetVertexId = (vertexId.get() + 1) % (inputSplit.getNumSplits() * totalRecords); float edgeValue = vertexId.get() * 100f; List<Edge<LongWritable, FloatWritable>> edges = Lists.newLinkedList(); edges.add(EdgeFactory.create(new LongWritable(targetVertexId), new FloatWritable(edgeValue))); vertex.initialize(vertexId, vertexValue, edges); ++recordsRead; if (LOG.isInfoEnabled()) { LOG.info("next: Return vertexId=" + vertex.getId().get() + ", vertexValue=" + vertex.getValue() + ", targetVertexId=" + targetVertexId + ", edgeValue=" + edgeValue); } return vertex; }
Example #2
Source File: LouvainVertexOutputFormat.java From distributed-louvain-modularity with Apache License 2.0 | 6 votes |
@Override public void writeVertex( Vertex<Text, LouvainNodeState, LongWritable, ?> vertex) throws IOException, InterruptedException { StringBuilder b = new StringBuilder(); b.append(vertex.getValue().getCommunity()); b.append("\t"); b.append(vertex.getValue().getInternalWeight()); b.append("\t"); for (Edge<Text,LongWritable> e: vertex.getEdges()){ b.append(e.getTargetVertexId()); b.append(":"); b.append(e.getValue()); b.append(","); } b.setLength(b.length() - 1); getRecordWriter().write(vertex.getId(), new Text(b.toString())); }
Example #3
Source File: ZombieTextVertexOutputFormat.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
public void writeVertex(Vertex<LongWritable, Text, LongWritable> vertex) throws IOException, InterruptedException { Iterable<Edge<LongWritable, LongWritable>> edges = vertex.getEdges(); StringBuilder strBuilder = new StringBuilder(); boolean isFirst = true; for (Edge<LongWritable, LongWritable> edge : edges) { if (isFirst) { isFirst = false; } else { strBuilder.append(","); } strBuilder.append(edge.getValue()); } newKey.set(vertex.getId().get() + "|" + vertex.getValue() + "|" + strBuilder.toString()); getRecordWriter().write(newKey, newValue); }
Example #4
Source File: ZombieTextVertexInputFormat.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
@Override public Vertex<LongWritable, Text, LongWritable> getCurrentVertex() throws IOException, InterruptedException { Text line = getRecordReader().getCurrentValue(); String[] majorParts = line.toString().split("\\|"); LongWritable id = new LongWritable(Long.parseLong(majorParts[0])); Text value = new Text(majorParts[1]); ArrayList<Edge<LongWritable, LongWritable>> edgeIdList = new ArrayList<Edge<LongWritable, LongWritable>>(); if (majorParts.length > 2) { String[] edgeIds = majorParts[2].split(","); for (String edgeId: edgeIds) { DefaultEdge<LongWritable, LongWritable> edge = new DefaultEdge<LongWritable, LongWritable>(); LongWritable longEdgeId = new LongWritable(Long.parseLong(edgeId)); edge.setTargetVertexId(longEdgeId); edge.setValue(longEdgeId); // dummy value edgeIdList.add(edge); } } Vertex<LongWritable, Text, LongWritable> vertex = getConf().createVertex(); vertex.initialize(id, value, edgeIdList); return vertex; }
Example #5
Source File: LouvainVertexOutputFormat.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
@Override public void writeVertex(Vertex<Text, LouvainNodeState, LongWritable> vertex) throws IOException, InterruptedException { StringBuilder b = new StringBuilder(); b.append(vertex.getValue().getCommunity()); b.append("\t"); b.append(vertex.getValue().getInternalWeight()); b.append("\t"); for (Edge<Text, LongWritable> e : vertex.getEdges()) { b.append(e.getTargetVertexId()); b.append(":"); b.append(e.getValue()); b.append(","); } b.deleteCharAt(b.length() - 1); getRecordWriter().write(vertex.getId(), new Text(b.toString())); }
Example #6
Source File: WeaklyConnectedComponentComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
@Override public void compute(Vertex<Text, Text, Text> vertex, Iterable<Text> messages) throws IOException { try { if (getSuperstep() == 0) { broadcastGreatestNeighbor(vertex); return; } boolean changed = false; String maxId = vertex.getValue().toString(); for (Text incomingMessage : messages) { if (maxId.compareTo(incomingMessage.toString()) < 0) { maxId = incomingMessage.toString(); changed = true; } } broadcastUpdates(vertex, changed, maxId); } catch (Exception e) { System.err.print(e.toString()); } }
Example #7
Source File: LeafCompressionComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
/** * Inform each node we are connected to if we only have one edge so that we can be purged from the graph, or vote * to halt * * @param vertex The current vertex being operated upon by the compute method */ private void sendEdges(Vertex<Text, Text, Text> vertex) { int vertexValue = getVertexValue(vertex.getValue().toString()); if (vertex.getNumEdges() == 1 && vertexValue != -1) { for (Edge<Text, Text> edge : vertex.getEdges()) { sendMessage(edge.getTargetVertexId(), new Text(vertex.getId().toString() + ":" + vertexValue)); } logger.debug("{} is being deleted.", vertex.getId()); vertex.setValue(new Text("-1")); // This node will never vote to halt, but will simply be deleted. } else if (vertexValue != -1) { // If we aren't being imminently deleted logger.debug("{} is still in the graph.", vertex.getId()); vertex.voteToHalt(); } }
Example #8
Source File: LeafCompressionComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
@Override public void compute(Vertex<Text, Text, Text> vertex, Iterable<Text> messages) throws IOException { try { // Check to see if we received any messages from connected nodes notifying us // that they have only a single edge, and can subsequently be pruned from the graph for (Text incomingMessage : messages) { Text messageVertex = new Text(incomingMessage.toString().split(":")[0]); int messageValue = getVertexValue(incomingMessage.toString().split(":")[1]); vertex.setValue(new Text(String.format("%d", getVertexValue(vertex.getValue().toString()) + 1 + messageValue))); // Remove the vertex and its corresponding edge removeVertexRequest(messageVertex); vertex.removeEdges(messageVertex); } // Broadcast the edges if we only have a single edge sendEdges(vertex); } catch (Exception e) { System.err.println(e.toString()); } }
Example #9
Source File: LouvainComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
/** * Replace each edge to a neighbor with an edge to that neigbors community * instead. Done just before exiting computation. In the next state of the * piple line this edges are aggregated and all communities are represented * as single nodes. Edges from the community to itself are tracked be the * ndoes interal weight. * * @param messages */ private void replaceNodeEdgesWithCommunityEdges(Vertex<Text, LouvainNodeState, LongWritable> vertex, Iterable<LouvainMessage> messages) { // group messages by communities. HashMap<String, LouvainMessage> communityMap = new HashMap<String, LouvainMessage>(); for (LouvainMessage message : messages) { String communityId = message.getCommunityId(); if (communityMap.containsKey(communityId)) { LouvainMessage m = communityMap.get(communityId); m.setEdgeWeight(m.getEdgeWeight() + message.getEdgeWeight()); } else { LouvainMessage newmess = new LouvainMessage(message); communityMap.put(communityId, newmess); } } List<Edge<Text, LongWritable>> edges = new ArrayList<Edge<Text, LongWritable>>(communityMap.size() + 1); for (Map.Entry<String, LouvainMessage> entry : communityMap.entrySet()) { edges.add(EdgeFactory.create(new Text(entry.getKey()), new LongWritable(entry.getValue().getEdgeWeight()))); } vertex.setEdges(edges); }
Example #10
Source File: LouvainComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
/** * Calculate this nodes contribution for the actual q value of the graph. */ private double calculateActualQ(Vertex<Text, LouvainNodeState, LongWritable> vertex, Iterable<LouvainMessage> messages) { // long start = System.currentTimeMillis(); LouvainNodeState state = vertex.getValue(); long k_i_in = state.getInternalWeight(); for (LouvainMessage m : messages) { if (m.getCommunityId().equals(state.getCommunity())) { try { k_i_in += vertex.getEdgeValue(new Text(m.getSourceId())).get(); } catch (NullPointerException e) { throw new IllegalStateException("Node: " + vertex.getId() + " does not have edge: " + m.getSourceId() + " check that the graph is bi-directional."); } } } long sigma_tot = vertex.getValue().getCommunitySigmaTotal(); long M = this.getTotalEdgeWeight(); long k_i = vertex.getValue().getNodeWeight() + vertex.getValue().getInternalWeight(); double q = ((((double) k_i_in) / M) - (((double) (sigma_tot * k_i)) / Math.pow(M, 2))); q = (q < 0) ? 0 : q; // long end = System.currentTimeMillis(); // System.out.println("calculated actual q in :"+(end-start)); return q; }
Example #11
Source File: PageRankComputation.java From distributed-graph-analytics with Apache License 2.0 | 6 votes |
@Override public void compute(Vertex<Text, DoubleWritable, Text> vertex, Iterable<DoubleWritable> messages) throws IOException { float dampingFactor = this.getConf().getFloat(DAMPING_FACTOR, DAMPING_FACTOR_DEFAULT_VALUE); long step = getSuperstep(); if (step == 0) { //set initial value logger.debug("Superstep is 0: Setting the default value."); vertex.setValue(new DoubleWritable(1.0 / getTotalNumVertices())); } else { // go until no one votes to continue double rank = 0; for (DoubleWritable partial : messages) { rank += partial.get(); } rank = ((1 - dampingFactor) / getTotalNumVertices()) + (dampingFactor * rank); double vertexValue = vertex.getValue().get(); double delta = Math.abs(rank - vertexValue) / vertexValue; aggregate(MAX_EPSILON, new DoubleWritable(delta)); vertex.setValue(new DoubleWritable(rank)); logger.debug("{} is calculated {} for a PageRank.", vertex.getId(), rank); } distributeRank(vertex); }
Example #12
Source File: ExecutionEngine.java From Arabesque with Apache License 2.0 | 6 votes |
@Override public void compute(Vertex<IntWritable, NullWritable, NullWritable> vertex, Iterable<MessageWrapper> receivedMessages) throws IOException { if (!firstVertex) { throw new RuntimeException("compute ran more than once in same SS. " + "Check # of aggs. Has to be less than # of partitions"); } communicationStrategy.startComputation(vertex, receivedMessages); if (getPhase() == 0) { expansionCompute(vertex); } communicationStrategy.endComputation(); firstVertex = false; }
Example #13
Source File: ODAGCommunicationStrategy.java From Arabesque with Apache License 2.0 | 6 votes |
@Override public void startComputation(Vertex<IntWritable, NullWritable, NullWritable> vertex, Iterable<MessageWrapper> messages) { super.startComputation(vertex, messages); if (getCurrentPhase() == 1) { aggregatedEmbeddingStash = new ODAGStash(); ODAG ezip = new ODAG(false); for (MessageWrapper messageWrapper : messages) { ODAGPartLZ4Wrapper ezipWrapper = messageWrapper.getMessage(); ezipWrapper.readEzip(ezip); aggregatedEmbeddingStash.aggregateUsingReusable(ezip); } } }
Example #14
Source File: IdWithValueTextOutputFormat.java From hgraphdb with Apache License 2.0 | 6 votes |
@Override protected Text convertVertexToLine(Vertex<I, V, E> vertex) throws IOException { StringBuilder str = new StringBuilder(); if (reverseOutput) { str.append(vertex.getValue().getValue()); str.append(delimiter); str.append(vertex.getId().toString()); } else { str.append(vertex.getId().toString()); str.append(delimiter); str.append(vertex.getValue().getValue()); } return new Text(str.toString()); }
Example #15
Source File: MaxComputation.java From hgraphdb with Apache License 2.0 | 6 votes |
@Override public void compute(final Vertex<ObjectWritable<Integer>, VertexValueWritable<IntWritable>, EdgeValueWritable<NullWritable>> vertex, final Iterable<IntWritable> messages) throws IOException { VertexValueWritable<IntWritable> vertexValue = vertex.getValue(); HBaseVertex v = vertexValue.getVertex(); if (vertexValue.getValue() == null) { vertexValue.setValue(new IntWritable(((Number) v.id()).intValue())); } int value = vertexValue.getValue().get(); boolean changed = false; for (IntWritable message : messages) { if (value < message.get()) { value = message.get(); vertexValue.setValue(new IntWritable(value)); changed = true; } } if (getSuperstep() == 0 || changed) { sendMessageToAllEdges(vertex, new IntWritable(value)); } vertex.voteToHalt(); }
Example #16
Source File: CacheCommunicationStrategy.java From Arabesque with Apache License 2.0 | 5 votes |
@Override public void startComputation(Vertex<IntWritable, NullWritable, NullWritable> vertex, Iterable<MessageWrapper> messages) { super.startComputation(vertex, messages); messageIterator = messages.iterator(); computation = getExecutionEngine().getComputation(); try { patternAggFilterDefined = computation.getClass().getMethod("aggregationFilter", Pattern.class).getDeclaringClass() != BasicComputation.class; } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
Example #17
Source File: PageRankAlgorithm.java From rheem with Apache License 2.0 | 5 votes |
@Override public void compute( Vertex<LongWritable, DoubleWritable, FloatWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { if(maxSupersteps == -1){ maxSupersteps = (PageRankParameters.hasElement(PageRankParameters.PageRankEnum.ITERATION))? PageRankParameters.getParameter(PageRankParameters.PageRankEnum.ITERATION): MAX_SUPERSTEPS; } if (getSuperstep() >= 1) { double sum = 0; for (DoubleWritable message : messages) { sum += message.get(); } 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() < maxSupersteps) { long edges = vertex.getNumEdges(); sendMessageToAllEdges(vertex, new DoubleWritable(vertex.getValue().get() / edges)); } else { vertex.voteToHalt(); } }
Example #18
Source File: PageRankAlgorithm.java From rheem with Apache License 2.0 | 5 votes |
@Override public void writeVertex( Vertex<LongWritable, DoubleWritable, FloatWritable> vertex) throws IOException, InterruptedException { getRecordWriter().write( new Text(vertex.getId().toString()), new Text(vertex.getValue().toString())); }
Example #19
Source File: HBSEOutputFormatTest.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { tw = mock(RecordWriter.class); GiraphConfiguration giraphConfiguration = new GiraphConfiguration(); giraphConfiguration.setComputationClass(BasicComputation.class); conf = new ImmutableClassesGiraphConfiguration<Text, VertexData, Text>(giraphConfiguration); vertex = mock(Vertex.class); vertex2 = mock(Vertex.class); when(vertex.getId()).thenReturn(new Text("1")); when(vertex.getValue()).thenReturn(new VertexData()); when(vertex2.getId()).thenReturn(new Text("2")); vertexData = new VertexData(); vertexData.setApproxBetweenness(1.0); when(vertex2.getValue()).thenReturn(vertexData); }
Example #20
Source File: DGAEdgeTDTOutputFormatTest.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { GiraphConfiguration giraphConfiguration = new GiraphConfiguration(); conf = new ImmutableClassesGiraphConfiguration<Text, Text, Text>(giraphConfiguration); tac = mock(TaskAttemptContext.class); vertex = mock(Vertex.class); when(vertex.getId()).thenReturn(new Text("34")); when(vertex.getValue()).thenReturn(new DoubleWritable(10.43433333389)); Iterable<Edge<Text, Text>> iterable = mock(Iterable.class); Iterator<Edge<Text, Text>> iterator = mock(Iterator.class); when(iterable.iterator()).thenReturn(iterator); edge1 = mock(Edge.class); when(edge1.getTargetVertexId()).thenReturn(new Text("12")); when(edge1.getValue()).thenReturn(new Text("1")); edge2 = mock(Edge.class); when(edge2.getTargetVertexId()).thenReturn(new Text("6")); when(edge2.getValue()).thenReturn(new Text("4")); rw = mock(RecordWriter.class); when(iterator.hasNext()).thenReturn(true, true, false); when(iterator.next()).thenReturn(edge1, edge2); }
Example #21
Source File: DGAEdgeTTTOutputFormatTest.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { GiraphConfiguration giraphConfiguration = new GiraphConfiguration(); conf = new ImmutableClassesGiraphConfiguration<Text, Text, Text>(giraphConfiguration); tac = mock(TaskAttemptContext.class); when(tac.getConfiguration()).thenReturn(conf); vertex = mock(Vertex.class); when(vertex.getId()).thenReturn(new Text("34")); when(vertex.getValue()).thenReturn(new Text("10")); Iterable<Edge<Text, Text>> iterable = mock(Iterable.class); Iterator<Edge<Text, Text>> iterator = mock(Iterator.class); when(iterable.iterator()).thenReturn(iterator); edge1 = mock(Edge.class); when(edge1.getTargetVertexId()).thenReturn(new Text("12")); when(edge1.getValue()).thenReturn(new Text("1")); edge2 = mock(Edge.class); when(edge2.getTargetVertexId()).thenReturn(new Text("6")); when(edge2.getValue()).thenReturn(new Text("4")); rw = mock(RecordWriter.class); when(iterator.hasNext()).thenReturn(true, true, false); when(iterator.next()).thenReturn(edge1, edge2); }
Example #22
Source File: LeafCompressionComputationTest.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
private void checkConnectionsFromVertex(TestGraph graph, String vertex, String ... edges) { Text vertexText = new Text(vertex); Vertex<Text, Text, Text> vert = graph.getVertex(vertexText); assertNotNull("Vertex " + vertex + " was null!", vert); Map<String, Edge<Text, Text>> existingEdges = buildLookup(vert); for (String node : edges) { assertNotNull("Node " + node + " was not found", existingEdges.get(node)); } }
Example #23
Source File: LeafCompressionComputationTest.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
private Map<String, Edge<Text, Text>> buildLookup(Vertex<Text, Text, Text> vertex) { Map<String, Edge<Text, Text>> lookup = new HashMap<String, Edge<Text, Text>>(); for(Edge<Text, Text> edge : vertex.getEdges()) { lookup.put(edge.getTargetVertexId().toString(), edge); } return lookup; }
Example #24
Source File: HBaseVertexOutputFormat.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public void writeVertex( Vertex<ObjectWritable, VertexValueWritable, Writable> vertex) throws IOException, InterruptedException { HBaseVertex v = vertex.getValue().getVertex(); v.setGraph(graph); writeVertex(getWriter(), v, vertex.getValue().getValue()); }
Example #25
Source File: WeaklyConnectedComponentComputation.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
/** * Sends a message to all neighbors if the greatest value has changed. * * @param vertex The current vertex. * @param changed Has the greatest value changed? * @param maxId The current id that has the greatest value. */ private void broadcastUpdates(Vertex<Text, Text, Text> vertex, boolean changed, String maxId) { if (changed) { logger.debug("{} has updated with component id {}", vertex.getId(), maxId); vertex.setValue(new Text(maxId)); sendMessageToAllEdges(vertex, new Text(vertex.getValue().toString())); } vertex.voteToHalt(); }
Example #26
Source File: WeaklyConnectedComponentComputation.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
/** * Only called during the first superstep. * For Each Edge, find the one who has the greatest id and broadcast that to all neighbors. * * @param vertex The current vertex being operated on. */ private void broadcastGreatestNeighbor(Vertex<Text, Text, Text> vertex) { String maxId = vertex.getId().toString(); for (Edge<Text, Text> edge : vertex.getEdges()) { if (maxId.compareTo(edge.getTargetVertexId().toString()) < 0) { maxId = edge.getTargetVertexId().toString(); } } logger.debug("First Superstep for {}: Sending {} to all my edges.", vertex.getId(), maxId); broadcastUpdates(vertex, true, maxId); }
Example #27
Source File: SimpleShortestPathsComputation.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public void compute( Vertex<ObjectWritable<Long>, VertexValueWritable<DoubleWritable>, EdgeValueWritable<FloatWritable>> vertex, Iterable<DoubleWritable> messages) throws IOException { VertexValueWritable<DoubleWritable> vertexValue = vertex.getValue(); if (getSuperstep() == 0) { vertexValue.setValue(new DoubleWritable(Double.MAX_VALUE)); } double 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()); } if (minDist < vertexValue.getValue().get()) { vertexValue.setValue(new DoubleWritable(minDist)); for (Edge<ObjectWritable<Long>, EdgeValueWritable<FloatWritable>> edge : vertex.getEdges()) { double distance = minDist + ((Number) edge.getValue().getEdge().property("weight").value()).doubleValue(); if (LOG.isDebugEnabled()) { LOG.debug("Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance); } sendMessage(edge.getTargetVertexId(), new DoubleWritable(distance)); } } vertex.voteToHalt(); }
Example #28
Source File: VertexWithDoubleValueNullEdgeTextOutputFormat.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public void writeVertex( Vertex<ObjectWritable<Long>, VertexValueWritable<DoubleWritable>, EdgeValueWritable<NullWritable>> vertex) throws IOException, InterruptedException { StringBuilder output = new StringBuilder(); output.append(vertex.getId().get()); output.append('\t'); output.append(vertex.getValue().getValue().get()); getRecordWriter().write(new Text(output.toString()), null); }
Example #29
Source File: LouvainComputation.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
/** * Each vertex will recieve its own communities sigma_total (if updated), * and then send its currenty community info to each of its neighbors. * * @param messages */ private void getAndSendCommunityInfo(Vertex<Text, LouvainNodeState, LongWritable> vertex, Iterable<LouvainMessage> messages) { LouvainNodeState state = vertex.getValue(); // set new community information. if (getSuperstep() > 0) { Iterator<LouvainMessage> it = messages.iterator(); if (!it.hasNext()) { throw new IllegalStateException("No community info recieved in getAndSendCommunityInfo! Superstep: " + getSuperstep() + " id: " + vertex.getId()); } LouvainMessage inMess = it.next(); if (it.hasNext()) { throw new IllegalStateException("More than one community info packets recieved in getAndSendCommunityInfo! Superstep: " + getSuperstep() + " id: " + vertex.getId()); } state.setCommunity(inMess.getCommunityId()); state.setCommunitySigmaTotal(inMess.getCommunitySigmaTotal()); } // send community info to all neighbors for (Edge<Text, LongWritable> edge : vertex.getEdges()) { LouvainMessage outMess = new LouvainMessage(); outMess.setCommunityId(state.getCommunity()); outMess.setCommunitySigmaTotal(state.getCommunitySigmaTotal()); outMess.setEdgeWeight(edge.getValue().get()); outMess.setSourceId(vertex.getId().toString()); this.sendMessage(edge.getTargetVertexId(), outMess); } }
Example #30
Source File: RyaVertexReader.java From rya with Apache License 2.0 | 5 votes |
@Override public Vertex<Text, RyaTypeWritable, RyaStatementWritable> getCurrentVertex() throws IOException, InterruptedException { RyaStatementWritable currentStatement = reader.getCurrentValue(); RyaStatement ryaStatement = currentStatement.getRyaStatement(); RyaTypeWritable vertexWritable = new RyaTypeWritable(); vertexWritable.setRyaType(ryaStatement.getSubject()); Text vertexId = new Text(ryaStatement.getSubject().getData()); Vertex<Text, RyaTypeWritable, RyaStatementWritable> vertex = classesConfiguration.createVertex(); Edge<Text, RyaStatementWritable> edge = EdgeFactory.create(new Text(ryaStatement.toString()), currentStatement); List<Edge<Text, RyaStatementWritable>> edges = new ArrayList<Edge<Text, RyaStatementWritable>>(); edges.add(edge); vertex.initialize(vertexId, vertexWritable, edges); return vertex; }