Skip to content

Commit

Permalink
Merge pull request #31 from bluescarni/linux_fixes
Browse files Browse the repository at this point in the history
Various fixes for compilation on linux with GCC/Clang.
  • Loading branch information
bjoern-andres authored Oct 4, 2016
2 parents 71c0b97 + cab6f3e commit 6f86885
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 79 deletions.
6 changes: 3 additions & 3 deletions include/andres/graph/bfs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public:
BreadthFirstSearchData(const GRAPH& graph)
: depth_(graph.numberOfVertices(), NOT_VISITED)
{}
size_type add(const size_type v, const size_type depth)
void add(const size_type v, const size_type depth)
{ depth_[v] = depth; queue_.push(v); }
void clearQueue()
{ queue_ = std::queue<size_type>(); }
Expand Down Expand Up @@ -161,13 +161,13 @@ breadthFirstSearch(
bool add;

callback(*it, depth, proceed, add);

if(!proceed)
{
data.clearQueue();
return;
}

if(add)
data.add(*it, depth);
}
Expand Down
8 changes: 4 additions & 4 deletions include/andres/graph/dfs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
DepthFirstSearchData(const GRAPH& graph)
: visited_(graph.numberOfVertices())
{}
size_type add(const size_type v)
void add(const size_type v)
{ stack_.push(v); }
void clearStack()
{ stack_ = std::stack<size_type>(); }
Expand Down Expand Up @@ -140,18 +140,18 @@ depthFirstSearch(
if (!data.visited(v))
{
data.visited(v) = 1;

bool proceed;
bool addNeighbors;

callback(v, proceed, addNeighbors);

if (!proceed)
{
data.clearStack();
return;
}

if (addNeighbors)
{
auto e_it = g.edgesFromVertexBegin(v);
Expand Down
8 changes: 3 additions & 5 deletions include/andres/graph/grid-graph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public:
std::random_access_iterator_tag,
const AdjacencyType
> {
public:
public:
typedef GridGraph<DIMENSION, Visitor> GraphType;
typedef std::iterator <
std::random_access_iterator_tag,
Expand Down Expand Up @@ -191,9 +191,9 @@ public:
size_type shape(const size_type) const;

size_type vertex(const VertexCoordinate&) const;
void vertex(const size_type, VertexCoordinate&) const;
void vertex(size_type, VertexCoordinate&) const;
size_type edge(const EdgeCoordinate&) const;
void edge(const size_type, EdgeCoordinate&) const;
void edge(size_type, EdgeCoordinate&) const;

private:
size_type vertexFromVertex(const VertexCoordinate&, const size_type, size_type&, bool&) const;
Expand Down Expand Up @@ -1408,5 +1408,3 @@ GridGraph<D, VISITOR>::EdgeIterator::operator[](
} // namespace andres

#endif // #ifndef ANDRES_GRAPH_GRID_GRAPH_HXX


1 change: 0 additions & 1 deletion include/andres/graph/hdf5/complete-graph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace andres {
namespace graph {
namespace hdf5 {

template<>
template<class VISITOR>
struct GraphTraitsHDF5<CompleteGraph<VISITOR> > {
static const int ID;
Expand Down
7 changes: 3 additions & 4 deletions include/andres/graph/hdf5/digraph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace andres {
namespace graph {
namespace hdf5 {

template<>
template<class VISITOR>
struct GraphTraitsHDF5<Digraph<VISITOR> > {
static const int ID;
Expand All @@ -36,7 +35,7 @@ save(
) {
HandleCheck<ANDRES_GRAPH_HDF5_DEBUG> handleCheck;
hid_t groupHandle = openGroup(parentHandle, graphName,true);

try {
save(groupHandle, "graph-type-id", GraphTraitsHDF5<Digraph<VISITOR> >::ID);
save(groupHandle, "multiple-edges-enabled", static_cast<unsigned char>(graph.multipleEdgesEnabled()));
Expand Down Expand Up @@ -70,9 +69,9 @@ load(
) {
HandleCheck<ANDRES_GRAPH_HDF5_DEBUG> handleCheck;
hid_t groupHandle = openGroup(parentHandle, graphName);

std::string sError;

try {
int id = 0;
load(groupHandle, "graph-type-id", id);
Expand Down
1 change: 0 additions & 1 deletion include/andres/graph/hdf5/graph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace andres {
namespace graph {
namespace hdf5 {

template<>
template<class VISITOR>
struct GraphTraitsHDF5<Graph<VISITOR> > {
static const int ID;
Expand Down
3 changes: 1 addition & 2 deletions include/andres/graph/hdf5/grid-graph.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace andres {
namespace graph {
namespace hdf5 {

template<>
template<unsigned char D, class VISITOR>
struct GraphTraitsHDF5<GridGraph<D, VISITOR> > {
static const int ID;
Expand Down Expand Up @@ -65,7 +64,7 @@ load(
) {
HandleCheck<ANDRES_GRAPH_HDF5_DEBUG> handleCheck;
hid_t groupHandle = openGroup(parentHandle, graphName);

std::string sError;
try {
int id;
Expand Down
22 changes: 11 additions & 11 deletions include/andres/graph/lifting.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ lift(

if(outputGraph.numberOfVertices() != 0)
throw std::runtime_error("output graph is not empty.");

outputGraph.insertVertices(inputGraph.numberOfVertices());

BreadthFirstSearchData<size_type> breadthFirstSearchData(inputGraph.numberOfVertices());
Expand All @@ -48,13 +48,13 @@ lift(
{
proceed = true;
add = false;

if (depth <= distanceUpperBound)
{
if (depth + 1 <= distanceUpperBound)
{
add = true;
visited.push_back(w);
visited.push_back(w);
}

if (depth > distanceLowerBound)
Expand All @@ -74,7 +74,7 @@ lift(
breadthFirstSearchData.depth(v) = BreadthFirstSearchData<size_type>::NOT_VISITED;
for (auto w : visited)
breadthFirstSearchData.depth(w) = BreadthFirstSearchData<size_type>::NOT_VISITED;

visited.clear();
}
}
Expand Down Expand Up @@ -124,12 +124,12 @@ lift(
std::size_t colN = cv[0] + offsetX;
if(colN > inputGraph.shape(0) - 1)
colN = inputGraph.shape(0) - 1;

for (std::size_t x = col0; x <= colN; ++x)
{
if (metric == LiftingMetric::PathLength)
{
const std::size_t distance = ::abs(x - cv[0]) + ::abs(yPlus - 1 - cv[1]);
const std::size_t distance = std::abs(x - cv[0]) + std::abs(yPlus - 1 - cv[1]);

if (distance > distanceLowerBound)
{
Expand Down Expand Up @@ -160,7 +160,7 @@ lift(

if (colN > inputGraph.shape(0) - 1)
colN = inputGraph.shape(0) - 1;

if (cv[0] > distanceLowerBound)
for (std::size_t x = col0; x <= cv[0] - distanceLowerBound - 1; ++x)
{
Expand All @@ -180,7 +180,7 @@ lift(
{
const std::size_t row0 = cv[1] + 1;
std::size_t rowN = cv[1] + distanceUpperBound;

if (cv[1] + distanceUpperBound > inputGraph.shape(1) - 1)
rowN = inputGraph.shape(1) - 1;

Expand All @@ -190,7 +190,7 @@ lift(
const std::size_t offsetX = (metric == LiftingMetric::PathLength) ?
distanceUpperBound - offsetY :
::floor(::sqrt(distanceUpperBoundSquared - offsetY * offsetY));

const std::size_t col0 = cv[0] < offsetX ? 0 : cv[0] - offsetX;
std::size_t colN = cv[0] + offsetX;

Expand All @@ -201,8 +201,8 @@ lift(
{
if (metric == LiftingMetric::PathLength)
{
const std::size_t distance = ::abs(x - cv[0]) + ::abs(y - cv[1]);
const std::size_t distance = std::abs(x - cv[0]) + std::abs(y - cv[1]);

if (distance > distanceLowerBound)
{
const size_type w = inputGraph.vertex({{x, y}});
Expand Down
20 changes: 10 additions & 10 deletions include/andres/graph/multicut-lifted/kernighan-lin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void kernighanLin(

// interatively update bipartition in order to minimize the total cost of the multicut
for (std::size_t k = 0; k < settings.numberOfOuterIterations; ++k)
{
{
auto energy_decrease = .0;

std::vector<std::unordered_set<std::size_t>> edges(numberOfComponents);
Expand Down Expand Up @@ -152,12 +152,12 @@ void kernighanLin(
continue;

bool flag = true;

while (flag && !visitor.time_limit_exceeded())
{
std::vector<std::size_t> new_set;
energy_decrease += twocut_lifted::kernighanLin(original_graph, lifted_graph, edgeCosts, partitions[i], new_set, twocut_buffers, twocut_settings);

flag = !new_set.empty();

if (!new_set.empty())
Expand All @@ -167,9 +167,9 @@ void kernighanLin(

if (energy_decrease == .0)
break;

std::stack<std::size_t> S;

std::fill(visited.begin(), visited.end(), 0);

// do connected component labeling on the original graph
Expand Down Expand Up @@ -211,7 +211,7 @@ void kernighanLin(
if (twocut_buffers.referenced_by[v0] != twocut_buffers.referenced_by[v1])
new_energy_value += edgeCosts[i];
}

// if the new true energy is higher, than the current one, revert the changes and terminate
if (new_energy_value >= current_energy_value - settings.epsilon)
{
Expand All @@ -225,15 +225,15 @@ void kernighanLin(

break;
}

// otherwise, form new partitions
partitions.clear();
partitions.resize(numberOfComponents);

for (std::size_t i = 0; i < original_graph.numberOfVertices(); ++i)
{
twocut_buffers.vertex_labels[i] = twocut_buffers.referenced_by[i];

partitions[twocut_buffers.vertex_labels[i]].push_back(i);
}

Expand Down Expand Up @@ -316,9 +316,9 @@ void kernighanLin(
const KernighanLinSettings settings = KernighanLinSettings())
{
struct Visitor {
constexpr bool operator()(std::vector<std::size_t>& vertex_labels)
constexpr bool operator()(std::vector<std::size_t>& vertex_labels) const
{ return true; }
constexpr bool time_limit_exceeded()
constexpr bool time_limit_exceeded() const
{ return false; }
} visitor;

Expand Down
5 changes: 3 additions & 2 deletions include/andres/graph/multicut/greedy-fixation.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cmath>
#include <cstddef>
#include <iterator>
#include <vector>
Expand Down Expand Up @@ -100,7 +101,7 @@ void greedyFixation(

bool operator <(Edge const& other) const
{
return fabs(w) < fabs(other.w);
return std::abs(w) < std::abs(other.w);
}
};

Expand Down Expand Up @@ -132,7 +133,7 @@ void greedyFixation(

if (!original_graph_cp.edgeExists(edge.a, edge.b) || edge.edition < edge_editions[edge.a][edge.b])
continue;

if (edge.w > typename EVA::value_type() && !original_graph_cp.isCutEdge(edge.a, edge.b))
{
auto stable_vertex = edge.a;
Expand Down
Loading

0 comments on commit 6f86885

Please sign in to comment.