2011-01-09 16:42:27 -05:00
|
|
|
/*
|
|
|
|
open source routing machine
|
|
|
|
Copyright (C) Dennis Luxen, others 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.
|
|
|
|
*/
|
|
|
|
|
2011-04-15 12:37:48 -04:00
|
|
|
#ifndef GRAPHLOADER_H
|
2011-01-09 16:42:27 -05:00
|
|
|
#define GRAPHLOADER_H
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
2012-04-14 12:01:06 -04:00
|
|
|
|
|
|
|
#include <algorithm>
|
2011-01-09 16:42:27 -05:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-10-12 11:31:18 -04:00
|
|
|
#include <boost/unordered_map.hpp>
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "../DataStructures/ImportNode.h"
|
2011-01-09 16:42:27 -05:00
|
|
|
#include "../DataStructures/ImportEdge.h"
|
2012-07-02 10:00:00 -04:00
|
|
|
#include "../DataStructures/NodeCoords.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "../DataStructures/Restriction.h"
|
2011-01-09 16:42:27 -05:00
|
|
|
#include "../typedefs.h"
|
|
|
|
|
2011-10-12 11:31:18 -04:00
|
|
|
typedef boost::unordered_map<NodeID, NodeID> ExternalNodeMap;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2012-03-06 13:25:54 -05:00
|
|
|
template<class EdgeT>
|
|
|
|
struct _ExcessRemover {
|
2012-07-13 11:01:21 -04:00
|
|
|
inline bool operator()( EdgeT & edge ) const {
|
2012-03-06 13:25:54 -05:00
|
|
|
return edge.source() == UINT_MAX;
|
2011-01-09 16:42:27 -05:00
|
|
|
}
|
2012-03-06 13:25:54 -05:00
|
|
|
};
|
2011-03-14 13:03:19 -04:00
|
|
|
|
2011-03-23 13:15:13 -04:00
|
|
|
template<typename EdgeT>
|
2012-01-02 07:09:20 -05:00
|
|
|
NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeID> &bollardNodes, std::vector<NodeID> &trafficLightNodes, std::vector<NodeInfo> * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) {
|
|
|
|
NodeID n, source, target;
|
2011-03-23 13:15:13 -04:00
|
|
|
EdgeID m;
|
2012-01-02 07:09:20 -05:00
|
|
|
short dir;// direction (0 = open, 1 = forward, 2+ = open)
|
2011-03-23 13:15:13 -04:00
|
|
|
ExternalNodeMap ext2IntNodeMap;
|
|
|
|
in.read((char*)&n, sizeof(NodeID));
|
2011-11-30 13:33:03 -05:00
|
|
|
DEBUG("Importing n = " << n << " nodes ");
|
2012-01-02 07:09:20 -05:00
|
|
|
_Node node;
|
2011-12-01 09:12:30 -05:00
|
|
|
for (NodeID i=0; i<n; ++i) {
|
2012-01-02 07:09:20 -05:00
|
|
|
in.read((char*)&node, sizeof(_Node));
|
|
|
|
int2ExtNodeMap->push_back(NodeInfo(node.lat, node.lon, node.id));
|
2012-04-14 12:18:18 -04:00
|
|
|
ext2IntNodeMap.insert(std::make_pair(node.id, i));
|
2012-01-02 07:09:20 -05:00
|
|
|
if(node.bollard)
|
|
|
|
bollardNodes.push_back(i);
|
|
|
|
if(node.trafficLight)
|
|
|
|
trafficLightNodes.push_back(i);
|
2011-03-23 13:15:13 -04:00
|
|
|
}
|
2012-01-02 07:09:20 -05:00
|
|
|
|
2012-04-25 11:12:46 -04:00
|
|
|
//tighten vector sizes
|
|
|
|
std::vector<NodeID>(bollardNodes).swap(bollardNodes);
|
|
|
|
std::vector<NodeID>(trafficLightNodes).swap(trafficLightNodes);
|
|
|
|
|
2011-03-23 13:15:13 -04:00
|
|
|
in.read((char*)&m, sizeof(unsigned));
|
2011-11-30 13:33:03 -05:00
|
|
|
DEBUG(" and " << m << " edges ");
|
2011-10-12 11:31:18 -04:00
|
|
|
for(unsigned i = 0; i < inputRestrictions.size(); ++i) {
|
|
|
|
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode);
|
|
|
|
if( intNodeID == ext2IntNodeMap.end()) {
|
2011-12-01 09:12:30 -05:00
|
|
|
DEBUG("Unmapped from Node of restriction");
|
|
|
|
continue;
|
|
|
|
|
2011-10-12 11:31:18 -04:00
|
|
|
}
|
|
|
|
inputRestrictions[i].fromNode = intNodeID->second;
|
|
|
|
|
|
|
|
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode);
|
|
|
|
if( intNodeID == ext2IntNodeMap.end()) {
|
2011-12-01 09:12:30 -05:00
|
|
|
DEBUG("Unmapped via node of restriction");
|
|
|
|
continue;
|
2011-10-12 11:31:18 -04:00
|
|
|
}
|
|
|
|
inputRestrictions[i].viaNode = intNodeID->second;
|
|
|
|
|
|
|
|
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode);
|
|
|
|
if( intNodeID == ext2IntNodeMap.end()) {
|
2011-12-01 09:12:30 -05:00
|
|
|
DEBUG("Unmapped to node of restriction");
|
|
|
|
continue;
|
2011-10-12 11:31:18 -04:00
|
|
|
}
|
|
|
|
inputRestrictions[i].toNode = intNodeID->second;
|
|
|
|
}
|
|
|
|
|
2011-03-23 13:15:13 -04:00
|
|
|
edgeList.reserve(m);
|
2011-11-22 10:47:15 -05:00
|
|
|
EdgeWeight weight;
|
|
|
|
short type;
|
|
|
|
NodeID nameID;
|
|
|
|
int length;
|
2012-03-22 05:25:04 -04:00
|
|
|
bool isRoundabout, ignoreInGrid, isAccessRestricted;
|
2011-11-22 10:47:15 -05:00
|
|
|
|
2011-12-01 09:12:30 -05:00
|
|
|
for (EdgeID i=0; i<m; ++i) {
|
2012-03-22 05:25:04 -04:00
|
|
|
in.read((char*)&source, sizeof(unsigned));
|
|
|
|
in.read((char*)&target, sizeof(unsigned));
|
|
|
|
in.read((char*)&length, sizeof(int));
|
|
|
|
in.read((char*)&dir, sizeof(short));
|
|
|
|
in.read((char*)&weight, sizeof(int));
|
|
|
|
in.read((char*)&type, sizeof(short));
|
|
|
|
in.read((char*)&nameID, sizeof(unsigned));
|
|
|
|
in.read((char*)&isRoundabout, sizeof(bool));
|
|
|
|
in.read((char*)&ignoreInGrid, sizeof(bool));
|
|
|
|
in.read((char*)&isAccessRestricted, sizeof(bool));
|
2011-03-28 12:32:47 -04:00
|
|
|
|
2011-12-01 09:12:30 -05:00
|
|
|
GUARANTEE(length > 0, "loaded null length edge" );
|
|
|
|
GUARANTEE(weight > 0, "loaded null weight");
|
|
|
|
GUARANTEE(0<=dir && dir<=2, "loaded bogus direction");
|
2011-03-23 13:15:13 -04:00
|
|
|
|
|
|
|
bool forward = true;
|
|
|
|
bool backward = true;
|
|
|
|
if (1 == dir) { backward = false; }
|
|
|
|
if (2 == dir) { forward = false; }
|
|
|
|
|
2011-12-16 08:05:30 -05:00
|
|
|
assert(type >= 0);
|
|
|
|
|
2011-03-23 13:15:13 -04:00
|
|
|
// translate the external NodeIDs to internal IDs
|
|
|
|
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
|
|
|
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
|
2011-03-30 08:26:38 -04:00
|
|
|
#ifndef NDEBUG
|
2011-11-30 13:33:03 -05:00
|
|
|
WARN(" unresolved source NodeID: " << source );
|
2011-03-30 08:26:38 -04:00
|
|
|
#endif
|
|
|
|
continue;
|
2011-03-23 13:15:13 -04:00
|
|
|
}
|
|
|
|
source = intNodeID->second;
|
|
|
|
intNodeID = ext2IntNodeMap.find(target);
|
2011-03-30 08:26:38 -04:00
|
|
|
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) {
|
|
|
|
#ifndef NDEBUG
|
2011-12-01 09:12:30 -05:00
|
|
|
WARN("unresolved target NodeID : " << target );
|
2011-03-30 08:26:38 -04:00
|
|
|
#endif
|
2011-11-14 13:36:31 -05:00
|
|
|
continue;
|
2011-03-30 08:26:38 -04:00
|
|
|
}
|
2011-03-23 13:15:13 -04:00
|
|
|
target = intNodeID->second;
|
2011-12-01 09:12:30 -05:00
|
|
|
GUARANTEE(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target");
|
2011-03-23 13:15:13 -04:00
|
|
|
|
2012-03-06 13:25:54 -05:00
|
|
|
if(source > target) {
|
|
|
|
std::swap(source, target);
|
|
|
|
std::swap(forward, backward);
|
|
|
|
}
|
|
|
|
|
2012-03-22 05:25:04 -04:00
|
|
|
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout, ignoreInGrid, isAccessRestricted );
|
2011-03-23 13:15:13 -04:00
|
|
|
edgeList.push_back(inputEdge);
|
|
|
|
}
|
2012-03-06 13:25:54 -05:00
|
|
|
std::sort(edgeList.begin(), edgeList.end());
|
|
|
|
for(unsigned i = 1; i < edgeList.size(); ++i) {
|
|
|
|
if( (edgeList[i-1].target() == edgeList[i].target()) && (edgeList[i-1].source() == edgeList[i].source()) ) {
|
2012-07-13 11:01:21 -04:00
|
|
|
bool edgeFlagsAreEquivalent = (edgeList[i-1].isForward() == edgeList[i].isForward()) && (edgeList[i-1].isBackward() == edgeList[i].isBackward());
|
|
|
|
bool edgeFlagsAreSuperSet1 = (edgeList[i-1].isForward() && edgeList[i-1].isBackward()) && (edgeList[i].isBackward() != edgeList[i].isBackward() );
|
|
|
|
bool edgeFlagsAreSuperSet2 = (edgeList[i].isForward() && edgeList[i].isBackward()) && (edgeList[i-1].isBackward() != edgeList[i-1].isBackward() );
|
|
|
|
|
|
|
|
if( edgeFlagsAreEquivalent ) {
|
2012-03-06 13:25:54 -05:00
|
|
|
edgeList[i]._weight = std::min(edgeList[i-1].weight(), edgeList[i].weight());
|
|
|
|
edgeList[i-1]._source = UINT_MAX;
|
2012-07-13 11:01:21 -04:00
|
|
|
} else if (edgeFlagsAreSuperSet1) {
|
|
|
|
if(edgeList[i-1].weight() <= edgeList[i].weight()) {
|
|
|
|
//edge i-1 is smaller and goes in both directions. Throw away the other edge
|
|
|
|
edgeList[i]._source = UINT_MAX;
|
|
|
|
} else {
|
|
|
|
//edge i-1 is open in both directions, but edge i is smaller in one direction. Close edge i-1 in this direction
|
|
|
|
edgeList[i-1].forward = ~edgeList[i].isForward();
|
|
|
|
edgeList[i-1].backward = ~edgeList[i].isBackward();
|
|
|
|
}
|
|
|
|
} else if (edgeFlagsAreSuperSet2) {
|
|
|
|
if(edgeList[i-1].weight() <= edgeList[i].weight()) {
|
|
|
|
//edge i-1 is smaller for one direction. edge i is open in both. close edge i in the other direction
|
|
|
|
edgeList[i].forward = ~edgeList[i-1].isForward();
|
|
|
|
edgeList[i].backward = ~edgeList[i-1].isBackward();
|
|
|
|
} else {
|
|
|
|
//edge i is smaller and goes in both direction. Throw away edge i-1
|
|
|
|
edgeList[i-1]._source = UINT_MAX;
|
|
|
|
}
|
2012-03-06 13:25:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::vector<ImportEdge>::iterator newEnd = std::remove_if(edgeList.begin(), edgeList.end(), _ExcessRemover<EdgeT>());
|
2011-03-23 13:15:13 -04:00
|
|
|
ext2IntNodeMap.clear();
|
2012-03-06 13:25:54 -05:00
|
|
|
std::vector<ImportEdge>(edgeList.begin(), newEnd).swap(edgeList); //remove excess candidates.
|
2012-03-08 05:35:40 -05:00
|
|
|
INFO("Graph loaded ok and has " << edgeList.size() << " edges");
|
2011-03-23 13:15:13 -04:00
|
|
|
return n;
|
|
|
|
}
|
2011-03-14 13:03:19 -04:00
|
|
|
template<typename EdgeT>
|
2012-04-14 12:18:18 -04:00
|
|
|
NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeInfo> * int2ExtNodeMap) {
|
2011-03-14 13:03:19 -04:00
|
|
|
NodeID n, source, target, id;
|
|
|
|
EdgeID m;
|
|
|
|
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
|
|
|
|
ExternalNodeMap ext2IntNodeMap;
|
|
|
|
in >> n;
|
2011-11-30 13:33:03 -05:00
|
|
|
DEBUG("Importing n = " << n << " nodes ");
|
|
|
|
for (NodeID i=0; i<n;++i) {
|
2011-03-14 13:03:19 -04:00
|
|
|
in >> id >> ycoord >> xcoord;
|
|
|
|
int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id));
|
2012-04-14 12:18:18 -04:00
|
|
|
ext2IntNodeMap.insert(std::make_pair(id, i));
|
2011-03-14 13:03:19 -04:00
|
|
|
}
|
|
|
|
in >> m;
|
2011-11-30 13:33:03 -05:00
|
|
|
DEBUG(" and " << m << " edges");
|
2011-03-14 13:03:19 -04:00
|
|
|
|
|
|
|
edgeList.reserve(m);
|
2011-11-30 13:33:03 -05:00
|
|
|
for (EdgeID i=0; i<m; ++i) {
|
2011-03-14 13:03:19 -04:00
|
|
|
EdgeWeight weight;
|
|
|
|
unsigned speedType(0);
|
|
|
|
short type(0);
|
2011-11-14 13:36:31 -05:00
|
|
|
// NodeID nameID;
|
2011-03-14 13:03:19 -04:00
|
|
|
int length;
|
|
|
|
in >> source >> target >> length >> dir >> speedType;
|
|
|
|
|
|
|
|
if(dir == 3)
|
|
|
|
dir = 0;
|
|
|
|
|
|
|
|
switch(speedType) {
|
|
|
|
case 1:
|
|
|
|
weight = 130;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
weight = 120;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
weight = 110;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
weight = 100;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
weight = 90;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
weight = 80;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
weight = 70;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
weight = 60;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
weight = 50;
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
weight = 40;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
weight = 30;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
weight = 20;
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
weight = length;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
weight = 10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
weight = 0;
|
2011-07-21 10:30:36 -04:00
|
|
|
break;
|
2011-03-14 13:03:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
weight = length*weight/3.6;
|
|
|
|
if(speedType == 13)
|
|
|
|
weight = length;
|
|
|
|
assert(length > 0);
|
|
|
|
assert(weight > 0);
|
|
|
|
if(dir <0 || dir > 2)
|
2011-11-30 13:33:03 -05:00
|
|
|
WARN("direction bogus: " << dir);
|
2011-03-14 13:03:19 -04:00
|
|
|
assert(0<=dir && dir<=2);
|
|
|
|
|
2011-01-09 16:42:27 -05:00
|
|
|
bool forward = true;
|
|
|
|
bool backward = true;
|
|
|
|
if (dir == 1) backward = false;
|
|
|
|
if (dir == 2) forward = false;
|
|
|
|
|
2011-11-30 13:33:03 -05:00
|
|
|
if(length == 0) { ERR("loaded null length edge"); }
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
// translate the external NodeIDs to internal IDs
|
|
|
|
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
2011-11-30 13:33:03 -05:00
|
|
|
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
|
|
|
|
ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source);
|
2011-01-09 16:42:27 -05:00
|
|
|
}
|
|
|
|
source = intNodeID->second;
|
|
|
|
intNodeID = ext2IntNodeMap.find(target);
|
2011-11-30 13:33:03 -05:00
|
|
|
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); }
|
2011-01-09 16:42:27 -05:00
|
|
|
target = intNodeID->second;
|
|
|
|
|
2011-11-30 13:33:03 -05:00
|
|
|
if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); }
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2011-03-14 13:03:19 -04:00
|
|
|
EdgeT inputEdge(source, target, 0, weight, forward, backward, type );
|
|
|
|
edgeList.push_back(inputEdge);
|
|
|
|
}
|
|
|
|
ext2IntNodeMap.clear();
|
2012-04-14 12:18:18 -04:00
|
|
|
std::vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
|
|
|
|
std::cout << "ok" << std::endl;
|
2011-03-14 13:03:19 -04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-07-07 04:15:56 -04:00
|
|
|
template<typename EdgeT>
|
2012-04-14 12:18:18 -04:00
|
|
|
NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeID> & int2ExtNodeMap) {
|
2011-10-12 11:31:18 -04:00
|
|
|
ExternalNodeMap nodeMap;
|
2011-03-14 13:03:19 -04:00
|
|
|
NodeID n, source, target;
|
2011-03-31 10:44:41 -04:00
|
|
|
unsigned numberOfNodes = 0;
|
2011-03-14 13:03:19 -04:00
|
|
|
char d;
|
|
|
|
EdgeID m;
|
|
|
|
int dir;// direction (0 = open, 1 = forward, 2+ = open)
|
|
|
|
in >> d;
|
|
|
|
in >> n;
|
|
|
|
in >> m;
|
2011-07-07 04:15:56 -04:00
|
|
|
#ifndef DEBUG
|
2011-03-31 10:44:41 -04:00
|
|
|
std::cout << "expecting " << n << " nodes and " << m << " edges ..." << flush;
|
2011-07-07 04:15:56 -04:00
|
|
|
#endif
|
2011-03-14 13:03:19 -04:00
|
|
|
edgeList.reserve(m);
|
|
|
|
for (EdgeID i=0; i<m; i++) {
|
|
|
|
EdgeWeight weight;
|
|
|
|
in >> source >> target >> weight >> dir;
|
|
|
|
|
|
|
|
assert(weight > 0);
|
|
|
|
if(dir <0 || dir > 3)
|
2011-11-30 13:33:03 -05:00
|
|
|
ERR( "[error] direction bogus: " << dir );
|
2011-03-14 13:03:19 -04:00
|
|
|
assert(0<=dir && dir<=3);
|
|
|
|
|
|
|
|
bool forward = true;
|
|
|
|
bool backward = true;
|
|
|
|
if (dir == 1) backward = false;
|
|
|
|
if (dir == 2) forward = false;
|
|
|
|
if (dir == 3) {backward = true; forward = true;}
|
|
|
|
|
2011-11-30 13:33:03 -05:00
|
|
|
if(weight == 0) { ERR("loaded null length edge"); }
|
2011-03-14 13:03:19 -04:00
|
|
|
|
2011-03-31 10:44:41 -04:00
|
|
|
if( nodeMap.find(source) == nodeMap.end()) {
|
2011-04-15 12:37:48 -04:00
|
|
|
nodeMap.insert(std::make_pair(source, numberOfNodes ));
|
2011-07-07 04:15:56 -04:00
|
|
|
int2ExtNodeMap.push_back(source);
|
2011-03-31 10:44:41 -04:00
|
|
|
numberOfNodes++;
|
|
|
|
}
|
|
|
|
if( nodeMap.find(target) == nodeMap.end()) {
|
2011-04-15 12:37:48 -04:00
|
|
|
nodeMap.insert(std::make_pair(target, numberOfNodes));
|
2011-07-07 04:15:56 -04:00
|
|
|
int2ExtNodeMap.push_back(target);
|
2011-03-31 10:44:41 -04:00
|
|
|
numberOfNodes++;
|
|
|
|
}
|
2011-04-15 12:37:48 -04:00
|
|
|
EdgeT inputEdge(source, target, 0, weight, forward, backward, 1 );
|
|
|
|
edgeList.push_back(inputEdge);
|
2011-11-14 13:36:31 -05:00
|
|
|
}
|
2012-04-14 12:18:18 -04:00
|
|
|
std::vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
|
2011-07-07 04:15:56 -04:00
|
|
|
|
2011-03-31 10:44:41 -04:00
|
|
|
nodeMap.clear();
|
|
|
|
return numberOfNodes;
|
2011-01-09 16:42:27 -05:00
|
|
|
}
|
|
|
|
|
2011-12-15 11:48:00 -05:00
|
|
|
template<typename NodeT, typename EdgeT>
|
2012-04-14 12:18:18 -04:00
|
|
|
unsigned readHSGRFromStream(std::istream &in, std::vector<NodeT>& nodeList, std::vector<EdgeT> & edgeList, unsigned * checkSum) {
|
2011-12-15 11:48:00 -05:00
|
|
|
unsigned numberOfNodes = 0;
|
2012-02-17 02:15:33 -05:00
|
|
|
in.read((char*) checkSum, sizeof(unsigned));
|
2011-12-15 11:48:00 -05:00
|
|
|
in.read((char*) & numberOfNodes, sizeof(unsigned));
|
2012-01-26 18:41:31 -05:00
|
|
|
nodeList.resize(numberOfNodes + 1);
|
2012-04-14 09:53:10 -04:00
|
|
|
in.read((char*) &(nodeList[0]), numberOfNodes*sizeof(NodeT));
|
2011-12-15 11:48:00 -05:00
|
|
|
|
|
|
|
unsigned numberOfEdges = 0;
|
|
|
|
in.read((char*) &numberOfEdges, sizeof(unsigned));
|
|
|
|
edgeList.resize(numberOfEdges);
|
2012-04-14 09:53:10 -04:00
|
|
|
in.read((char*) &(edgeList[0]), numberOfEdges*sizeof(EdgeT));
|
2011-12-15 11:48:00 -05:00
|
|
|
|
|
|
|
return numberOfNodes;
|
|
|
|
}
|
|
|
|
|
2011-04-15 12:37:48 -04:00
|
|
|
#endif // GRAPHLOADER_H
|