Commit d1bb6aad authored by jonasseidel's avatar jonasseidel
Browse files

csv gather function now output data in order readible by pgfplots

parent 73c09d64
......@@ -48,8 +48,52 @@ std::map<std::string, std::vector<Data>> sort_data_by_parent_directory_name(cons
}
return parent_folder_map;
};
}
std::pair<bool, std::map<std::pair<double,double>, std::vector<Data>> > sort_data_by_parent_directory_name(const std::vector<Data>& data_vector, const axis_data& x_axis_data, const axis_data& y_axis_data){
bool belongs = true;
std::map<std::pair<double,double>, std::vector<Data>> parent_folder_map;
for(const Data& data : data_vector){
double xval = -1;
double yval = -1;
{
std::stringstream raster_entry_folder_name;
raster_entry_folder_name << std::filesystem::path(data.path).parent_path().filename().string();
// parsing folder name
std::string curr;
std::getline(raster_entry_folder_name, curr, ':');
if(curr == "raster_pos"){
// parse for x_axis_val
std::getline(raster_entry_folder_name, curr, '=');
if(curr != x_axis_data.name){
std::cout << curr << "!=" << x_axis_data.name << std::endl;
belongs = false;
}
std::getline(raster_entry_folder_name, curr, '_');
xval = std::stod(curr);
// parse for y_axis_val
std::getline(raster_entry_folder_name, curr, '=');
if(curr != y_axis_data.name){
std::cout << curr << "!=" << y_axis_data.name << std::endl;
belongs = false;
}
std::getline(raster_entry_folder_name, curr);
yval = std::stod(curr);
}else{
std::cout << curr << "!=" << "raster_pos" << std::endl;
belongs = false;
}
}
auto iter = parent_folder_map.emplace(std::pair{xval,yval}, std::vector<Data>());
iter.first->second.push_back(data);
}
return {belongs, parent_folder_map};
}
bool sorted_data_to_csv(std::fstream& file, const std::map<std::string, std::vector<Data>>& sorted_data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models){
bool all_belonged = true;
......@@ -63,3 +107,16 @@ bool sorted_data_to_csv(std::fstream& file, const std::map<std::string, std::vec
return all_belonged;
}
bool sorted_data_to_csv(std::fstream& file, const std::map<std::pair<double,double>, std::vector<Data>>& sorted_data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models){
bool all_belonged = true;
file << reduced_csv_test_data_title(x_axis_data, y_axis_data, models) << "\n";
for(const auto& category_pair : sorted_data){
auto [belonged, csv_string] = csv_average_performance_coords_sorted(category_pair.first, category_pair.second, x_axis_data, y_axis_data, models);
all_belonged = (all_belonged && belonged);
file << csv_string << "\n";
}
return all_belonged;
}
......@@ -327,6 +327,37 @@ std::string csv_test_data_title(const axis_data& x_axis_data, const axis_data& y
return csv_string.str();
}
std::string reduced_csv_test_data_title(const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models){
std::stringstream csv_string;
csv_string << "marked_for_inspection" << ","
<< "path" << ","
<< "name" << ","
<< x_axis_data.name << ","
<< y_axis_data.name << ","
<< "graph_type" << ","
<< "number_of_nodes_gen" << ","
<< "avg_incid_per_node_gen" << ","
<< "share_of_critical_gen" << ","
<< "nodes_per_step_gen" << ","
<< "fuzzing_gen" << ","
<< "number_of_epochs_gen" << ","
<< "simulate_multiple_terminals_gen" << ","
<< "only_tip_fringes_gen" << ","
<< "only_tip_extreme_layer_gen";
for(std::string model : models){
csv_string << "," << "time_in_sec" << "_" << model << ","
<< "number_of_bnb_runs" << "_" << model << ","
<< "number_of_reopt_runs" << "_" << model << ","
<< "number_of_nodes_explored" << "_" << model << ","
<< "max_depth" << "_" << model << ","
<< "dual_bound" << "_" << model << ","
<< "primal_bound" << "_" << model << ","
<< "gap" << "_" << model << ","
<< "number_of_primal_sols" << "_" << model;
}
return csv_string.str();
}
// belongs|csv format
std::pair<bool, std::string> csv(const Data& data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models){
bool belongs = true;
......@@ -478,6 +509,79 @@ std::pair<bool, std::string> csv_average_performance(const std::vector<Data>& da
return {belongs, csv_string.str()};
}
std::pair<bool, std::string> csv_average_performance_coords_sorted(const std::pair<double, double> position, const std::vector<Data>& data_vector, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models){
bool belongs = true;
std::stringstream csv_string;
const Data& data = data_vector.front();
for(const Data& curr_data : data_vector){
double xval = position.first;
double yval = position.second;
std::stringstream raster_entry_folder_name;
raster_entry_folder_name << std::filesystem::path(curr_data.path).parent_path().filename().string();
{
// parsing folder name
std::string curr;
std::getline(raster_entry_folder_name, curr, ':');
if(curr == "raster_pos"){
// parse for x_axis_val
std::getline(raster_entry_folder_name, curr, '=');
if(curr != x_axis_data.name){
std::cout << curr << "!=" << x_axis_data.name << std::endl;
belongs = false;
}
std::getline(raster_entry_folder_name, curr, '_');
if( xval != (xval = std::stod(curr)) ) belongs = false;
// parse for y_axis_val
std::getline(raster_entry_folder_name, curr, '=');
if(curr != y_axis_data.name){
std::cout << curr << "!=" << y_axis_data.name << std::endl;
belongs = false;
}
std::getline(raster_entry_folder_name, curr);
if( yval != (yval = std::stod(curr)) ) belongs = false;
}else{
std::cout << curr << "!=" << "raster_pos" << std::endl;
belongs = false;
}
}
if(&curr_data == &data_vector.front()){
csv_string << curr_data.marked_for_inspection << ","
<< raster_entry_folder_name.str() << ","
<< curr_data.name << ","
<< xval << ","
<< yval << ","
<< csv(curr_data.gen_data);
}else{
if(curr_data.marked_for_inspection != data_vector.front().marked_for_inspection) belongs = false;
if(raster_entry_folder_name.str() != std::filesystem::path(curr_data.path).parent_path().filename().string()) belongs = false;
if(curr_data.name != data_vector.front().name) belongs = false;
if(xval != position.first) belongs = false;
if(yval != position.second) belongs = false;
if(curr_data.gen_data != data_vector.front().gen_data) belongs = false;
}
}
// concatenate execution data
for(std::string model : models){
std::vector<Derived_Performance_Data> aggr_exec_vector;
for(const Data& curr_data : data_vector){
const std::vector<Derived_Performance_Data>& curr_exec_vector = curr_data.derived_performance.find(model)->second;
aggr_exec_vector.insert(aggr_exec_vector.begin(), curr_exec_vector.begin(), curr_exec_vector.end());
}
csv_string << ",";
csv_string << csv(aggr_exec_vector);
}
return {belongs, csv_string.str()};
}
std::istream& operator>>(std::istream& is, Data& data){
std::string curr;
is >> curr;
......@@ -504,7 +608,7 @@ std::istream& operator>>(std::istream& is, Data& data){
}
bool operator==(Generation_Parameters& a, Generation_Parameters& b){
bool operator==(const Generation_Parameters& a, const Generation_Parameters& b){
if(a.graph_type != b.graph_type) return false;
if(a.number_of_nodes != b.number_of_nodes) return false;
if(std::abs(a.avg_incid_per_node - b.avg_incid_per_node) > CMP_EPS) return false;
......@@ -519,7 +623,7 @@ bool operator==(Generation_Parameters& a, Generation_Parameters& b){
return true;
}
bool operator!=(Generation_Parameters& a, Generation_Parameters& b){
bool operator!=(const Generation_Parameters& a, const Generation_Parameters& b){
return !(a == b);
}
......
......@@ -129,12 +129,14 @@ std::istream& operator>>(std::istream& is, Data& data);
std::string csv_test_data_title(const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
std::string reduced_csv_test_data_title(const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
std::pair<bool, std::string> csv(const Data& data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
std::pair<bool, std::string> csv_average_performance(const std::vector<Data>& data_vector, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
std::pair<bool, std::string> csv_average_performance_coords_sorted(const std::pair<double, double> position, const std::vector<Data>& data_vector, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
bool operator==(Generation_Parameters& a, Generation_Parameters& b);
bool operator==(const Generation_Parameters& a, const Generation_Parameters& b);
bool operator!=(Generation_Parameters& a, Generation_Parameters& b);
bool operator!=(const Generation_Parameters& a, const Generation_Parameters& b);
bool values_complete(Derived_Performance_Data& perf_data);
bool values_complete(Derived_Problem_Data& prob_data);
......
......@@ -17,6 +17,10 @@ bool execute_tests(std::filesystem::path path, bool check_all_problem_data = fal
bool gather_data(std::filesystem::path path, std::vector<Data>& data_vector, int depth = 0);
std::map<std::string, std::vector<Data>> sort_data_by_parent_directory_name(const std::vector<Data>& data_vector);
bool sorted_data_to_csv(std::fstream& file, const std::map<std::string, std::vector<Data>>& sorted_data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
std::pair<bool, std::map<std::pair<double,double>, std::vector<Data>> > sort_data_by_parent_directory_name(const std::vector<Data>& data_vector, const axis_data& x_axis_data, const axis_data& y_axis_data);
bool sorted_data_to_csv(std::fstream& file, const std::map<std::pair<double,double>, std::vector<Data>>& sorted_data, const axis_data& x_axis_data, const axis_data& y_axis_data, const std::vector<std::string>& models);
// generates raster of tests
// gathers specified fields into a table which can be easily be plotted afterwards with pgfplots
bool generate_and_execute_2d_plot_test(std::filesystem::path path, size_t number_of_instances_per_coord, const axis_data& x_axis_data, const axis_data& y_axis_data, std::function<Generation_Parameters(double x, double y)> test_generator);
......
......@@ -24,12 +24,12 @@ int main(int argc, char** argv){
std::fstream file;
file.open("./data.csv", std::ios::out);
auto sorted_data = sort_data_by_parent_directory_name(data_vector);
auto [pure, sorted_data] = sort_data_by_parent_directory_name(data_vector, axis_data{x_name}, axis_data{y_name});
bool pure = sorted_data_to_csv(file, sorted_data, axis_data{x_name}, axis_data{y_name}, models);
if(!pure) std::cout << "not all data belongs to the same raster" << std::endl;
auto pure2 = sorted_data_to_csv(file, sorted_data, axis_data{x_name}, axis_data{y_name}, models);
if(!pure || !pure2) std::cout << "not all data belongs to the same raster" << std::endl;
file.close();
assert(all_fine && pure);
assert(all_fine && pure && pure2);
}
......@@ -22,5 +22,5 @@ int main(int argc, char** argv){
};
return generate_and_execute_2d_plot_test(path, 15, axis_data{"nincidences", 5, 3, 7}, axis_data{"nedges", 4, 50, 125}, test_generator);
return generate_and_execute_2d_plot_test(path, 50, axis_data{"nincidences", 9, 3, 7}, axis_data{"nedges", 11, 30, 40}, test_generator);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment