Skip to content

Commit 84354c5

Browse files
authored
Merge pull request #179 from veenits123/week5-july5-july11
GSoC-2021 Week5: pgr_edgeColoring
2 parents a005f60 + 75e213c commit 84354c5

File tree

5 files changed

+119
-53
lines changed

5 files changed

+119
-53
lines changed

.github/workflows/update.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19+
<<<<<<< HEAD
20+
<<<<<<< HEAD
1921
old_pgr: [3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0]
22+
=======
23+
old_pgr: [3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0, 3.1.1, 3.1.2, 3.1.3]
24+
>>>>>>> origin/main
25+
=======
26+
old_pgr: [3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0]
27+
>>>>>>> 9509fa40c40867ba9a153c61ad09a91f4da342e0
2028

2129
steps:
2230
- uses: actions/checkout@v2
@@ -97,7 +105,15 @@ jobs:
97105
- name: Test old version after update
98106
run: |
99107
sudo service postgresql start
108+
<<<<<<< HEAD
109+
<<<<<<< HEAD
110+
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.0';"
111+
=======
112+
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.2.0';"
113+
>>>>>>> origin/main
114+
=======
100115
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.0';"
116+
>>>>>>> 9509fa40c40867ba9a153c61ad09a91f4da342e0
101117
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();"
102118
sudo -u postgres bash ./tools/testers/pg_prove_tests.sh postgres 5432
103119
sudo -u postgres dropdb -p 5432 ___pgr___test___
@@ -113,6 +129,14 @@ jobs:
113129
114130
- name: Test old version with new lib after update
115131
run: |
132+
<<<<<<< HEAD
133+
<<<<<<< HEAD
134+
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.0';"
135+
=======
136+
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.2.0';"
137+
>>>>>>> origin/main
138+
=======
116139
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.0';"
140+
>>>>>>> 9509fa40c40867ba9a153c61ad09a91f4da342e0
117141
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();"
118142
sudo -u postgres bash ./tools/testers/pg_prove_tests.sh postgres 5432

include/coloring/pgr_edgeColoring.hpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,48 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3030
#include <boost/config.hpp>
3131
#include <boost/graph/adjacency_list.hpp>
3232

33-
#include <iostream>
34-
#include <limits>
3533
#include <map>
3634
#include <vector>
3735

38-
#include "cpp_common/basic_edge.h"
39-
#include "cpp_common/basic_vertex.h"
36+
#include "c_types/pgr_edge_t.h"
37+
#include "c_types/pgr_vertex_color_rt.h"
4038
#include "cpp_common/pgr_assert.h"
4139
#include "cpp_common/pgr_messages.h"
4240

