7 #ifndef CMR_DUALGROUP_H 8 #define CMR_DUALGROUP_H 17 #include <unordered_map> 24 template <
typename numtype>
35 cut_pi(std::move(D.cut_pi)),
42 cut_pi = std::move(D.cut_pi);
65 template <
typename numtype>
70 using CutType = HyperGraph::Type;
76 vector<double> full_pi;
77 vector<double> d_node_pi;
78 vector<double> d_cut_pi;
80 const vector<HyperGraph> &cuts = ext_cuts.get_cuts();
82 const vector<int> &def_tour = clique_bank.ref_tour();
84 int node_count = def_tour.size();
86 if (relax.
num_rows() != node_count + cuts.size()) {
87 cerr <<
"Relaxation row count: " << relax.
num_rows() <<
", " 88 <<
"ExternalCuts expects: " 89 << (node_count + cuts.size()) <<
"\n";
90 throw std::logic_error(
"Size mismatch.");
96 node_pi = vector<numtype>(full_pi.begin(), full_pi.begin() + node_count);
100 cut_pi = vector<numtype>(full_pi.begin() + node_count, full_pi.end());
102 if (
node_pi.size() != node_count ||
cut_pi.size() != cuts.size())
103 throw std::logic_error(
"Node pi or cut pi size mismatch");
106 for (
int i = 0; i < cuts.size(); ++i) {
107 if (cuts[i].get_sense() ==
'G') {
109 cout <<
"\tCorrection: setting >= dual " 110 <<
cut_pi[i] <<
" to zero.\n";
113 }
else if (cuts[i].get_sense() ==
'L') {
115 cout <<
"\tCorrection: setting <= dual " 116 <<
cut_pi[i] <<
" to zero.\n";
124 for (
int i = 0; i < cuts.size(); ++i) {
125 const HyperGraph &H = cuts[i];
127 if (H.cut_type() == CutType::Non)
128 throw std::logic_error(
"Tried to get_duals with Non cut present.");
130 if (H.cut_type() == CutType::Domino)
133 numtype pival =
cut_pi[i];
143 for (
const std::pair<Sep::Clique, numtype> &kv :
clique_pi) {
145 numtype pival = kv.second;
149 for (
int k = seg.start; k <= seg.end; ++k) {
150 int node = def_tour[k];
153 node_pi_est[node] += pival;
156 }
else if (pival < 0.0) {
158 for (
int k = seg.start; k <= seg.end; ++k) {
159 int node = def_tour[k];
169 for (
int i = 0; i < cuts.size(); ++i) {
170 const HyperGraph &H = cuts[i];
171 if (H.cut_type() != CutType::Domino)
174 numtype pival =
cut_pi[i];
179 for (
const Segment &seg : handle_ref->seg_list()) {
180 for (
int k = seg.start; k <= seg.end; ++k) {
181 int node = def_tour[k];
182 node_pi_est[node] += pival;
188 for (
const Segment &seg : tpart.seg_list())
189 for (
int k = seg.start; k <= seg.end; ++k) {
190 int node = def_tour[k];
192 node_pi_est[node] += pival;
195 }
catch (
const std::exception &e) {
196 std::cerr << e.what() <<
"\n";
197 throw std::runtime_error(
"Problem in DualGroup constructor.");
void get_pi(std::vector< double > &pi, int begin, int end) const
Get a range of dual values.
Definition: lp_interface.cpp:926
std::unordered_map< Sep::Clique, numtype > clique_pi
Dual values/multiplicities for Cliques.
Definition: dualgroup.hpp:52
Type
Enumeration for the types of HyperGraph inequalities.
Definition: hypergraph.hpp:65
Representing cuts outside the LP solver.
The external storage of a collection of HyperGraph cuts in a Relaxation.
Definition: hypergraph.hpp:126
std::vector< numtype > node_pi
Dual values for degree constraints.
Definition: dualgroup.hpp:47
std::shared_ptr< Clique > Ptr
shared_ptr alias declaration.
Definition: cliq.hpp:54
int size() const
The number of unique Cliques in the bank.
Definition: cliq.hpp:195
Interface to the LP solver.
const std::vector< Segment > & seg_list() const
A constant reference to the list of segments in the Clique.
Definition: cliq.hpp:60
std::vector< numtype > node_pi_est
Overestimates of node_pi.
Definition: dualgroup.hpp:48
int num_rows() const
Number of rows in the model.
Definition: lp_interface.cpp:346
std::vector< numtype > cut_pi
Dual values for cuts.
Definition: dualgroup.hpp:49
Storage of a repository of Cliques, for use in building a HyperGraph.
Definition: cliq.hpp:167
Class for storing segment lists representing edges of a hypergraph.
Definition: cliq.hpp:34
std::shared_ptr< Tooth > Ptr
Pointer alias declaration.
Definition: cliq.hpp:104
Class for storing an lp relaxation via interface to an lp solver.
Definition: lp_interface.hpp:33
External representation of a cut added to the lp relaxation.
Definition: hypergraph.hpp:31
The namespace for this project.
Definition: abc_nodesel.hpp:20
Class template for storing dual LP solutions.
Definition: dualgroup.hpp:25
DualGroup()=default
Construct an empty DualGroup.
Simple utility struct for storing an interval of nodes.
Definition: util.hpp:198