大数据分析,同步图计算,三角形计数,graphlite
#题目要求
#代码实现
1.定义结构体存统计结果
2.图输入
3.结果输出(定义类外的变量以从计算函数类vertex传出结果)
4.对Aggregator的输入类型更改,涉及到对指针的使用https://blog.youkuaiyun.com/liu100m/article/details/90731422
5.计算函数注意超步中变量的存在周期,compute函数中的变量只存在于一个超步,新的超步会更新。用map函数在vertex类中存每个点的出边和入边
6.注意迭代器的使用,find函数,end函数;
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include "GraphLite.h"
#define VERTEX_CLASS_NAME(name) DirectedTriangleCount##name
#define EPS 1e-6
typedef struct result{
int through_num;
int cycle_num;
}RESULT;
class VERTEX_CLASS_NAME(InputFormatter): public InputFormatter {
public:
int64_t getVertexNum() {
unsigned long long n;
sscanf(m_ptotal_vertex_line, "%lld", &n);
m_total_vertex= n;
return m_total_vertex;
}
int64_t getEdgeNum() {
unsigned long long n;
sscanf(m_ptotal_edge_line, "%lld", &n);
m_total_edge= n;
return m_total_edge;
}
int getVertexValueSize() {
m_n_value_size = sizeof(int);
return m_n_value_size;
}
int getEdgeValueSize() {
m_e_value_size = sizeof(int);
return m_e_value_size;
}
int getMessageValueSize() {
m_m_value_size = sizeof(int64_t);
return m_m_value_size;
}
void loadGraph() {
unsigned long long last_vertex;
unsigned long long from;
unsigned long long to;
int weight = 0;
int value = 1;
int outdegree = 0;
const char *line= getEdgeLine();
// Note: modify this if an edge weight is to be read
// modify the 'weight' variable
sscanf(line, "%lld %lld", &from, &to);
addEdge(from, to, &weight);
last_vertex = from;
++outdegree;
for (int64_t i = 1; i < m_total_edge; ++i) {
line= getEdgeLine();
// Note: modify this if an edge weight is to be read
// modify the 'weight' variable
sscanf(line, "%lld %lld", &from