本文整理汇总了C++中graphchi_vertex::get_data方法的典型用法代码示例。如果您正苦于以下问题:C++ graphchi_vertex::get_data方法的具体用法?C++ graphchi_vertex::get_data怎么用?C++ graphchi_vertex::get_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphchi_vertex
的用法示例。
在下文中一共展示了graphchi_vertex::get_data方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (first_iteration) {
vertex.set_data(SCCinfo(vertex.id()));
}
if (vertex.get_data().confirmed) {
return;
}
/* Vertices with only in or out edges cannot be part of a SCC (Trimming) */
if (vertex.num_inedges() == 0 || vertex.num_outedges() == 0) {
if (vertex.num_edges() > 0) {
// TODO: check this logic!
vertex.set_data(SCCinfo(vertex.id()));
}
vertex.remove_alledges();
return;
}
remainingvertices = true;
VertexDataType vertexdata = vertex.get_data();
bool propagate = false;
if (gcontext.iteration == 0) {
vertexdata = vertex.id();
propagate = true;
/* Clean up in-edges. This would be nicer in the messaging abstraction... */
for(int i=0; i < vertex.num_inedges(); i++) {
bidirectional_label edgedata = vertex.inedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = vertex.id();
vertex.inedge(i)->set_data(edgedata);
}
} else {
/* Loop over in-edges and choose minimum color */
vid_t minid = vertexdata.color;
for(int i=0; i < vertex.num_inedges(); i++) {
minid = std::min(minid, vertex.inedge(i)->get_data().neighbor_label(vertex.id(), vertex.inedge(i)->vertexid));
}
if (minid != vertexdata.color) {
vertexdata.color = minid;
propagate = true;
}
}
vertex.set_data(vertexdata);
if (propagate) {
for(int i=0; i < vertex.num_outedges(); i++) {
bidirectional_label edgedata = vertex.outedge(i)->get_data();
edgedata.my_label(vertex.id(), vertex.outedge(i)->vertexid) = vertexdata.color;
vertex.outedge(i)->set_data(edgedata);
gcontext.scheduler->add_task(vertex.outedge(i)->vertexid, true);
}
}
}
示例2: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (vertex.get_data().confirmed) {
return;
}
VertexDataType vertexdata = vertex.get_data();
bool propagate = false;
if (gcontext.iteration == 0) {
/* "Leader" of the SCC */
if (vertexdata.color == vertex.id()) {
propagate = true;
vertex.remove_alloutedges();
}
} else {
/* Loop over in-edges and see if there is a match */
bool match = false;
for(int i=0; i < vertex.num_outedges(); i++) {
if (!vertex.outedge(i)->get_data().deleted()) {
if (vertex.outedge(i)->get_data().neighbor_label(vertex.id(), vertex.outedge(i)->vertexid) == vertexdata.color) {
match = true;
break;
}
}
}
if (match) {
propagate = true;
vertex.remove_alloutedges();
vertex.set_data(SCCinfo(vertexdata.color, true));
} else {
vertex.set_data(SCCinfo(vertex.id(), false));
}
}
if (propagate) {
for(int i=0; i < vertex.num_inedges(); i++) {
bidirectional_label edgedata = vertex.inedge(i)->get_data();
if (!edgedata.deleted()) {
edgedata.my_label(vertex.id(), vertex.inedge(i)->vertexid) = vertexdata.color;
vertex.inedge(i)->set_data(edgedata);
gcontext.scheduler->add_task(vertex.inedge(i)->vertexid, true);
}
}
}
}
示例3: update
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if(gcontext.iteration == 0){
VertexDataType vertexdata = vertex.get_data();
if(!vertexdata.confirmed || !vertexdata.reconfirmed)
return ;
assert(vertex.num_inedges() * vertex.num_outedges() <= product);
for(int i=0; i<vertex.num_outedges(); i++){
bidirectional_label edgedata = vertex.outedge(i)->get_data();
if(edgedata.is_equal()){
/*
if(edgedata.smaller_one != 0)
std::cout<<edgedata.smaller_one<<" \t"<<edgedata.larger_one<<"\t root="<<root<<std::endl;
*/
if(root == edgedata.my_label(vertex.id(), vertex.outedge(i)->vertexid)){
lock.lock();
fprintf(fpout, "%u\t%u\n", vertex.id(), vertex.outedge(i)->vertexid);
lock.unlock();
continue;
}
}
/*
lock.lock();
fprintf(fpout1, "%u\t%u\n", vertex.id(), vertex.outedge(i)->vertexid);
lock.unlock();
*/
}
}
}
示例4: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &ginfo) {
float sum=0;
if (ginfo.iteration == 0) {
/* On first iteration, initialize vertex and out-edges.
The initialization is important,
because on every run, GraphChi will modify the data in the edges on disk.
*/
update_edge_data(v, 1.0);
v.set_data(RANDOMRESETPROB);
} else {
/* Compute the sum of neighbors' weighted pageranks by
reading from the in-edges. */
for(int i=0; i < v.num_inedges(); i++) {
//float val = v.inedge(i)->get_data();
//sum += val;
struct weightE eData = v.inedge(i)->get_data();
sum += eData.pagerank;
}
/* Compute my pagerank */
float pagerank = RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum;
/* Write my pagerank divided by the number of out-edges to
each of my out-edges. */
update_edge_data(v, pagerank);
/* Keep track of the progression of the computation.
GraphChi engine writes a file filename.deltalog. */
ginfo.log_change(std::abs(pagerank - v.get_data()));
/* Set my new pagerank as the vertex value */
v.set_data(pagerank);
}
}
示例5: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
int ninedges = 0;
if (gcontext.iteration == 0) {
for(int i=0; i < vertex.num_inedges(); i++) {
vertex.inedge(i)->set_data(vertex.id());
ninedges++;
}
} else {
// Keep track of the number of edegs to ensure that
// deletion works fine.
if (vertex.get_data() != vertex.num_inedges()) {
logstream(LOG_ERROR) << "Discrepancy in edge counts: " << vertex.get_data() << " != " << vertex.num_inedges() << std::endl;
}
assert(vertex.get_data() == vertex.num_inedges());
for(int i=0; i < vertex.num_outedges(); i++) {
graphchi_edge<vid_t> * edge = vertex.outedge(i);
vid_t outedgedata = edge->get_data();
vid_t expected = edge->vertex_id() + gcontext.iteration - (edge->vertex_id() > vertex.id());
if (!is_deleted_edge_value(edge->get_data())) {
if (outedgedata != expected) {
logstream(LOG_ERROR) << outedgedata << " != " << expected << std::endl;
assert(false);
}
}
}
for(int i=0; i < vertex.num_inedges(); i++) {
vertex.inedge(i)->set_data(vertex.id() + gcontext.iteration);
if (std::rand() % 4 == 1) {
vertex.remove_inedge(i);
__sync_add_and_fetch(&ndeleted, 1);
} else {
ninedges++;
}
}
}
if (gcontext.iteration == gcontext.num_iterations - 1) {
vertex.set_data(gcontext.iteration + 1);
} else {
vertex.set_data(ninedges);
}
}
示例6: update
/**
* This method runs only for the query nodes. Its actual function is divided
* into several methods, as not all is needed in each phase.
*/
void update(graphchi_vertex<TypeVertex, FeatureEdge> &v,
graphchi_context &ginfo) {
// TODO Use a scheduler instead of this?
if (v.get_data().type == QUERY) { // Only queries have outedges (TODO: ???)
/* We count the number of queries. */
if (ginfo.iteration == 0) {
num_queries++;
}
score_documents(v, ginfo);
if (phase == TRAINING) {
compute_gradients(v, parallel_models[omp_get_thread_num()]);
}
if (phase == TRAINING || phase == VALIDATION || phase == TESTING) {
evaluate_model(v, ginfo);
}
}
}
示例7: update
/**
* Vertex update function.
* On first iteration ,each vertex chooses a label = the vertex id.
* On subsequent iterations, each vertex chooses the minimum of the neighbor's
* label (and itself).
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext)
{
/* This program requires selective scheduling. */
assert(gcontext.scheduler != NULL);
if(gcontext.iteration == 0)
{
set_data(vertex, vertex.id());
/* Schedule neighbor for update */
gcontext.scheduler->add_task(vertex.id());
return;
}
else
{
vid_t curmin = vertex_values[vertex.id()];
for(int i=0; i < vertex.num_edges(); i++)
{
vid_t nblabel = neighbor_value(vertex.edge(i));
curmin = std::min(nblabel, curmin);
}
if ( curmin < vertex.get_data() )
{
for(int i=0; i < vertex.num_edges(); i++)
{
if (curmin < neighbor_value(vertex.edge(i)))
{
/* Schedule neighbor for update */
gcontext.scheduler->add_task(vertex.edge(i)->vertex_id());
}
}
set_data(vertex, curmin);
}
}
/* On subsequent iterations, find the minimum label of my neighbors */
/* If my label changes, schedule neighbors */
}
示例8: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VType, EType> &v, graphchi_context &ginfo) {
//array[v.id()]++;
if(v.num_edges() == 0) return;
if (ginfo.iteration == 0) {
//int partid = getPId(v.id());
vid_t newid = getNewId(v.id());
v.set_data(newid);
for(int i=0; i<v.num_edges(); i++){
graphchi_edge<EType> * edge = v.edge(i);
EType edata = edge->get_data();
edata.my_label(v.id(), edge->vertex_id()) = newid;
edge->set_data(edata);
}
} else if(ginfo.iteration == 1){
/*
if(v.id() == 0){
fprintf(fp_list, "%u %u\n", num_vertices, num_edges);
}
*/
if(v.num_outedges() > 0){
vid_t mylabel = v.get_data();
for(int i=0; i<v.num_outedges(); i++){
graphchi_edge<EType> * edge = v.outedge(i);
EType edata = edge->get_data();
vid_t nblabel = edata.nb_label(v.id(), edge->vertex_id());
//vid_t nb_id = edge->vertex_id();
assert(mylabel != nblabel);
if(!flag_weight){
lock.lock();
fprintf(fp_list, "%u\t%u\n", mylabel, nblabel);
lock.unlock();
}else{
lock.lock();
fprintf(fp_list, "%u\t%u\t%.3f\n", mylabel, nblabel, edata.weight);
lock.unlock();
}
//edge->set_data(edata);
}
}/*else{
fprintf(fp_list, "\n");
}*/
}
}
示例9: update
/**
* Pagerank update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &ginfo) {
float sum=0;
float prv = 0.0;
float pagerankcont = 0.0;
if (ginfo.iteration == 0) {
/* On first iteration, initialize vertex and out-edges.
The initialization is important,
because on every run, GraphChi will modify the data in the edges on disk.
*/
/* For the weighted version */
update_edge_data(v, 1.0, true);
v.set_data(RANDOMRESETPROB);
//v.set_data(1.0);
} else {
/* We need to come up with the weighted version */
for(int i=0; i < v.num_inedges(); i++) {
chivector<float> * evector = v.inedge(i)->get_vector();
assert(evector->size() >= 2);
sum += evector->get(1);
//std::cout << v.id() << " with data: " << evector->get(1) << " with weight " << evector->get(0) << std::endl;
//std::cout << v.id() << " edge endpoint: " << v.inedge(i)->vertex_id() << std::endl;
//evector->clear();
}
/* Compute my pagerank */
prv = RANDOMRESETPROB + (1 - RANDOMRESETPROB) * sum;
//std::cout << "sum" << sum << "pagerank: " << prv << std::endl;
update_edge_data(v, prv, false);
/* Keep track of the progression of the computation.
GraphChi engine writes a file filename.deltalog. */
double delta = std::abs(prv - v.get_data());
//std::cout << "pagerank: " << prv << "v.data" << v.get_data() << "delta: " << delta << std::endl;
ginfo.log_change(delta);
/* Set my new pagerank as the vertex value */
v.set_data(prv);
}
}
示例10: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &v, graphchi_context &gcontext) {
if (gcontext.iteration % 2 == 0) {
adjcontainer->grab_adj(v);
} else {
uint32_t oldcount = v.get_data();
uint32_t newcounts = 0;
v.sort_edges_indirect();
vid_t lastvid = 0;
/**
* Iterate through the edges, and if an edge is from a
* pivot vertex, compute intersection of the relevant
* adjacency lists.
*/
for(int i=0; i<v.num_edges(); i++) {
graphchi_edge<uint32_t> * e = v.edge(i);
if (e->vertexid > v.id() && e->vertexid >= adjcontainer->pivot_st) {
assert(!is_deleted_edge_value(e->get_data()));
if (e->vertexid != lastvid) { // Handles reciprocal edges (a->b, b<-a)
if (adjcontainer->is_pivot(e->vertexid)) {
uint32_t pivot_triangle_count = adjcontainer->intersection_size(v, e->vertexid, i);
newcounts += pivot_triangle_count;
/* Write the number of triangles into edge between this vertex and pivot */
if (pivot_triangle_count == 0 && e->get_data() == 0) {
/* ... or remove the edge, if the count is zero. */
v.remove_edge(i);
} else {
e->set_data(e->get_data() + pivot_triangle_count);
}
} else {
break;
}
}
lastvid = e->vertexid;
}
assert(newcounts >= 0);
}
if (newcounts > 0) {
v.set_data(oldcount + newcounts);
}
}
/* Collect triangle counts matched by vertices with id lower than
his one, and delete */
if (gcontext.iteration % 2 == 0) {
int newcounts = 0;
for(int i=0; i < v.num_edges(); i++) {
graphchi_edge<uint32_t> * e = v.edge(i);
if (e->vertexid < v.id()) {
newcounts += e->get_data();
e->set_data(0);
// This edge can be now deleted. Is there some other situations we can delete?
if (v.id() < adjcontainer->pivot_st && e->vertexid < adjcontainer->pivot_st) {
v.remove_edge(i);
}
}
}
v.set_data(v.get_data() + newcounts);
}
}
示例11: update
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
/*
* Concurrent accessor to access the rvec value corresponding to the current vertex.
*/
tbb::concurrent_hash_map<unsigned int, nlohmann::json>::accessor ac;
rvec_map.insert(ac,vertex.id());
nlohmann::json rvec = ac->second;
int dependencies; //The number of active dependencies of the current vertex.
/*
* vertex_false to keep track of all the query vertices marked false for the vertex in the current iteration
*/
std::vector<vid_t> vertex_false;
/*
* If the vertex has a null rvec, it is being computed for the first time.
* Compare the vertex with each of the vertices in the query graph.
* If the current node matches the query node, add the dependencies of the query node to the rvec.
* If the query node does not have any dependencies, set rvec[i] as true. (This implies a direct match)
* If the query node and the current node don't match, set rvec[i] to false and add i to vertex_false.
*/
if(rvec.is_null()){
dependencies = 0; //Vertex is being computed for the first time and hence has zero dependencies.
for(unsigned int i=0; i < query_json["node"].size(); i++) {
if(check_equal(vertex_json[vertex.id()],query_json["node"][i])) {
unsigned int out_d = query_json["node"][i]["out_degree"];
if(out_d == 0){
rvec[i] = true;
}
else if(vertex.num_outedges() == 0)
{
rvec[i] = false;
vertex_false.push_back(i);
}
else
{ for(unsigned int j=0; j <query_json["edge"].size(); j++){
unsigned int source = query_json["edge"][j]["source"], target = query_json["edge"][j]["target"];
if(i == source )
rvec[i][target] = vertex.num_outedges();
}
dependencies++;
}
}
else
{
rvec[i] = false;
vertex_false.push_back(i);
}
}
/*
* If the vertex has dependencies, schedule the children of the current vertex (outedges).
*/
if(dependencies != 0){
for(int i = 0; i <vertex.num_outedges();i++)
gcontext.scheduler->add_task(vertex.outedge(i)->vertex_id());
}
/*
* Vertex data is set to the number of dependencies.
* If the vertex data is greater than 0, then it is processed whenever it is scheduled in the subsequent iterations.
* If the vertex data is 0, it is not processed in the subsequent iterations.
*/
vertex.set_data(dependencies);
}
dependencies = vertex.get_data();
/*
* If the current vertex has dependencies, it has to be processed.
* Collect the edge data of all it's outgoing edges and for each outgoing edge which is updated, update the corresponding dependency.
* Else, clear all the outedges.
*/
if(dependencies != 0 ) {
nlohmann::json updates;
for(int i = 0; i < vertex.num_outedges(); i++){
chivector<vid_t> * e_vector = vertex.outedge(i)->get_vector();
int evector_size = e_vector->size();
for( int j =0; j < evector_size; j++){
vid_t t = e_vector->get(j);
if(updates[t].is_null())
updates[t] = 1;
else {
int n = updates[t];
updates[t] = n +1;
}
}
e_vector->clear();
//.........这里部分代码省略.........
示例12: update
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
/* This program requires selective scheduling. */
assert(gcontext.scheduler != NULL);
vid_t newlabel;
if (gcontext.iteration == 0) {
/* On first iteration, choose label vertex id */
vid_t firstlabel = vertex.id();
vertex.set_data(firstlabel);
newlabel = firstlabel;
/* Scheduler myself for next iteration */
gcontext.scheduler->add_task(vertex.id());
} else {
if (vertex.num_edges() == 0) return; // trivial
/* The basic idea is to find the label that is most popular among
this vertex's neighbors. This label will be chosen as the new label
of this vertex. */
// This part could be optimized: STL map is quite slow.
std::map<vid_t, int> counts;
int maxcount=0;
vid_t maxlabel=0;
/* Iterate over all the edges */
for(int i=0; i < vertex.num_edges(); i++) {
/* Extract neighbor's current label. The edge contains the labels of
both vertices it connects, so we need to use the right one.
(See comment for bidirectional_label above) */
bidirectional_label edgelabel = vertex.edge(i)->get_data();
vid_t nblabel = neighbor_label(edgelabel, vertex.id(), vertex.edge(i)->vertex_id());
/* Check if this label (nblabel) has been encountered before ... */
std::map<vid_t, int>::iterator existing = counts.find(nblabel);
int newcount = 0;
if(existing == counts.end()) {
/* ... if not, we add this label with count of one to the map */
counts.insert(std::pair<vid_t,int>(nblabel, 1));
newcount = 1;
} else {
/* ... if yes, we increment the counter for this label by 1 */
existing->second++;
newcount = existing->second;
}
/* Finally, we keep track of the most frequent label */
if (newcount > maxcount || (maxcount == newcount && nblabel > maxlabel)) {
maxlabel = nblabel;
maxcount = newcount;
}
}
newlabel = maxlabel;
}
/**
* Write my label to my neighbors.
*/
if (newlabel != vertex.get_data() || gcontext.iteration == 0) {
vertex.set_data(newlabel);
for(int i=0; i<vertex.num_edges(); i++) {
bidirectional_label labels_on_edge = vertex.edge(i)->get_data();
my_label(labels_on_edge, vertex.id(), vertex.edge(i)->vertex_id()) = newlabel;
vertex.edge(i)->set_data(labels_on_edge);
// On first iteration, everyone schedules themselves.
if (gcontext.iteration > 0)
gcontext.scheduler->add_task(vertex.edge(i)->vertex_id());
}
}
}