Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions include/components/pgr_components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Pgr_components {
//! Articulation Points
std::vector<pgr_components_rt> articulationPoints(
G &graph);

//! Bridges
std::vector<pgr_components_rt> bridges(
G &graph);
private:
//! Generate Results, Vertex Version
std::vector<pgr_components_rt> generate_results(
Expand Down Expand Up @@ -199,4 +203,44 @@ Pgr_components< G >::articulationPoints(
return results;
}

//! Bridges
template < class G >
std::vector<pgr_components_rt>
Pgr_components< G >::bridges(
G &graph) {
size_t totalNodes = num_vertices(graph.graph);
std::vector< int > tmp_comp(totalNodes);
std::vector< E > res_bridges;
int ini_comps = boost::connected_components(graph.graph, &tmp_comp[0]);

// perform the algorithm
E_i ei, ei_end;
for (boost::tie(ei, ei_end) = edges(graph.graph); ei != ei_end; ++ei) {
boost::remove_edge(*ei, graph.graph);

int now_comps = boost::connected_components(graph.graph, &tmp_comp[0]);
if (now_comps > ini_comps) {
res_bridges.push_back(*ei);
}

boost::add_edge(boost::source(*ei, graph.graph),
boost::target(*ei, graph.graph),
graph.graph);
}

// get the results
std::vector <pgr_components_rt> results;
size_t totalBridges = res_bridges.size();
results.resize(totalBridges);
for (size_t i = 0; i < totalBridges; i++)
results[i].identifier = graph[res_bridges[i]].id;

// sort identifier
std::sort(results.begin(), results.end(),
[](const pgr_components_rt &left, const pgr_components_rt &right) {
return left.identifier < right.identifier; });

return results;
}

#endif // INCLUDE_COMPONENTS_PGR_COMPONENTS_HPP_
63 changes: 63 additions & 0 deletions include/drivers/components/bridges_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*PGR-GNU*****************************************************************
File: bridges_driver.h

Generated with Template by:
Copyright (c) 2015 pgRouting developers
Mail: project@pgrouting.org

Function's developer:
Copyright (c) 2015 Celia Virginia Vergara Castillo
Mail: vicky_vergara@hotmail.com

------

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) 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 General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

#ifndef INCLUDE_DRIVERS_COMPONENTS_BRIDGES_DRIVER_H_
#define INCLUDE_DRIVERS_COMPONENTS_BRIDGES_DRIVER_H_
#pragma once

#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_components_rt.h"

#ifdef __cplusplus
extern "C" {
#endif

/*********************************************************
TEXT,
BIGINT,
BIGINT,
********************************************************/


void
do_pgr_bridges(
pgr_edge_t *data_edges,
size_t total_edges,
pgr_components_rt **return_tuples,
size_t *return_count,
char ** log_msg,
char ** notice_msg,
char ** err_msg);


#ifdef __cplusplus
}
#endif

#endif // INCLUDE_DRIVERS_COMPONENTS_BRIDGES_DRIVER_H_
1 change: 1 addition & 0 deletions sql/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SET(LOCAL_FILES
strongComponentsV.sql
biconnectedComponents.sql
articulationPoints.sql
bridges.sql
)

# Do not modify bellow this line
Expand Down
38 changes: 38 additions & 0 deletions sql/components/bridges.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*PGR-GNU*****************************************************************
File: bridges.sql

Generated with Template by:
Copyright (c) 2016 pgRouting developers
Mail: project@pgrouting.org

Function's developer:
Copyright (c) 2017 Celia Virginia Vergara Castillo
Mail: vicky_vergara@hotmail.com

------

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) 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 General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

CREATE OR REPLACE FUNCTION pgr_bridges(
TEXT, -- edges_sql
OUT seq INTEGER, -- seq
OUT edge BIGINT) -- the number of the edge

RETURNS SETOF RECORD AS
'$libdir/${PGROUTING_LIBRARY_NAME}', 'bridges'
LANGUAGE c IMMUTABLE STRICT;

4 changes: 3 additions & 1 deletion src/components/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ ADD_LIBRARY(components OBJECT
strongComponentsV.c
biconnectedComponents.c
articulationPoints.c
bridges.c

connectedComponentsV_driver.cpp
strongComponentsV_driver.cpp
biconnectedComponents_driver.cpp
articulationPoints_driver.cpp)
articulationPoints_driver.cpp
bridges_driver.cpp)
2 changes: 1 addition & 1 deletion src/components/src/articulationPoints_driver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
File: connectedComponentsV_driver.cpp
File: articulationPoints_driver.cpp

Generated with Template by:
Copyright (c) 2015 pgRouting developers
Expand Down
Loading