Skip to content

Commit

Permalink
Merge 305e9a6 into 454bbe9
Browse files Browse the repository at this point in the history
  • Loading branch information
MengLiuPurdue committed Apr 4, 2019
2 parents 454bbe9 + 305e9a6 commit 21bbee8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
7 changes: 5 additions & 2 deletions localgraphclustering/src/lib/MQI_weighted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ void graph<vtype,itype>::build_map_weighted(unordered_map<vtype, vtype>& R_map,
unordered_map<vtype, vtype>& degree_map, vtype* R, vtype nR,
double* degrees)
{
vtype deg;
double deg;
for(vtype i = 0; i < nR; i ++){
//cout << R[i] - offset << " " << i << endl;
R_map[R[i] - offset] = i;
}
for(auto iter = R_map.begin(); iter != R_map.end(); ++iter){
Expand Down Expand Up @@ -77,7 +78,9 @@ void graph<vtype,itype>::build_list_weighted(unordered_map<vtype, vtype>& R_map,
if(R_map.count(v) > 0){
vtype v1 = got->second;
double w = A * a[j];
addEdge(u1, v1, w);
if(v1 > u1) {
addEdge(u1, v1, w);
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions localgraphclustering/src/lib/MQI_weighted_c_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "include/MQI_weighted_c_interface.h"
#include "include/MQI_weighted.h"
#include <iostream>


using namespace std;
Expand All @@ -10,14 +11,14 @@ int64_t MQI_weighted64(int64_t n, int64_t nR, int64_t* ai, int64_t* aj, double*
return g.MQI_weighted(nR,R,ret_set);
}

int32_t MQI_weighted32(int32_t n, int32_t nR, int32_t* ai, int32_t* aj, double* a, double* degrees, int32_t offset, int32_t* R, int32_t* ret_set)
uint32_t MQI_weighted32(uint32_t n, uint32_t nR, uint32_t* ai, uint32_t* aj, double* a, double* degrees, uint32_t offset, uint32_t* R, uint32_t* ret_set)
{
graph<int32_t,int32_t> g(ai[n],n,ai,aj,a,offset,degrees);
graph<uint32_t,uint32_t> g(ai[n],n,ai,aj,a,offset,degrees);
return g.MQI_weighted(nR,R, ret_set);
}

int32_t MQI_weighted32_64(int32_t n, int32_t nR, int64_t* ai, int32_t* aj, double* a, double* degrees, int32_t offset, int32_t* R, int32_t* ret_set)
uint32_t MQI_weighted32_64(uint32_t n, uint32_t nR, int64_t* ai, uint32_t* aj, double* a, double* degrees, uint32_t offset, uint32_t* R, uint32_t* ret_set)
{
graph<int32_t,int64_t> g(ai[n],n,ai,aj,a,offset,degrees);
graph<uint32_t,int64_t> g(ai[n],n,ai,aj,a,offset,degrees);
return g.MQI_weighted(nR,R, ret_set);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ extern "C"
#endif

int64_t MQI_weighted64(int64_t n, int64_t nR, int64_t* ai, int64_t* aj, double* a, double* degrees, int64_t offset, int64_t* R, int64_t* ret_set);
int32_t MQI_weighted32(int32_t n, int32_t nR, int32_t* ai, int32_t* aj, double* a, double* degrees, int32_t offset, int32_t* R, int32_t* ret_set);
int32_t MQI_weighted32_64(int32_t n, int32_t nR, int64_t* ai, int32_t* aj, double* a, double* degrees, int32_t offset, int32_t* R, int32_t* ret_set);
uint32_t MQI_weighted32(uint32_t n, uint32_t nR, uint32_t* ai, uint32_t* aj, double* a, double* degrees, uint32_t offset, uint32_t* R, uint32_t* ret_set);
uint32_t MQI_weighted32_64(uint32_t n, uint32_t nR, int64_t* ai, uint32_t* aj, double* a, double* degrees, uint32_t offset, uint32_t* R, uint32_t* ret_set);

#ifdef __cplusplus
}
Expand Down
14 changes: 10 additions & 4 deletions localgraphclustering/src/lib/include/maxflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ double graph<vtype,itype>::sendFlow(vtype init_u, double init_flow, vtype t, vec


// template<typename vtype, typename itype>
// double graph<vtype,itype>::sendFlow(vtype u, double flow, vtype t, vtype start[])
// double graph<vtype,itype>::sendFlow(vtype u, double flow, vtype t, vector<vtype>& start)
// {
// //cout << u << " " << start[u] << endl;
// // Sink reached
Expand Down Expand Up @@ -235,6 +235,12 @@ void graph<vtype,itype>::find_cut(vtype u, vector<bool>& mincut, vtype& length)
template<typename vtype, typename itype>
pair<double,vtype> graph<vtype,itype>::DinicMaxflow(vtype s, vtype t, vtype V, vector<bool>& mincut)
{
for(int i = 0; i < V; i ++){
for(int j = 0; j < adj[i].size(); j ++){
Edge<vtype,itype> &e = adj[i][j];
//cout << i << " " << e.v << " " << e.C << " " << e.rev << " " << adj[e.v][e.rev].v << " " << adj[e.v][e.rev].C << " " << adj[e.v][e.rev].rev << endl;
}
}
// Corner case
if (s == t)
return make_pair(-1,0);
Expand All @@ -251,13 +257,13 @@ pair<double,vtype> graph<vtype,itype>::DinicMaxflow(vtype s, vtype t, vtype V, v
// from V { 0 to V }
fill(start.begin(),start.end(),0);
// while flow is not zero in graph from S to D
double flow = sendFlow(s, INT_MAX, t, start, SnapShots);
//cout << flow << endl;
double flow = sendFlow(s, numeric_limits<double>::max(), t, start, SnapShots);
while (flow > 0) {
// Add path flow to overall flow
total += flow;
flow = sendFlow(s, INT_MAX, t, start, SnapShots);
flow = sendFlow(s, numeric_limits<double>::max(), t, start, SnapShots);
}
//cout << "curr flow: " << total << endl;
//cout << "BFS" << endl;
}
//cout << "out" << endl;
Expand Down
7 changes: 4 additions & 3 deletions localgraphclustering/src/lib/include/routines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class graph{
void addEdge(vtype u, vtype v, double C);
bool BFS(vtype s, vtype t, vtype V);
double sendFlow(vtype u, double flow, vtype t, vector<vtype>& start, vector<pair<int,double>>& SnapShots);
//double sendFlow(vtype u, double flow, vtype t, vector<vtype>& start);
pair<double,vtype> DinicMaxflow(vtype s, vtype t, vtype V, vector<bool>& mincut);
void find_cut(vtype u, vector<bool>& mincut, vtype& length);

Expand Down Expand Up @@ -189,10 +190,10 @@ template<typename vtype, typename itype>
void graph<vtype,itype>::addEdge(vtype u, vtype v, double C)
{
// Forward edge : 0 flow and C capacity
Edge<vtype,itype> p{v, 0, C, (itype)adj[v].size()};
Edge<vtype,itype> p{v, 0, C, adj[v].size()};

// Back edge : 0 flow and 0 capacity
Edge<vtype,itype> q{u, 0, 0, (itype)adj[u].size()};
// Back edge : 0 flow and C capacity
Edge<vtype,itype> q{u, 0, C, adj[u].size()};

adj[u].push_back(p);
adj[v].push_back(q); // reverse edge
Expand Down
2 changes: 1 addition & 1 deletion notebooks/new_visualization_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 21bbee8

Please sign in to comment.