Commit 552ca77a authored by Davis King's avatar Davis King

Added an overload of find_max_factor_graph_potts() which takes a regular

undirected graph rather than the special purpose potts_problem type
object.
parent 6683acfb
......@@ -6,6 +6,9 @@
#include "find_max_factor_graph_potts_abstract.h"
#include "../matrix.h"
#include "min_cut.h"
#include "general_potts_problem.h"
#include "../algs.h"
#include "../graph_utils.h"
namespace dlib
{
......@@ -458,6 +461,31 @@ namespace dlib
mc(pfg, m.number_of_nodes(), m.number_of_nodes()+1);
}
// ----------------------------------------------------------------------------------------
template <
typename graph_type
>
void find_max_factor_graph_potts (
const graph_type& g,
std::vector<node_label>& labels
)
{
DLIB_ASSERT(graph_contains_length_one_cycle(g) == false,
"\t void find_max_factor_graph_potts(g,labels)"
<< "\n\t Invalid inputs were given to this function."
);
typedef typename graph_type::edge_type edge_type;
typedef typename graph_type::type type;
// The edges and node's have to use the same type to represent factor weights!
COMPILE_TIME_ASSERT((is_same_type<edge_type, type>::value == true));
dlib::impl::general_potts_problem<graph_type> gg(g, labels);
find_max_factor_graph_potts(gg);
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -5,6 +5,7 @@
#include "../matrix.h"
#include "min_cut_abstract.h"
#include "../graph_utils.h"
namespace dlib
{
......@@ -211,6 +212,34 @@ namespace dlib
- The optimal labels are stored in #prob.
!*/
// ----------------------------------------------------------------------------------------
template <
typename graph_type
>
void find_max_factor_graph_potts (
const graph_type& g,
std::vector<node_label>& labels
);
/*!
requires
- graph_type is an implementation of dlib/graph/graph_kernel_abstract.h
- graph_type::edge_type is some signed type such as int or double
- graph_type::type must be the same type as graph_type::edge_type
- graph_contains_length_one_cycle(g) == false
ensures
- This routine simply converts g into a potts_problem and calls the
version of find_max_factor_graph_potts() defined above on it. Therefore,
this routine is just a convenience wrapper that lets you use a dlib::graph
to represent a potts problem.
- #labels.size() == g.number_of_nodes()
- for all valid i:
- #labels[i] == the optimal label for g.node(i)
- The correspondence between g and a potts_problem is the following:
- the factor_value() for a node is stored in g.node(i).data.
- the factor_value_disagreement(i,j) is stored in edge(g,i,j).
!*/
// ----------------------------------------------------------------------------------------
}
......
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_GENERAL_POTTS_PRoBLEM_H__
#define DLIB_GENERAL_POTTS_PRoBLEM_H__
#include "../graph_utils.h"
#include "min_cut.h"
#include <vector>
namespace dlib
{
// ----------------------------------------------------------------------------------------
namespace impl
{
template <
typename graph_type
>
class general_potts_problem
{
const graph_type& g;
std::vector<node_label>& labels;
public:
general_potts_problem (
const graph_type& g_,
std::vector<node_label>& labels_
) : g(g_), labels(labels_)
{
labels.resize(g.number_of_nodes());
}
unsigned long number_of_nodes (
) const { return g.number_of_nodes(); }
unsigned long number_of_neighbors (
unsigned long idx
) const { return g.node(idx).number_of_neighbors(); }
unsigned long get_neighbor (
unsigned long idx,
unsigned long n
) const { return g.node(idx).neighbor(n).index(); }
unsigned long get_neighbor_idx (
unsigned long idx1,
unsigned long idx2
) const
{
for (unsigned long i = 0; i < g.node(idx1).number_of_neighbors(); ++i)
{
if (g.node(idx1).neighbor(i).index() == idx2)
return i;
}
// This should never ever execute
return 0;
}
void set_label (
const unsigned long& idx,
node_label value
)
{
labels[idx] = value;
}
node_label get_label (
const unsigned long& idx
) const { return labels[idx]; }
typedef typename graph_type::edge_type value_type;
value_type factor_value (
unsigned long idx
) const
{
return g.node(idx).data;
}
value_type factor_value_disagreement (
unsigned long idx1,
unsigned long idx2
) const
{
return edge(g, idx1, idx2);
}
};
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_GENERAL_POTTS_PRoBLEM_H__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment