Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #777

Closed
wants to merge 22 commits into from
Closed

Dev #777

Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c2f6283
Implemented Fast LSC.
AidenPearce-ZYQ Nov 22, 2024
c5c00f7
Implemented K-hop alogrithm.
AidenPearce-ZYQ Nov 23, 2024
6d35ef5
Delete lsc.
AidenPearce-ZYQ Nov 23, 2024
fd14b25
Merge branch 'master' into khop
AidenPearce-ZYQ Nov 23, 2024
188517a
Merge branch 'master' of github.com:TuGraph-family/tugraph-db into khop
AidenPearce-ZYQ Nov 23, 2024
4ec3703
Merge branch 'khop' of github.com:AidenPearce-ZYQ/tugraph-db into khop
AidenPearce-ZYQ Nov 23, 2024
2ac9f66
Fixed code format.
AidenPearce-ZYQ Nov 23, 2024
da103b6
Fixed code format.
AidenPearce-ZYQ Nov 23, 2024
10ac832
Fix more format bugs.
AidenPearce-ZYQ Nov 23, 2024
6c471bc
Implemented Fast LSC.
AidenPearce-ZYQ Nov 22, 2024
89a3e16
Implemented K-hop alogrithm.
AidenPearce-ZYQ Nov 23, 2024
97ff4d1
Delete lsc.
AidenPearce-ZYQ Nov 23, 2024
b9e29ef
Fixed code format.
AidenPearce-ZYQ Nov 23, 2024
e948411
Fixed code format.
AidenPearce-ZYQ Nov 23, 2024
8341aac
Fix more format bugs.
AidenPearce-ZYQ Nov 23, 2024
ec37db3
Merge branch 'khop' of github.com:AidenPearce-ZYQ/tugraph-db into khop
AidenPearce-ZYQ Nov 23, 2024
9314f28
[Doc] Updated k-hop section in community docs.
AidenPearce-ZYQ Nov 25, 2024
82ab6fc
Add files via upload
ZhengHeber Nov 25, 2024
b53c85c
Delete procedures/algo_cpp/khop_core.cpp
ZhengHeber Nov 25, 2024
6d53c20
Merge pull request #1 from ZhengHeber/ZhengHeber-patch-2
AidenPearce-ZYQ Nov 25, 2024
fd260db
Merge pull request #2 from ZhengHeber/ZhengHeber-patch-3
AidenPearce-ZYQ Nov 25, 2024
dc4b242
把/procedures/algo_cpp/khop_standalone.cpp移动到/procedures/community目录下
iwanttoknowwhy Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions procedures/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ add_standalone(wlpa)
add_standalone(subgraph_isomorphism)
add_standalone(sybilrank)
add_standalone(leiden)
add_stanalone(khop)

add_embed(apsp)
add_embed(bfs)
11 changes: 10 additions & 1 deletion procedures/community/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# community procedures

In this directory, The procedures are contribution from the commmunity.
In this directory, The procedures are contribution from the commmunity.

## K-hop Algorithm
The K-hop algorithm is used to find all nodes within K hops from a given starting node in a graph. It is particularly useful in social network analysis, recommendation systems, and network topology analysis.

### Contributor
This algorithm was contributed by AidenPearce-ZYQ, iwanttoknowwhy and ZhengHeber.

### Usage
For detailed usage, please refer to the TuGraph-DB OLAP C++ API documentation and run khop_standalone --help.
60 changes: 60 additions & 0 deletions procedures/community/khop_core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright 2024 Yingqi Zhao
*
* @Function: Compute the k-hop algorithm.
* @param:
*
*
*
*
graph:
The graph to compute on.
root_vid: Identifier of root node.
result:
Set of reachable nodes in K-hop.
value_k: Number of search layers.
* @return: Number of nodes in K_hop.
*/
// #include <cstddef>
#include "lgraph/olap_base.h"
#include "./algo.h"

using namespace lgraph_api;
using namespace lgraph_api::olap;

