Skip to content

Commit

Permalink
Using boolean instead of enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvergara committed Feb 22, 2024
1 parent 0680320 commit 8b89570
Show file tree
Hide file tree
Showing 53 changed files with 126 additions and 183 deletions.
6 changes: 3 additions & 3 deletions include/contraction/pgr_contractionGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge> {
typedef typename boost::graph_traits < G >::in_edge_iterator EI_i;

/*!
Prepares the _graph_ to be of type *gtype*
Prepares the _graph_ to be of type *directed*
*/
explicit Pgr_contractionGraph<G>(graphType gtype)
: Pgr_base_graph<G, CH_vertex, CH_edge >(gtype) {
explicit Pgr_contractionGraph<G>(bool directed)
: Pgr_base_graph<G, CH_vertex, CH_edge >(directed) {
}

/*! @brief get the vertex descriptors of adjacent vertices of *v*
Expand Down
36 changes: 16 additions & 20 deletions include/cpp_common/pgr_base_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>

#include "cpp_common/graph_enum.hpp"

#include "cpp_common/basic_vertex.hpp"
#include "cpp_common/xy_vertex.hpp"
#include "cpp_common/basic_edge.hpp"
Expand Down Expand Up @@ -129,20 +127,20 @@ std::vector< Basic_Vertex > vertices(pgrouting::extract_vertices(my_edges));
There are several ways to initialize the graph
~~~~{.c}
// 1. Initializes an empty graph
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(true);
// 2. Initializes a graph based on the vertices
pgrouting::DirectedGraph digraph(
verices,
gType);
true);
vertices.clear();
3. Initializes a graph based on the extracted vertices
pgrouting::DirectedGraph digraph(
pgrouting::extract_vertices(my_edges, total_edges);
gType);
true);
4. Initializes a graph based on the extracted vertices
pgrouting::DirectedGraph digraph(
pgrouting::extract_vertices(my_edges);
gType);
true);
~~~~
1. Initializes an empty graph
- vertices vector size is 0
Expand Down Expand Up @@ -262,7 +260,7 @@ class Pgr_base_graph {
//! @name The Graph
//@{
G graph; //!< The graph
graphType m_gType; //!< type (DIRECTED or UNDIRECTED)
bool m_is_directed; //!< type (DIRECTED or UNDIRECTED)
//@}

//! @name Id mapping handling
Expand Down Expand Up @@ -297,12 +295,12 @@ class Pgr_base_graph {
- The vertices must be checked (if necessary) before calling the constructor
*/
Pgr_base_graph< G , T_V, T_E >(
const std::vector< T_V > &vertices, graphType gtype)
const std::vector< T_V > &vertices, bool directed)
: graph(vertices.size()),
#if 0
m_num_vertices(vertices.size()),
#endif
m_gType(gtype),
m_is_directed(directed),
vertIndex(boost::get(boost::vertex_index, graph)),
propmapIndex(mapIndex) {
// add_vertices(vertices);
Expand Down Expand Up @@ -339,12 +337,12 @@ class Pgr_base_graph {
/*!
Prepares the _graph_ to be of type gtype with 0 vertices
*/
explicit Pgr_base_graph< G , T_V, T_E >(graphType gtype)
explicit Pgr_base_graph< G , T_V, T_E >(bool directed)
: graph(0),
#if 0
m_num_vertices(0),
#endif
m_gType(gtype),
m_is_directed(directed),
vertIndex(boost::get(boost::vertex_index, graph)),
propmapIndex(mapIndex) {
}
Expand Down Expand Up @@ -552,8 +550,8 @@ class Pgr_base_graph {
//! @name to be or not to be
//@{

bool is_directed() const {return m_gType == DIRECTED;}
bool is_undirected() const {return m_gType == UNDIRECTED;}
bool is_directed() const {return m_is_directed;}
bool is_undirected() const {return !m_is_directed;}
bool is_source(V v_idx, E e_idx) const {return v_idx == source(e_idx);}
bool is_target(V v_idx, E e_idx) const {return v_idx == target(e_idx);}

Expand Down Expand Up @@ -857,7 +855,7 @@ Pgr_base_graph< G, T_V, T_E >::disconnect_vertex(V vertex) {
}

// special case
if (m_gType == DIRECTED) {
if (m_is_directed) {
EI_i in, in_end;
for (boost::tie(in, in_end) = in_edges(vertex, graph);
in != in_end; ++in) {
Expand Down Expand Up @@ -968,8 +966,7 @@ Pgr_base_graph< G, T_V, T_E >::graph_add_edge(const T &edge, bool normal) {
}

if (edge.reverse_cost >= 0
&& (m_gType == DIRECTED
|| (m_gType == UNDIRECTED && edge.cost != edge.reverse_cost))) {
&& (m_is_directed || (!m_is_directed && edge.cost != edge.reverse_cost))) {
boost::tie(e, inserted) =
boost::add_edge(vm_t, vm_s, graph);

Expand Down Expand Up @@ -1014,8 +1011,7 @@ Pgr_base_graph< G, T_V, T_E >::graph_add_min_edge_no_parallel(const T &edge) {
}

if (edge.reverse_cost >= 0
&& (m_gType == DIRECTED
|| (m_gType == UNDIRECTED && edge.cost != edge.reverse_cost))) {
&& (m_is_directed || (!m_is_directed && edge.cost != edge.reverse_cost))) {
E e1;
bool found;
boost::tie(e1, found) = boost::edge(vm_t, vm_s, graph);
Expand Down Expand Up @@ -1064,8 +1060,8 @@ Pgr_base_graph< G, T_V, T_E >::graph_add_neg_edge(const T &edge, bool normal) {
}
graph[e].id = edge.id;

if (m_gType == DIRECTED
|| (m_gType == UNDIRECTED && edge.cost > edge.reverse_cost)) {
if (m_is_directed
|| (!m_is_directed && edge.cost > edge.reverse_cost)) {
boost::tie(e, inserted) =
boost::add_edge(vm_t, vm_s, graph);
if (edge.reverse_cost < 0) {
Expand Down
6 changes: 3 additions & 3 deletions include/lineGraph/pgr_lineGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class Pgr_lineGraph : public Pgr_base_graph<G, T_V, T_E> {
typedef typename boost::graph_traits < G >::in_edge_iterator EI_i;


explicit Pgr_lineGraph< G, T_V, T_E >(graphType gtype)
: Pgr_base_graph< G, T_V, T_E >(gtype) {
explicit Pgr_lineGraph< G, T_V, T_E >(bool directed)
: Pgr_base_graph< G, T_V, T_E >(directed) {
}

explicit Pgr_lineGraph< G, T_V, T_E >(const pgrouting::DirectedGraph &digraph)
: Pgr_base_graph< G, T_V, T_E >(graphType::DIRECTED) {
: Pgr_base_graph< G, T_V, T_E >(true) {
insert_vertices(digraph);
create_edges(digraph);
}
Expand Down
6 changes: 3 additions & 3 deletions include/lineGraph/pgr_lineGraphFull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class Pgr_lineGraphFull : public Pgr_base_graph<G, T_V, T_E> {
typedef typename boost::graph_traits < G >::in_edge_iterator EI_i;


explicit Pgr_lineGraphFull< G, T_V, T_E >(const graphType &gtype)
: Pgr_base_graph< G, T_V, T_E >(gtype),
explicit Pgr_lineGraphFull< G, T_V, T_E >(bool directed)
: Pgr_base_graph< G, T_V, T_E >(directed),
m_num_edges(0) {
}

explicit Pgr_lineGraphFull< G, T_V, T_E >(const pgrouting::DirectedGraph &digraph)
: Pgr_base_graph< G, T_V, T_E >(graphType::DIRECTED) {
: Pgr_base_graph< G, T_V, T_E >(true) {
apply_transformation(digraph);
store_edge_costs(digraph);
}
Expand Down
10 changes: 4 additions & 6 deletions src/allpairs/floydWarshall_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
void
pgr_do_floydWarshall(
char *edges_sql,
bool directedFlag,
bool directed,

IID_t_rt **return_tuples,
size_t *return_count,
Expand All @@ -62,8 +62,6 @@ pgr_do_floydWarshall(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directedFlag? DIRECTED: UNDIRECTED;

hint = edges_sql;
auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, true);

Expand All @@ -72,14 +70,14 @@ pgr_do_floydWarshall(
}
hint = nullptr;

if (directedFlag) {
if (directed) {
log << "Processing Directed graph\n";
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);
pgr_floydWarshall(digraph, *return_count, return_tuples);
} else {
log << "Processing Undirected graph\n";
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);
pgr_floydWarshall(undigraph, *return_count, return_tuples);
}
Expand Down
6 changes: 2 additions & 4 deletions src/allpairs/johnson_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ pgr_do_johnson(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directed? DIRECTED: UNDIRECTED;

hint = edges_sql;
auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, true);

Expand All @@ -73,12 +71,12 @@ pgr_do_johnson(

if (directed) {
log << "Processing Directed graph\n";
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);
pgr_johnson(digraph, *return_count, return_tuples);
} else {
log << "Processing Undirected graph\n";
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);
pgr_johnson(undigraph, *return_count, return_tuples);
}
Expand Down
2 changes: 1 addition & 1 deletion src/alpha_shape/pgr_alphaShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct CompareRadius {
* Constructor
*/
Pgr_alphaShape::Pgr_alphaShape(const std::vector<Edge_xy_t> &edges) :
graph(UNDIRECTED) {
graph(false) {
graph.insert_edges(edges);
make_triangles();
}
Expand Down
6 changes: 3 additions & 3 deletions src/astar/astar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ void pgr_do_astar(
}


graphType gType = directed? DIRECTED: UNDIRECTED;


std::deque<Path> paths;
if (directed) {
pgrouting::xyDirectedGraph graph(gType);
pgrouting::xyDirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgrouting::algorithms::astar(graph, combinations, heuristic, factor, epsilon, only_cost);
} else {
pgrouting::xyUndirectedGraph graph(gType);
pgrouting::xyUndirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgrouting::algorithms::astar(graph, combinations, heuristic, factor, epsilon, only_cost);
}
Expand Down
6 changes: 3 additions & 3 deletions src/bdAstar/bdAstar_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void pgr_do_bdAstar(
}
hint = nullptr;

graphType gType = directed? DIRECTED: UNDIRECTED;


std::deque<Path> paths;
if (directed) {
pgrouting::xyDirectedGraph graph(gType);
pgrouting::xyDirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgrouting::algorithms::bdastar(graph, combinations, heuristic, factor, epsilon, only_cost);
} else {
pgrouting::xyUndirectedGraph graph(gType);
pgrouting::xyUndirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgrouting::algorithms::bdastar(graph, combinations, heuristic, factor, epsilon, only_cost);
}
Expand Down
6 changes: 3 additions & 3 deletions src/bdDijkstra/bdDijkstra_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pgr_do_bdDijkstra(
return;
}

graphType gType = directed? DIRECTED: UNDIRECTED;


hint = edges_sql;
auto edges = pgrouting::pgget::get_edges(std::string(edges_sql), true, false);
Expand All @@ -136,11 +136,11 @@ pgr_do_bdDijkstra(
std::deque<Path> paths;

if (directed) {
pgrouting::DirectedGraph graph(gType);
pgrouting::DirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgr_bdDijkstra(graph, combinations, only_cost);
} else {
pgrouting::UndirectedGraph graph(gType);
pgrouting::UndirectedGraph graph(directed);
graph.insert_edges(edges);
paths = pgr_bdDijkstra(graph, combinations, only_cost);
}
Expand Down
6 changes: 3 additions & 3 deletions src/bellman_ford/bellman_ford_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pgr_do_bellman_ford(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directed? DIRECTED: UNDIRECTED;


hint = combinations_sql;
auto combinations = get_combinations(combinations_sql, starts, ends, true);
Expand All @@ -151,11 +151,11 @@ pgr_do_bellman_ford(

std::deque<Path> paths;
if (directed) {
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);
paths = bellman_ford(digraph, combinations, only_cost);
} else {
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);
paths = bellman_ford(undigraph, combinations, only_cost);
}
Expand Down
6 changes: 3 additions & 3 deletions src/bellman_ford/bellman_ford_neg_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pgr_do_bellman_ford_neg(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directed? DIRECTED: UNDIRECTED;


hint = combinations_sql;
auto combinations = get_combinations(combinations_sql, starts, ends, normal);
Expand Down Expand Up @@ -154,12 +154,12 @@ pgr_do_bellman_ford_neg(

std::deque<Path> paths;
if (directed) {
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);
digraph.insert_negative_edges(neg_edges);
paths = bellman_ford(digraph, combinations, only_cost);
} else {
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);
undigraph.insert_negative_edges(neg_edges);
paths = pgr_bellman_ford(undigraph, combinations, only_cost);
Expand Down
6 changes: 3 additions & 3 deletions src/bellman_ford/edwardMoore_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pgr_do_edwardMoore(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directed? DIRECTED: UNDIRECTED;


hint = combinations_sql;
auto combinations = get_combinations(combinations_sql, starts, ends, true);
Expand All @@ -146,11 +146,11 @@ pgr_do_edwardMoore(

std::deque<Path> paths;
if (directed) {
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);
paths = edwardMoore(digraph, combinations);
} else {
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);
paths = edwardMoore(undigraph, combinations);
}
Expand Down
6 changes: 3 additions & 3 deletions src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pgr_do_binaryBreadthFirstSearch(
pgassert(!(*return_tuples));
pgassert(*return_count == 0);

graphType gType = directed? DIRECTED: UNDIRECTED;


hint = combinations_sql;
auto combinations = get_combinations(combinations_sql, starts, ends, true);
Expand All @@ -179,7 +179,7 @@ pgr_do_binaryBreadthFirstSearch(

std::deque< Path >paths;
if (directed) {
pgrouting::DirectedGraph digraph(gType);
pgrouting::DirectedGraph digraph(directed);
digraph.insert_edges(edges);

if (!(costCheck(digraph))) {
Expand All @@ -190,7 +190,7 @@ pgr_do_binaryBreadthFirstSearch(
paths = binaryBreadthFirstSearch(digraph, combinations);

} else {
pgrouting::UndirectedGraph undigraph(gType);
pgrouting::UndirectedGraph undigraph(directed);
undigraph.insert_edges(edges);

if (!(costCheck(undigraph))) {
Expand Down
Loading

0 comments on commit 8b89570

Please sign in to comment.