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
100 changes: 50 additions & 50 deletions include/drivers/metrics_driver.hpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/*PGR-GNU*****************************************************************
File: metrics_driver.hpp
Copyright (c) 2025 pgRouting developers
Mail: project@pgrouting.org
Developer:
Copyright (c) 2025 Saloni Kumari
Mail: chaudharysaloni2510 at gmail.com
Generated with Template by:
Copyright (c) 2025 pgRouting developers
Mail: project@pgrouting.org
------
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_METRICS_DRIVER_HPP_
#define INCLUDE_DRIVERS_METRICS_DRIVER_HPP_
#pragma once
#include <cstddef>
#include <string>
#include <cstdint>
#include "c_types/iid_t_rt.h"
void
do_metrics(
std::string,
int,
IID_t_rt**, size_t*,
char**, char**);
#endif // INCLUDE_DRIVERS_METRICS_DRIVER_HPP_
/*PGR-GNU*****************************************************************
File: metrics_driver.hpp

Copyright (c) 2025 pgRouting developers
Mail: project@pgrouting.org

Developer:
Copyright (c) 2025 Saloni Kumari
Mail: chaudharysaloni2510 at gmail.com

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

------

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_METRICS_DRIVER_HPP_
#define INCLUDE_DRIVERS_METRICS_DRIVER_HPP_
#pragma once

#include <cstddef>
#include <string>
#include <cstdint>

#include "c_types/iid_t_rt.h"
void
do_metrics(
std::string,
int,

IID_t_rt**, size_t*,
char**, char**);

#endif // INCLUDE_DRIVERS_METRICS_DRIVER_HPP_
48 changes: 18 additions & 30 deletions include/metrics/bandwidth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#pragma once

#include <vector>
#include <limits>
#include <numeric>
#include <cstdint>

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/bandwidth.hpp>

#include "c_types/iid_t_rt.h"
#include "cpp_common/base_graph.hpp"
#include "cpp_common/interruption.hpp"

namespace pgrouting {
namespace metrics {

template <class G>
int bandwidth(const G &graph) {
CHECK_FOR_INTERRUPTS();

using GraphType = typename std::remove_reference<decltype(graph.graph)>::type;
using Vertex = typename boost::graph_traits<GraphType>::vertex_descriptor;

int bw = std::numeric_limits<int>::max();

// We need a vertex index map for consistent ordering
auto index_map = boost::get(boost::vertex_index, graph.graph);

// Loop over all edges to compute max absolute difference of vertex indices
typename boost::graph_traits<GraphType>::edge_iterator ei, ei_end;
for (boost::tie(ei, ei_end) = boost::edges(graph.graph); ei != ei_end; ++ei) {
Vertex u = boost::source(*ei, graph.graph);
Vertex v = boost::target(*ei, graph.graph);

int diff = std::abs(static_cast<int>(index_map[u]) - static_cast<int>(index_map[v]));
if (diff < bw) {
bw = diff;
}
}

// If graph has no edges, bandwidth is zero
if (bw == std::numeric_limits<int>::max()) {
bw = 0;
uint64_t bandwidth(const G &graph) {
CHECK_FOR_INTERRUPTS();

try {
const auto& boost_graph = graph.graph;

return static_cast<uint64_t>(boost::bandwidth(boost_graph));
} catch (boost::exception const& ex) {
(void)ex;
throw;
} catch (std::exception &e) {
(void)e;
throw;
} catch (...) {
throw;
}
return bw;
}

} // namespace metrics
Expand Down
15 changes: 7 additions & 8 deletions pgtap/metrics/bandwidth/types_check.pg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

Copyright (c) 2018 pgRouting developers
Copyright (c) 2025 pgRouting developers
Mail: project@pgrouting.org

------
Expand All @@ -19,32 +19,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
BEGIN;

SELECT CASE WHEN NOT min_version('4.0.0') THEN plan(1) ELSE plan(5) END;
SELECT CASE WHEN min_version('4.0.0') THEN plan(5) ELSE plan(1) END;

CREATE OR REPLACE FUNCTION types_check()
RETURNS SETOF TEXT AS
$BODY$
BEGIN

IF NOT min_version('4.0.0') THEN
RETURN QUERY
SELECT skip(1, 'pgr_bandwidth:Function is new on 4.0.0');
RETURN QUERY SELECT skip(1, 'pgr_bandwidth:Function is new on 4.0.0');
RETURN;
END IF;

RETURN QUERY SELECT has_function('pgr_bandwidth');
RETURN QUERY SELECT has_function('pgr_bandwidth', ARRAY['text']);
RETURN QUERY SELECT function_returns('pgr_bandwidth', ARRAY['text'], 'BIGINT');
RETURN QUERY SELECT function_returns('pgr_bandwidth', ARRAY['text'], 'bigint');

RETURN QUERY
SELECT function_args_eq('pgr_bandwidth',
$$SELECT '{""}'::TEXT[] $$
$$SELECT ('{"",bandwidth}'::TEXT[]) $$
);

RETURN QUERY
SELECT function_types_eq('pgr_cuthillmckeeordering',
SELECT function_types_eq('pgr_bandwidth',
$$VALUES
('{text}'::TEXT[])
('{text, int8}'::TEXT[])
$$
);
END;
Expand Down
122 changes: 61 additions & 61 deletions src/metrics/bandwidth.c
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
/*PGR-GNU*****************************************************************
File: bandwidth.c
Generated with Template by:
Copyright (c) 2025 pgRouting developers
Mail: project@pgrouting.org
Function's developer:
Copyright (c) 2025 Saloni Kumari
Mail: chaudharysaloni2510 at gmail.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*/
#include <stdbool.h>
#include "c_common/postgres_connection.h"
#include "c_types/iid_t_rt.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
#include "process/metrics_process.h"
PGDLLEXPORT Datum _pgr_bandwidth(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(_pgr_bandwidth);
PGDLLEXPORT Datum
_pgr_bandwidth(PG_FUNCTION_ARGS) {
IID_t_rt *result_tuples = NULL;
size_t result_count = 0;
pgr_process_metrics(
text_to_cstring(PG_GETARG_TEXT_P(0)),
0, /* bandwidth */
&result_tuples,
&result_count);
if (result_count == 0) {
PG_RETURN_UINT64(0);
} else {
PG_RETURN_UINT64(result_tuples[0].from_vid);
}
}
/*PGR-GNU*****************************************************************
File: bandwidth.c

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

Function's developer:
Copyright (c) 2025 Saloni Kumari
Mail: chaudharysaloni2510 at gmail.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*/

#include <stdbool.h>
#include "c_common/postgres_connection.h"

#include "c_types/iid_t_rt.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"

#include "process/metrics_process.h"

PGDLLEXPORT Datum _pgr_bandwidth(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(_pgr_bandwidth);


PGDLLEXPORT Datum
_pgr_bandwidth(PG_FUNCTION_ARGS) {
IID_t_rt *result_tuples = NULL;
size_t result_count = 0;

pgr_process_metrics(
text_to_cstring(PG_GETARG_TEXT_P(0)),
0, /* bandwidth */
&result_tuples,
&result_count);

if (result_count == 0) {
PG_RETURN_UINT64(0);
} else {
PG_RETURN_UINT64((uint64_t)result_tuples[0].from_vid);
}
}

Loading
Loading