Camargue
lp_util.hpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7 #ifndef CMR_LP_UTIL_H
8 #define CMR_LP_UTIL_H
9 
10 #include <iostream>
11 #include <memory>
12 #include <stdexcept>
13 #include <utility>
14 #include <vector>
15 
16 
17 namespace CMR {
18 
20 namespace LP {
21 
25 namespace CutAge {
26 
27 constexpr int Babby = -1;
28 constexpr int PivOld = 30;
29 constexpr int TourOld = 20;
30 
31 }
32 
34 enum class PivType {
35  Frac,
36  Subtour,
37  Tour,
39 };
40 
42 enum class SolStat {
43  Optimal,
44  Infeas,
45  Abort
46 };
47 
48 inline std::ostream &operator<<(std::ostream &os, SolStat stat)
49 {
50  if (stat == SolStat::Optimal)
51  os << "Optimal";
52  else if (stat == SolStat::Infeas)
53  os << "Infeasible";
54  else if (stat == SolStat::Abort)
55  os << "Limit Abort";
56  else
57  throw std::logic_error("Unimplemented SolStat ostream<<");
58 
59  return os;
60 }
61 
62 inline bool is_tour_piv(PivType P)
63 {
64  return P == PivType::Tour || P == PivType::FathomedTour;
65 }
66 
68 enum BStat {
69  AtLower = 0,
70  Basic = 1,
71  AtUpper = 2,
72  FreeSuper = 3
73 };
74 
76 struct Basis {
77  Basis() = default;
78  Basis(Basis &&B) noexcept
79  : colstat(std::move(B.colstat)), rowstat(std::move(B.rowstat)) {}
80 
81  Basis &operator=(Basis &&B) noexcept
82  {
83  colstat = std::move(B.colstat);
84  rowstat = std::move(B.rowstat);
85  return *this;
86  }
87 
89  bool empty() const { return colstat.empty() || rowstat.empty(); }
90 
91  std::vector<int> colstat;
92  std::vector<int> rowstat;
93 
94  using Ptr = std::unique_ptr<Basis>;
95 };
96 
98 struct Estimate {
99  Estimate() = default;
100 
101  Estimate(double val)
102  : sol_stat(Stat::Abort), value(val), sb_base() {}
103 
104  Estimate(Estimate &&E) noexcept
105  : sol_stat(E.sol_stat), value(E.value), sb_base(std::move(E.sb_base))
106  {}
107 
108  Estimate &operator=(Estimate &&E) noexcept
109  {
110  sol_stat = E.sol_stat;
111  value = E.value;
112  sb_base = std::move(E.sb_base);
113 
114  return *this;
115  }
116 
118  enum class Stat {
119  Abort,
120  Infeas,
121  Prune
122  } sol_stat;
123 
124  double value;
125 
130  Basis::Ptr sb_base;
131 };
132 
133 inline std::ostream &operator<<(std::ostream &os, Estimate::Stat estat)
134 {
135  using Estat = Estimate::Stat;
136  if (estat == Estat::Prune)
137  os << "Prunable";
138  else if (estat == Estat::Infeas)
139  os << "Infeasible";
140  else if (estat == Estat::Abort)
141  os << "Limit Abort";
142  else
143  throw std::logic_error("Unimplemented Estimate::Stat ostream<<");
144 
145  return os;
146 }
147 
149 struct SparseRow {
150  std::vector<int> rmatind;
151  std::vector<double> rmatval;
152  char sense = '\0';
153  double rhs = 0.0;
154  double lp_viol = 0.0;
155 };
156 
157 inline std::ostream &operator<<(std::ostream &os, PivType piv)
158 {
159  using Ptype = LP::PivType;
160 
161  if (piv == Ptype::Frac)
162  os << "Fractional";
163  else if (piv == Ptype::Subtour)
164  os << "Integral subtour";
165  else if (piv == Ptype::Tour)
166  os << "Tour";
167  else if (piv == Ptype::FathomedTour)
168  os << "Optimal tour";
169 
170  return os;
171 }
172 
173 
174 }
175 }
176 
177 #endif
Non-basic and at upper bound.
Definition: lp_util.hpp:71
SolStat
Enum class for categorizing solution statuses.
Definition: lp_util.hpp:42
BStat
Variable basis statuses.
Definition: lp_util.hpp:68
Fractional solution.
PivType
Enum class for categorizing lp solutions.
Definition: lp_util.hpp:34
Non-basic and at lower bound.
Definition: lp_util.hpp:69
std::vector< int > rowstat
Row statuses.
Definition: lp_util.hpp:92
A tour with a dual feasible basis in the current lp.
Basis::Ptr sb_base
The basis from the strong branch search.
Definition: lp_util.hpp:130
Solution aborted due to external limit.
Free variable.
Definition: lp_util.hpp:72
Row and column basic statuses corresponding to some LP solution.
Definition: lp_util.hpp:76
bool empty() const
Is the basis empty/invalid.
Definition: lp_util.hpp:89
double value
The objective value estimate.
Definition: lp_util.hpp:124
Model proved infeasible.
Basic variable.
Definition: lp_util.hpp:70
std::vector< int > rmatind
Indices of nonzero entries.
Definition: lp_util.hpp:150
Integral subtour.
std::vector< double > rmatval
Coefficients for indices in rmatind.
Definition: lp_util.hpp:151
Struct for storing info from branching estimates.
Definition: lp_util.hpp:98
constexpr int Babby
A new or reset cut.
Definition: lp_util.hpp:27
The namespace for this project.
Definition: abc_nodesel.hpp:20
std::vector< int > colstat
Column statuses.
Definition: lp_util.hpp:91
constexpr int TourOld
Old cut age at tour dual solution.
Definition: lp_util.hpp:29
constexpr int PivOld
Old cut age at pivot duals.
Definition: lp_util.hpp:28
Simple struct representing sparse matrix row for passing to LP solver.
Definition: lp_util.hpp:149
A new or augmented tour.
Stat
Solution statuses from strong branch pivoting.
Definition: lp_util.hpp:118
Optimal solution.