Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgr_edwardMoore GSOC-2019 week 11 - Pre Week Changes #27

Merged
merged 12 commits into from Aug 5, 2019
Merged
6 changes: 2 additions & 4 deletions configuration.conf
Expand Up @@ -30,16 +30,14 @@ vrp_basic | N | Y | Y
withPoints | Y | Y | Y
lineGraph | Y | Y | Y
components | Y | Y | Y
bellman_ford | Y | Y | Y
bellman_ford | Y | Y | N
cpp_common | Y | N | N
dagShortestPath | Y | Y | Y
chinese | Y | Y | Y
spanningTree | Y | Y | Y
mincut | Y | Y | Y
version | Y | Y | Y
breadthFirstSearch | Y | Y | N
binaryBreadthFirstSearch | Y | Y | N
edwardMoore | Y | Y | N
breadthFirstSearch | Y | Y | Y
#----------------------
# SQL only directories
#----------------------
Expand Down
12 changes: 0 additions & 12 deletions doc/binaryBreadthFirstSearch/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions doc/breadthFirstSearch/CMakeLists.txt
@@ -1,6 +1,7 @@

SET(LOCAL_FILES
pgr_breadthFirstSearch.rst
pgr_binaryBreadthFirstSearch.rst
)

foreach (f ${LOCAL_FILES})
Expand Down
1 change: 1 addition & 0 deletions docqueries/bellman_ford/CMakeLists.txt
@@ -1,6 +1,7 @@
# Do not use extensions
SET(LOCAL_FILES
doc-pgr_bellmanFord
doc-pgr_edwardMoore
)

foreach (f ${LOCAL_FILES})
Expand Down
86 changes: 86 additions & 0 deletions docqueries/bellman_ford/doc-pgr_edwardMoore.result
@@ -0,0 +1,86 @@
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
-- q1
SELECT * FROM pgr_edwardMoore(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
2, 3
);
seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
1 | 1 | 2 | 4 | 1 | 0
2 | 2 | 5 | 8 | 1 | 1
3 | 3 | 6 | 9 | 1 | 2
4 | 4 | 9 | 16 | 1 | 3
5 | 5 | 4 | 3 | 1 | 4
6 | 6 | 3 | -1 | 0 | 5
(6 rows)

-- q2
SELECT * FROM pgr_edwardMoore(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
2, 3,
FALSE
);
seq | path_seq | node | edge | cost | agg_cost
-----+----------+------+------+------+----------
1 | 1 | 2 | 2 | 1 | 0
2 | 2 | 3 | -1 | 0 | 1
(2 rows)

-- q3
SELECT * FROM pgr_edwardMoore(
'SELECT id, source, target, cost FROM edge_table',
2, ARRAY[3,5],
FALSE
);
seq | path_seq | end_vid | node | edge | cost | agg_cost
-----+----------+---------+------+------+------+----------
1 | 1 | 3 | 2 | 4 | 1 | 0
2 | 2 | 3 | 5 | 8 | 1 | 1
3 | 3 | 3 | 6 | 5 | 1 | 2
4 | 4 | 3 | 3 | -1 | 0 | 3
5 | 1 | 5 | 2 | 4 | 1 | 0
6 | 2 | 5 | 5 | -1 | 0 | 1
(6 rows)

-- q4
SELECT * FROM pgr_edwardMoore(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
ARRAY[2,11], 5
);
seq | path_seq | start_vid | node | edge | cost | agg_cost
-----+----------+-----------+------+------+------+----------
1 | 1 | 2 | 2 | 4 | 1 | 0
2 | 2 | 2 | 5 | -1 | 0 | 1
3 | 1 | 11 | 11 | 13 | 1 | 0
4 | 2 | 11 | 12 | 15 | 1 | 1
5 | 3 | 11 | 9 | 9 | 1 | 2
6 | 4 | 11 | 6 | 8 | 1 | 3
7 | 5 | 11 | 5 | -1 | 0 | 4
(7 rows)

-- q5
SELECT * FROM pgr_edwardMoore(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
ARRAY[2,11], ARRAY[3,5],
FALSE
);
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | 2 | 3 | 2 | 2 | 1 | 0
2 | 2 | 2 | 3 | 3 | -1 | 0 | 1
3 | 1 | 2 | 5 | 2 | 4 | 1 | 0
4 | 2 | 2 | 5 | 5 | -1 | 0 | 1
5 | 1 | 11 | 3 | 11 | 11 | 1 | 0
6 | 2 | 11 | 3 | 6 | 5 | 1 | 1
7 | 3 | 11 | 3 | 3 | -1 | 0 | 2
8 | 1 | 11 | 5 | 11 | 11 | 1 | 0
9 | 2 | 11 | 5 | 6 | 8 | 1 | 1
10 | 3 | 11 | 5 | 5 | -1 | 0 | 2
(10 rows)

-- q6
ROLLBACK;
ROLLBACK
2 changes: 2 additions & 0 deletions docqueries/bellman_ford/test.conf
Expand Up @@ -6,9 +6,11 @@
'data' => [ ],
'tests' => [qw(
doc-pgr_bellmanFord
doc-pgr_edwardMoore
)],
'documentation' => [qw(
doc-pgr_bellmanFord
doc-pgr_edwardMoore
)]
},

Expand Down
12 changes: 12 additions & 0 deletions docqueries/breadthFirstSearch/CMakeLists.txt
@@ -0,0 +1,12 @@
# Do not use extensions
SET(LOCAL_FILES
doc-pgr_breadthFirstSearch
doc-pgr_binaryBreadthFirstSearch
)

foreach (f ${LOCAL_FILES})
configure_file("${f}.result" "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries")
list(APPEND LOCAL_DOC_FILES "${PGR_DOCUMENTATION_SOURCE_DIR}/${f}.queries")
endforeach()

set(PGROUTING_DOC_FILES ${PGROUTING_DOC_FILES} ${LOCAL_DOC_FILES} PARENT_SCOPE)
Expand Up @@ -6,9 +6,11 @@
'data' => [ ],
'tests' => [qw(
doc-pgr_breadthFirstSearch
doc-pgr_binaryBreadthFirstSearch
)],
'documentation' => [qw(
doc-pgr_breadthFirstSearch
doc-pgr_binaryBreadthFirstSearch
)]
},

Expand Down
Expand Up @@ -18,25 +18,26 @@ 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_MST_PGR_EDWARDMOORE_HPP_
#define INCLUDE_MST_PGR_EDWARDMOORE_HPP_
#ifndef INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_
#define INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_
#pragma once

#include<limits>
#include<algorithm>
#include<vector>
#include <deque>


#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
//******************************************

