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

Implement 3D Offline Reconstruction Pipeline #19

Merged
merged 7 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ output/

__pycache__/
*.pyc

# App/Reconstruction folder
fragments/
scene/
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace pmc {
};

inline static void print_mc_info(vector<int> &C_max, double &sec) {
cout << "*** [pmc: thread " << omp_get_thread_num() + 1;
cout << "] current max clique = " << C_max.size();
cout << ", time = " << get_time() - sec << " sec" <<endl;
// cout << "*** [pmc: thread " << omp_get_thread_num() + 1;
// cout << "] current max clique = " << C_max.size();
// cout << ", time = " << get_time() - sec << " sec" <<endl;
};
};
#endif
137 changes: 69 additions & 68 deletions 3rdparty/teaser_plusplus/3rdparty/pmc/pmc_clique_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,71 @@
============================================================================
*/

#include "pmc/pmc_graph.h"
#include <algorithm>
#include "pmc/pmc_graph.h"


using namespace std;
using namespace pmc;

int pmc_graph::initial_pruning(pmc_graph& G, int* &pruned, int lb) {
int pmc_graph::initial_pruning(pmc_graph &G, int *&pruned, int lb) {
int lb_idx = 0;
for (int i = G.num_vertices()-1; i >= 0; i--) {
if (kcore[kcore_order[i]] == lb) lb_idx = i;
if (kcore[kcore_order[i]] <= lb) pruned[kcore_order[i]] = 1;
for (int i = G.num_vertices() - 1; i >= 0; i--) {
if (kcore[kcore_order[i]] == lb)
lb_idx = i;
if (kcore[kcore_order[i]] <= lb)
pruned[kcore_order[i]] = 1;
}

double sec = get_time();
cout << "[pmc: initial k-core pruning] before pruning: |V| = " << G.num_vertices();
cout << ", |E| = " << G.num_edges() <<endl;
// cout << "[pmc: initial k-core pruning] before pruning: |V| = " <<
// G.num_vertices(); cout << ", |E| = " << G.num_edges() <<endl;
G.reduce_graph(pruned);
cout << "[pmc: initial k-core pruning] after pruning: |V| = " << G.num_vertices() - lb_idx;
cout << ", |E| = " << G.num_edges() <<endl;
cout << "[pmc] initial pruning took " << get_time()-sec << " sec" <<endl;
// cout << "[pmc: initial k-core pruning] after pruning: |V| = " <<
// G.num_vertices() - lb_idx; cout << ", |E| = " << G.num_edges() <<endl;
// cout << "[pmc] initial pruning took " << get_time()-sec << " sec"
// <<endl;

G.update_degrees();
G.degree_bucket_sort(true); // largest to smallest degree
G.degree_bucket_sort(true); // largest to smallest degree

return lb_idx;
}


int pmc_graph::initial_pruning(pmc_graph& G, int* &pruned, int lb, vector<vector<bool>> &adj) {
int pmc_graph::initial_pruning(pmc_graph &G, int *&pruned, int lb,
vector<vector<bool>> &adj) {
int lb_idx = 0;
for (int i = G.num_vertices()-1; i >= 0; i--) {
if (kcore[kcore_order[i]] == lb) lb_idx = i;
for (int i = G.num_vertices() - 1; i >= 0; i--) {
if (kcore[kcore_order[i]] == lb)
lb_idx = i;
if (kcore[kcore_order[i]] <= lb) {
pruned[kcore_order[i]] = 1;
for (long long j = vertices[kcore_order[i]]; j < vertices[kcore_order[i] + 1]; j++) {
for (long long j = vertices[kcore_order[i]];
j < vertices[kcore_order[i] + 1]; j++) {
adj[kcore_order[i]][edges[j]] = false;
adj[edges[j]][kcore_order[i]] = false;
}
}
}

double sec = get_time();
cout << "[pmc: initial k-core pruning] before pruning: |V| = " << G.num_vertices() << ", |E| = " << G.num_edges() <<endl;
// cout << "[pmc: initial k-core pruning] before pruning: |V| = " <<
// G.num_vertices() << ", |E| = " << G.num_edges() <<endl;
G.reduce_graph(pruned);
cout << "[pmc: initial k-core pruning] after pruning: |V| = " << G.num_vertices() - lb_idx << ", |E| = " << G.num_edges() <<endl;
cout << "[pmc] initial pruning took " << get_time()-sec << " sec" <<endl;
// cout << "[pmc: initial k-core pruning] after pruning: |V| = " <<
// G.num_vertices() - lb_idx << ", |E| = " << G.num_edges() <<endl; cout <<
// "[pmc] initial pruning took " << get_time()-sec << " sec" <<endl;

G.update_degrees();
G.degree_bucket_sort(true);

return lb_idx;
}


void pmc_graph::order_vertices(vector<Vertex> &V, pmc_graph &G,
int &lb_idx, int &lb, string vertex_ordering, bool decr_order) {

srand (time(NULL));
void pmc_graph::order_vertices(vector<Vertex> &V, pmc_graph &G, int &lb_idx,
int &lb, string vertex_ordering,
bool decr_order) {
srand(time(NULL));
int u = 0, val = 0;
for (int k = lb_idx; k < G.num_vertices(); k++) {
if (degree[kcore_order[k]] >= lb - 1) {
Expand All @@ -101,9 +108,9 @@ void pmc_graph::order_vertices(vector<Vertex> &V, pmc_graph &G,
for (long long j = vertices[u]; j < vertices[u + 1]; j++) {
val = val + kcore[edges[j]];
}
}
else val = vertices[u + 1] - vertices[u];
V.push_back(Vertex(u,val));
} else
val = vertices[u + 1] - vertices[u];
V.push_back(Vertex(u, val));
}
}
if (decr_order)
Expand All @@ -112,34 +119,30 @@ void pmc_graph::order_vertices(vector<Vertex> &V, pmc_graph &G,
std::sort(V.begin(), V.end(), incr_bound);
}


/**
* Reduce the graph by removing the pruned vertices
* + Systematically speeds algorithm up by reducing the neighbors as more vertices are searched
* + Systematically speeds algorithm up by reducing the neighbors as more
* vertices are searched
*
* The algorithm below is for parallel maximum clique finders and has the following features:
* The algorithm below is for parallel maximum clique finders and has the
* following features:
* + Thread-safe, since local copy of vertices/edges are passed in..
* + Pruned is a shared variable, but it is safe, since only reads/writes can occur, no deletion
* + Pruned is a shared variable, but it is safe, since only reads/writes can
* occur, no deletion
*/
void pmc_graph::reduce_graph(
vector<long long>& vs,
vector<int>& es,
int* &pruned,
pmc_graph& G,
int id,
int& mc) {

void pmc_graph::reduce_graph(vector<long long> &vs, vector<int> &es,
int *&pruned, pmc_graph &G, int id, int &mc) {
int num_vs = vs.size();

vector<long long> V(num_vs,0);
vector<long long> V(num_vs, 0);
vector<int> E;
E.reserve(es.size());

int start = 0;
for (int i = 0; i < num_vs - 1; i++) {
start = E.size();
if (!pruned[i]) { //skip these V_local...
for (long long j = vs[i]; j < vs[i + 1]; j++ ) {
if (!pruned[i]) { // skip these V_local...
for (long long j = vs[i]; j < vs[i + 1]; j++) {
if (!pruned[es[j]])
E.push_back(es[j]);
}
Expand All @@ -150,33 +153,35 @@ void pmc_graph::reduce_graph(
vs = V;
es = E;

// compute k-cores and share bounds: ensure operation completed by single process
#pragma omp single nowait
// compute k-cores and share bounds: ensure operation completed by single
// process
#pragma omp single nowait
{
cout << ">>> [pmc: thread " << omp_get_thread_num() + 1 << "]" <<endl;
G.induced_cores_ordering(vs,es,pruned);
// cout << ">>> [pmc: thread " << omp_get_thread_num() + 1 << "]" << endl;
G.induced_cores_ordering(vs, es, pruned);
}
V.clear();
E.clear();
}


void pmc_graph::print_info(vector<int> &C_max, double &sec) {
cout << "*** [pmc: thread " << omp_get_thread_num() + 1;
cout << "] current max clique = " << C_max.size();
cout << ", time = " << get_time() - sec << " sec" <<endl;
// cout << "*** [pmc: thread " << omp_get_thread_num() + 1;
// cout << "] current max clique = " << C_max.size();
// cout << ", time = " << get_time() - sec << " sec" << endl;
}


void pmc_graph::print_break() {
cout << "-----------------------------------------------------------------------" <<endl;
// cout << "------------------------------------------------------------------"
// "-----"
// << endl;
}

bool pmc_graph::time_left(vector<int> &C_max, double sec, double time_limit, bool &time_expired_msg) {
bool pmc_graph::time_left(vector<int> &C_max, double sec, double time_limit,
bool &time_expired_msg) {
if ((get_time() - sec) > time_limit) {
if (time_expired_msg) {
cout << "\n### Time limit expired, terminating search. ###" <<endl;
cout << "Size: " << C_max.size() <<endl;
cout << "\n### Time limit expired, terminating search. ###" << endl;
cout << "Size: " << C_max.size() << endl;
print_max_clique(C_max);
time_expired_msg = false;
}
Expand All @@ -185,17 +190,13 @@ bool pmc_graph::time_left(vector<int> &C_max, double sec, double time_limit, boo
return true;
}

void pmc_graph::graph_stats(pmc_graph& G, int& mc, int id, double &sec) {
cout << "[pmc: bounds updated - thread " << omp_get_thread_num() + 1 << "] ";
cout << "time = " << get_time() - sec << " sec, ";
cout << "|V| = " << (G.num_vertices() - id);
cout << " (" << id << " / " << G.num_vertices();
cout << "), |E| = " << G.num_edges();
cout << ", w = " << mc;
cout << ", p = " << G.density();
cout << ", d_min = " << G.get_min_degree();
cout << ", d_avg = " << G.get_avg_degree();
cout << ", d_max = " << G.get_max_degree();
cout << ", k_max = " << G.get_max_core();
cout <<endl;
void pmc_graph::graph_stats(pmc_graph &G, int &mc, int id, double &sec) {
// cout << "[pmc: bounds updated - thread " << omp_get_thread_num() + 1 <<
// "] "; cout << "time = " << get_time() - sec << " sec, "; cout << "|V| =
// " << (G.num_vertices() - id); cout << " (" << id << " / " <<
// G.num_vertices(); cout << "), |E| = " << G.num_edges(); cout << ", w = "
// << mc; cout << ", p = " << G.density(); cout << ", d_min = " <<
// G.get_min_degree(); cout << ", d_avg = " << G.get_avg_degree(); cout <<
// ", d_max = " << G.get_max_degree(); cout << ", k_max = " <<
// G.get_max_core(); cout <<endl;
}
38 changes: 19 additions & 19 deletions 3rdparty/teaser_plusplus/3rdparty/pmc/pmc_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ void pmc_graph::read_graph(const string& filename) {
}

void pmc_graph::basic_stats(double sec) {
cout << "Reading time " << get_time() - sec << endl;
cout << "|V|: " << num_vertices() <<endl;
cout << "|E|: " << num_edges() <<endl;
cout << "p: " << density() <<endl;
cout << "d_max: " << get_max_degree() <<endl;
cout << "d_avg: " << get_avg_degree() <<endl;
// cout << "Reading time " << get_time() - sec << endl;
// cout << "|V|: " << num_vertices() <<endl;
// cout << "|E|: " << num_edges() <<endl;
// cout << "p: " << density() <<endl;
// cout << "d_max: " << get_max_degree() <<endl;
// cout << "d_avg: " << get_avg_degree() <<endl;
}


Expand Down Expand Up @@ -282,7 +282,7 @@ void pmc_graph::create_adj() {
for (long long j = vertices[i]; j < vertices[i + 1]; j++ )
adj[i][edges[j]] = true;
}
cout << "Created adjacency matrix in " << get_time() - sec << " seconds" <<endl;
// cout << "Created adjacency matrix in " << get_time() - sec << " seconds" <<endl;
}


Expand Down Expand Up @@ -504,16 +504,16 @@ void pmc_graph::reduce_graph(


void pmc_graph::bound_stats(int alg, int lb, pmc_graph& G) {
cout << "graph: " << fn <<endl;
cout << "alg: " << alg <<endl;
cout << "-------------------------------" <<endl;
cout << "Graph Stats for Max-Clique:" <<endl;
cout << "-------------------------------" <<endl;
cout << "|V|: " << num_vertices() <<endl;
cout << "|E|: " << num_edges() <<endl;
cout << "d_max: " << get_max_degree() <<endl;
cout << "d_avg: " << get_avg_degree() <<endl;
cout << "p: " << density() <<endl;
// cout << "graph: " << fn <<endl;
// cout << "alg: " << alg <<endl;
// cout << "-------------------------------" <<endl;
// cout << "Graph Stats for Max-Clique:" <<endl;
// cout << "-------------------------------" <<endl;
// cout << "|V|: " << num_vertices() <<endl;
// cout << "|E|: " << num_edges() <<endl;
// cout << "d_max: " << get_max_degree() <<endl;
// cout << "d_avg: " << get_avg_degree() <<endl;
// cout << "p: " << density() <<endl;
}


Expand Down Expand Up @@ -612,8 +612,8 @@ void pmc_graph::degree_bucket_sort(bool desc) {
}
}

cout << "[pmc: sorting neighbors] |E| = " << edges.size();
cout << ", |E_sorted| = " << tmp_edges.size() <<endl;
// cout << "[pmc: sorting neighbors] |E| = " << edges.size();
// cout << ", |E_sorted| = " << tmp_edges.size() <<endl;
edges = tmp_edges;
}

Expand Down
8 changes: 4 additions & 4 deletions 3rdparty/teaser_plusplus/3rdparty/pmc/pmc_heu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int pmc_heu::search_bounds(pmc_graph& G,
C = X; P = T;
}
}
cout << "[pmc heuristic]\t mc = " << mc <<endl;
// cout << "[pmc heuristic]\t mc = " << mc <<endl;
return mc;
}

Expand Down Expand Up @@ -180,8 +180,8 @@ int pmc_heu::search(pmc_graph& G, vector<int>& C_max) {


inline void pmc_heu::print_info(vector<int> C_max) {
cout << "*** [pmc heuristic: thread " << omp_get_thread_num() + 1;
cout << "] current max clique = " << C_max.size();
cout << ", time = " << get_time() - sec << " sec" <<endl;
// cout << "*** [pmc heuristic: thread " << omp_get_thread_num() + 1;
// cout << "] current max clique = " << C_max.size();
// cout << ", time = " << get_time() - sec << " sec" <<endl;
}

4 changes: 2 additions & 2 deletions 3rdparty/teaser_plusplus/3rdparty/pmc/pmc_maxclique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void pmc_maxclique::branch(
print_mc_info(C,sec);
if (mc >= param_ub) {
not_reached_ub = false;
cout << "[pmc: upper bound reached] omega = " << mc <<endl;
// cout << "[pmc: upper bound reached] omega = " << mc <<endl;
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ void pmc_maxclique::branch_dense(
print_mc_info(C,sec);
if (mc >= param_ub) {
not_reached_ub = false;
cout << "[pmc: upper bound reached] omega = " << mc <<endl;
// cout << "[pmc: upper bound reached] omega = " << mc <<endl;
}
}

Expand Down
8 changes: 4 additions & 4 deletions 3rdparty/teaser_plusplus/3rdparty/pmc/pmcx_maxclique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int pmcx_maxclique::search(pmc_graph& G, vector<int>& sol) {
vector<Vertex> V;
V.reserve(G.num_vertices());
G.order_vertices(V,G,lb_idx,lb,vertex_ordering,decr_order);
cout << "|V| = " << V.size() <<endl;
// cout << "|V| = " << V.size() <<endl;

vector<short> ind(G.num_vertices(),0);
vector<int> es = G.get_edges_array();
Expand Down Expand Up @@ -154,7 +154,7 @@ void pmcx_maxclique::branch(
print_mc_info(C,sec);
if (mc >= param_ub) {
not_reached_ub = false;
cout << "[pmc: upper bound reached] omega = " << mc <<endl;
// cout << "[pmc: upper bound reached] omega = " << mc <<endl;
}
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ int pmcx_maxclique::search_dense(pmc_graph& G, vector<int>& sol) {
vector<Vertex> V;
V.reserve(G.num_vertices());
G.order_vertices(V,G,lb_idx,lb,vertex_ordering,decr_order);
cout << "|V| = " << V.size() <<endl;
// cout << "|V| = " << V.size() <<endl;

vector<short> ind(G.num_vertices(),0);
vector<int> es = G.get_edges_array();
Expand Down Expand Up @@ -311,7 +311,7 @@ void pmcx_maxclique::branch_dense(
print_mc_info(C,sec);
if (mc >= param_ub) {
not_reached_ub = false;
cout << "[pmc: upper bound reached] omega = " << mc <<endl;
// cout << "[pmc: upper bound reached] omega = " << mc <<endl;
}
}
}
Expand Down
Loading