int set_source(int type, char *filename) { struct sourceinfo *info; if (!sources_loaded) { load_sources(); sources_loaded = 1; } info = search_for_registered_source(type); if (!info) { printf("Unknown source type\n"); return -1; } source_type = type; if (!info->open_input) { printf("This source does not support input functionality\n"); return -1; } return info->open_input(filename); }
bool load_instance(Data* data_p, std::string const& file_p) { LOG(INFO) << "Loading Instance inside the data structure : " << file_p; // VLOG(2) << "Found cookies in DEBUG"; VLOG(1) << "Openning the file"; std::ifstream file_stream_l(file_p); // get length of file: file_stream_l.seekg (0, file_stream_l.end); int length = file_stream_l.tellg(); file_stream_l.seekg (0, file_stream_l.beg); VLOG(1) << "The length of file is : " << length; VLOG(1) << "Reading the file"; char * buffer = new char [length]; file_stream_l.read (buffer,length); if (file_stream_l) VLOG(1) << "All characters read successfully."; else LOG(FATAL) << "Error : only " << file_stream_l.gcount() << " could be read"; file_stream_l.close(); VLOG(1) << "Parsing the file"; rapidxml::xml_document<> doc; // character type defaults to char doc.parse<0>(buffer); // 0 means default parse flags VLOG(1) << "Extracting Data"; rapidxml::xml_node<> *root = doc.first_node(); // Node IRP_R_C_I /** Extraction of the tree ! */ // Unit rapidxml::xml_node<> *child_l = root->first_node(); check_name(child_l,"unit"); data_p->unit(std::stoi(child_l->value())); VLOG(1) << "Unit = " << data_p->unit(); // Horizon child_l = child_l->next_sibling(); check_name(child_l,"horizon"); data_p->horizon(std::stoi(child_l->value())); VLOG(1) << "Horizon = " << data_p->horizon(); // Time Matrices child_l = child_l->next_sibling(); check_name(child_l,"timeMatrices"); int size_time_matrices = load_time_matrices(data_p, child_l); VLOG(1) << "Time Matrix loaded of size = " << size_time_matrices; // Drivers child_l = child_l->next_sibling(); check_name(child_l,"drivers"); int num_drivers = load_drivers(data_p, child_l); VLOG(1) << "Vector of driverd loaded of size = " << num_drivers; // Trailers child_l = child_l->next_sibling(); check_name(child_l,"trailers"); int num_trailers = load_trailers(data_p, child_l); VLOG(1) << "Vector of trailers loaded of size = " << num_trailers; // Bases child_l = child_l->next_sibling(); check_name(child_l,"bases"); data_p->bases_index(std::stoi(child_l->first_node()->value())); VLOG(1) << "bases = " << data_p->bases_index(); // Sources child_l = child_l->next_sibling(); check_name(child_l,"sources"); int num_sources = load_sources(data_p, child_l); VLOG(1) << "Vector of sources loaded of size = " << num_sources; // Customers child_l = child_l->next_sibling(); check_name(child_l,"customers"); int num_customers = load_customers(data_p, child_l); VLOG(1) << "Vector of customers loaded of size = " << num_customers; // Time Matrices child_l = child_l->next_sibling(); check_name(child_l,"distMatrices"); int size_dist_matrices = load_dist_matrices(data_p, child_l); VLOG(1) << "Dist Matrix loaded of size = " << size_dist_matrices; // Clearing memory space delete[] buffer; return true; }