size_t k_hop(OlapBase<Empty>& graph, size_t root_vid, ParallelVector<size_t>& result, size_t k) {
size_t root = root_vid;
auto active_in = graph.AllocVertexSubset();
active_in.Add(root);
auto active_out = graph.AllocVertexSubset();
auto parent = graph.AllocVertexArray<size_t>();
parent.Fill(0);
parent[root] = root;
size_t num_activations = 1;
size_t discovered_vertices, j = 0;
for (size_t ii = 0; ii < k; ii++) {
active_out.Clear();
num_activations = graph.ProcessVertexActive<size_t>(
[&](size_t vi) {
size_t num_activations = 0;
for (auto& edge : graph.OutEdges(vi)) {
size_t dst = edge.neighbour;
if (parent[dst] == 0) {
auto lock = graph.GuardVertexLock(dst);
if (parent[dst] == 0) {
parent[dst] = vi;
num_activations += 1;
active_out.Add(dst);
result[j++] = dst;
}
}
}
return num_activations;
},
active_in);
printf("activates(%lu) <= %lu \n", ii+1, num_activations);
discovered_vertices += num_activations;
active_in.Swap(active_out);
}
return discovered_vertices;
}
79 changes: 79 additions & 0 deletions procedures/community/khop_standalone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2024 Yingqi Zhao
#include "olap/olap_on_disk.h"
#include "tools/json.hpp"
#include "./algo.h"
using namespace lgraph_api;
using namespace lgraph_api::olap;
using json = nlohmann::json;

class MyConfig : public ConfigBase<Empty> {
public:
std::string root = "0";
std::string name = std::string("khop");
size_t value_k = 3;
void AddParameter(fma_common::Configuration& config) {
ConfigBase<Empty>::AddParameter(config);
config.Add(root, "root", true).Comment("Identifier of the root node.");
config.Add(value_k, "value_k", true).Comment(
"Number of search layers(value of k in K-hop algorithm).");
}
void Print() {
ConfigBase<Empty>::Print();
std::cout << " name: " << name << std::endl;
std::cout << " root: " << name << std::endl;
std::cout << " value_k: " << value_k << std::endl;
}
MyConfig(int& argc, char**& argv) : ConfigBase<Empty>(argc, argv) {
fma_common::Configuration config;
AddParameter(config);
config.ExitAfterHelp(true);
config.ParseAndFinalize(argc, argv);
Print();
}
};

extern size_t k_hop(OlapBase<Empty>& graph, size_t root_vid,
ParallelVector<size_t>& result, size_t k);

int main(int argc, char** argv) {
double start_time;
MemUsage memUsage;
memUsage.startMemRecord();
start_time = get_time();
MyConfig config(argc, argv);
OlapOnDisk<Empty> graph;
graph.Load(config, INPUT_SYMMETRIC);
size_t root_vid;
auto result = graph.AllocVertexArray<size_t>();
result.Fill(0);
if (config.id_mapping)
root_vid = graph.hash_list_.find(config.root);
else
root_vid = std::stoi(config.root);
size_t value_k = config.value_k;
memUsage.print();
memUsage.reset();
auto prepare_cost = get_time()- start_time;
printf("prepare_cost = %.2lf(s)\n", prepare_cost);

start_time = get_time();
size_t count_result = k_hop(graph, root_vid, result, value_k);
memUsage.print();
memUsage.reset();
auto core_cost = get_time()- start_time;

start_time = get_time();
if (config.output_dir != "") {
graph.Write<size_t>(config, result, graph.NumVertices(), config.name);
}
printf("\n================\n");
printf("Find %lu vertexes in %lu-hop from node NO.%lu", count_result, value_k, root_vid);
printf("\n================\n");
auto output_cost = get_time()- start_time;

printf("core_cost = %.2lf(s)\n", core_cost);
printf("output_cost = %.2lf(s)\n", output_cost);
printf("total_cost = %.2lf(s)\n", prepare_cost + core_cost + output_cost);
printf("DONE.\n");
return 0;
}