2 #ifndef DP_SOLUTION_HPP
3 #define DP_SOLUTION_HPP
9 #include "utils/graph_typedefs.hpp"
10 #include "utils/min_matrix.hpp"
12 namespace scaffold{
namespace solv{
namespace DP{
18 template<
class Compare = std::less<
size_t> >
35 typedef typename PCMinMatrix<Compare>::entries_t entries_t;
38 bool no_solutions()
const
40 return entries->empty();
53 entries_t* old_entries = entries;
54 entries =
new entries_t();
55 for(
const auto& E : *old_entries){
57 for(
const auto& SE : *S.entries) put(pc + SE.first, *E.second, *SE.second);
68 DEBUG4(std::cout <<
"combining solutions"<<std::endl);
70 if(global.weight || !global.has_no_edges()){
71 for(
auto& E : *entries){
73 const typename entries_t::const_iterator SE = S.entries->find(pc);
75 if((SE == S.entries->end()) || !put(pc, *SE->second, S.global)) *E.second += global;
81 for(
const auto& SE : *(S.entries)) put(SE.first, *SE.second, S.global);
87 assert(entries->size() == 0);
94 best_index = S.best_index;
96 S.entries =
new entries_t();
100 void add_edge_global(
const VertexName& u,
const VertexName& v,
const size_t weight){
101 DEBUG4(std::cout <<
"globally adding ("<<u<<
","<<v<<
") to solution"<<std::endl);
102 global.append_edge(EdgeName(u,v), weight);
107 friend std::ostream& operator<<(std::ostream& os, const DynProgSolution<Compare>& S){
108 return os <<
"globally +"<<S.global.weight<<std::endl << (PCMinMatrix<Compare>)(S);
115 template<
class Compare = std::less<
unsigned> >
119 const RawScaffoldGraph& g = I.
get_graph();
120 const unsigned n = boost::num_vertices(g);
121 const unsigned m = boost::num_edges(g);
122 const bool is_cycle = (n == m);
123 DEBUG4(std::cout <<
"instance has "<<n<<
" vertices, "<<m<<
" edges. Requested: "<<I.
num_paths<<
" & "<<I.
num_cycles<<std::endl);
129 const std::pair<ScafVertexPair, unsigned> nb = I.
get_infos().bridges.get_cheapest_nonbridge();
130 const EdgeName nb_name(g[nb.first.first].name, g[nb.first.second].name);
139 if(!is_equal(nb.first, *r, g))
Definition: min_matrix.hpp:191
Definition: read_adj_list.hpp:22
unsigned num_cycles
max number of cycles in solutions
Definition: instance.hpp:33
an instance is a ScaffoldGraph with given path- & cycle- numbers and a solution to keep track of dele...
Definition: instance.hpp:27
an edge iterator that skips over all edges for which the predicate evaluates to false ...
Definition: adv_edge_iters.hpp:19
Definition: dp_solution.hpp:19
const Graph & get_graph() const
get a const reference to the underlying graph
Definition: scaffold_graph.hpp:227
EdgeName get_edge_name(const VertexPair< Graph > &uv) const
get a copy of the name of the edge uv; independent of its presence
Definition: scaffold_graph.hpp:421
unsigned num_paths
max number of paths in solutions
Definition: instance.hpp:32
Definition: min_matrix.hpp:36
const GraphInfos< Graph > & get_infos() const
get a const reference to the graph infos
Definition: scaffold_graph.hpp:221
Definition: graph_typedefs.hpp:26
Predicated_EdgeIter< Graph, Predicate, EdgeIter< Graph > > get_edges(const Predicate &pred=Predicate()) const
get all edges satisfying a predicate
Definition: scaffold_graph.hpp:468