2010-07-09 05:05:40 -04: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.
*/
# ifndef EDGE_H
# define EDGE_H
# include <cassert>
2011-11-14 13:36:31 -05:00
class NodeBasedEdge {
2010-07-09 05:05:40 -04:00
public :
2011-11-14 13:36:31 -05:00
bool operator < ( const NodeBasedEdge & e ) const {
2010-07-09 05:05:40 -04:00
if ( source ( ) = = e . source ( ) ) {
if ( target ( ) = = e . target ( ) ) {
if ( weight ( ) = = e . weight ( ) ) {
return ( isForward ( ) & & isBackward ( ) & &
( ( ! e . isForward ( ) ) | | ( ! e . isBackward ( ) ) ) ) ;
}
return ( weight ( ) < e . weight ( ) ) ;
}
return ( target ( ) < e . target ( ) ) ;
}
return ( source ( ) < e . source ( ) ) ;
}
2013-01-18 15:28:13 -05:00
explicit NodeBasedEdge ( NodeID s , NodeID t , NodeID n , EdgeWeight w , bool f , bool b , short ty , bool ra , bool ig , bool ar , bool cf ) :
_source ( s ) , _target ( t ) , _name ( n ) , _weight ( w ) , forward ( f ) , backward ( b ) , _type ( ty ) , _roundabout ( ra ) , _ignoreInGrid ( ig ) , _accessRestricted ( ar ) , _contraFlow ( cf ) { if ( ty < 0 ) { ERR ( " Type: " < < ty ) ; } ; }
2010-07-09 05:05:40 -04:00
NodeID target ( ) const { return _target ; }
2010-09-23 11:34:22 -04:00
NodeID source ( ) const { return _source ; }
NodeID name ( ) const { return _name ; }
2010-07-09 05:05:40 -04:00
EdgeWeight weight ( ) const { return _weight ; }
2010-09-29 11:22:38 -04:00
short type ( ) const { assert ( _type > = 0 ) ; return _type ; }
2010-07-09 05:05:40 -04:00
bool isBackward ( ) const { return backward ; }
bool isForward ( ) const { return forward ; }
2010-09-29 11:22:38 -04:00
bool isLocatable ( ) const { return _type ! = 14 ; }
2011-11-22 10:47:15 -05:00
bool isRoundabout ( ) const { return _roundabout ; }
2011-12-16 08:05:30 -05:00
bool ignoreInGrid ( ) const { return _ignoreInGrid ; }
2012-03-22 05:25:04 -04:00
bool isAccessRestricted ( ) const { return _accessRestricted ; }
2013-01-18 15:28:13 -05:00
bool isContraFlow ( ) const { return _contraFlow ; }
2010-09-02 11:47:55 -04:00
2011-07-18 10:18:12 -04:00
NodeID _source ;
NodeID _target ;
2011-11-14 13:36:31 -05:00
NodeID _name ;
EdgeWeight _weight ;
bool forward ;
bool backward ;
2011-01-12 12:09:04 -05:00
short _type ;
2011-11-22 10:47:15 -05:00
bool _roundabout ;
2011-12-16 08:05:30 -05:00
bool _ignoreInGrid ;
2012-03-22 05:25:04 -04:00
bool _accessRestricted ;
2013-01-18 15:28:13 -05:00
bool _contraFlow ;
private :
/** Default constructor. target and weight are set to 0.*/
NodeBasedEdge ( ) :
_source ( 0 ) , _target ( 0 ) , _name ( 0 ) , _weight ( 0 ) , forward ( 0 ) , backward ( 0 ) , _type ( 0 ) , _roundabout ( false ) , _ignoreInGrid ( false ) , _accessRestricted ( false ) , _contraFlow ( false ) { assert ( false ) ; } //shall not be used.
2010-07-09 05:05:40 -04:00
} ;
2011-11-14 13:36:31 -05:00
class EdgeBasedEdge {
public :
bool operator < ( const EdgeBasedEdge & e ) const {
if ( source ( ) = = e . source ( ) ) {
if ( target ( ) = = e . target ( ) ) {
if ( weight ( ) = = e . weight ( ) ) {
return ( isForward ( ) & & isBackward ( ) & &
( ( ! e . isForward ( ) ) | | ( ! e . isBackward ( ) ) ) ) ;
}
return ( weight ( ) < e . weight ( ) ) ;
}
return ( target ( ) < e . target ( ) ) ;
}
return ( source ( ) < e . source ( ) ) ;
}
template < class EdgeT >
EdgeBasedEdge ( const EdgeT & myEdge ) :
_source ( myEdge . source ) ,
_target ( myEdge . target ) ,
2012-04-25 04:51:16 -04:00
_edgeID ( myEdge . data . via ) ,
// _nameID1(myEdge.data.nameID),
2011-11-14 13:36:31 -05:00
_weight ( myEdge . data . distance ) ,
2011-11-25 06:02:52 -05:00
_forward ( myEdge . data . forward ) ,
2012-04-25 04:51:16 -04:00
_backward ( myEdge . data . backward ) //,
// _turnInstruction(myEdge.data.turnInstruction)
{ }
2011-11-14 13:36:31 -05:00
/** Default constructor. target and weight are set to 0.*/
EdgeBasedEdge ( ) :
2012-05-23 15:18:38 -04:00
_source ( 0 ) , _target ( 0 ) , _edgeID ( 0 ) , _weight ( 0 ) , _forward ( false ) , _backward ( false ) { }
2011-11-14 13:36:31 -05:00
2012-04-25 04:57:19 -04:00
explicit EdgeBasedEdge ( NodeID s , NodeID t , NodeID v , EdgeWeight w , bool f , bool b ) :
_source ( s ) , _target ( t ) , _edgeID ( v ) , _weight ( w ) , _forward ( f ) , _backward ( b ) { }
2011-11-14 13:36:31 -05:00
NodeID target ( ) const { return _target ; }
NodeID source ( ) const { return _source ; }
EdgeWeight weight ( ) const { return _weight ; }
2012-04-25 04:51:16 -04:00
NodeID id ( ) const { return _edgeID ; }
2011-11-25 06:02:52 -05:00
bool isBackward ( ) const { return _backward ; }
bool isForward ( ) const { return _forward ; }
2011-11-14 13:36:31 -05:00
NodeID _source ;
NodeID _target ;
2012-04-25 04:51:16 -04:00
NodeID _edgeID ;
2012-05-15 10:44:29 -04:00
EdgeWeight _weight : 30 ;
bool _forward : 1 ;
bool _backward : 1 ;
2011-11-14 13:36:31 -05:00
} ;
2013-01-01 17:01:52 -05:00
struct MinimalEdgeData {
public :
EdgeWeight distance ;
bool forward ;
bool backward ;
} ;
2011-11-14 13:36:31 -05:00
typedef NodeBasedEdge ImportEdge ;
2010-07-09 05:05:40 -04:00
# endif // EDGE_H