本文整理了Java中org.apache.giraph.graph.Vertex.initialize()
方法的一些代码示例,展示了Vertex.initialize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.initialize()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:initialize
[英]Initialize id and value. Vertex edges will be empty. This method (or the alternative form initialize(id, value, edges)) must be called after instantiation, unless readFields() is called.
[中]初始化id和值。顶点边将为空。除非调用readFields(),否则实例化后必须调用此方法(或替代形式initialize(id、value、edges))。
代码示例来源:origin: qcri/Arabesque
@Override
public Vertex<IntWritable, NullWritable, NullWritable> getCurrentVertex() throws IOException, InterruptedException {
Vertex<IntWritable, NullWritable, NullWritable> vertex =
getConf().createVertex();
IntWritable id = new IntWritable(inputSplit.getSplitIndex());
List<Edge<IntWritable, NullWritable>> edges = Collections.emptyList();
vertex.initialize(id, NullWritable.get(), edges);
generated = true;
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public Vertex<LongWritable, DoubleWritable, NullWritable>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, NullWritable>
vertex = conf.createVertex();
String[] tokens =
separator.split(getRecordReader().getCurrentValue().toString());
List<Edge<LongWritable, NullWritable>> edges =
Lists.newArrayListWithCapacity(tokens.length - 1);
for (int n = 1; n < tokens.length; n++) {
edges.add(EdgeFactory.create(
new LongWritable(Long.parseLong(tokens[n])),
NullWritable.get()));
}
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* The backing store of the current vertex id is now released.
* Further calls to getCurrentVertexId () without calling next()
* will return null.
*
* @return Current vertex id that was released
*/
public I releaseCurrentVertexId() {
I releasedVertexId = vertex.getId();
vertex.initialize(null, vertex.getValue());
return releasedVertexId;
}
代码示例来源:origin: apache/giraph
public void initializeVertex(
Vertex<I, V, E> v, I id, Supplier<V> valueSupplier,
List<Edge<I, E>> edgesList) {
v.initialize(
id,
valueSupplier != null ?
valueSupplier.get() : getConf().createVertexValue(),
edgesList != null ? edgesList : new ArrayList<Edge<I, E>>());
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Create a vertex
*
* @param id the id of the vertex
* @param value the vertex value
* @param edges edges to other vertices
* @return a new vertex
*/
protected Vertex<I, V, E> makeVertex(I id, V value,
Entry<I, E>... edges) {
Vertex<I, V, E> vertex = conf.createVertex();
vertex.initialize(id, value, createEdges(edges));
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add an edge to an existing vertex
*
* @param vertexId Edge origin
* @param edgePair The edge
* @return this
*/
public TestGraph<I, V, E> addEdge(I vertexId, Entry<I, E> edgePair) {
if (!vertices.containsKey(vertexId)) {
Vertex<I, V, E> v = conf.createVertex();
v.initialize(vertexId, conf.createVertexValue());
vertices.put(vertexId, v);
}
vertices.get(vertexId)
.addEdge(EdgeFactory.create(edgePair.getKey(),
edgePair.getValue()));
return this;
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public Vertex<LongWritable, DoubleWritable, FloatWritable>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, FloatWritable>
vertex = conf.createVertex();
String[] tokens = neighborSeparator.split(getRecordReader()
.getCurrentValue().toString());
List<Edge<LongWritable, FloatWritable>> edges =
Lists.newArrayListWithCapacity(tokens.length - 1);
for (int n = 1; n < tokens.length; n++) {
String[] parts = weightSeparator.split(tokens[n]);
edges.add(EdgeFactory.create(
new LongWritable(Long.parseLong(parts[0])),
new FloatWritable(Float.parseFloat(parts[1]))));
}
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public Vertex<LongWritable, DoubleWritable, DoubleWritable>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, DoubleWritable>
vertex = conf.createVertex();
String[] tokens =
separator.split(getRecordReader().getCurrentValue().toString());
List<Edge<LongWritable, DoubleWritable>> edges =
Lists.newArrayListWithCapacity(tokens.length - 1);
float weight = 1.0f / (tokens.length - 1);
for (int n = 1; n < tokens.length; n++) {
edges.add(EdgeFactory.create(
new LongWritable(Long.parseLong(tokens[n])),
new DoubleWritable(weight)));
}
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public Vertex<LongWritable, DoubleWritable, DoubleWritable>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex =
conf.createVertex();
String[] tokens = edgeSeparator.split(getRecordReader()
.getCurrentValue().toString());
List<Edge<LongWritable, DoubleWritable>> edges = Lists
.newArrayListWithCapacity(tokens.length - 1);
parse(tokens, edges);
normalize(edges);
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add an edge to an existing vertex
*
* @param vertexId Edge origin
* @param toVertex Edge destination
* @param edgeValue Edge value
* @return this
*/
public TestGraph<I, V, E> addEdge(I vertexId, I toVertex, E edgeValue) {
if (!vertices.containsKey(vertexId)) {
Vertex<I, V, E> v = conf.createVertex();
v.initialize(vertexId, conf.createVertexValue());
vertices.put(vertexId, v);
}
vertices.get(vertexId)
.addEdge(EdgeFactory.create(toVertex, edgeValue));
return this;
}
/**
代码示例来源:origin: org.apache.giraph/giraph-examples
@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;
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Sends a request to create a vertex that will be available during the
* next superstep.
*
* @param id Vertex id
* @param value Vertex value
* @param edges Initial edges
*/
@Override
public void addVertexRequest(I id, V value,
OutEdges<I, E> edges) throws IOException {
Vertex<I, V, E> vertex = getConf().createVertex();
vertex.initialize(id, value, edges);
workerClientRequestProcessor.addVertexRequest(vertex);
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Reset the empty Vertex to an initial state.
*/
private void resetEmptyVertex() {
vertex = configuration.createVertex();
I id = configuration.createVertexId();
V value = configuration.createVertexValue();
OutEdges<I, E> edges = configuration.createOutEdges();
vertex.initialize(id, value, edges);
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public final Vertex<I, V, Writable> getCurrentVertex() throws IOException,
InterruptedException {
Vertex<I, V, Writable> vertex = getConf().createVertex();
vertex.initialize(getCurrentVertexId(), getCurrentVertexValue());
return vertex;
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Moves to the next element in the iteration.
*/
public void next() {
// If the vertex was released, create another one
if (vertex == null) {
resetEmptyVertex();
}
// If the vertex id was released, create another one
if (vertex.getId() == null) {
vertex.initialize(configuration.createVertexId(), vertex.getValue());
}
try {
WritableUtils.reinitializeVertexFromDataInput(
extendedDataInput, vertex, configuration);
} catch (IOException e) {
throw new IllegalStateException("next: IOException", e);
}
}
代码示例来源:origin: apache/giraph
/**
* Creates a new Vertex object, without adding it into the graph.
*
* This function is safe to call from multiple threads at the same time,
* and then synchronize only on actual addition of Vertex to the graph
* itself.
*/
public Vertex<I, V, E> makeVertex(
Number vertexId, V vertexValue,
Entry<? extends Number, ? extends Number>... edges) {
Vertex<I, V, E> vertex = getConf().createVertex();
List<Edge<I, E>> edgesList = new ArrayList<>();
int i = 0;
for (Entry<? extends Number, ? extends Number> edge: edges) {
edgesList.add(EdgeFactory.create(
numberToVertexId(edge.getKey()),
numberToEdgeValue(edge.getValue())));
i++;
}
vertex.initialize(
numberToVertexId(vertexId),
vertexValue != null ?
vertexValue : getConf().createVertexValue(),
edgesList);
return vertex;
}
代码示例来源:origin: apache/giraph
/**
* Creates a new Vertex object, without adding it into the graph.
*
* This function is safe to call from multiple threads at the same time,
* and then synchronize only on actual addition of Vertex to the graph
* itself.
*/
public Vertex<I, V, E> makeVertex(
Number vertexId, Number value,
Number edgeValue, Number... edges) {
Vertex<I, V, E> vertex = getConf().createVertex();
List<Edge<I, E>> edgesList = new ArrayList<>();
for (Number edge: edges) {
edgesList.add(
EdgeFactory.create(numberToVertexId.apply(edge),
numberToEdgeValue(edgeValue)));
}
vertex.initialize(
numberToVertexId.apply(vertexId),
numberToVertexValue(value),
edgesList);
return vertex;
}
代码示例来源:origin: apache/giraph
/**
* Creates a new Vertex object, without adding it into the graph.
*
* This function is safe to call from multiple threads at the same time,
* and then synchronize only on actual addition of Vertex to the graph
* itself.
*/
public Vertex<I, V, E> makeVertex(
Number vertexId, V vertexValue,
Supplier<E> edgeSupplier, Number... edges) {
Vertex<I, V, E> vertex = getConf().createVertex();
List<Edge<I, E>> edgesList = new ArrayList<>();
for (Number edge: edges) {
edgesList.add(
EdgeFactory.create(numberToVertexId.apply(edge),
edgeSupplier != null ?
edgeSupplier.get() : getConf().createEdgeValue()));
}
vertex.initialize(
numberToVertexId.apply(vertexId),
vertexValue != null ?
vertexValue : getConf().createVertexValue(),
edgesList);
return vertex;
}
代码示例来源:origin: org.apache.giraph/giraph-core
vertex.initialize(new LongWritable(vertexId),
new DoubleWritable(rnd.nextDouble()), edges);
++verticesRead;
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public void initialize(int partitionId, Progressable progressable) {
super.initialize(partitionId, progressable);
vertexMap = new MapMaker().concurrencyLevel(
getConf().getNettyServerExecutionConcurrency()).makeMap();
representativeVertex = getConf().createVertex();
representativeVertex.initialize(
getConf().createVertexId(),
getConf().createVertexValue(),
getConf().createOutEdges());
representativeCombinerVertex = getConf().createVertex();
representativeCombinerVertex.initialize(
getConf().createVertexId(),
getConf().createVertexValue(),
getConf().createOutEdges());
useUnsafeSerialization = getConf().useUnsafeSerialization();
}
内容来源于网络,如有侵权,请联系作者删除!