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
2 changes: 1 addition & 1 deletion Algorithms/GreedyColoringLimitedMaxColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int GreedyColoringLimitedMaxColor::color() {
for (int v : order) {
std::vector<unsigned int> forbiddenColors(boost::num_vertices(GraphInstance), -1);
forbiddenColors[0] = v;
ForEachNeighbor(GraphInstance, v, [&](int n) {
ForEachNeighbor(GraphInstance, v, [&](const int n) {
int c = boost::get(vertex_color, GraphInstance, n);
if (c > 0)forbiddenColors[c] = v;
});
Expand Down
9 changes: 4 additions & 5 deletions Algorithms/GreedyColoringSimpleGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
* @return the number of colors
*/
int GreedyColoringSimpleGraph::color() {
vector<unsigned int> &order = V_c;
for (int v : order) {
for (vector<unsigned int> &order = V_c; int v : order) {
// Since vertex numbering starts at zero, we initialize forbiddenColors with the (non-existing) vertex -1
std::vector<unsigned int> forbiddenColors(boost::num_vertices(GraphInstance), -1);
forbiddenColors[0] = v;
ForEachNeighbor(GraphInstance, v, [&](int n) {
int c = boost::get(vertex_color, GraphInstance, n);
if (c > 0) forbiddenColors[c] = v;
});
//Find first color which can be assigned to v
auto result = find_if(forbiddenColors.begin(), forbiddenColors.end(), [&](int i) { return i != v; });
auto res_color = distance(forbiddenColors.begin(), result);
//Find the first color which can be assigned to v
const auto result = std::ranges::find_if(forbiddenColors, [&](int i) { return i != v; });
const auto res_color = distance(forbiddenColors.begin(), result);
SetVertexColor(GraphInstance, v, res_color);
}
return NumOfColors();
Expand Down
19 changes: 4 additions & 15 deletions Algorithms/ISet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,12 @@ class ISet : public IndependentSet {

//Get distance-1 neighbors
graph_traits<Graph>::adjacency_iterator n_1, n_1_end;
for (tie(n_1, n_1_end) = adjacent_vertices(v_c, G_b); n_1 != n_1_end; n_1++) {

for (tie(n_1, n_1_end) = adjacent_vertices(v_c, G_b); n_1 != n_1_end; ++n_1) {
bool is_deleted = false;

//E_1 -> E_2
//Emulate reverse_iterator because of erase-operation
for (list<graph_traits<Graph>::edge_iterator>::iterator e =
E_1.begin();
e != E_1.end();
++e) {

for (auto e = E_1.begin();e != E_1.end();++e) {
if (source(**e, G_b) == *n_1 || target(**e, G_b) == *n_1) {

//Delete adjacent vertices
if (!is_deleted) {
V_r.erase(find(V_r.begin(), V_r.end(), *n_1));
Expand All @@ -145,11 +138,7 @@ class ISet : public IndependentSet {

//E_3 -> E_4
//Emulate reverse_iterator because of erase-operation
for (list<graph_traits<Graph>::edge_iterator>::iterator e =
E_3.begin();
e != E_3.end();
++e) {

for (auto e = E_3.begin();e != E_3.end();++e) {
if (source(**e, G_b) == *n_1 || target(**e, G_b) == *n_1) {
E_4.push_back(*e);
e = E_3.erase(e);
Expand All @@ -158,7 +147,7 @@ class ISet : public IndependentSet {
}
}

V_c.erase(find(V_c.begin(), V_c.end(), v_c));
V_c.erase(std::ranges::find(V_c, v_c));
}
}

Expand Down
37 changes: 13 additions & 24 deletions Algorithms/ISetRestricted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class ISetRestricted : public IndependentSet{
public:
using IndependentSet::IndependentSet;

vector<int> compute() {
vector<int> compute() override
{
vector<int> IS;
list <graph_traits<Graph>::edge_iterator> E_1;
list <graph_traits<Graph>::edge_iterator> E_2;
list <graph_traits<Graph>::edge_iterator> E_3;
list <graph_traits<Graph>::edge_iterator> E_4;
int NumVertices_V_r = V_r.size();
int NumVertices = V_r.size() + V_c.size();
double rho = mode / 2;
if (rho == 0) rho = 1.5;
Expand Down Expand Up @@ -87,20 +87,16 @@ class ISetRestricted : public IndependentSet{

//Get distance-1 neighbors
graph_traits<Graph>::adjacency_iterator n_1, n_1_end;
for (tie(n_1, n_1_end) = adjacent_vertices(v_r, G_b); n_1 != n_1_end; n_1++) {
for (tie(n_1, n_1_end) = adjacent_vertices(v_r, G_b); n_1 != n_1_end; ++n_1) {

bool is_deleted = false;

//E_1 -> E_3
//Emulate reverse_iterator because of erase-operation
for (list<graph_traits<Graph>::edge_iterator>::iterator e = E_1.begin();
e != E_1.end();
++e) {

for (auto e = E_1.begin();e != E_1.end();++e) {
if (source(**e, G_b) == *n_1 || target(**e, G_b) == *n_1) {

if (!is_deleted) {
V_c.erase(find(V_c.begin(), V_c.end(), *n_1));
V_c.erase(std::ranges::find(V_c, *n_1));
is_deleted = true;
}

Expand All @@ -112,9 +108,7 @@ class ISetRestricted : public IndependentSet{

//E_2 -> E_4
//Emulate reverse_iterator because of erase-operation
for (list<graph_traits<Graph>::edge_iterator>::iterator e = E_2.begin();
e != E_2.end();
++e) {
for (auto e = E_2.begin();e != E_2.end();++e) {

if (source(**e, G_b) == *n_1 || target(**e, G_b) == *n_1) {
E_4.push_back(*e);
Expand All @@ -123,18 +117,16 @@ class ISetRestricted : public IndependentSet{
}
}
}
V_r.erase(find(V_r.begin(), V_r.end(), v_r));
V_r.erase(std::ranges::find(V_r, v_r));

} else {

IS.push_back(v_c);

//Get distance-1 neighbors
graph_traits<Graph>::adjacency_iterator n_1, n_1_end;
for (tie(n_1, n_1_end) = adjacent_vertices(v_c, G_b); n_1 != n_1_end; n_1++) {

for (tie(n_1, n_1_end) = adjacent_vertices(v_c, G_b); n_1 != n_1_end; ++n_1) {
bool is_deleted = false;

//E_1 -> E_2
//Emulate reverse_iterator because of erase-operation
for (auto e = E_1.begin();e != E_1.end();++e) {
Expand All @@ -143,7 +135,7 @@ class ISetRestricted : public IndependentSet{

//Delete adjacent vertices
if (!is_deleted) {
V_r.erase(find(V_r.begin(), V_r.end(), *n_1));
V_r.erase(std::ranges::find(V_r, *n_1));
is_deleted = true;
}

Expand All @@ -155,10 +147,7 @@ class ISetRestricted : public IndependentSet{

//E_3 -> E_4
//Emulate reverse_iterator because of erase-operation
for (list<graph_traits<Graph>::edge_iterator>::iterator e = E_3.begin();
e != E_3.end();
++e) {

for (auto e = E_3.begin();e != E_3.end();++e) {
if (source(**e, G_b) == *n_1 || target(**e, G_b) == *n_1) {
E_4.push_back(*e);
e = E_3.erase(e);
Expand All @@ -167,18 +156,18 @@ class ISetRestricted : public IndependentSet{
}
}

V_c.erase(find(V_c.begin(), V_c.end(), v_c));
V_c.erase(std::ranges::find(V_c, v_c));
}
}

if (!V_r.empty()) {
for (vector<unsigned int>::iterator v_r = V_r.begin(); v_r != V_r.end(); ++v_r) {
for (auto v_r = V_r.begin(); v_r != V_r.end(); ++v_r) {
IS.push_back(*v_r);
}
}

if (!V_c.empty()) {
for (vector<unsigned int>::iterator v_c = V_c.begin(); v_c != V_c.end(); ++v_c) {
for (auto v_c = V_c.begin(); v_c != V_c.end(); ++v_c) {
IS.push_back(*v_c);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Algorithms/OneSidedD2ColorNonReqDiag.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class OneSidedD2ColorNonReqDiag : public ColoringAlgorithms {
N_2 = neighbors::Distance2NeighborsRestricted(GraphInstance, v);
forbiddenColors[0] = v;
//Iterate over distance-2 neighbors
for_each(N_2.begin(), N_2.end(), [&](unsigned int n_2) {
std::ranges::for_each(N_2, [&](unsigned int n_2) {
//Mark colors which are used by distance-2 neighbors in forbiddenColors
if (get(vertex_color, GraphInstance, n_2) > 0) {
forbiddenColors[get(vertex_color, GraphInstance, n_2)] = v;
}
});

//Find the first color which can be assigned to v
auto result = find_if(forbiddenColors.begin(), forbiddenColors.end(),
bind(not_equal_to<int>(), v, std::placeholders::_1));
auto result = std::ranges::find_if(forbiddenColors,
bind(not_equal_to<int>(), v, std::placeholders::_1));

int col1 = distance(forbiddenColors.begin(), result);
///////////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 5 additions & 5 deletions Algorithms/OneSidedD2ColoringNonReq.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class OneSidedD2ColoringNonReq : public ColoringAlgorithms {
vector<unsigned int> N_2;
vector<unsigned int> forbiddenColors(NumOfVertices(GraphInstance), -1);
//All edges in E_S have edge_weight=1; otherwise edge_weight=0
//Iterate over all vertices which should be colored
for_each(V.begin(), V.end(), [&](unsigned int v) {
//Iterate over all vertices that should be colored
std::ranges::for_each(V, [&](unsigned int v) {
if (get(vertex_color, GraphInstance, v) == 0) {
forbiddenColors[0] = v;
if (neighbors::IncidentToReqEdge(GraphInstance, v)) {
Expand All @@ -44,9 +44,9 @@ class OneSidedD2ColoringNonReq : public ColoringAlgorithms {
}
});

//Find first color which can be assigned to v
vector<unsigned int>::iterator result = find_if(forbiddenColors.begin(), forbiddenColors.end(),
std::bind(std::not_equal_to<int>(), v, std::placeholders::_1));
//Find the first color which can be assigned to v
auto result = std::ranges::find_if(forbiddenColors,
std::bind(std::not_equal_to<int>(), v, std::placeholders::_1));

//Color v
SetVertexColor(GraphInstance, v, distance(forbiddenColors.begin(), result));
Expand Down
22 changes: 9 additions & 13 deletions Algorithms/OneSidedD2ColoringNonReqBalanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ class OneSidedD2ColoringNonReqBalanced : public ColoringAlgorithms {
});

//Find the first color which can be assigned to v
vector<unsigned int>::iterator result = find_if(forbiddenColors.begin(),
forbiddenColors.end(),
std::bind(std::not_equal_to<int>(), v, std::placeholders::_1));
const auto result = std::ranges::find_if(forbiddenColors,
std::bind(std::not_equal_to<int>(), v, std::placeholders::_1));

//Color v
SetVertexColor(GraphInstance, v, distance(forbiddenColors.begin(), result));
// put(color, v, distance(forbiddenColors.begin(), result));

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
vector<unsigned int> non_neighbours;
for_each(V_c.begin(), V_c.end(), [&](Ver vc) {
if (find(N_2.begin(), N_2.end(), vc) == N_2.end())
std::ranges::for_each(V_c, [&](Ver vc) {
if (std::ranges::find(N_2, vc) == N_2.end())
if(get(vertex_color, GraphInstance, vc) == 0)
non_neighbours.push_back(vc);
});
Expand All @@ -71,7 +68,7 @@ class OneSidedD2ColoringNonReqBalanced : public ColoringAlgorithms {
//map from the positions to number of that nonrequired
map<unsigned int, int> pos_num;
//Iterate over distance-2 neighbors
for_each(non_neighbours.begin(), non_neighbours.end(), [&](unsigned int nn) {
std::ranges::for_each(non_neighbours, [&](unsigned int nn) {
int cnt_nreq_det = 0;
//Mark colors which are used by distance-2 neighbors in forbiddenColors
for_each(adjacent_vertices(nn, GraphInstance).first, adjacent_vertices(nn, GraphInstance).second,
Expand Down Expand Up @@ -102,12 +99,11 @@ class OneSidedD2ColoringNonReqBalanced : public ColoringAlgorithms {

});
int cnt = 0;
for_each(pos_num.begin(), pos_num.end(), [&](auto map_elem) {
std::ranges::for_each(pos_num, [&](auto map_elem) {
if (cnt <= std::any_cast<int>(CustomParameters["alpha"])) {
if (map_elem.second == min_nreq_det) {
cnt++;
SetVertexColor(GraphInstance,map_elem.first, distance(forbiddenColors.begin(), result));
// put(color, map_elem.first, distance(forbiddenColors.begin(), result));
}
}
});
Expand All @@ -117,12 +113,12 @@ class OneSidedD2ColoringNonReqBalanced : public ColoringAlgorithms {
int min_pos = -1;
int max_req = 0;
int max_pos = -1;
for_each(pos_num.begin(), pos_num.end(), [&](auto map_elem) {
std::ranges::for_each(pos_num, [&](auto map_elem) {
if (map_elem.second == max_nreq_det) {
int cnt_req = 0;
for_each(adjacent_vertices(map_elem.first, GraphInstance).first,
adjacent_vertices(map_elem.first, GraphInstance).second,
[&](Ver adj_) {
[&](const Ver adj_) {
if (get(edge_weight, GraphInstance, edge(map_elem.first, adj_, GraphInstance).first) == 1) {
cnt_req++;
}
Expand Down Expand Up @@ -160,4 +156,4 @@ class OneSidedD2ColoringNonReqBalanced : public ColoringAlgorithms {
};


#endif //PRECOL_ONESIDEDD2COLORING_H
#endif //PRECOL_D2ColorNonReqBalanced
8 changes: 4 additions & 4 deletions Algorithms/exact_coloring.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <iostream>
#include <set>
#include <algorithm>
Expand Down Expand Up @@ -38,14 +39,13 @@ static void gen_ind_set(Graph g,Lambda func) {

static int alpha(dynbit X, set<dynbit> F) {
int cnt = 0;
for_each(F.begin(),F.end(),[&X,&cnt](dynbit db) {
dynbit tmp = db & X;
if(tmp.none()) cnt++;
ranges::for_each(F,[&X,&cnt](const dynbit& db) {
if(const dynbit tmp = db & X; tmp.none()) cnt++;
});
return cnt;
}

//F is actually the all independent set
//F is actually the all-independent set
static int c_k(set<dynbit> F, Graph g, int k) {
int cnt = 0;
power_set(NumOfVertices(g), [&](dynbit vi) {
Expand Down
15 changes: 6 additions & 9 deletions Algorithms/kClique.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ bool step(const Graph& G_c,
vector<unsigned int>& prev_vertices,
int level) {

graph_traits<Graph>::adjacency_iterator ai, ai_ptr, ai_lt_vtx, ai_end;
graph_traits<Graph>::adjacency_iterator ai, ai_end;
tie(ai, ai_end) = adjacent_vertices(Vertex, G_c);
ai_lt_vtx = ai;
for (vector<unsigned int>::iterator pv = prev_vertices.begin();
graph_traits<Graph>::adjacency_iterator ai_lt_vtx = ai;
for (auto pv = prev_vertices.begin();
pv != prev_vertices.end();
++pv) {

bool exists = 0;

for (ai_ptr = ai; ai_ptr != ai_end; ++ai_ptr) {
bool exists = false;
for (graph_traits<Graph>::adjacency_iterator ai_ptr = ai; ai_ptr != ai_end; ++ai_ptr) {

// all adjacent vertices are ordered ascending
// for next step we need only larger vertices than Vertex
Expand All @@ -40,9 +39,7 @@ bool step(const Graph& G_c,
}
}
if (!exists) {
// copy(prev_vertices.begin(), prev_vertices.end(),ostream_iterator<int>(cout, " "));
// cout << " " << Vertex << endl;
return 0;
return false;
}
}
if (level == 1) {
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#cmake_minimum_required(VERSION 4.0)
cmake_minimum_required(VERSION 3.5)
project(precol)
set (CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down
Loading