narayanan2004 / GraphMat

GraphMat graph analytics framework
Other
101 stars 41 forks source link

The differences between Degree and InDegree #21

Closed IslandGod closed 7 years ago

IslandGod commented 7 years ago

I read the definition about Degree in PageRank.cpp and InDegree in TopologicalSort.cpp. I guess they are both used to get in-degrees for all vertexes, but I do not understand that , why it uses this->order = GraphMat::IN_EDGES; in PageRank , and it uses this->order = GraphMat::OUT_EDGES; in TopologicalSort. What is the differences?

template<class V, class E=int>
class Degree : public GraphMat::GraphProgram<int, int, V, E> {
  public:

  Degree() {
    this->order = GraphMat::IN_EDGES;
    this->process_message_requires_vertexprop = false;
  }

  bool send_message(const V& vertexprop, int& message) const {
    message = 1;
    return true;
  }

  void process_message(const int& message, const E edge_value, const V& vertexprop, int& result) const {
    result = message;
  }

  void reduce_function(int& a, const int& b) const {
    a += b;
  }

  void apply(const int& message_out, V& vertexprop) {
    vertexprop.degree = message_out; 
  }

};
class InDegree : public GraphMat::GraphProgram<int, int, V, E> {
  public:

  InDegree() {
    this->activity = GraphMat::ALL_VERTICES;
    this->order = GraphMat::OUT_EDGES;
    this->process_message_requires_vertexprop = false;
  }

  bool send_message(const V& vertex, int& message) const {
    message = 1;
    return true;
  }

  void process_message(const int& message, const E edge_value, const V& vertex, int& result) const {
    result = message;
  }

  void reduce_function(int& a, const int& b) const {
    a += b;
  }

  void apply(const int& message_out, V& vertex) {
    vertex.in_degree = message_out; 
  }

};

Please give me some suggestion or solution. Any info will help, thank you !!

narayanan2004 commented 7 years ago

The degree in PageRank is the out_degree i.e. the number of outgoing edges from a vertex. For topological sort, we need the in_degree (number of incoming edges at a vertex). This distinction is meaningful only for directed graphs. this->order specifies which edges the messages are sent to. It can be GraphMat::IN_EDGES, GraphMat::OUT_EDGES or GraphMat::ALL_EDGES. To calculate the out_degree, we need to send a message from each vertex along its incoming edges and then sum up all the messages that reach a vertex. For example, if a graph is {1 -> 2, 1 -> 3}, then to calculate the out_degree of vertex 1 we need to receive a message from 2 & 3. Vice versa for in_degree.

Hope that helps.

IslandGod commented 7 years ago

I see , thank you for your response!