void DocumentNKController::setReceiveName(Contractor receiver) { if(receiver.isCompany()) view->getLineReceiveName()->setText(receiver.getRepresentative()); else view->getLineReceiveName()->setText(receiver.getName()); }
void DocumentFKController::selectContractor() { SelectContractorController dialog(view); dialog.showDialog(); if(dialog.getCancel() !=1) { Contractor c =dialog.addContractor(); if(c.isCompany()) view->setLineReceiveName(c.getRepresentative()); else view->setLineReceiveName(c.getName()); view->setContractorDataNew(c); if(!view->getContractorDataNew()->toPlainText().isEmpty() && symbol == "FK") managerFK->getFKPolicy()->setContractor(c); else if(!view->getContractorDataNew()->toPlainText().isEmpty() && symbol == "FZK") managerFK->getFZKPolicy()->setContractor(c); } }
int main(int argc, char *argv[]) { try { LogPolicy::GetInstance().Unmute(); TIMER_START(preparing); TIMER_START(expansion); boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path; unsigned int requested_num_threads; bool use_elevation; // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( "config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path) ->default_value("contractor.ini"), "Path to a configuration file."); // declare a group of options that will be allowed both on command line and in config file boost::program_options::options_description config_options("Configuration"); config_options.add_options()( "restrictions,r", boost::program_options::value<boost::filesystem::path>(&restrictions_path), "Restrictions file in .osrm.restrictions format")( "profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path) ->default_value("profile.lua"),"Path to LUA routing profile")( "elevation,e", boost::program_options::value<bool>(&use_elevation)->default_value(true), "Process node elevations")( "threads,t", boost::program_options::value<unsigned int>(&requested_num_threads)->default_value(tbb::task_scheduler_init::default_num_threads()), "Number of threads to use"); // hidden options, will be allowed both on command line and in config file, but will not be // shown to the user boost::program_options::options_description hidden_options("Hidden options"); hidden_options.add_options()( "input,i", boost::program_options::value<boost::filesystem::path>(&input_path), "Input file in .osm, .osm.bz2 or .osm.pbf format"); // positional option boost::program_options::positional_options_description positional_options; positional_options.add("input", 1); // combine above options for parsing boost::program_options::options_description cmdline_options; cmdline_options.add(generic_options).add(config_options).add(hidden_options); boost::program_options::options_description config_file_options; config_file_options.add(config_options).add(hidden_options); boost::program_options::options_description visible_options( "Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]"); visible_options.add(generic_options).add(config_options); // parse command line options boost::program_options::variables_map option_variables; boost::program_options::store(boost::program_options::command_line_parser(argc, argv) .options(cmdline_options) .positional(positional_options) .run(), option_variables); if (option_variables.count("version")) { SimpleLogger().Write() << g_GIT_DESCRIPTION; return 0; } if (option_variables.count("help")) { SimpleLogger().Write() << "\n" << visible_options; return 0; } boost::program_options::notify(option_variables); if (!option_variables.count("restrictions")) { restrictions_path = std::string(input_path.string() + ".restrictions"); } if (!option_variables.count("input")) { SimpleLogger().Write() << "\n" << visible_options; return 0; } if (!boost::filesystem::is_regular_file(input_path)) { SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!"; return 1; } if (!boost::filesystem::is_regular_file(profile_path)) { SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!"; return 1; } if (1 > requested_num_threads) { SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger"; return 1; } const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads(); SimpleLogger().Write() << "Input file: " << input_path.filename().string(); SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string(); SimpleLogger().Write() << "Profile: " << profile_path.filename().string(); SimpleLogger().Write() << "Using elevation: " << use_elevation; SimpleLogger().Write() << "Threads: " << requested_num_threads; if (recommended_num_threads != requested_num_threads) { SimpleLogger().Write(logWARNING) << "The recommended number of threads is " << recommended_num_threads << "! This setting may have performance side-effects."; } tbb::task_scheduler_init init(requested_num_threads); LogPolicy::GetInstance().Unmute(); boost::filesystem::ifstream restriction_stream(restrictions_path, std::ios::binary); TurnRestriction restriction; FingerPrint fingerprint_loaded, fingerprint_orig; unsigned number_of_usable_restrictions = 0; restriction_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint)); if (!fingerprint_loaded.TestPrepare(fingerprint_orig)) { SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n" "Reprocess to get rid of this warning."; } restriction_stream.read((char *)&number_of_usable_restrictions, sizeof(unsigned)); restriction_list.resize(number_of_usable_restrictions); if (number_of_usable_restrictions > 0) { restriction_stream.read((char *)&(restriction_list[0]), number_of_usable_restrictions * sizeof(TurnRestriction)); } restriction_stream.close(); boost::filesystem::ifstream in; in.open(input_path, std::ios::in | std::ios::binary); const std::string node_filename = input_path.string() + ".nodes"; const std::string edge_out = input_path.string() + ".edges"; const std::string geometry_filename = input_path.string() + ".geometry"; const std::string graphOut = input_path.string() + ".hsgr"; const std::string rtree_nodes_path = input_path.string() + ".ramIndex"; const std::string rtree_leafs_path = input_path.string() + ".fileIndex"; /*** Setup Scripting Environment ***/ // Create a new lua state lua_State *lua_state = luaL_newstate(); // Connect LuaBind to this lua state luabind::open(lua_state); // open utility libraries string library; luaL_openlibs(lua_state); // adjust lua load path luaAddScriptFolderToLoadPath(lua_state, profile_path.string().c_str()); // Now call our function in a lua script if (0 != luaL_dofile(lua_state, profile_path.string().c_str())) { std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl; return 1; } EdgeBasedGraphFactory::SpeedProfileProperties speed_profile; if (0 != luaL_dostring(lua_state, "return traffic_signal_penalty\n")) { std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl; return 1; } speed_profile.trafficSignalPenalty = 10 * lua_tointeger(lua_state, -1); SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: " << speed_profile.trafficSignalPenalty; if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n")) { std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl; return 1; } speed_profile.uTurnPenalty = 10 * lua_tointeger(lua_state, -1); speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function"); #ifdef WIN32 #pragma message ("Memory consumption on Windows can be higher due to memory alignment") #else static_assert(sizeof(ImportEdge) == 20, "changing ImportEdge type has influence on memory consumption!"); #endif std::vector<ImportEdge> edge_list; NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream(in, edge_list, barrier_node_list, traffic_light_list, &internal_to_external_node_map, restriction_list, use_elevation); in.close(); if (edge_list.empty()) { SimpleLogger().Write(logWARNING) << "The input data is empty, exiting."; return 1; } SimpleLogger().Write() << restriction_list.size() << " restrictions, " << barrier_node_list.size() << " bollard nodes, " << traffic_light_list.size() << " traffic lights"; /*** * Building an edge-expanded graph from node-based input and turn restrictions */ SimpleLogger().Write() << "Generating edge-expanded graph representation"; std::shared_ptr<NodeBasedDynamicGraph> node_based_graph = NodeBasedDynamicGraphFromImportEdges(number_of_node_based_nodes, edge_list); std::unique_ptr<RestrictionMap> restriction_map = std::unique_ptr<RestrictionMap>(new RestrictionMap(node_based_graph, restriction_list)); EdgeBasedGraphFactory *edge_based_graph_factor = new EdgeBasedGraphFactory(node_based_graph, std::move(restriction_map), barrier_node_list, traffic_light_list, internal_to_external_node_map, speed_profile); edge_list.clear(); edge_list.shrink_to_fit(); edge_based_graph_factor->Run(edge_out, geometry_filename, lua_state); restriction_list.clear(); restriction_list.shrink_to_fit(); barrier_node_list.clear(); barrier_node_list.shrink_to_fit(); traffic_light_list.clear(); traffic_light_list.shrink_to_fit(); unsigned number_of_edge_based_nodes = edge_based_graph_factor->GetNumberOfEdgeBasedNodes(); BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max()); DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList; #ifndef WIN32 static_assert(sizeof(EdgeBasedEdge) == 16, "changing ImportEdge type has influence on memory consumption!"); #endif edge_based_graph_factor->GetEdgeBasedEdges(edgeBasedEdgeList); std::vector<EdgeBasedNode> node_based_edge_list; edge_based_graph_factor->GetEdgeBasedNodes(node_based_edge_list); delete edge_based_graph_factor; // TODO actually use scoping: Split this up in subfunctions node_based_graph.reset(); TIMER_STOP(expansion); // Building grid-like nearest-neighbor data structure SimpleLogger().Write() << "building r-tree ..."; StaticRTree<EdgeBasedNode> *rtree = new StaticRTree<EdgeBasedNode>(node_based_edge_list, rtree_nodes_path.c_str(), rtree_leafs_path.c_str(), internal_to_external_node_map); delete rtree; IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32; unsigned node_based_edge_list_CRC32 = crc32(node_based_edge_list.begin(), node_based_edge_list.end()); node_based_edge_list.clear(); node_based_edge_list.shrink_to_fit(); SimpleLogger().Write() << "CRC32: " << node_based_edge_list_CRC32; /*** * Writing info on original (node-based) nodes */ SimpleLogger().Write() << "writing node map ..."; boost::filesystem::ofstream node_stream(node_filename, std::ios::binary); const unsigned size_of_mapping = internal_to_external_node_map.size(); node_stream.write((char *)&size_of_mapping, sizeof(unsigned)); if (size_of_mapping > 0) { node_stream.write((char *)&(internal_to_external_node_map[0]), size_of_mapping * sizeof(NodeInfo)); } node_stream.close(); internal_to_external_node_map.clear(); internal_to_external_node_map.shrink_to_fit(); /*** * Contracting the edge-expanded graph */ SimpleLogger().Write() << "initializing contractor"; Contractor *contractor = new Contractor(number_of_edge_based_nodes, edgeBasedEdgeList); TIMER_START(contraction); contractor->Run(); TIMER_STOP(contraction); SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec"; DeallocatingVector<QueryEdge> contracted_edge_list; contractor->GetEdges(contracted_edge_list); delete contractor; /*** * Sorting contracted edges in a way that the static query graph can read some in in-place. */ std::sort(contracted_edge_list.begin(), contracted_edge_list.end()); unsigned max_used_node_id = 0; unsigned contracted_edge_count = contracted_edge_list.size(); SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count << " edges"; boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary); hsgr_output_stream.write((char *)&fingerprint_orig, sizeof(FingerPrint)); for (const QueryEdge &edge : contracted_edge_list) { BOOST_ASSERT(UINT_MAX != edge.source); BOOST_ASSERT(UINT_MAX != edge.target); max_used_node_id = std::max(max_used_node_id, edge.source); max_used_node_id = std::max(max_used_node_id, edge.target); } SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes << " nodes"; SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; max_used_node_id += 1; std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array; node_array.resize(number_of_edge_based_nodes + 1); SimpleLogger().Write() << "Building node array"; StaticGraph<EdgeData>::EdgeIterator edge = 0; StaticGraph<EdgeData>::EdgeIterator position = 0; StaticGraph<EdgeData>::EdgeIterator last_edge = edge; for (StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node) { last_edge = edge; while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node)) { ++edge; } node_array[node].first_edge = position; //=edge position += edge - last_edge; // remove } for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size(); ++sentinel_counter) { // sentinel element, guarded against underflow node_array[sentinel_counter].first_edge = contracted_edge_count; } unsigned node_array_size = node_array.size(); // serialize crc32, aka checksum hsgr_output_stream.write((char *)&node_based_edge_list_CRC32, sizeof(unsigned)); // serialize number of nodes hsgr_output_stream.write((char *)&node_array_size, sizeof(unsigned)); // serialize number of edges hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned)); // serialize all nodes if (node_array_size > 0) { hsgr_output_stream.write((char *)&node_array[0], sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size); } // serialize all edges SimpleLogger().Write() << "Building edge array"; edge = 0; int number_of_used_edges = 0; StaticGraph<EdgeData>::EdgeArrayEntry current_edge; for (unsigned edge = 0; edge < contracted_edge_list.size(); ++edge) { // no eigen loops BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target); current_edge.target = contracted_edge_list[edge].target; current_edge.data = contracted_edge_list[edge].data; // every target needs to be valid BOOST_ASSERT(current_edge.target < max_used_node_id); #ifndef NDEBUG if (current_edge.data.distance <= 0) { SimpleLogger().Write(logWARNING) << "Edge: " << edge << ",source: " << contracted_edge_list[edge].source << ", target: " << contracted_edge_list[edge].target << ", dist: " << current_edge.data.distance; SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node " << contracted_edge_list[edge].source << "/" << node_array.size() - 1; return 1; } #endif hsgr_output_stream.write((char *)¤t_edge, sizeof(StaticGraph<EdgeData>::EdgeArrayEntry)); ++number_of_used_edges; } hsgr_output_stream.close(); TIMER_STOP(preparing); SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds"; SimpleLogger().Write() << "Expansion : " << (number_of_node_based_nodes / TIMER_SEC(expansion)) << " nodes/sec and " << (number_of_edge_based_nodes / TIMER_SEC(expansion)) << " edges/sec"; SimpleLogger().Write() << "Contraction: " << (number_of_edge_based_nodes / TIMER_SEC(contraction)) << " nodes/sec and " << number_of_used_edges / TIMER_SEC(contraction) << " edges/sec"; node_array.clear(); SimpleLogger().Write() << "finished preprocessing"; } catch (boost::program_options::too_many_positional_options_error &) { SimpleLogger().Write(logWARNING) << "Only one file can be specified"; return 1; } catch (boost::program_options::error &e) { SimpleLogger().Write(logWARNING) << e.what(); return 1; } catch (const std::exception &e) { SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl; return 1; } return 0; }
int main (int argc, char *argv[]) { if(argc < 3) { ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>"); } double startupTime = get_timestamp(); unsigned numberOfThreads = omp_get_num_procs(); std::string SRTM_ROOT; if(testDataFile("contractor.ini")) { ContractorConfiguration contractorConfig("contractor.ini"); if(atoi(contractorConfig.GetParameter("Threads").c_str()) != 0 && (unsigned)atoi(contractorConfig.GetParameter("Threads").c_str()) <= numberOfThreads) numberOfThreads = (unsigned)atoi( contractorConfig.GetParameter("Threads").c_str() ); if(0 < contractorConfig.GetParameter("SRTM").size() ) SRTM_ROOT = contractorConfig.GetParameter("SRTM"); } if(0 != SRTM_ROOT.size()) INFO("Loading SRTM from/to " << SRTM_ROOT); omp_set_num_threads(numberOfThreads); INFO("preprocessing data from input file " << argv[2] << " using STL " #ifdef _GLIBCXX_PARALLEL "parallel (GCC)" #else "serial" #endif " mode"); INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], ios::binary); _Restriction restriction; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); for(unsigned i = 0; i < usableRestrictionsCounter; ++i) { restrictionsInstream.read((char *)&(restriction), sizeof(_Restriction)); inputRestrictions.push_back(restriction); } restrictionsInstream.close(); ifstream in; in.open (argv[1], ifstream::in | ifstream::binary); if (!in.is_open()) { ERR("Cannot open " << argv[1]); } char nodeOut[1024]; strcpy(nodeOut, argv[1]); strcat(nodeOut, ".nodes"); char edgeOut[1024]; strcpy(edgeOut, argv[1]); strcat(edgeOut, ".hsgr"); char ramIndexOut[1024]; strcpy(ramIndexOut, argv[1]); strcat(ramIndexOut, ".ramIndex"); char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex"); char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); std::vector<ImportEdge> edgeList; NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternaleNodeMapping, inputRestrictions); in.close(); INFO("Loaded " << inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternaleNodeMapping, SRTM_ROOT); edgeList.clear(); std::vector<ImportEdge>().swap(edgeList); edgeBasedGraphFactory->Run(); NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); std::vector<EdgeBasedEdge> edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); std::vector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); DELETE(edgeBasedGraphFactory); double expansionHasFinishedTime = get_timestamp() - startupTime; WritableGrid * writeableGrid = new WritableGrid(); INFO("building grid ..."); writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut); DELETE( writeableGrid ); CRC32 crc32; unsigned crc32OfNodeBasedEdgeList = crc32((char *)&(nodeBasedEdgeList[0]), nodeBasedEdgeList.size()*sizeof(EdgeBasedGraphFactory::EdgeBasedNode)); // INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); nodeBasedEdgeList.clear(); std::vector<EdgeBasedGraphFactory::EdgeBasedNode>().swap(nodeBasedEdgeList); INFO("writing node map ..."); std::ofstream mapOutFile(nodeOut, ios::binary); mapOutFile.write((char *)&(internalToExternaleNodeMapping[0]), internalToExternaleNodeMapping.size()*sizeof(NodeInfo)); mapOutFile.close(); std::vector<NodeInfo>().swap(internalToExternaleNodeMapping); inputRestrictions.clear(); std::vector<_Restriction>().swap(inputRestrictions); // unsigned crc32OfNodeBasedEdgeList = crc32((char*)&edgeBasedEdgeList[0], edgeBasedEdgeList.size()); // INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); INFO("initializing contractor"); Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec"); std::vector< ContractionCleanup::Edge > contractedEdges; contractor->GetEdges( contractedEdges ); delete contractor; ContractionCleanup * cleanup = new ContractionCleanup(edgeBasedNodeNumber, contractedEdges); contractedEdges.clear(); std::vector<ContractionCleanup::Edge>().swap(contractedEdges); cleanup->Run(); std::vector< InputEdge> cleanedEdgeList; cleanup->GetData(cleanedEdgeList); DELETE( cleanup ); INFO("Building Node Array"); sort(cleanedEdgeList.begin(), cleanedEdgeList.end()); unsigned numberOfNodes = 0; unsigned numberOfEdges = cleanedEdgeList.size(); INFO("Serializing compacted graph"); ofstream edgeOutFile(edgeOut, ios::binary); BOOST_FOREACH(InputEdge & edge, cleanedEdgeList) { if(edge.source > numberOfNodes) { numberOfNodes = edge.source; } if(edge.target > numberOfNodes) { numberOfNodes = edge.target; } } numberOfNodes+=1; std::vector< StaticGraph<EdgeData>::_StrNode > _nodes; _nodes.resize( numberOfNodes + 1 ); StaticGraph<EdgeData>::EdgeIterator edge = 0; StaticGraph<EdgeData>::EdgeIterator position = 0; for ( StaticGraph<EdgeData>::NodeIterator node = 0; node <= numberOfNodes; ++node ) { StaticGraph<EdgeData>::EdgeIterator lastEdge = edge; while ( edge < numberOfEdges && cleanedEdgeList[edge].source == node ) ++edge; _nodes[node].firstEdge = position; //=edge position += edge - lastEdge; //remove } //Serialize numberOfNodes, nodes edgeOutFile.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned)); edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph<EdgeData>::_StrNode)*(numberOfNodes+1)); //Serialize number of Edges edgeOutFile.write((char*) &position, sizeof(unsigned)); edge = 0; int usedEdgeCounter = 0; StaticGraph<EdgeData>::_StrEdge currentEdge; for ( StaticGraph<EdgeData>::NodeIterator node = 0; node < numberOfNodes; ++node ) { for ( StaticGraph<EdgeData>::EdgeIterator i = _nodes[node].firstEdge, e = _nodes[node+1].firstEdge; i != e; ++i ) { currentEdge.target = cleanedEdgeList[edge].target; currentEdge.data = cleanedEdgeList[edge].data; if(currentEdge.data.distance <= 0) { INFO("Edge: " << i << ",source: " << cleanedEdgeList[edge].source << ", target: " << cleanedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); ERR("Failed at edges of node " << node << " of " << numberOfNodes); } //Serialize edges edgeOutFile.write((char*) ¤tEdge, sizeof(StaticGraph<EdgeData>::_StrEdge)); ++edge; ++usedEdgeCounter; } } double endTime = (get_timestamp() - startupTime); INFO("Expansion : " << (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"); INFO("Contraction: " << (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< usedEdgeCounter/endTime << " edges/sec"); edgeOutFile.close(); cleanedEdgeList.clear(); _nodes.clear(); INFO("finished preprocessing"); return 0; }
void CsvContractorExporterDialogController::fillTable() { contractors = service->getContractors(); QTableWidget *tableWidget = view->getTableWidget(); Contractor contractor; tableWidget->setRowCount(contractors.size()); for(int row = 0; row < contractors.size(); row++) { contractor = contractors[row]; tableWidget->setItem(row, 0, new QTableWidgetItem(contractor.getSymbol())); tableWidget->setItem(row, 1, new QTableWidgetItem(contractor.getName())); tableWidget->setItem(row, 2, new QTableWidgetItem(contractor.getContractorGroup().getName())); tableWidget->setItem(row, 3, new QTableWidgetItem(contractor.getPostcode())); tableWidget->setItem(row, 4, new QTableWidgetItem(contractor.getCity())); tableWidget->setItem(row, 5, new QTableWidgetItem(contractor.getAddress())); tableWidget->setItem(row, 6, new QTableWidgetItem(contractor.getDefultPhone())); tableWidget->setItem(row, 7, new QTableWidgetItem(contractor.getNip())); tableWidget->setItem(row, 8, new QTableWidgetItem(contractor.getEmail())); tableWidget->setItem(row, 9, new QTableWidgetItem(contractor.getWebsite())); tableWidget->setItem(row, 10, new QTableWidgetItem(contractor.getDiscount())); } }
int main (int argc, char *argv[]) { if(argc <= 1) { cerr << "usage: " << endl << argv[0] << " <osrm-data>" << endl; exit(-1); } unsigned numberOfThreads = omp_get_num_procs(); if(testDataFile("contractor.ini")) { ContractorConfiguration contractorConfig("contractor.ini"); if(atoi(contractorConfig.GetParameter("Threads").c_str()) != 0 && (unsigned)atoi(contractorConfig.GetParameter("Threads").c_str()) <= numberOfThreads) numberOfThreads = (unsigned)atoi( contractorConfig.GetParameter("Threads").c_str() ); } omp_set_num_threads(numberOfThreads); cout << "preprocessing data from input file " << argv[1]; #ifdef _GLIBCXX_PARALLEL cout << " using STL parallel mode" << std::endl; #else cout << " using STL serial mode" << std::endl; #endif ifstream in; in.open (argv[1]); if (!in.is_open()) { cerr << "Cannot open " << argv[1] << endl; exit(-1); } vector<ImportEdge> edgeList; const NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, int2ExtNodeMap); in.close(); char nodeOut[1024]; char edgeOut[1024]; char ramIndexOut[1024]; char fileIndexOut[1024]; char levelInfoOut[1024]; strcpy(nodeOut, argv[1]); strcpy(edgeOut, argv[1]); strcpy(ramIndexOut, argv[1]); strcpy(fileIndexOut, argv[1]); strcpy(levelInfoOut, argv[1]); strcat(nodeOut, ".nodes"); strcat(edgeOut, ".hsgr"); strcat(ramIndexOut, ".ramIndex"); strcat(fileIndexOut, ".fileIndex"); strcat(levelInfoOut, ".levels"); cout << "initializing contractor ..." << flush; Contractor* contractor = new Contractor( n, edgeList ); contractor->Run(); LevelInformation * levelInfo = contractor->GetLevelInformation(); std::cout << "sorting level info" << std::endl; for(unsigned currentLevel = levelInfo->GetNumberOfLevels(); currentLevel>0; currentLevel--) { std::vector<unsigned> & level = levelInfo->GetLevel(currentLevel-1); std::sort(level.begin(), level.end()); } std::cout << "writing level info" << std::endl; ofstream levelOutFile(levelInfoOut, ios::binary); unsigned numberOfLevels = levelInfo->GetNumberOfLevels(); levelOutFile.write((char *)&numberOfLevels, sizeof(unsigned)); for(unsigned currentLevel = 0; currentLevel < levelInfo->GetNumberOfLevels(); currentLevel++ ) { std::vector<unsigned> & level = levelInfo->GetLevel(currentLevel); unsigned sizeOfLevel = level.size(); levelOutFile.write((char *)&sizeOfLevel, sizeof(unsigned)); for(unsigned currentLevelEntry = 0; currentLevelEntry < sizeOfLevel; currentLevelEntry++) { unsigned node = level[currentLevelEntry]; levelOutFile.write((char *)&node, sizeof(unsigned)); assert(node < n); } } levelOutFile.close(); std::vector< ContractionCleanup::Edge > contractedEdges; contractor->GetEdges( contractedEdges ); delete contractor; ContractionCleanup * cleanup = new ContractionCleanup(n, contractedEdges); contractedEdges.clear(); cleanup->Run(); std::vector< InputEdge> cleanedEdgeList; cleanup->GetData(cleanedEdgeList); delete cleanup; cout << "Serializing edges " << flush; ofstream edgeOutFile(edgeOut, ios::binary); Percent p(cleanedEdgeList.size()); for(std::vector< InputEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) { p.printIncrement(); int distance= it->data.distance; assert(distance > 0); bool shortcut= it->data.shortcut; bool forward= it->data.forward; bool backward= it->data.backward; NodeID middle; if(shortcut) middle = it->data.middleName.middle; else { middle = it->data.middleName.nameID; } NodeID source = it->source; NodeID target = it->target; short type = it->data.type; edgeOutFile.write((char *)&(distance), sizeof(int)); edgeOutFile.write((char *)&(shortcut), sizeof(bool)); edgeOutFile.write((char *)&(forward), sizeof(bool)); edgeOutFile.write((char *)&(backward), sizeof(bool)); edgeOutFile.write((char *)&(middle), sizeof(NodeID)); edgeOutFile.write((char *)&(type), sizeof(short)); edgeOutFile.write((char *)&(source), sizeof(NodeID)); edgeOutFile.write((char *)&(target), sizeof(NodeID)); } edgeOutFile.close(); cleanedEdgeList.clear(); std::cout << "writing node map ..." << std::flush; ofstream mapOutFile(nodeOut, ios::binary); for(NodeID i = 0; i < int2ExtNodeMap->size(); i++) { mapOutFile.write((char *)&(int2ExtNodeMap->at(i)), sizeof(NodeInfo)); } mapOutFile.close(); std::cout << "ok" << std::endl; WritableGrid * writeableGrid = new WritableGrid(); cout << "building grid ..." << flush; writeableGrid->ConstructGrid(edgeList, int2ExtNodeMap, ramIndexOut, fileIndexOut); delete writeableGrid; int2ExtNodeMap->clear(); delete int2ExtNodeMap; cout << "finished" << endl; return 0; }
void DocumentView::setContractorData(Contractor contractor) { this->contractorData->setText(contractor.getContractorData()); if(!contractor.getAdditionalId().getValue().isEmpty() && controller->getSymbol()=="RR") contractorData->append(contractor.getAdditionalId().getType().getName()+":"+ contractor.getAdditionalId().getValue()); }
int main (int argc, char *argv[]) { if(argc < 3) { ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>"); } double startupTime = get_timestamp(); unsigned numberOfThreads = omp_get_num_procs(); std::string SRTM_ROOT; if(testDataFile("contractor.ini")) { ContractorConfiguration contractorConfig("contractor.ini"); if(atoi(contractorConfig.GetParameter("Threads").c_str()) != 0 && (unsigned)atoi(contractorConfig.GetParameter("Threads").c_str()) <= numberOfThreads) numberOfThreads = (unsigned)atoi( contractorConfig.GetParameter("Threads").c_str() ); if(0 < contractorConfig.GetParameter("SRTM").size() ) SRTM_ROOT = contractorConfig.GetParameter("SRTM"); } if(0 != SRTM_ROOT.size()) INFO("Loading SRTM from/to " << SRTM_ROOT); omp_set_num_threads(numberOfThreads); INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], ios::binary); if(!restrictionsInstream.good()) { ERR("Could not access <osrm-restrictions> files"); } _Restriction restriction; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); inputRestrictions.resize(usableRestrictionsCounter); restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction)); restrictionsInstream.close(); std::ifstream in; in.open (argv[1], std::ifstream::in | std::ifstream::binary); if (!in.is_open()) { ERR("Cannot open " << argv[1]); } char nodeOut[1024]; strcpy(nodeOut, argv[1]); strcat(nodeOut, ".nodes"); char edgeOut[1024]; strcpy(edgeOut, argv[1]); strcat(edgeOut, ".edges"); char graphOut[1024]; strcpy(graphOut, argv[1]); strcat(graphOut, ".hsgr"); char ramIndexOut[1024]; strcpy(ramIndexOut, argv[1]); strcat(ramIndexOut, ".ramIndex"); char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex"); char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); std::vector<ImportEdge> edgeList; NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions); in.close(); INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); if(!testDataFile("profile.lua")) { ERR("Need profile.lua to apply traffic signal penalty"); } /*** Setup Scripting Environment ***/ // Create a new lua state lua_State *myLuaState = luaL_newstate(); // Connect LuaBind to this lua state luabind::open(myLuaState); // Now call our function in a lua script if(0 != luaL_dofile(myLuaState, "profile.lua")) { ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); } EdgeBasedGraphFactory::SpeedProfileProperties speedProfile; if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) { ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); } speedProfile.trafficSignalPenalty = lua_tointeger(myLuaState, -1); if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); } speedProfile.uTurnPenalty = lua_tointeger(myLuaState, -1); /*** * Building an edge-expanded graph from node-based input an turn restrictions */ INFO("Generating edge-expanded graph representation"); EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); std::vector<ImportEdge>().swap(edgeList); edgeBasedGraphFactory->Run(edgeOut); std::vector<_Restriction>().swap(inputRestrictions); std::vector<NodeID>().swap(bollardNodes); std::vector<NodeID>().swap(trafficLightNodes); NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); if(0 == edgeBasedEdgeList.size()) ERR("The input data is broken. It is impossible to do any turns in this graph"); /*** * Writing info on original (node-based) nodes */ INFO("writing node map ..."); std::ofstream mapOutFile(nodeOut, std::ios::binary); mapOutFile.write((char *)&(internalToExternalNodeMapping[0]), internalToExternalNodeMapping.size()*sizeof(NodeInfo)); mapOutFile.close(); std::vector<NodeInfo>().swap(internalToExternalNodeMapping); /*** * Writing info on original (node-based) edges */ INFO("writing info on original edges"); std::vector<OriginalEdgeData> originalEdgeData; edgeBasedGraphFactory->GetOriginalEdgeData(originalEdgeData); // std::ofstream oedOutFile(edgeOut, std::ios::binary); // unsigned numberOfOrigEdges = originalEdgeData.size(); // oedOutFile.write((char*)&numberOfOrigEdges, sizeof(unsigned)); // oedOutFile.write((char*)&(originalEdgeData[0]), originalEdgeData.size()*sizeof(OriginalEdgeData)); // oedOutFile.close(); // std::vector<OriginalEdgeData>().swap(originalEdgeData); DeallocatingVector<EdgeBasedGraphFactory::EdgeBasedNode> nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); delete edgeBasedGraphFactory; double expansionHasFinishedTime = get_timestamp() - startupTime; /*** * Building grid-like nearest-neighbor data structure */ INFO("building grid ..."); WritableGrid * writeableGrid = new WritableGrid(); writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut); delete writeableGrid; IteratorbasedCRC32<DeallocatingVector<EdgeBasedGraphFactory::EdgeBasedNode> > crc32; unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); nodeBasedEdgeList.clear(); INFO("CRC32 based checksum is " << crc32OfNodeBasedEdgeList); /*** * Contracting the edge-expanded graph */ INFO("initializing contractor"); Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec"); DeallocatingVector< QueryEdge > contractedEdgeList; contractor->GetEdges( contractedEdgeList ); delete contractor; /*** * Sorting contracted edges in a way that the static query graph can read some in in-place. */ INFO("Building Node Array"); sort(contractedEdgeList.begin(), contractedEdgeList.end()); unsigned numberOfNodes = 0; unsigned numberOfEdges = contractedEdgeList.size(); INFO("Serializing compacted graph"); ofstream edgeOutFile(graphOut, ios::binary); BOOST_FOREACH(QueryEdge & edge, contractedEdgeList) { if(edge.source > numberOfNodes) { numberOfNodes = edge.source; } if(edge.target > numberOfNodes) { numberOfNodes = edge.target; } } numberOfNodes+=1; std::vector< StaticGraph<EdgeData>::_StrNode > _nodes; _nodes.resize( numberOfNodes + 1 ); StaticGraph<EdgeData>::EdgeIterator edge = 0; StaticGraph<EdgeData>::EdgeIterator position = 0; for ( StaticGraph<EdgeData>::NodeIterator node = 0; node <= numberOfNodes; ++node ) { StaticGraph<EdgeData>::EdgeIterator lastEdge = edge; while ( edge < numberOfEdges && contractedEdgeList[edge].source == node ) ++edge; _nodes[node].firstEdge = position; //=edge position += edge - lastEdge; //remove } ++numberOfNodes; //Serialize numberOfNodes, nodes edgeOutFile.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned)); edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph<EdgeData>::_StrNode)*(numberOfNodes)); //Serialize number of Edges edgeOutFile.write((char*) &position, sizeof(unsigned)); --numberOfNodes; edge = 0; int usedEdgeCounter = 0; StaticGraph<EdgeData>::_StrEdge currentEdge; for ( StaticGraph<EdgeData>::NodeIterator node = 0; node < numberOfNodes; ++node ) { for ( StaticGraph<EdgeData>::EdgeIterator i = _nodes[node].firstEdge, e = _nodes[node+1].firstEdge; i != e; ++i ) { assert(node != contractedEdgeList[edge].target); currentEdge.target = contractedEdgeList[edge].target; currentEdge.data = contractedEdgeList[edge].data; if(currentEdge.data.distance <= 0) { INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); ERR("Failed at edges of node " << node << " of " << numberOfNodes); } //Serialize edges edgeOutFile.write((char*) ¤tEdge, sizeof(StaticGraph<EdgeData>::_StrEdge)); ++edge; ++usedEdgeCounter; } } double endTime = (get_timestamp() - startupTime); INFO("Expansion : " << (nodeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< (edgeBasedNodeNumber/expansionHasFinishedTime) << " edges/sec"); INFO("Contraction: " << (edgeBasedNodeNumber/expansionHasFinishedTime) << " nodes/sec and "<< usedEdgeCounter/endTime << " edges/sec"); edgeOutFile.close(); //cleanedEdgeList.clear(); _nodes.clear(); INFO("finished preprocessing"); return 0; }
int Prepare::Process(int argc, char *argv[]) { LogPolicy::GetInstance().Unmute(); TIMER_START(preparing); TIMER_START(expansion); if (!ParseArguments(argc, argv)) { return 0; } if (!boost::filesystem::is_regular_file(input_path)) { SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!"; return 1; } if (!boost::filesystem::is_regular_file(profile_path)) { SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!"; return 1; } if (1 > requested_num_threads) { SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger"; return 1; } const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads(); SimpleLogger().Write() << "Input file: " << input_path.filename().string(); SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string(); SimpleLogger().Write() << "Profile: " << profile_path.filename().string(); SimpleLogger().Write() << "Threads: " << requested_num_threads; if (recommended_num_threads != requested_num_threads) { SimpleLogger().Write(logWARNING) << "The recommended number of threads is " << recommended_num_threads << "! This setting may have performance side-effects."; } tbb::task_scheduler_init init(requested_num_threads); LogPolicy::GetInstance().Unmute(); FingerPrint fingerprint_orig; CheckRestrictionsFile(fingerprint_orig); boost::filesystem::ifstream input_stream(input_path, std::ios::in | std::ios::binary); node_filename = input_path.string() + ".nodes"; edge_out = input_path.string() + ".edges"; geometry_filename = input_path.string() + ".geometry"; graph_out = input_path.string() + ".hsgr"; rtree_nodes_path = input_path.string() + ".ramIndex"; rtree_leafs_path = input_path.string() + ".fileIndex"; /*** Setup Scripting Environment ***/ // Create a new lua state lua_State *lua_state = luaL_newstate(); // Connect LuaBind to this lua state luabind::open(lua_state); EdgeBasedGraphFactory::SpeedProfileProperties speed_profile; if (!SetupScriptingEnvironment(lua_state, speed_profile)) { return 1; } #ifdef WIN32 #pragma message("Memory consumption on Windows can be higher due to different bit packing") #else static_assert(sizeof(ImportEdge) == 20, "changing ImportEdge type has influence on memory consumption!"); #endif NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream(input_stream, edge_list, barrier_node_list, traffic_light_list, &internal_to_external_node_map, restriction_list); input_stream.close(); if (edge_list.empty()) { SimpleLogger().Write(logWARNING) << "The input data is empty, exiting."; return 1; } SimpleLogger().Write() << restriction_list.size() << " restrictions, " << barrier_node_list.size() << " bollard nodes, " << traffic_light_list.size() << " traffic lights"; std::vector<EdgeBasedNode> node_based_edge_list; unsigned number_of_edge_based_nodes = 0; DeallocatingVector<EdgeBasedEdge> edge_based_edge_list; // init node_based_edge_list, edge_based_edge_list by edgeList number_of_edge_based_nodes = BuildEdgeExpandedGraph(lua_state, number_of_node_based_nodes, node_based_edge_list, edge_based_edge_list, speed_profile); lua_close(lua_state); TIMER_STOP(expansion); BuildRTree(node_based_edge_list); IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32; const unsigned node_based_edge_list_CRC32 = crc32(node_based_edge_list.begin(), node_based_edge_list.end()); node_based_edge_list.clear(); node_based_edge_list.shrink_to_fit(); SimpleLogger().Write() << "CRC32: " << node_based_edge_list_CRC32; WriteNodeMapping(); /*** * Contracting the edge-expanded graph */ SimpleLogger().Write() << "initializing contractor"; Contractor *contractor = new Contractor(number_of_edge_based_nodes, edge_based_edge_list); TIMER_START(contraction); contractor->Run(); TIMER_STOP(contraction); SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec"; DeallocatingVector<QueryEdge> contracted_edge_list; contractor->GetEdges(contracted_edge_list); delete contractor; /*** * Sorting contracted edges in a way that the static query graph can read some in in-place. */ tbb::parallel_sort(contracted_edge_list.begin(), contracted_edge_list.end()); const unsigned contracted_edge_count = contracted_edge_list.size(); SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count << " edges"; boost::filesystem::ofstream hsgr_output_stream(graph_out, std::ios::binary); hsgr_output_stream.write((char *)&fingerprint_orig, sizeof(FingerPrint)); const unsigned max_used_node_id = 1 + [&contracted_edge_list] { unsigned tmp_max = 0; for (const QueryEdge &edge : contracted_edge_list) { BOOST_ASSERT(SPECIAL_NODEID != edge.source); BOOST_ASSERT(SPECIAL_NODEID != edge.target); tmp_max = std::max(tmp_max, edge.source); tmp_max = std::max(tmp_max, edge.target); } return tmp_max; }(); SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes << " nodes"; SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array; node_array.resize(number_of_edge_based_nodes + 1); SimpleLogger().Write() << "Building node array"; StaticGraph<EdgeData>::EdgeIterator edge = 0; StaticGraph<EdgeData>::EdgeIterator position = 0; StaticGraph<EdgeData>::EdgeIterator last_edge = edge; // initializing 'first_edge'-field of nodes: for (const auto node : osrm::irange(0u, max_used_node_id)) { last_edge = edge; while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node)) { ++edge; } node_array[node].first_edge = position; //=edge position += edge - last_edge; // remove } for (const auto sentinel_counter : osrm::irange<unsigned>(max_used_node_id, node_array.size())) { // sentinel element, guarded against underflow node_array[sentinel_counter].first_edge = contracted_edge_count; } SimpleLogger().Write() << "Serializing node array"; const unsigned node_array_size = node_array.size(); // serialize crc32, aka checksum hsgr_output_stream.write((char *)&node_based_edge_list_CRC32, sizeof(unsigned)); // serialize number of nodes hsgr_output_stream.write((char *)&node_array_size, sizeof(unsigned)); // serialize number of edges hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned)); // serialize all nodes if (node_array_size > 0) { hsgr_output_stream.write((char *)&node_array[0], sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size); } // serialize all edges SimpleLogger().Write() << "Building edge array"; edge = 0; int number_of_used_edges = 0; StaticGraph<EdgeData>::EdgeArrayEntry current_edge; for (const auto edge : osrm::irange<std::size_t>(0, contracted_edge_list.size())) { // no eigen loops BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target); current_edge.target = contracted_edge_list[edge].target; current_edge.data = contracted_edge_list[edge].data; // every target needs to be valid BOOST_ASSERT(current_edge.target < max_used_node_id); #ifndef NDEBUG if (current_edge.data.distance <= 0) { SimpleLogger().Write(logWARNING) << "Edge: " << edge << ",source: " << contracted_edge_list[edge].source << ", target: " << contracted_edge_list[edge].target << ", dist: " << current_edge.data.distance; SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node " << contracted_edge_list[edge].source << "/" << node_array.size() - 1; return 1; } #endif hsgr_output_stream.write((char *)¤t_edge, sizeof(StaticGraph<EdgeData>::EdgeArrayEntry)); ++number_of_used_edges; } hsgr_output_stream.close(); TIMER_STOP(preparing); SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds"; SimpleLogger().Write() << "Expansion : " << (number_of_node_based_nodes / TIMER_SEC(expansion)) << " nodes/sec and " << (number_of_edge_based_nodes / TIMER_SEC(expansion)) << " edges/sec"; SimpleLogger().Write() << "Contraction: " << (number_of_edge_based_nodes / TIMER_SEC(contraction)) << " nodes/sec and " << number_of_used_edges / TIMER_SEC(contraction) << " edges/sec"; node_array.clear(); SimpleLogger().Write() << "finished preprocessing"; return 0; }
bool ContractionHierarchies::Preprocess( IImporter* importer, QString dir ) { QString filename = fileInDirectory( dir, "Contraction Hierarchies" ); std::vector< IImporter::RoutingNode > inputNodes; std::vector< IImporter::RoutingEdge > inputEdges; if ( !importer->GetRoutingNodes( &inputNodes ) ) return false; if ( !importer->GetRoutingEdges( &inputEdges ) ) return false; unsigned numEdges = inputEdges.size(); unsigned numNodes = inputNodes.size(); Contractor* contractor = new Contractor( numNodes, inputEdges ); std::vector< IImporter::RoutingEdge >().swap( inputEdges ); contractor->Run(); std::vector< Contractor::Witness > witnessList; contractor->GetWitnessList( witnessList ); std::vector< ContractionCleanup::Edge > contractedEdges; std::vector< ContractionCleanup::Edge > contractedLoops; contractor->GetEdges( &contractedEdges ); contractor->GetLoops( &contractedLoops ); delete contractor; ContractionCleanup* cleanup = new ContractionCleanup( inputNodes.size(), contractedEdges, contractedLoops, witnessList ); std::vector< ContractionCleanup::Edge >().swap( contractedEdges ); std::vector< ContractionCleanup::Edge >().swap( contractedLoops ); std::vector< Contractor::Witness >().swap( witnessList ); cleanup->Run(); std::vector< CompressedGraph::Edge > edges; std::vector< NodeID > map; cleanup->GetData( &edges, &map ); delete cleanup; { std::vector< unsigned > edgeIDs( numEdges ); for ( unsigned edge = 0; edge < edges.size(); edge++ ) { if ( edges[edge].data.shortcut ) continue; unsigned id = 0; unsigned otherEdge = edge; while ( true ) { if ( otherEdge == 0 ) break; otherEdge--; if ( edges[otherEdge].source != edges[edge].source ) break; if ( edges[otherEdge].target != edges[edge].target ) continue; if ( edges[otherEdge].data.shortcut ) continue; id++; } edgeIDs[edges[edge].data.id] = id; } importer->SetEdgeIDMap( edgeIDs ); } std::vector< IRouter::Node > nodes( numNodes ); for ( std::vector< IImporter::RoutingNode >::const_iterator i = inputNodes.begin(), iend = inputNodes.end(); i != iend; i++ ) nodes[map[i - inputNodes.begin()]].coordinate = i->coordinate; std::vector< IImporter::RoutingNode >().swap( inputNodes ); std::vector< IRouter::Node > pathNodes; { std::vector< IImporter::RoutingNode > edgePaths; if ( !importer->GetRoutingEdgePaths( &edgePaths ) ) return false; pathNodes.resize( edgePaths.size() ); for ( unsigned i = 0; i < edgePaths.size(); i++ ) pathNodes[i].coordinate = edgePaths[i].coordinate; } if ( !importer->GetRoutingEdges( &inputEdges ) ) return false; { std::vector< QString > inputNames; if ( !importer->GetRoutingWayNames( &inputNames ) ) return false; QFile nameFile( filename + "_names" ); if ( !openQFile( &nameFile, QIODevice::WriteOnly ) ) return false; std::vector< unsigned > nameMap( inputNames.size() ); for ( unsigned name = 0; name < inputNames.size(); name++ ) { nameMap[name] = nameFile.pos(); QByteArray buffer = inputNames[name].toUtf8(); buffer.push_back( ( char ) 0 ); nameFile.write( buffer ); } nameFile.close(); nameFile.open( QIODevice::ReadOnly ); const char* test = ( const char* ) nameFile.map( 0, nameFile.size() ); for ( unsigned name = 0; name < inputNames.size(); name++ ) { QString testName = QString::fromUtf8( test + nameMap[name] ); assert( testName == inputNames[name] ); } for ( unsigned edge = 0; edge < numEdges; edge++ ) inputEdges[edge].nameID = nameMap[inputEdges[edge].nameID]; } { std::vector< QString > inputTypes; if ( !importer->GetRoutingWayTypes( &inputTypes ) ) return false; QFile typeFile( filename + "_types" ); if ( !openQFile( &typeFile, QIODevice::WriteOnly ) ) return false; QStringList typeList; for ( unsigned type = 0; type < inputTypes.size(); type++ ) typeList.push_back( inputTypes[type] ); typeFile.write( typeList.join( ";" ).toUtf8() ); } for ( std::vector< IImporter::RoutingEdge >::iterator i = inputEdges.begin(), iend = inputEdges.end(); i != iend; i++ ) { i->source = map[i->source]; i->target = map[i->target]; } CompressedGraphBuilder* builder = new CompressedGraphBuilder( 1u << m_settings.blockSize, nodes, edges, inputEdges, pathNodes ); if ( !builder->run( filename, &map ) ) return false; delete builder; importer->SetIDMap( map ); return true; }