Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fda23c

Browse files
authored
Add files via upload
1 parent 47d9827 commit 5fda23c

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

community.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ void Community::cycles(Graph*& graph_projection, vector<unsigned int>& list_inde
6060
vec_depth->push_back(0);
6161
}
6262

63-
srand(unsigned(time(NULL)));
64-
6563
int i = rand() % list_index_nodes.size();
6664
bool new_node = true;
6765

libs.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ struct comp_pair
4141
return true;
4242
if(lhs.second < rhs.second)
4343
return false;
44-
if(lhs.first < rhs.first)
45-
return true;
46-
return false;
44+
45+
return true;
46+
47+
// if(lhs.first < rhs.first)
48+
// return true;
49+
// return false;
4750
}
4851
};
4952

main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Projection* select_similarity(string similarity_index)
5151
}
5252

5353
int main(int argc, const char* argv[])
54-
{
54+
{
5555
string path_dataset, similarity_index;
5656
int distance, depth_best;
5757
static set<string> list_valid_similarities = {"cn", "aa", "ji"};
@@ -100,6 +100,8 @@ int main(int argc, const char* argv[])
100100
main_graph->load_graph(path_dataset);
101101
cerr << " n = " << main_graph->n << endl << " m = " << main_graph->m/2 << endl;
102102

103+
srand(unsigned(time(NULL)));
104+
103105
Community* c = new Community(main_graph, depth_best);
104106
Projection* p;
105107
Graph* g;
@@ -131,11 +133,12 @@ int main(int argc, const char* argv[])
131133

132134
cerr << endl << "--------------" << endl;
133135

136+
unsigned int i;
134137
for(auto& e : c->community)
135138
{
136-
for(auto& node : e.second)
137-
cout << node->id << " ";
138-
cout << endl;
139+
for(i=0; i<e.second.size()-1; i++)
140+
cout << e.second[i]->id << " ";
141+
cout << e.second[e.second.size()-1]->id << endl;
139142
}
140143

141144
for(auto& g : list_subgraphs)

projection.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void Projection::project(Graph*& in_graph, unsigned int distance)
1919

2020
unordered_map<unsigned int, Node*> map_node;
2121
unordered_map<unsigned int, set<pair<unsigned int, float>, comp_pair>> map_neighbor;
22-
22+
vector<unsigned int> shuffle;
23+
2324
index = 0;
2425
while(index < in_graph->size_list_nodes)
2526
{
@@ -30,14 +31,19 @@ void Projection::project(Graph*& in_graph, unsigned int distance)
3031
map_node[index]->main_index = in_graph->list_nodes[index]->main_index;
3132

3233
for(auto& n : list_distance_neighbors)
34+
shuffle.push_back(n->index);
35+
random_shuffle(shuffle.begin(), shuffle.end());
36+
37+
for(auto& index_neighbor : shuffle)
3338
{
34-
projection_weight = similarity_projection(in_graph, index, n->index);
39+
projection_weight = similarity_projection(in_graph, index, index_neighbor);
3540

3641
if(projection_weight > 0.0)
37-
map_neighbor[index].insert(make_pair(n->index, projection_weight));
42+
map_neighbor[index].insert(make_pair(index_neighbor, projection_weight));
3843
}
3944

4045
index += in_graph->list_nodes[index]->nb_neighbors + 1;
46+
shuffle.clear();
4147
}
4248

4349
graph_projection->create_graph(map_node, map_neighbor);

0 commit comments

Comments
 (0)