namespace pgrouting
{
namespace functions
{
namespace pgrouting {
namespace functions {

template <class G>
class Pgr_edwardMoore
{
public:
class Pgr_edwardMoore {
public:
typedef typename G::V V;
typedef typename G::E E;
typedef typename G::B_G B_G;
Expand All @@ -46,13 +47,10 @@ class Pgr_edwardMoore
std::deque<Path> edwardMoore(
G &graph,
std::vector<int64_t> start_vertex,
std::vector<int64_t> end_vertex)
{

std::vector<int64_t> end_vertex) {
std::deque<Path> paths;

for (auto source : start_vertex)
{
for (auto source : start_vertex) {
std::deque<Path> result_paths = one_to_many_edwardMoore(
graph,
source,
Expand All @@ -76,19 +74,16 @@ class Pgr_edwardMoore
return paths;
}

private:
private:
E DEFAULT_EDGE;

std::deque<Path> one_to_many_edwardMoore(
G &graph,
int64_t start_vertex,
std::vector<int64_t> end_vertex)
{

std::vector<int64_t> end_vertex) {
std::deque<Path> paths;

if (graph.has_vertex(start_vertex) == false)
{
if (graph.has_vertex(start_vertex) == false) {
return paths;
}

Expand All @@ -104,8 +99,7 @@ class Pgr_edwardMoore
isInQ[bgl_start_vertex] = true;
dq.push_front(bgl_start_vertex);

while (dq.empty() == false)
{
while (dq.empty() == false) {
int64_t head_vertex = dq.front();

dq.pop_front();
Expand All @@ -114,17 +108,14 @@ class Pgr_edwardMoore
updateVertexCosts(graph, current_cost, isInQ, from_edge, dq, head_vertex);
}

for (auto target_vertex : end_vertex)
{
if (graph.has_vertex(target_vertex) == false)
{
for (auto target_vertex : end_vertex) {
if (graph.has_vertex(target_vertex) == false) {
continue;
}

int64_t bgl_target_vertex = graph.get_V(target_vertex);

if (from_edge[bgl_target_vertex] == DEFAULT_EDGE)
{
if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) {
continue;
}

Expand All @@ -141,16 +132,14 @@ class Pgr_edwardMoore
int64_t target,
int64_t bgl_target_vertex,
std::vector<E> &from_edge,
std::vector<double> &current_cost)
{
std::vector<double> &current_cost) {
int64_t current_node = bgl_target_vertex;

Path path = Path(graph[bgl_start_vertex].id, graph[current_node].id);

path.push_back({target, -1, 0, current_cost[current_node]});

do
{
do {
E e = from_edge[current_node];
auto from = graph.source(e);

Expand All @@ -169,40 +158,34 @@ class Pgr_edwardMoore
std::vector<bool> &isInQ,
std::vector<E> &from_edge,
std::deque<int64_t> &dq,
int64_t &head_vertex)
{
int64_t &head_vertex) {
auto out_edges = boost::out_edges(head_vertex, graph.graph);
E e;
EO_i out_i;
EO_i out_end;
V v_source, v_target;

for (boost::tie(out_i, out_end) = out_edges;
out_i != out_end; ++out_i)
{

out_i != out_end; ++out_i) {
e = *out_i;
v_target = graph.target(e);
v_source = graph.source(e);
double edge_cost = graph[e].cost;

if (std::isinf(current_cost[v_target]) or current_cost[v_source] + edge_cost < current_cost[v_target])
{

if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
current_cost[v_target] = current_cost[v_source] + edge_cost;

from_edge[v_target] = e;

if (isInQ[v_target] == false)
{
if (isInQ[v_target] == false) {
dq.push_back(v_target);
isInQ[v_target] = true;
}
}
}
}
};
} // namespace functions
} // namespace pgrouting
} // namespace functions
} // namespace pgrouting

#endif // INCLUDE_MST_PGR_EDWARDMOORE_HPP_
#endif // INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_
Expand Up @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

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

#ifndef INCLUDE_DRIVERS_EDWARDMOORE_EDWARDMOORE_DRIVER_H_
#define INCLUDE_DRIVERS_EDWARDMOORE_EDWARDMOORE_DRIVER_H_
#ifndef INCLUDE_DRIVERS_BELLMAN_FORD_EDWARDMOORE_DRIVER_H_
#define INCLUDE_DRIVERS_BELLMAN_FORD_EDWARDMOORE_DRIVER_H_
#pragma once

/* for size-t */
Expand Down Expand Up @@ -75,4 +75,4 @@ extern "C" {
}
#endif

#endif // INCLUDE_DRIVERS_EDWARDMOORE_EDWARDMOORE_DRIVER_H_
#endif // INCLUDE_DRIVERS_BELLMAN_FORD_EDWARDMOORE_DRIVER_H_
2 changes: 2 additions & 0 deletions sql/bellman_ford/CMakeLists.txt
Expand Up @@ -4,6 +4,8 @@ SET(LOCAL_FILES
bellman_ford.sql
#_bellman_ford_neg.sql
#bellman_ford_neg.sql
_edwardMoore.sql
edwardMoore.sql
)

# Do not modify bellow this line
Expand Down
Expand Up @@ -46,7 +46,7 @@ CREATE OR REPLACE FUNCTION _pgr_edwardMoore(
OUT agg_cost FLOAT)

RETURNS SETOF RECORD AS
'MODULE_PATHNAME', 'edwardMoore'
'MODULE_PATHNAME'
LANGUAGE c IMMUTABLE STRICT;


Expand Down
File renamed without changes.
12 changes: 0 additions & 12 deletions sql/binaryBreadthFirstSearch/CMakeLists.txt

This file was deleted.