Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoern-andres committed Nov 16, 2015
1 parent 2d3a232 commit faaabd7
Showing 1 changed file with 26 additions and 59 deletions.
85 changes: 26 additions & 59 deletions include/andres/graph/twocut-lifted/kernighan-lin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
#include <limits>
#include <vector>


namespace andres {
namespace graph {
namespace twocut_lifted {


struct TwoCutSettings
{
struct TwoCutSettings {
std::size_t numberOfIterations { std::numeric_limits<std::size_t>::max() };
double epsilon { 1e-9 };
};

template<typename ORIGINAL_GRAPH>
struct TwoCutBuffers
{
TwoCutBuffers(const ORIGINAL_GRAPH&);

struct TwoCutBuffers {
TwoCutBuffers(const ORIGINAL_GRAPH& graph)
: differences(graph.numberOfVertices()),
is_moved(graph.numberOfVertices()),
referenced_by(graph.numberOfVertices()),
vertex_labels(graph.numberOfVertices())
{}
std::vector<double> differences;
std::vector<char> is_moved;
std::size_t max_not_used_label;
Expand All @@ -30,63 +30,16 @@ struct TwoCutBuffers
};

template<typename ORIGINAL_GRAPH, typename LIFTED_GRAPH, typename SET, typename ECA>
double kernighanLin(
const ORIGINAL_GRAPH& original_graph,
const LIFTED_GRAPH& lifted_graph,
const ECA& edge_costs,
SET& A,
SET& B,
const TwoCutSettings settings = TwoCutSettings());

template<typename ORIGINAL_GRAPH, typename LIFTED_GRAPH, typename SET, typename ECA>
double kernighanLin(
const ORIGINAL_GRAPH& original_graph,
const LIFTED_GRAPH& lifted_graph,
const ECA& edge_costs,
SET& A,
SET& B,
TwoCutBuffers<ORIGINAL_GRAPH>& buffer,
const TwoCutSettings settings = TwoCutSettings());








template<typename ORIGINAL_GRAPH>
TwoCutBuffers<ORIGINAL_GRAPH>::TwoCutBuffers(const ORIGINAL_GRAPH& graph) :
differences(graph.numberOfVertices()),
is_moved(graph.numberOfVertices()),
referenced_by(graph.numberOfVertices()),
vertex_labels(graph.numberOfVertices())
{}

template<typename ORIGINAL_GRAPH, typename LIFTED_GRAPH, typename SET, typename ECA>
inline
double kernighanLin(
const ORIGINAL_GRAPH& original_graph,
const LIFTED_GRAPH& lifted_graph,
const ECA& edge_costs,
SET& A,
SET& B,
const TwoCutSettings settings)
{
TwoCutBuffers<ORIGINAL_GRAPH> buffer(original_graph);
return kernighanLin(original_graph, lifted_graph, edge_costs, A, B, buffer, settings);
}

template<typename ORIGINAL_GRAPH, typename LIFTED_GRAPH, typename SET, typename ECA>
inline
double kernighanLin(
inline double
kernighanLin(
const ORIGINAL_GRAPH& original_graph,
const LIFTED_GRAPH& lifted_graph,
const ECA& edge_costs,
SET& A,
SET& B,
TwoCutBuffers<ORIGINAL_GRAPH>& buffer,
const TwoCutSettings settings)
const TwoCutSettings settings
)
{
struct Move
{
Expand Down Expand Up @@ -302,6 +255,20 @@ double kernighanLin(
return .0;
}

template<typename ORIGINAL_GRAPH, typename LIFTED_GRAPH, typename SET, typename ECA>
inline double
kernighanLin(
const ORIGINAL_GRAPH& original_graph,
const LIFTED_GRAPH& lifted_graph,
const ECA& edge_costs,
SET& A,
SET& B,
const TwoCutSettings settings
) {
TwoCutBuffers<ORIGINAL_GRAPH> buffer(original_graph);
return kernighanLin(original_graph, lifted_graph, edge_costs, A, B, buffer, settings);
}

}
}
}
Expand Down

0 comments on commit faaabd7

Please sign in to comment.