Revision 4fe0cb58 custompackages/graph-parser/src/simulation.cpp

View differences:

custompackages/graph-parser/src/simulation.cpp
68 68
    boost::relative_betweenness_centrality(gm.g_, v_centrality_pmap);
69 69
}
70 70

  
71
void run_simulation_for_a_graph(string input_path, double& elapsed_secs_bc, double& elapsed_secs_hbc, int number_of_experiments, bool is_weighted_graph) {
71
void run_simulation_for_a_graph(string input_path, double& bc_clock_begin, double& bc_clock_end,
72
        double& hbc_clock_begin, double& hbc_clock_end, int number_of_experiments, bool is_weighted_graph) {
72 73
    /* Returns the running time for Brandes BC and HBC
73 74
    */
74
    clock_t begin, end;
75
    double begin, end;
75 76

  
76 77
    // Disable the console output: http://stackoverflow.com/questions/30184998/how-to-disable-cout-output-in-the-runtime
77 78
    streambuf* orig_buf = cout.rdbuf(); // get underlying buffer
......
82 83
    readEdgeFileGraphManager(input_path, gm);
83 84

  
84 85
    // For Brandes BC
85
    begin = clock();
86
    bc_clock_begin = clock();
86 87
    bool targets_inclusion = true;
87 88
    calculate_brandes_bc(gm, targets_inclusion);
88
    end = clock();
89
    elapsed_secs_bc = double(end - begin) / CLOCKS_PER_SEC;
89
    bc_clock_end = clock();
90 90

  
91 91
    // For HBC
92
    begin = clock();
92
    hbc_clock_begin = clock();
93 93
    BiConnectedComponents bcc = BiConnectedComponents(gm);
94 94
    bcc.run();
95
    end = clock();
96
    elapsed_secs_hbc = double(end - begin) / CLOCKS_PER_SEC;
97

  
98
    // Restore the console output
95
    hbc_clock_end = clock();
99 96
    cout.rdbuf(orig_buf);
100

  
101
    // time_log = make_tuple(elapsed_secs_bc, elapsed_secs_hbc);
102 97
}
103 98

  
104
void write_simulation_result(string out_file_path, string filename, int run_index, double bc_time, double hbc_time) {
99
void write_simulation_result(string out_file_path, string filename, int run_index, double bc_clock_begin, double bc_clock_end, double hbc_clock_begin, double hbc_clock_end) {
105 100
    ofstream out_file(out_file_path.c_str(), std::ofstream::out | std::ofstream::app);
106 101

  
107 102
    // Extract information from file name
......
110 105
    string::size_type sep_pos = filename.find('_');
111 106
    string number_of_nodes = filename.substr(2, sep_pos - 2);
112 107

  
108
    long double bc_seconds = (bc_clock_end - bc_clock_begin) * 1.0 / CLOCKS_PER_SEC;
109
    if (bc_seconds < 0) {
110
        bc_seconds = bc_seconds + 2147;
111
    }
112
    long double hbc_seconds = (hbc_clock_end - hbc_clock_begin) * 1.0 / CLOCKS_PER_SEC;
113
    if (hbc_seconds < 0) {
114
        hbc_seconds = hbc_seconds + 2147;
115
    }
116

  
117
    cout << "    " << run_index << " " << bc_seconds << " | " << hbc_seconds << endl;
118

  
113 119
    string separator = "\t";
114 120
    if (out_file.is_open()) {
115 121
        out_file << filename << separator;
116 122
        out_file << graph_type << separator;
117 123
        out_file << number_of_nodes << separator;
118 124
        out_file << run_index << separator;
119
        out_file << bc_time << separator;
120
        out_file << hbc_time << separator << endl;
125
        out_file << bc_seconds << separator;
126
        out_file << hbc_seconds << separator;
127
        out_file << bc_clock_begin << separator;
128
        out_file << bc_clock_end << separator;
129
        out_file << hbc_clock_begin << separator;
130
        out_file << hbc_clock_end << endl;
121 131
    }
122 132
    out_file.close();
123 133
}
......
164 174
    for (string file : files) {
165 175
        cout << "Running for file " << file << endl;
166 176
        for (int run_index = 0; run_index < number_of_experiments; ++run_index) {
167
            double bc_time;
168
            double hbc_time;
177
            double bc_clock_begin, bc_clock_end;
178
            double hbc_clock_begin, hbc_clock_end;
179

  
169 180
            string input_path = input_dir + "/" + file;
170
            run_simulation_for_a_graph(input_path, bc_time, hbc_time, number_of_experiments, is_weighted_graph);
171
            cout << "    " << run_index << ": " << bc_time << " | " << hbc_time << endl;
172
            write_simulation_result(output_file_path, file, run_index, bc_time, hbc_time);
181
            run_simulation_for_a_graph(input_path, bc_clock_begin, bc_clock_end, hbc_clock_begin, hbc_clock_end, number_of_experiments, is_weighted_graph);
182
            write_simulation_result(output_file_path, file, run_index, bc_clock_begin, bc_clock_end, hbc_clock_begin, hbc_clock_end);
173 183
        }
174 184
    }
185

  
186
    cout << "CLOCKS_PER_SEC = " << CLOCKS_PER_SEC << endl;
175 187
}
176 188

  
177 189

  
190

  
191
// # Negative - end_clock - begin_clock
192
// # -2054053648 | 31706352 - 2085760000
193
// #
194
// # Normal result: 93420000

Also available in: Unified diff