PBeFS
Parallel Best-First Search
Loading...
Searching...
No Matches
Romania.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File Romania.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
15/*--------------------------------------------------------------------------*/
16/*------------------------------ DEFINITIONS -------------------------------*/
17/*--------------------------------------------------------------------------*/
18
19#ifndef __PBeFS_Romania
20 #define __PBeFS_Romania
21 /* self-identification: #endif at the end of the file */
22
23/*--------------------------------------------------------------------------*/
24/*-------------------------------- INCLUDES --------------------------------*/
25/*--------------------------------------------------------------------------*/
26
27#include <array>
28
29#include <cmath>
30
31#include <cstdint>
32
33#include <stdexcept>
34
35#include <string>
36
38
39/*--------------------------------------------------------------------------*/
40/*------------------------------- NAMESPACE --------------------------------*/
41/*--------------------------------------------------------------------------*/
42
44namespace PBeFS_di_unipi_it
45{
46
47/*--------------------------------------------------------------------------*/
48/*----------------------------- CLASS Romania ------------------------------*/
49/*--------------------------------------------------------------------------*/
51
60
61class Romania : public ExplicitGraph< double > {
62
63/*------------------------ PUBLIC PART OF THE CLASS ------------------------*/
64
65 public:
66
67/*------------------------------ PUBLIC TYPES ------------------------------*/
68
70 enum City : std::uint32_t { Arad , Bucharest , Craiova , Drobeta , Eforie ,
75
77 struct Road { City a , b; int km; };
78
79/*------------------------------ CONSTRUCTOR -------------------------------*/
80
82
83 Romania( City from = Arad , City to = Bucharest )
84 : ExplicitGraph< double >( NCities , from , to ) {
85 for( const Road & r : roads() )
86 add_edge( r.a , r.b , r.km );
87 for( std::uint32_t c = 0 ; c < NCities ; ++c )
88 set_heuristic( c , to == Bucharest
89 ? double( c_to_bucharest[ c ] )
90 : std::hypot( c_xy[ c ][ 0 ] - c_xy[ to ][ 0 ] ,
91 c_xy[ c ][ 1 ] - c_xy[ to ][ 1 ] ) );
92 }
93
94/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
96
97 [[nodiscard]] static const char * name( std::uint32_t c ) {
98 static const char * const n[ NCities ] = {
99 "Arad" , "Bucharest" , "Craiova" , "Drobeta" , "Eforie" , "Fagaras" ,
100 "Giurgiu" , "Hirsova" , "Iasi" , "Lugoj" , "Mehadia" , "Neamt" ,
101 "Oradea" , "Pitesti" , "Rimnicu" , "Sibiu" , "Timisoara" , "Urziceni" ,
102 "Vaslui" , "Zerind" };
103 if( c >= NCities )
104 throw( std::invalid_argument( "Romania::name: no such city" ) );
105 return( n[ c ] );
106 }
107
109
110 [[nodiscard]] static City find( const std::string & city_name ) {
111 for( std::uint32_t c = 0 ; c < NCities ; ++c )
112 if( city_name == name( c ) )
113 return( City( c ) );
114 return( NCities );
115 }
116
117/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
119
120 [[nodiscard]] static const std::array< Road , 23 > & roads( void ) {
121 static const std::array< Road , 23 > r = { {
122 { Oradea , Zerind , 71 } , { Oradea , Sibiu , 151 } ,
123 { Zerind , Arad , 75 } , { Arad , Sibiu , 140 } ,
124 { Arad , Timisoara , 118 } ,
125 { Timisoara , Lugoj , 111 } , { Lugoj , Mehadia , 70 } ,
126 { Mehadia , Drobeta , 75 } , { Drobeta , Craiova , 120 } ,
127 { Craiova , Rimnicu , 146 } , { Craiova , Pitesti , 138 } ,
128 { Sibiu , Rimnicu , 80 } , { Sibiu , Fagaras , 99 } ,
129 { Rimnicu , Pitesti , 97 } , { Fagaras , Bucharest , 211 } ,
130 { Pitesti , Bucharest , 101 } , { Bucharest , Giurgiu , 90 } ,
131 { Bucharest , Urziceni , 85 } , { Urziceni , Hirsova , 98 } ,
132 { Hirsova , Eforie , 86 } , { Urziceni , Vaslui , 142 } ,
133 { Vaslui , Iasi , 92 } , { Iasi , Neamt , 87 } } };
134 return( r );
135 }
136
137/*----------------------- PRIVATE PART OF THE CLASS ------------------------*/
138
139 private:
140
142 static constexpr int c_to_bucharest[ NCities ] = {
143 366 , 0 , 160 , 242 , 161 , 176 , 77 , 151 , 226 , 244 , 241 , 234 , 380 ,
144 100 , 193 , 253 , 329 , 80 , 199 , 374 };
145
147 static constexpr int c_xy[ NCities ][ 2 ] = {
148 { 91 , 492 } , { 400 , 327 } , { 253 , 288 } , { 165 , 299 } ,
149 { 562 , 293 } , { 305 , 449 } , { 375 , 270 } , { 534 , 350 } ,
150 { 473 , 506 } , { 165 , 379 } , { 168 , 339 } , { 406 , 537 } ,
151 { 131 , 571 } , { 320 , 368 } , { 233 , 410 } , { 207 , 457 } ,
152 { 94 , 410 } , { 456 , 350 } , { 509 , 444 } , { 108 , 531 } };
153
154 }; // end( class( Romania ) )
155
156/*--------------------------------------------------------------------------*/
157
158} // end( namespace PBeFS_di_unipi_it )
159
160/*--------------------------------------------------------------------------*/
161
162#endif /* __PBeFS_Romania */
163
164/*--------------------------------------------------------------------------*/
165/*--------------------------- End File Romania.h ---------------------------*/
166/*--------------------------------------------------------------------------*/
Header file for the class template ExplicitAdjacency, the arcs of a weighted graph given one by one,...
void add_edge(state_type u, state_type v, double c, bool directed=false)
Definition ExplicitGraph.h:163
void set_heuristic(state_type u, double h)
Definition ExplicitGraph.h:175
ExplicitGraph(std::size_t n, state_type s, state_type t)
Definition ExplicitGraph.h:153
City
the cities, in alphabetical order
Definition Romania.h:70
@ Hirsova
Definition Romania.h:71
@ Rimnicu
Definition Romania.h:72
@ Neamt
Definition Romania.h:72
@ Lugoj
Definition Romania.h:71
@ Iasi
Definition Romania.h:71
@ Vaslui
Definition Romania.h:73
@ Oradea
Definition Romania.h:72
@ Eforie
Definition Romania.h:70
@ Pitesti
Definition Romania.h:72
@ Mehadia
Definition Romania.h:72
@ Sibiu
Definition Romania.h:73
@ Zerind
Definition Romania.h:73
@ Timisoara
Definition Romania.h:73
@ Urziceni
Definition Romania.h:73
@ Drobeta
Definition Romania.h:70
@ Arad
Definition Romania.h:70
@ Bucharest
Definition Romania.h:70
@ NCities
Definition Romania.h:74
@ Craiova
Definition Romania.h:70
@ Fagaras
Definition Romania.h:71
@ Giurgiu
Definition Romania.h:71
static City find(const std::string &city_name)
the city called name, NCities if there is none
Definition Romania.h:110
Romania(City from=Arad, City to=Bucharest)
constructor of the trip from the city from to the city to
Definition Romania.h:83
static const std::array< Road, 23 > & roads(void)
the roads of figure 3.2 of the book
Definition Romania.h:120
static const char * name(std::uint32_t c)
the name of the city c
Definition Romania.h:97
namespace for the Parallel Best-First Search library
Definition AStar.h:83
a road and its length in km
Definition Romania.h:77
City a
Definition Romania.h:77
int km
Definition Romania.h:77
City b
Definition Romania.h:77