Skip to content

Commit 99aab68

Browse files
authored
Merge pull request #443 from Saloni-2005/week-1-bandwidth
Continued Week 1 bandwidth
2 parents 7d62acb + a869453 commit 99aab68

File tree

15 files changed

+682
-6
lines changed

15 files changed

+682
-6
lines changed

doc/metrics/metrics-family.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ Metrics - Family of functions
3333
* :doc:`pgr_betweennessCentrality` - Calculates relative betweenness centrality
3434
using Brandes Algorithm
3535

36+
* :doc:`pgr_bandwidth` - Computes the bandwidth of a graph.
37+
3638
.. experimental-end
3739
3840
.. toctree::
3941
:hidden:
4042

4143
pgr_degree
4244
pgr_betweennessCentrality
45+
pgr_bandwidth
4346

4447
See Also
4548
-------------------------------------------------------------------------------

doc/src/pgRouting-introduction.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Rajat Shinde,
145145
Razequl Islam,
146146
Regina Obe,
147147
Rohith Reddy,
148+
Saloni Kumari,
148149
Sarthak Agarwal,
149150
Shobhit Chaurasia,
150151
Sourabh Garg,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*PGR-GNU*****************************************************************
2+
File: graph_bandwidth_rt.h
3+
4+
Copyright (c) 2025 pgRouting developers
5+
6+
7+
Function's developer:
8+
Copyright (c) 2025 Saloni Kumari
9+
10+
11+
********************************************************************PGR-GNU*/
12+
#ifndef INCLUDE_C_TYPES_GRAPH_BANDWIDTH_RT_H_
13+
#define INCLUDE_C_TYPES_GRAPH_BANDWIDTH_RT_H_
14+
#pragma once
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
typedef struct {
21+
int id;
22+
int bandwidth;
23+
} GraphBandwidth_rt;
24+
25+
#ifdef __cplusplus
26+
}
27+
#endif
28+
29+
#endif // INCLUDE_C_TYPES_GRAPH_BANDWIDTH_RT_H_
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*PGR-GNU*****************************************************************
2+
File: bandwidth_driver.h
3+
4+
Generated with Template by:
5+
Copyright (c) 2025 pgRouting developers
6+
7+
8+
Function's developer:
9+
Copyright (c) 2025 Saloni Kumari
10+
11+
12+
------
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program; if not, write to the Free Software
26+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27+
28+
********************************************************************PGR-GNU*/
29+
30+
#ifndef INCLUDE_DRIVERS_METRICS_BANDWIDTH_DRIVER_H_
31+
#define INCLUDE_DRIVERS_METRICS_BANDWIDTH_DRIVER_H_
32+
#pragma once
33+
34+
/* for size_t */
35+
#ifdef __cplusplus
36+
# include <cstddef>
37+
using GraphBandwidth_rt = struct GraphBandwidth_rt;
38+
#else
39+
# include <stddef.h>
40+
# include <stdbool.h>
41+
typedef struct GraphBandwidth_rt GraphBandwidth_rt;
42+
#endif
43+
44+
#ifdef __cplusplus
45+
extern "C" {
46+
#endif
47+
48+
void
49+
pgr_bandwidth(
50+
const char* edges_sql,
51+
bool directed,
52+
GraphBandwidth_rt** result,
53+
size_t* result_count,
54+
char** log_msg,
55+
char** notice_msg);
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
60+
61+
#endif // INCLUDE_DRIVERS_METRICS_BANDWIDTH_DRIVER_H_

include/metrics/bandwidth.hpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*PGR-GNU*****************************************************************
2+
File: bandwidth.hpp
3+
4+
Copyright (c) 2025 pgRouting developers
5+
6+
7+
Copyright (c) 2025 Saloni Kumari
8+
9+
10+
------
11+
12+
This program is free software; you can redistribute it and/or modify
13+
it under the terms of the GNU General Public License as published by
14+
the Free Software Foundation; either version 2 of the License, or
15+
(at your option) any later version.
16+
17+
This program is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
GNU General Public License for more details.
21+
22+
You should have received a copy of the GNU General Public License
23+
along with this program; if not, write to the Free Software
24+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25+
26+
********************************************************************PGR-GNU*/
27+
28+
#ifndef INCLUDE_METRICS_BANDWIDTH_HPP_
29+
#define INCLUDE_METRICS_BANDWIDTH_HPP_
30+
#pragma once
31+
32+
#include <vector>
33+
#include <limits>
34+
35+
#include <boost/config.hpp>
36+
#include <boost/graph/adjacency_list.hpp>
37+
38+
#include "c_types/iid_t_rt.h"
39+
#include "cpp_common/base_graph.hpp"
40+
#include "cpp_common/interruption.hpp"
41+
42+
namespace pgrouting {
43+
namespace metrics {
44+
45+
template <class G>
46+
int bandwidth(const G &graph) {
47+
CHECK_FOR_INTERRUPTS();
48+
49+
using GraphType = typename std::remove_reference<decltype(graph.graph)>::type;
50+
using Vertex = typename boost::graph_traits<GraphType>::vertex_descriptor;
51+
52+
int bw = std::numeric_limits<int>::max();
53+
54+
// We need a vertex index map for consistent ordering
55+
auto index_map = boost::get(boost::vertex_index, graph.graph);
56+
57+
// Loop over all edges to compute max absolute difference of vertex indices
58+
typename boost::graph_traits<GraphType>::edge_iterator ei, ei_end;
59+
for (boost::tie(ei, ei_end) = boost::edges(graph.graph); ei != ei_end; ++ei) {
60+
Vertex u = boost::source(*ei, graph.graph);
61+
Vertex v = boost::target(*ei, graph.graph);
62+
63+
int diff = std::abs(static_cast<int>(index_map[u]) - static_cast<int>(index_map[v]));
64+
if (diff < bw) {
65+
bw = diff;
66+
}
67+
}
68+
69+
// If graph has no edges, bandwidth is zero
70+
if (bw == std::numeric_limits<int>::max()) {
71+
bw = 0;
72+
}
73+
return bw;
74+
}
75+
76+
} // namespace metrics
77+
} // namespace pgrouting
78+
79+
#endif // INCLUDE_METRICS_BANDWIDTH_HPP_
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*PGR-GNU*****************************************************************
2+
File: bandwidth_process.h
3+
4+
Function's developer:
5+
Copyright (c) 2025 Saloni kumari
6+
7+
8+
------
9+
10+
This program is free software; you can redistribute it and/or modify
11+
it under the terms of the GNU General Public License as published by
12+
the Free Software Foundation; either version 2 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software
22+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23+
24+
********************************************************************PGR-GNU*/
25+
26+
#ifndef INCLUDE_PROCESS_METRICS_BANDWIDTH_PROCESS_H_
27+
#define INCLUDE_PROCESS_METRICS_BANDWIDTH_PROCESS_H_
28+
#pragma once
29+
30+
#ifdef __cplusplus
31+
#include <cstddef>
32+
using GraphBandwidth_rt = struct GraphBandwidth_rt;
33+
#else
34+
#include <stddef.h>
35+
#include <stdbool.h>
36+
typedef struct GraphBandwidth_rt GraphBandwidth_rt;
37+
#endif
38+
39+
#ifdef __cplusplus
40+
extern "C" {
41+
#endif
42+
43+
void pgr_process_bandwidth(
44+
const char* edges_sql,
45+
GraphBandwidth_rt** result_tuples,
46+
size_t* result_count,
47+
char** log_msg,
48+
char** notice_msg);
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif // INCLUDE_PROCESS_METRICS_BANDWIDTH_PROCESS_H_

locale/en/LC_MESSAGES/pgrouting_doc_strings.po

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: pgRouting v3.8\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-05-31 14:26+0000\n"
11+
"POT-Creation-Date: 2025-06-07 22:16+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -3433,6 +3433,9 @@ msgid ""
34333433
"centrality using Brandes Algorithm"
34343434
msgstr ""
34353435

3436+
msgid ":doc:`pgr_bandwidth` - Computes the bandwidth of a graph."
3437+
msgstr ""
3438+
34363439
msgid ":doc:`TRSP-family`"
34373440
msgstr ""
34383441

@@ -7517,9 +7520,9 @@ msgid ""
75177520
"Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan, "
75187521
"Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, "
75197522
"Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, "
7520-
"Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen Woodbridge, "
7521-
"Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit Kumar, Vidhan "
7522-
"Jain, Virginia Vergara, Yige Huang"
7523+
"Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen "
7524+
"Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit "
7525+
"Kumar, Vidhan Jain, Virginia Vergara, Yige Huang"
75237526
msgstr ""
75247527

75257528
msgid "Corporate Sponsors (in alphabetical order)"

locale/pot/pgrouting_doc_strings.pot

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: pgRouting v4.0\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-05-31 14:26+0000\n"
11+
"POT-Creation-Date: 2025-06-07 22:16+0000\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -3106,6 +3106,9 @@ msgstr ""
31063106
msgid ":doc:`pgr_betweennessCentrality` - Calculates relative betweenness centrality using Brandes Algorithm"
31073107
msgstr ""
31083108

3109+
msgid ":doc:`pgr_bandwidth` - Computes the bandwidth of a graph."
3110+
msgstr ""
3111+
31093112
msgid ":doc:`TRSP-family`"
31103113
msgstr ""
31113114

@@ -6541,7 +6544,7 @@ msgstr ""
65416544
msgid "Individuals (in alphabetical order)"
65426545
msgstr ""
65436546

6544-
msgid "Aasheesh Tiwari, Abhinav Jain, Aditya Pratap Singh, Adrien Berchet, Akio Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Aryan Gupta, Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Cayetano Benavent, Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, David Techer, Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Florian Thurkow, Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang Wu, Himanshu Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, Kishore Kumar, Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit Kumar, Vidhan Jain, Virginia Vergara, Yige Huang"
6547+
msgid "Aasheesh Tiwari, Abhinav Jain, Aditya Pratap Singh, Adrien Berchet, Akio Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Aryan Gupta, Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Cayetano Benavent, Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, David Techer, Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Florian Thurkow, Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang Wu, Himanshu Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, Kishore Kumar, Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit Kumar, Vidhan Jain, Virginia Vergara, Yige Huang"
65456548
msgstr ""
65466549

65476550
msgid "Corporate Sponsors (in alphabetical order)"

sql/metrics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ SET(LOCAL_FILES
33
_betweennessCentrality.sql
44
betweennessCentrality.sql
55
degree.sql
6+
_bandwidth.sql
7+
bandwidth.sql
68
)
79

810
foreach (f ${LOCAL_FILES})

sql/metrics/_bandwidth.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
File: _bandwidth.sql
4+
5+
Template:
6+
Copyright (c) 2025 pgRouting developers
7+
8+
9+
Function developer:
10+
Copyright (c) 2025 Saloni Kumari
11+
12+
13+
This program is free software; you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation; either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
This program is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with this program; if not, write to the Free Software
25+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26+
27+
********************************************************************PGR-GNU*/
28+
29+
--------------------------------
30+
-- _pgr_bandwidth
31+
--------------------------------
32+
--v3.4.0
33+
CREATE FUNCTION _pgr_bandwidth(
34+
edges_sql TEXT,
35+
directed BOOLEAN,
36+
37+
OUT graph_id INTEGER,
38+
OUT bandwidth INTEGER
39+
)
40+
RETURNS SETOF RECORD AS
41+
'MODULE_PATHNAME'
42+
LANGUAGE C VOLATILE STRICT;
43+
44+
-- Comment
45+
COMMENT ON FUNCTION _pgr_bandwidth(TEXT, BOOLEAN)
46+
IS 'pgRouting internal function';

0 commit comments

Comments
 (0)