4341
namespace pgrouting {
4442
namespace functions {
4543

4644
class Pgr_edgeColoring : public Pgr_messages {
47-
public:
45+
public:
4846
using EdgeColoring_Graph =
49-
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, pgrouting::Basic_vertex, size_t,
50-
pgrouting::Basic_edge>;
47+
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property,
48+
size_t, boost::no_property>;
5149

5250
using V = boost::graph_traits<EdgeColoring_Graph>::vertex_descriptor;
5351
using E = boost::graph_traits<EdgeColoring_Graph>::edge_descriptor;
5452
using V_it = boost::graph_traits<EdgeColoring_Graph>::vertex_iterator;
5553
using E_it = boost::graph_traits<EdgeColoring_Graph>::edge_iterator;
5654

57-
std::vector<pgr_vertex_color_rt> edgeColoring(EdgeColoring_Graph&);
55+
public:
5856

59-
void insert_edges(EdgeColoring_Graph&, pgr_edge_t*, size_t);
57+
std::vector<pgr_vertex_color_rt> edgeColoring();
6058

61-
#if 0
59+
Pgr_edgeColoring(pgr_edge_t*, size_t);
6260
Pgr_edgeColoring() = delete;
63-
#endif
6461

6562
#if 0
6663
#if Boost_VERSION_MACRO >= 106800
6764
friend std::ostream& operator<<(std::ostream &, const Pgr_edgeColoring&);
6865
#endif
6966
#endif
7067

71-
private:
68+
private:
69+
V get_boost_vertex(int64_t id) const;
70+
int64_t get_vertex_id(V v) const;
71+
int64_t get_edge_id(E e) const;
72+
73+
74+
private:
7275
EdgeColoring_Graph graph;
7376
std::map<int64_t, V> id_to_V;
7477
std::map<V, int64_t> V_to_id;

src/coloring/edgeColoring_driver.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2828

2929
#include "drivers/coloring/edgeColoring_driver.h"
3030

31-
#include <algorithm>
32-
#include <sstream>
33-
#include <string>
3431
#include <vector>
3532

36-
#include "c_types/graph_enum.h"
3733
#include "coloring/pgr_edgeColoring.hpp"
34+
35+
#include "c_types/graph_enum.h"
3836
#include "cpp_common/pgr_alloc.hpp"
3937
#include "cpp_common/pgr_assert.h"
4038

@@ -66,11 +64,9 @@ void do_pgr_edgeColoring(
6664
graphType gType = UNDIRECTED;
6765
pgrouting::functions::Pgr_edgeColoring::EdgeColoring_Graph undigraph(gType);
6866

69-
pgrouting::functions::Pgr_edgeColoring fn_edgeColoring;
70-
71-
fn_edgeColoring.insert_edges(undigraph, data_edges, total_edges);
67+
pgrouting::functions::Pgr_edgeColoring fn_edgeColoring {data_edges, total_edges};
7268

73-
results = fn_edgeColoring.edgeColoring(undigraph);
69+
results = fn_edgeColoring.edgeColoring();
7470

7571
auto count = results.size();
7672

src/coloring/pgr_edgeColoring.cpp

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2626
2727
********************************************************************PGR-GNU*/
2828

29-
#include <boost/graph/adjacency_list.hpp>
29+
#include "coloring/pgr_edgeColoring.hpp"
3030
#include <boost/graph/edge_coloring.hpp>
3131
#include <boost/graph/graph_utility.hpp>
32-
#include <boost/graph/iteration_macros.hpp>
3332

34-
#include <sstream>
35-
#include <string>
3633
#include <vector>
37-
#include <algorithm>
38-
39-
#include "drivers/coloring/edgeColoring_driver.h"
40-
#include "coloring/pgr_edgeColoring.hpp"
4134

42-
#include "cpp_common/pgr_alloc.hpp"
35+
#include "cpp_common/identifiers.hpp"
4336
#include "cpp_common/pgr_assert.h"
4437

45-
namespace {
46-
47-
typedef typename boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, pgrouting::Basic_vertex, size_t,
48-
pgrouting::Basic_edge>
49-
EdgeColoring_Graph;
50-
typedef typename boost::graph_traits<EdgeColoring_Graph>::vertex_descriptor V;
51-
typedef typename boost::graph_traits<EdgeColoring_Graph>::edge_descriptor E;
52-
typedef typename boost::graph_traits<EdgeColoring_Graph>::vertex_iterator V_it;
53-
typedef typename boost::graph_traits<EdgeColoring_Graph>::edge_iterator E_it;
54-
55-
} // namespace
5638

5739
namespace pgrouting {
5840
namespace functions {
5941

6042
std::vector<pgr_vertex_color_rt>
61-
Pgr_edgeColoring::edgeColoring(EdgeColoring_Graph &graph) {
43+
Pgr_edgeColoring::edgeColoring() {
6244
std::vector<pgr_vertex_color_rt> results;
6345

64-
auto i_map = boost::get(boost::edge_bundle, graph);
65-
66-
std::vector<size_t> colors(boost::num_edges(graph));
67-
68-
auto color_map = boost::make_iterator_property_map(colors.begin(), i_map);
69-
7046
#if 0
7147
CHECK_FOR_INTERRUPTS();
7248
#endif
7349

7450
try {
75-
boost::edge_coloring(graph, color_map);
51+
boost::edge_coloring(graph, boost::get(boost::edge_bundle, graph));
7652
} catch (boost::exception const &ex) {
7753
(void)ex;
7854
throw;
@@ -84,16 +60,48 @@ Pgr_edgeColoring::edgeColoring(EdgeColoring_Graph &graph) {
8460
}
8561

8662
for (auto e_i : boost::make_iterator_range(boost::edges(graph))) {
87-
int64_t edge = E_to_id[e_i];
88-
int64_t color = colors[edge];
63+
auto edge = E_to_id[e_i];
64+
int64_t color = graph[e_i];
8965
results.push_back({edge, (color + 1)});
9066
}
9167
return results;
9268
}
9369

94-
void Pgr_edgeColoring::insert_edges(EdgeColoring_Graph &graph, pgr_edge_t *edges, size_t count) {
95-
for (size_t i = 0; i < count; i++)
96-
add_edge(edges[i].source, edges[i].target, graph);
70+
Pgr_edgeColoring::Pgr_edgeColoring(pgr_edge_t *edges,
71+
size_t total_edges) {
72+
/*
73+
* Inserting vertices
74+
*/
75+
Identifiers<int64_t> ids;
76+
for (size_t i = 0; i < total_edges; ++i) {
77+
ids += edges[i].source;
78+
ids += edges[i].target;
79+
}
80+
81+
for (const auto id : ids) {
82+
auto v = add_vertex(graph);
83+
id_to_V.insert(std::make_pair(id, v));
84+
V_to_id.insert(std::make_pair(v, id));
85+
}
86+
87+
/*
88+
* Inserting edges
89+
*/
90+
bool added;
91+
for (size_t i = 0; i < total_edges; ++i) {
92+
auto edge = edges[i];
93+
auto v1 = get_boost_vertex(edge.source);
94+
auto v2 = get_boost_vertex(edge.target);
95+
auto e_exists = boost::edge(v1, v2, graph);
96+
if (e_exists.second) continue;
97+
98+
if (edge.source == edge.target) continue;
99+
100+
E e;
101+
boost::tie(e, added) = boost::add_edge(v1, v2, edge.cost, graph);
102+
103+
E_to_id.insert(std::make_pair(e, edge.id));
104+
}
97105
}
98106

99107
} // namespace functions

src/version/_version.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*PGR-GNU*****************************************************************
2+
3+
File: _version.h.in
4+
5+
Function's developer:
6+
Copyright (c) 2015 Celia Virginia Vergara Castillo
7+
8+
9+
------
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; either version 2 of the License, or
14+
(at your option) any later version.
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program; if not, write to the Free Software
23+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24+
25+
********************************************************************PGR-GNU*/
26+
27+
#define BOOST_VERSION "1.74.0";
28+
#define CMAKE_BUILD_TYPE "Release";
29+
#define COMPILER_VERSION "GNU-10.3.0";
30+
#define COMPILATION_DATE "2021/06/30";
31+
#define PROJECT_GIT_HASH "aa8d57db3";
32+
#define PROJECT_LIB_NAME "pgrouting-3.3.0";
33+
#define CMAKE_SYSTEM_NAME "Linux-5.11.0-22-generic";
34+
#define POSTGRES_VERSION "PostgreSQL 13.3 (Ubuntu 13.3-0ubuntu0.21.04.1)";
35+

0 commit comments

Comments
 (0)