2012-09-25 11:28:39 -04:00
|
|
|
/*
|
|
|
|
open source routing machine
|
|
|
|
Copyright (C) Dennis Luxen, 2010
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU AFFERO General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
or see http://www.gnu.org/licenses/agpl.txt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../typedefs.h"
|
|
|
|
#include "../Algorithms/StronglyConnectedComponents.h"
|
|
|
|
#include "../DataStructures/BinaryHeap.h"
|
|
|
|
#include "../DataStructures/DeallocatingVector.h"
|
|
|
|
#include "../DataStructures/DynamicGraph.h"
|
|
|
|
#include "../DataStructures/QueryEdge.h"
|
2012-12-19 05:04:02 -05:00
|
|
|
#include "../DataStructures/TurnInstructions.h"
|
2012-09-25 11:28:39 -04:00
|
|
|
#include "../Util/GraphLoader.h"
|
2013-08-06 11:46:49 -04:00
|
|
|
#include "../Util/IniFile.h"
|
|
|
|
#include "../Util/InputFileUtil.h"
|
2013-08-06 06:28:19 -04:00
|
|
|
#include "../Util/OSRMException.h"
|
2013-08-08 08:17:01 -04:00
|
|
|
#include "../Util/SimpleLogger.h"
|
2013-08-19 07:42:34 -04:00
|
|
|
#include "../Util/UUID.h"
|
2012-09-25 11:28:39 -04:00
|
|
|
|
2013-06-27 16:08:33 -04:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <fstream>
|
|
|
|
#include <istream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2012-09-25 11:28:39 -04:00
|
|
|
|
2013-06-27 16:08:33 -04:00
|
|
|
typedef QueryEdge::EdgeData EdgeData;
|
2012-09-25 11:28:39 -04:00
|
|
|
typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
|
|
|
|
|
2013-06-27 16:08:33 -04:00
|
|
|
std::vector<NodeInfo> internal_to_external_node_map;
|
2013-08-14 05:59:46 -04:00
|
|
|
std::vector<TurnRestriction> restrictions_vector;
|
2013-06-27 16:08:33 -04:00
|
|
|
std::vector<NodeID> bollard_node_IDs_vector;
|
|
|
|
std::vector<NodeID> traffic_light_node_IDs_vector;
|
2012-09-25 11:28:39 -04:00
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
int main (int argc, char * argv[]) {
|
2013-08-10 08:43:49 -04:00
|
|
|
LogPolicy::GetInstance().Unmute();
|
2013-08-14 05:59:46 -04:00
|
|
|
if(argc < 3) {
|
|
|
|
SimpleLogger().Write(logWARNING) <<
|
|
|
|
"usage:\n" << argv[0] << " <osrm> <osrm.restrictions>";
|
2013-08-06 06:28:19 -04:00
|
|
|
return -1;
|
2012-09-25 11:28:39 -04:00
|
|
|
}
|
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
SimpleLogger().Write() <<
|
|
|
|
"Using restrictions from file: " << argv[2];
|
|
|
|
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
|
2013-08-19 07:42:34 -04:00
|
|
|
const UUID uuid_orig;
|
|
|
|
UUID uuid_loaded;
|
|
|
|
restriction_ifstream.read((char *) &uuid_loaded, sizeof(UUID));
|
|
|
|
|
|
|
|
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
|
|
|
|
SimpleLogger().Write(logWARNING) <<
|
|
|
|
argv[2] << " was prepared with a different build. "
|
|
|
|
"Reprocess to get rid of this warning.";
|
|
|
|
}
|
|
|
|
|
2013-06-27 16:08:33 -04:00
|
|
|
if(!restriction_ifstream.good()) {
|
2013-08-06 06:28:19 -04:00
|
|
|
throw OSRMException("Could not access <osrm-restrictions> files");
|
2012-09-25 11:28:39 -04:00
|
|
|
}
|
2013-06-27 16:08:33 -04:00
|
|
|
uint32_t usable_restriction_count = 0;
|
|
|
|
restriction_ifstream.read(
|
|
|
|
(char*)&usable_restriction_count,
|
|
|
|
sizeof(uint32_t)
|
|
|
|
);
|
|
|
|
restrictions_vector.resize(usable_restriction_count);
|
|
|
|
|
|
|
|
restriction_ifstream.read(
|
|
|
|
(char *)&(restrictions_vector[0]),
|
2013-08-14 05:59:46 -04:00
|
|
|
usable_restriction_count*sizeof(TurnRestriction)
|
2013-06-27 16:08:33 -04:00
|
|
|
);
|
|
|
|
restriction_ifstream.close();
|
|
|
|
|
|
|
|
std::ifstream input_stream;
|
2013-08-14 05:59:46 -04:00
|
|
|
input_stream.open( argv[1], std::ifstream::in | std::ifstream::binary );
|
2013-06-27 16:08:33 -04:00
|
|
|
|
|
|
|
if (!input_stream.is_open()) {
|
2013-08-06 06:28:19 -04:00
|
|
|
throw OSRMException("Cannot open osrm file");
|
2012-09-25 11:28:39 -04:00
|
|
|
}
|
|
|
|
|
2013-06-27 16:08:33 -04:00
|
|
|
std::vector<ImportEdge> edge_list;
|
|
|
|
NodeID node_based_node_count = readBinaryOSRMGraphFromStream(
|
|
|
|
input_stream,
|
|
|
|
edge_list,
|
|
|
|
bollard_node_IDs_vector,
|
|
|
|
traffic_light_node_IDs_vector,
|
|
|
|
&internal_to_external_node_map,
|
|
|
|
restrictions_vector
|
|
|
|
);
|
|
|
|
input_stream.close();
|
|
|
|
|
2013-08-19 07:42:34 -04:00
|
|
|
BOOST_ASSERT_MSG(
|
|
|
|
restrictions_vector.size() == usable_restriction_count,
|
|
|
|
"size of restrictions_vector changed"
|
|
|
|
);
|
|
|
|
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() <<
|
2013-06-27 16:08:33 -04:00
|
|
|
restrictions_vector.size() << " restrictions, " <<
|
|
|
|
bollard_node_IDs_vector.size() << " bollard nodes, " <<
|
2013-08-08 08:17:01 -04:00
|
|
|
traffic_light_node_IDs_vector.size() << " traffic lights";
|
2012-09-25 11:28:39 -04:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Building an edge-expanded graph from node-based input an turn restrictions
|
|
|
|
*/
|
|
|
|
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Starting SCC graph traversal";
|
2013-06-27 16:08:33 -04:00
|
|
|
TarjanSCC * tarjan = new TarjanSCC (
|
|
|
|
node_based_node_count,
|
|
|
|
edge_list,
|
|
|
|
bollard_node_IDs_vector,
|
|
|
|
traffic_light_node_IDs_vector,
|
|
|
|
restrictions_vector,
|
|
|
|
internal_to_external_node_map
|
|
|
|
);
|
|
|
|
std::vector<ImportEdge>().swap(edge_list);
|
|
|
|
|
2012-09-25 11:28:39 -04:00
|
|
|
tarjan->Run();
|
2013-06-27 16:08:33 -04:00
|
|
|
|
2013-08-14 05:59:46 -04:00
|
|
|
std::vector<TurnRestriction>().swap(restrictions_vector);
|
2013-06-27 16:08:33 -04:00
|
|
|
std::vector<NodeID>().swap(bollard_node_IDs_vector);
|
|
|
|
std::vector<NodeID>().swap(traffic_light_node_IDs_vector);
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "finished component analysis";
|
2012-09-25 11:28:39 -04:00
|
|
|
return 0;
|
|
|
|
}
|