Skip to content
Draft
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
2 changes: 1 addition & 1 deletion docqueries/coloring/edgeColoring.result
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SELECT edge, color FROM pgr_edgeColoring(
);
edge | color
------+-------
1 | 3
1 | 1
2 | 2
3 | 3
4 | 4
Expand Down
5 changes: 4 additions & 1 deletion include/c_common/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ enum Which {
DFS = 520,
BFS = 530,
DIJKSTRADD = 540,
MAXFLOW, PUSHRELABEL, BOYKOV, EDMONDSKARP
/* For flow */
MAXFLOW, PUSHRELABEL, BOYKOV, EDMONDSKARP,
/* For coloring */
EDGECOLORING, BIPARTITE, SEQUENTIAL
};

#endif // INCLUDE_C_COMMON_ENUMS_H_
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*PGR-GNU*****************************************************************
File: bipartite_driver.h
File: bipartite.hpp

Generated with Template by:
Copyright (c) 2013-2026 pgRouting developers
Copyright (c) 2021-2026 pgRouting developers
Mail: project@pgrouting.org

Function's developer:
Expand All @@ -27,33 +27,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

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

#ifndef INCLUDE_DRIVERS_COLORING_BIPARTITE_DRIVER_H_
#define INCLUDE_DRIVERS_COLORING_BIPARTITE_DRIVER_H_

#ifndef INCLUDE_COLORING_BIPARTITE_HPP_
#define INCLUDE_COLORING_BIPARTITE_HPP_
#pragma once

/* for size-t */
#ifdef __cplusplus
# include <cstddef>
using II_t_rt = struct II_t_rt;
#else
# include <stddef.h>
typedef struct II_t_rt II_t_rt;
#endif
#include <vector>

#include "c_types/ii_t_rt.h"
#include "cpp_common/base_graph.hpp"

#ifdef __cplusplus
extern "C" {
#endif
namespace pgrouting {
namespace functions {

void
pgr_do_bipartite(
const char*,
std::vector<II_t_rt> pgr_bipartite(pgrouting::UndirectedGraph&);

II_t_rt**, size_t*,
char**, char**, char**);
} // namespace functions
} // namespace pgrouting

#ifdef __cplusplus
}
#endif

#endif // INCLUDE_DRIVERS_COLORING_BIPARTITE_DRIVER_H_
#endif // INCLUDE_COLORING_BIPARTITE_HPP_
97 changes: 0 additions & 97 deletions include/coloring/bipartite_driver.hpp

This file was deleted.

43 changes: 2 additions & 41 deletions include/coloring/edgeColoring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#define INCLUDE_COLORING_EDGECOLORING_HPP_
#pragma once

#include <iostream>
#include <map>
#include <vector>
#include <cstdint>

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

#include "cpp_common/edge_t.hpp"
#include "c_types/ii_t_rt.h"
#include "cpp_common/assert.hpp"
#include "cpp_common/messages.hpp"
#include "cpp_common/base_graph.hpp"

namespace pgrouting {
namespace functions {

class Pgr_edgeColoring : public Pgr_messages {
public:
using EdgeColoring_Graph =
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property,
int64_t, boost::no_property>;

using V = boost::graph_traits<EdgeColoring_Graph>::vertex_descriptor;
using E = boost::graph_traits<EdgeColoring_Graph>::edge_descriptor;
using V_it = boost::graph_traits<EdgeColoring_Graph>::vertex_iterator;
using E_it = boost::graph_traits<EdgeColoring_Graph>::edge_iterator;

public:
std::vector<II_t_rt> edgeColoring();

explicit Pgr_edgeColoring(const std::vector<Edge_t>&);
Pgr_edgeColoring() = delete;

#if BOOST_VERSION >= 106800
friend std::ostream& operator<<(std::ostream &, const Pgr_edgeColoring&);
#endif

private:
V get_boost_vertex(int64_t id) const;
int64_t get_vertex_id(V v) const;
int64_t get_edge_id(E e) const;

std::vector<II_t_rt> edgeColoring(pgrouting::UndirectedGraph);

private:
EdgeColoring_Graph graph;
std::map<int64_t, V> id_to_V;
std::map<V, int64_t> V_to_id;
std::map<E, int64_t> E_to_id;
};

} // namespace functions
} // namespace pgrouting
Expand Down
102 changes: 1 addition & 101 deletions include/coloring/sequentialVertexColoring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,117 +28,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#define INCLUDE_COLORING_SEQUENTIALVERTEXCOLORING_HPP_
#pragma once

#include <algorithm>
#include <vector>
#include <map>
#include <cstdint>

#include <boost/property_map/property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/vector_property_map.hpp>
#include <boost/type_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/sequential_vertex_coloring.hpp>

#include "cpp_common/base_graph.hpp"
#include "cpp_common/interruption.hpp"

#include "c_types/ii_t_rt.h"

namespace pgrouting {
namespace functions {

//*************************************************************

template < class G >
class Pgr_sequentialVertexColoring {
public:
typedef typename G::V V;
typedef typename G::E E;
typedef boost::adjacency_list < boost::listS, boost::vecS, boost::undirectedS > Graph;
typedef boost::graph_traits < Graph > ::vertices_size_type vertices_size_type;

/** @name SequentialVertexColoring
* @{
*
*/

/** @brief sequentialVertexColoring function
*
* It does all the processing and returns the results.
*
* @param graph the graph containing the edges
*
* @returns results, when results are found
*
* @see [boost::sequential_vertex_coloring]
* (https://www.boost.org/libs/graph/doc/sequential_vertex_coloring.html)
*/
std::vector <II_t_rt> sequentialVertexColoring(G &graph) {
std::vector <II_t_rt> results;

auto i_map = boost::get(boost::vertex_index, graph.graph);

// vector which will store the color of all the vertices in the graph
std::vector < vertices_size_type > colors(boost::num_vertices(graph.graph));

// An iterator property map which records the color of each vertex
auto color_map = boost::make_iterator_property_map(colors.begin(), i_map);

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

try {
boost::sequential_vertex_coloring(graph.graph, color_map);
} catch (boost::exception const& ex) {
(void)ex;
throw;
} catch (std::exception &e) {
(void)e;
throw;
} catch (...) {
throw;
}

results = get_results(colors, graph);

return results;
}

//@}

private:
/** @brief to get the results
*
* Uses the `colors` vector to get the results i.e. the color of every vertex.
*
* @param colors vector which contains the color of every vertex
* @param graph the graph containing the edges
*
* @returns `results` vector
*/
std::vector <II_t_rt> get_results(
std::vector < vertices_size_type > &colors,
const G &graph) {
std::vector <II_t_rt> results;

typename boost::graph_traits < Graph > ::vertex_iterator v, vend;

for (boost::tie(v, vend) = vertices(graph.graph); v != vend; ++v) {
int64_t node = graph[*v].id;
auto color = colors[*v];
results.push_back({{node}, {static_cast<int64_t>(color + 1)}});
}

// ordering the results in an increasing order of the node id
std::sort(results.begin(), results.end(),
[](const II_t_rt row1, const II_t_rt row2) {
return row1.d1.id < row2.d1.id;
});
std::vector<II_t_rt> sequentialVertexColoring(const pgrouting::UndirectedGraph&);

return results;
}
};
} // namespace functions
} // namespace pgrouting

Expand Down
Loading
Loading