Commit 744777c0 authored by jonasseidel's avatar jonasseidel
Browse files

Data gathering now averages values for a datapoint

parent c5afe07d
......@@ -13,6 +13,7 @@ maintenance_problem_test
*.test_param
*.test_data
*.out
*.csv
benders_test
preprocessor_test
scip_test
......
......@@ -12,7 +12,7 @@ Maintenance_Problem::Maintenance_Problem() : Linear_Program("maintenance_problem
}
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem& mp) : Linear_Program("maintenance_problem_ip", true) {
Maintenance_Problem::Maintenance_Problem(const Maintenance_Problem& mp) : Linear_Program("maintenance_problem_ip", true) {
*this = mp;
}
......@@ -203,16 +203,14 @@ std::vector<SCIP*> Maintenance_Problem::all_computational_models(){
return {scip_basic/*, scip_semiassign/*, scip_benders/*, benders_native*/};
}
void Maintenance_Problem::operator=(Maintenance_Problem& mp){
this->Linear_Program::operator=(mp);
void Maintenance_Problem::operator=(const Maintenance_Problem& mp){
this->Linear_Program::operator=(const_cast<Maintenance_Problem&>(mp)); // yeah, I am not doing const correctness for Linear_Program... not gonna happen
this->_number_of_epochs = mp._number_of_epochs;
auto copy_and_lookup = mp._g.copy_ret_lookup();
this->_g = copy_and_lookup.first;
auto source_lookup = copy_and_lookup.second.find(mp._source);
if(source_lookup == copy_and_lookup.second.end()) throw std::invalid_argument("source not contained in graph");
this->_source = source_lookup->second;
auto target_lookup = copy_and_lookup.second.find(mp._target);
if(target_lookup == copy_and_lookup.second.end()) throw std::invalid_argument("target not contained in graph");
this->_target = target_lookup->second;
}
......
......@@ -20,7 +20,7 @@ class Maintenance_Problem : public Linear_Program {
Node* _target;
public:
Maintenance_Problem();
Maintenance_Problem(Maintenance_Problem& mp);
Maintenance_Problem(const Maintenance_Problem& mp);
Maintenance_Problem(Maintenance_Problem&& mp);
Maintenance_Problem(const Graph& g, const Node* source, const Node* target, size_t intervals);
......@@ -31,7 +31,7 @@ public:
std::vector<SCIP*> all_computational_models();
void operator=(Maintenance_Problem& mp);
void operator=(const Maintenance_Problem& mp);
void operator=(Maintenance_Problem&& mp);
Maintenance_Problem(std::istream& is);
......
#include <sstream>
#include <vector>
bool gather_data(int depth, std::filesystem::path path, std::vector<Data>& data_vector){
bool gather_data(std::filesystem::path path, std::vector<Data>& data_vector, int depth){
std::stringstream buffer;
for(int i = 0; i < depth; i++){
buffer << " ";
......@@ -12,7 +12,7 @@ bool gather_data(int depth, std::filesystem::path path, std::vector<Data>& data_
// iterate over instances in folder
for (const auto & entry : std::filesystem::directory_iterator(path)){
if(entry.is_directory()){
all_fine = ( all_fine && gather_data(depth+1, entry.path(), data_vector) );
all_fine = ( all_fine && gather_data(entry.path(), data_vector, depth+1) );
}else{
// check if data describes instance and if it has previously been executed (all data has been calculated)
try{
......@@ -20,18 +20,17 @@ bool gather_data(int depth, std::filesystem::path path, std::vector<Data>& data_
data_file.open(entry.path(), std::ios::in);
data_vector.push_back(Data{});
Data& curr_data = data_vector.back();
data_file >> curr_data;
data_file >> data_vector.back();
data_file.close();
if(!values_complete(curr_data)) {
if(!values_complete(data_vector.back())) {
all_fine = false;
data_vector.pop_back();
std::cout << "file contained instance test data, but not all values where determined!" << std::endl;
throw std::invalid_argument("not all data has been calculated; execute the models first");
}
std::cout << buffer.str() << "data appears correct; collecting..." << std::endl;
}catch(std::exception& e){
data_vector.pop_back();
std::cout << buffer.str() << e.what() << std::endl;
std::cout << buffer.str() << "file doesn't appear to contain test data" << std::endl;
}
......@@ -41,21 +40,25 @@ bool gather_data(int depth, std::filesystem::path path, std::vector<Data>& data_
return all_fine;
}
std::pair<bool, std::vector<Data>> gather_data(std::filesystem::path path){
std::vector<Data> data_vector;
return {gather_data(0, path, data_vector), std::move(data_vector)};
}
std::map<std::string, std::vector<Data>> sort_data_by_parent_directory_name(const std::vector<Data>& data_vector){
std::map<std::string, std::vector<Data>> parent_folder_map;
for(const Data& data : data_vector){
auto iter = parent_folder_map.emplace(std::filesystem::path(data.path).parent_path().filename().string(), std::vector<Data>());
iter.first->second.push_back(data);
}
bool data_to_csv(std::fstream& file, 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 all_belonged;
return 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;
file << csv_test_data_title(x_axis_data, y_axis_data, models) << "\n";
for(const Data& data : data_vector){
std::cout << "start" << std::endl;
auto [belonged, csv_string] = csv(data, x_axis_data, y_axis_data, models);
for(const auto& category_pair : sorted_data){
auto [belonged, csv_string] = csv_average_performance(category_pair.second, x_axis_data, y_axis_data, models);
all_belonged = (all_belonged && belonged);
file << csv_string << "\n";
std::cout << "end" << std::endl;
}
return all_belonged;
......
......@@ -160,44 +160,34 @@ std::string csv(const Derived_Performance_Data& exec_data){
}
std::string csv(const std::vector<Derived_Performance_Data>& exec_vector){
// only convert to csv if fully initialized
std::cout << "marker" << std::endl;
// only call convert to csv if fully initialized
double time_in_sec = 0;
AVG_PERF_OVER_VEC(exec_vector, time_in_sec);
std::cout << "marker" << std::endl;
double number_of_bnb_runs = 0;
AVG_PERF_OVER_VEC(exec_vector, number_of_bnb_runs);
std::cout << "marker" << std::endl;
double number_of_reopt_runs = 0;
AVG_PERF_OVER_VEC(exec_vector, number_of_reopt_runs);
std::cout << "marker" << std::endl;
double number_of_nodes_explored = 0;
AVG_PERF_OVER_VEC(exec_vector, number_of_nodes_explored);
std::cout << "marker" << std::endl;
double max_depth = 0;
AVG_PERF_OVER_VEC(exec_vector, max_depth);
std::cout << "marker" << std::endl;
double dual_bound = 0;
AVG_PERF_OVER_VEC(exec_vector, dual_bound);
std::cout << "marker" << std::endl;
double gap = 0;
AVG_PERF_OVER_VEC(exec_vector, gap);
std::cout << "marker" << std::endl;
double primal_bound = 0;
AVG_PERF_OVER_VEC(exec_vector, primal_bound);
std::cout << "marker" << std::endl;
double number_of_primal_sols = 0;
AVG_PERF_OVER_VEC(exec_vector, number_of_primal_sols);
std::cout << "marker" << std::endl;
std::stringstream csv_string;
csv_string << time_in_sec << ","
<< number_of_bnb_runs << ","
......@@ -336,7 +326,6 @@ std::string csv_test_data_title(const axis_data& x_axis_data, const axis_data& y
// 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){
std::cout << "start csv" << std::endl;
bool belongs = true;
std::stringstream csv_string;
......@@ -347,30 +336,29 @@ std::pair<bool, std::string> csv(const Data& data, const axis_data& x_axis_dat
raster_entry_folder_name << data_path.parent_path().filename().string();
// parsing folder name
std::cout << "1" << std::endl;
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, xval, '_');
// parse for y_axis_val
std::getline(raster_entry_folder_name, curr, '=');
if(curr != x_axis_data.name){
if(curr != y_axis_data.name){
std::cout << curr << "!=" << y_axis_data.name << std::endl;
belongs = false;
}
std::getline(raster_entry_folder_name, yval);
}else{
std::cout << curr << "!=" << "raster_pos" << std::endl;
belongs = false;
}
std::cout << "2" << std::endl;
csv_string << data.marked_for_inspection << ","
<< data.path << ","
<< data.name << ","
......@@ -380,18 +368,109 @@ std::pair<bool, std::string> csv(const Data& data, const axis_data& x_axis_dat
<< csv(data.derived_problem);
for(std::string model : models){
std::cout << model << std::endl;
std::cout << data << std::endl;
auto exec_vector = data.derived_performance.find(model)->second;
for(int i = 0; i < exec_vector.size(); i++){
std::cout << exec_vector[i] << std::endl;
}
csv_string << ",";
csv_string << csv(exec_vector);
}
std::cout << "end" << std::endl;
return {belongs, csv_string.str()};
}
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){
bool belongs = true;
std::stringstream csv_string;
const Data& data = data_vector.front();
std::string xval = "";
std::string yval = "";
std::filesystem::path data_path(data.path);
{
std::stringstream raster_entry_folder_name;
raster_entry_folder_name << 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, xval, '_');
// 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, yval);
}else{
std::cout << curr << "!=" << "raster_pos" << std::endl;
belongs = false;
}
}
csv_string << data.marked_for_inspection << ","
<< data_path.parent_path().string() << ","
<< data.name << ","
<< xval << ","
<< yval << ","
<< csv(data.gen_data) << ","
<< csv(data.derived_problem);
// check that data is grouped sensibly
for(const Data& curr_data : data_vector){
std::string curr_xval = "";
std::string curr_yval = "";
std::filesystem::path curr_data_path(curr_data.path);
std::stringstream curr_raster_entry_folder_name;
curr_raster_entry_folder_name << curr_data_path.parent_path().filename().string();
// parsing folder name
std::string curr;
std::getline(curr_raster_entry_folder_name, curr, ':');
if(curr == "raster_pos"){
// parse for x_axis_val
std::getline(curr_raster_entry_folder_name, curr, '=');
if(curr != x_axis_data.name){
std::cout << curr << "!=" << x_axis_data.name << std::endl;
belongs = false;
}
std::getline(curr_raster_entry_folder_name, curr_xval, '_');
// parse for y_axis_val
std::getline(curr_raster_entry_folder_name, curr, '=');
if(curr != y_axis_data.name){
std::cout << curr << "!=" << y_axis_data.name << std::endl;
belongs = false;
}
std::getline(curr_raster_entry_folder_name, curr_yval);
}else{
std::cout << curr << "!=" << "raster_pos" << std::endl;
belongs = false;
}
if(xval != curr_xval) belongs = false;
if(yval != curr_yval) 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()};
}
......@@ -405,7 +484,13 @@ std::istream& operator>>(std::istream& is, Data& data){
while(is >> curr && curr != "}"){
IF_READ_VAR_SET_VAR_DIRECT(is, data, marked_for_inspection, curr);
IF_READ_VAR_SET_VAR_GETLINE(is, data, path, curr);
if(data.path.size() > 0 && data.path.c_str()[0] == ' '){
data.path = data.path.substr(1, std::string::npos);
}
IF_READ_VAR_SET_VAR_GETLINE(is, data, name, curr);
if(data.name.size() > 0 && data.name.c_str()[0] == ' '){
data.name = data.name.substr(1, std::string::npos);
}
IF_READ_VAR_SET_VAR_DIRECT(is, data, gen_data, curr);
IF_READ_VAR_SET_VAR_DIRECT(is, data, mp, curr);
IF_READ_VAR_SET_VAR_DIRECT(is, data, derived_problem, curr);
......
......@@ -130,7 +130,7 @@ 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::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);
bool operator==(Generation_Parameters& a, Generation_Parameters& b);
......
......@@ -14,9 +14,9 @@
bool generate_tests_data(std::filesystem::path path, int number_of_instances);
bool execute_tests(std::filesystem::path path, bool check_all_problem_data = false, bool add_new_execution = false);
std::pair<bool, std::vector<Data>> gather_data(std::filesystem::path path);
bool data_to_csv(std::fstream& file, 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 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);
// 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);
......
......@@ -16,19 +16,20 @@ int main(int argc, char** argv){
models.push_back(argv[index]);
}
auto [all_fine, data_vector] = gather_data(top_level_path);
std::vector<Data> data_vector;
bool all_fine = gather_data(top_level_path, data_vector);
if(!all_fine) std::cout << "there seem to have been something unexpected; trying to continue" << std::endl;
std::cout << "finished reading; writing gathered data to \"./data.csv\"" << std::endl;
for(auto iter_data : data_vector){
if(!iter_data.derived_problem.number_of_edges.first){
std::cout << "-------------------------------->>>>>>" << iter_data.path << std::endl;
}
}
std::fstream file("data.csv");
bool pure = data_to_csv(file, data_vector, axis_data{x_name}, axis_data{y_name}, models);
std::fstream file;
file.open("./data.csv", std::ios::out);
auto sorted_data = sort_data_by_parent_directory_name(data_vector);
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;
file.close();
assert(!all_fine && pure);
assert(all_fine && pure);
}
......@@ -12,10 +12,10 @@ int main(int argc, char** argv){
Maintenance_Problem mp;
size_t number_of_nodes = 15;
size_t number_of_nodes = 100;
double avg_incid_per_node = 6;
double share_of_critical = 1;
size_t nodes_per_step = 5;
size_t nodes_per_step = 25;
size_t fuzzing = 1;
size_t number_of_epochs = 3;
......
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