8 #include "CoinHelperFunctions.hpp"
9 #include "CoinWarmStartBasis.hpp"
47 const int varnum = vars.
size();
49 const int cutnum = cuts.
size();
52 int newly_changed = 0;
62 printf(
"LP: Reduced cost fixing has changed the bounds on %i vars\n",
70 for (i = 0; i < varnum; ++i)
75 for (i = 0; i < cutnum; ++i)
78 bool lost_primal_feasibility =
false;
87 if (2 * changed_pos.
size() != new_bd.
size())
90 const int change_num = changed_pos.
size();
93 const double *
x = lpres.
x();
95 for (i = 0; i < change_num; ++i) {
98 const int pos = changed_pos[i];
99 const double old_lb = vars[
pos]->lb();
100 const double old_ub = vars[
pos]->ub();
101 const double new_lb = new_bd[2*i];
102 const double new_ub = new_bd[2*i+1];
103 if (old_lb > new_lb + petol || old_ub < new_ub - petol) {
108 if (new_lb < old_lb + petol && new_ub > old_ub - petol) {
109 printf(
"LP: BCP_lp_fix_vars(): WARNING: no change in bounds.\n");
115 new_bd[2*bd_changes] = new_lb;
116 new_bd[2*bd_changes+1] = new_ub;
117 changed_pos[bd_changes] =
pos;
119 if ((x[pos] < new_lb - petol) || (x[pos] > new_ub + petol))
120 lost_primal_feasibility =
true;
122 changed_pos.
erase(changed_pos.
entry(bd_changes), changed_pos.
end());
127 if (bd_changes > 0) {
132 printf(
"LP: Logical fixing has changed the bounds on %i vars\n",
138 return lost_primal_feasibility;
145 const bool error_if_deletable)
148 const int delnum = deletable.
size();
149 const int posnum = pos.
size();
150 for (i = 0, j = 0; i < delnum && j < posnum; ) {
152 if (error_if_deletable && deletable[i] == pos[j])
155 if (deletable[i] < pos[j]) {
162 for ( ; j < posnum; ++
j) {
174 deletable.
erase(std::lower_bound(deletable.
begin(), deletable.
end(),
175 num-added_num), deletable.
end());
176 for (
int i = num - added_num; i < num; ++i) {
179 if (pos && !pos->
empty()) {
181 std::lower_bound(deletable.
begin(), deletable.
end(), (*pos)[0]);
183 std::upper_bound(ifirst, deletable.
end(), pos->
back());
184 deletable.
erase(ifirst, ilast);
191 const int added_colnum,
192 const int added_rownum,
193 const bool from_fathom,
194 const bool force_delete)
204 const size_t varnum = vars.
size();
206 const size_t cutnum = cuts.
size();
209 CoinWarmStart*
ws = lp->getWarmStart();
210 CoinWarmStartBasis* bas =
dynamic_cast<CoinWarmStartBasis*
>(
ws);
213 deletable.
reserve(CoinMax(varnum, cutnum));
219 del_num = deletable.
size();
222 std::sort(deletable.
begin(), deletable.
end());
223 deletable.
erase(std::unique(deletable.
begin(), deletable.
end()),
225 del_num = deletable.
size();
226 if (can && added_colnum) {
230 del_num = deletable.
size();
236 for (
int i = 0; i < del_num; ++i) {
237 const int ind = deletable[i];
238 if (can && ind >= (
int)(varnum - added_colnum))
240 const CoinWarmStartBasis::Status stat = bas->getStructStatus(ind);
241 if (stat == CoinWarmStartBasis::basic ||
242 stat == CoinWarmStartBasis::isFree) {
247 if (! do_not_delete.
empty()) {
249 del_num = deletable.
size();
256 int min_to_del = force_delete ?
259 if (del_num > min_to_del) {
261 printf(
"LP: Deleting %i columns from the matrix.\n", del_num);
269 bas->deleteColumns(del_num, &deletable[0]);
271 p.
lp_solver->deleteCols(del_num, &deletable[0]);
273 deletable.
begin(), deletable.
end());
282 del_num = deletable.
size();
285 std::sort(deletable.
begin(), deletable.
end());
286 deletable.
erase(std::unique(deletable.
begin(), deletable.
end()),
288 del_num = deletable.
size();
289 if (can && added_rownum) {
293 del_num = deletable.
size();
299 for (
int i = 0; i < del_num; ++i) {
300 const int ind = deletable[i];
301 if (can && ind >= (
int)(cutnum - added_rownum))
303 const CoinWarmStartBasis::Status stat = bas->getArtifStatus(ind);
304 if (stat != CoinWarmStartBasis::basic) {
309 if (! do_not_delete.
empty()) {
311 del_num = deletable.
size();
318 min_to_del = force_delete ?
321 if (del_num > min_to_del) {
323 printf(
"LP: Deleting %i rows from the matrix.\n", del_num);
334 bas->deleteRows(del_num, &deletable[0]);
338 deletable.
begin(), deletable.
end());
344 if (varnum != vars.
size() || cutnum != cuts.
size()) {
346 lp->setWarmStart(bas);
361 const int cutnum = cuts.
size();
369 const double * rlb = p.
lp_solver->getRowLower();
370 const double * rub = p.
lp_solver->getRowUpper();
374 if (rlb[i] + petol < lhs[i] && lhs[i] < rub[i] - petol) {
390 if (CoinAbs(pi[i]) < detol) {
402 printf(
"LP: Row effectiveness: rownum: %i ineffective: %i\n",
420 if (added_rows < cp.
size()) {
428 for (
int i = cp.
size() - 1; i >= 0; --i) {
436 const double*
c = p.
lp_solver->getObjCoefficients();
438 const double cnorm = sqrt(std::inner_product(c, c+n, c, 0.0));
439 for (
int i = cp.
size() - 1; i >= 0; --i) {
443 fabs(cut.
row()->dotProduct(c)));
459 (
"BCP_lp_add_from_local_cut_pool() : rows are not valid.\n");
469 const CoinPackedVectorBase** rows =
470 new const CoinPackedVectorBase*[added_rows];
481 while (++cpi != last) {
493 while (++cpi != last) {
499 int leftover = cp.
size() - added_rows;
503 leftover = (frac <= 0.0) ? 0 :
static_cast<int>(frac * leftover);
505 if (leftover > maxnum)
506 leftover = maxnum > 0 ? maxnum : 0;
529 if (added_cols < vp.
size()) {
538 (
"BCP_lp_add_from_local_var_pool() : cols are not valid.\n");
548 const CoinPackedVectorBase** cols =
549 new const CoinPackedVectorBase*[added_cols];
563 while (++vpi != last) {
581 while (++vpi != last) {
double LowerBound() const
Return the lower bound.
BCP_vec< int > * implied_var_pos
This class holds a column in a compressed form.
double LowerBound() const
Return the lower bound.
The violation is the distance of the fractional point from the cut.
bool empty() const
Test if there are any entries in the object.
double UpperBound() const
Return the upper bound.
BCP_lp_node * node
Description he current search tree node.
void set_ub(const double ub)
Set the upper bound.
static void BCP_lp_reset_positions(const BCP_vec< int > &deletable, BCP_vec< int > &pos, const bool error_if_deletable)
How cut violation should be computed.
pos
position where the operator should be printed when printing the expression
void clear()
Delete every entry.
char param(BCP_lp_par::chr_params key) const
The maximum fraction of the violated but not added cuts to be kept from one iteration to the next...
void set_effective_count(const int cnt)
Set the effectiveness count to the given value.
void reduced_cost_fixing(const double *dj, const double *x, const double gap, BCP_vec< BCP_var * > &vars, int &newly_changed)
Reduced cost fixing.
double granularity() const
Abstract base class that defines members common to all types of cuts.
The violation is the directional (in the direction of the objective distance of the fractional point ...
void move_deletable_to_pool(const BCP_vec< int > &deletable_cuts, BCP_vec< BCP_cut * > &pool)
Move the cut pointers whose indices are listed in deletable_cuts into the pool.
iterator begin()
Return an iterator to the beginning of the object.
const double * lhs() const
The number of rows that must be marked for deletion before matrix compression can occur...
This class is just a collection of pointers to cuts with a number of methods to manipulate these cuts...
void reserve(const size_t n)
Reallocate the object to make space for n entries.
static int BCP_compare_waiting_col_ptr(const BCP_lp_waiting_col *wcol0, const BCP_lp_waiting_col *wcol1)
reference back()
Return a reference to the last entry.
int BCP_lp_add_from_local_var_pool(BCP_lp_prob &p)
static const CouNumber pi
void push_back(const_reference x)
Append x to the end of the vector.
Constraints with dual variables at level zero are considered ineffective.
static int BCP_compare_waiting_row_ptr(const BCP_lp_waiting_row *wrow0, const BCP_lp_waiting_row *wrow1)
Indicates which constraints should be considered ineffective.
int decrease_effective_count()
Decrease the effectiveness count by 1 (or to -1 if it was positive).
void fint fint fint real fint real real real real real real real real real * e
BCP_vec< int > * implied_cut_pos
bool is_non_removable() const
Return whether the cut marked as NotRemovable.
BCP_lp_cut_pool * local_cut_pool
double ub() const
Return the upper bound.
void erase(iterator pos)
Erase the entry pointed to by pos.
double primalTolerance() const
Return the primal tolerance of the solver.
BCP_lp_user * user
A class that holds the methods about how to pack things.
BCP_vec< int > * forced_cut_pos
Positions of cuts whose bounds change ("forcibly", by branching) in the children. ...
void fint fint fint real fint real real real real real real real real real fint real fint * lp
void BCP_lp_adjust_row_effectiveness(BCP_lp_prob &p)
int increase_effective_count()
Increase the effectiveness count by 1 (or to 1 if it was negative).
bool rows_are_valid() const
OsiSolverInterface * lp_solver
A class that holds the methods about how to pack things.
BCP_lp_result * lp_result
size_t cutnum() const
Return the number of cuts in the core.
void erase_by_index(const BCP_vec< int > &positions)
Erase the entries indexed by indices.
This class describes a generic branching object.
Print the number of variables whose bounds have been changed by reduced cost fixing or logical fixing...
BCP_vec< double > lb_at_cutgen
bool BCP_lp_fix_vars(BCP_lp_prob &p)
The maximum number of variables that can be added per iteration.
double Objective() const
Return the objective coefficient.
The number of columns that must be marked for deletion before matrix compression can occur...
BCP_lp_var_pool * local_var_pool
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
BCP_var_t var_type() const
Return the integrality type of the variable.
void insert(iterator position, const void *first, const size_t num)
Insert num entries starting from memory location first into the vector from position pos...
virtual void select_vars_to_delete(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool before_fathom, BCP_vec< int > &deletable)
int BCP_lp_add_from_local_cut_pool(BCP_lp_prob &p)
virtual void logical_fixing(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const BCP_vec< BCP_obj_status > &var_status, const BCP_vec< BCP_obj_status > &cut_status, const int var_bound_changes_since_logical_fixing, BCP_vec< int > &changed_pos, BCP_vec< double > &new_bd)
This method provides an opportunity for the user to tighten the bounds of variables.
BCP_vec< int > * forced_var_pos
Positions of variables whose bounds change ("forcibly", by branching) in the children.
void set_lb_ub(const BCP_vec< int > &pos, BCP_vec< double >::const_iterator bounds)
Set the lower/upper bound pairs of the entries given by the contents of pos to the values in [bounds...
Abstract base class that defines members common to all types of variables.
Currently there isn't any error handling in BCP.
double UpperBound() const
Return the upper bound.
void BCP_lp_check_ub(BCP_lp_prob &p)
The maximum number of violated but not added cuts to be kept from one iteration to the next...
The fraction of columns that must be marked for deletion before matrix compression can occur...
The violation is interpreted in the normal sense, i.e., max(0, max(lb-lhs, lhs-ub)) ...
virtual void select_cuts_to_delete(const BCP_lp_result &lpres, const BCP_vec< BCP_var * > &vars, const BCP_vec< BCP_cut * > &cuts, const bool before_fathom, BCP_vec< int > &deletable)
size_t size() const
Return the current number of entries.
BCP_vec< BCP_cut * > slack_pool
iterator end()
Return an iterator to the end of the object.
This class is just a collection of pointers to variables with a number of methods to manipulate these...
void set_violation(double v)
The class BCP_vec serves the same purpose as the vector class in the standard template library...
const double * pi() const
double dualTolerance() const
Return the dual tolerance of the solver.
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
void purge_ptr_vector_by_index(BCP_vec< T * > &pvec, typename BCP_vec< int >::const_iterator first, typename BCP_vec< int >::const_iterator last)
This function purges the entries indexed by [first,last) from the vector of pointers pvec...
Print the number of ineffective rows in the current problem.
double lb() const
Return the lower bound.
void purge_ptr_vector(BCP_vec< T * > &pvec, typename BCP_vec< T * >::iterator first, typename BCP_vec< T * >::iterator last)
This function purges the entries [first,last) from the vector of pointers pvec.
Print the number of columns and rows that were deleted during matrix compression. ...
Constraints with nonzero (primal) slack value are considered ineffective.
void set_lb(const double lb)
Set the lower bound.
The fraction of rows that must be marked for deletion before matrix compression can occur...
void BCP_delete_unwanted_candidates(const int num, const int added_num, const BCP_vec< int > *pos, BCP_vec< int > &deletable)
This class holds the results after solving an LP relaxation.
bool cols_are_valid() const
iterator entry(const int i)
Return an iterator to the i-th entry.
void BCP_lp_delete_cols_and_rows(BCP_lp_prob &p, BCP_lp_branching_object *can, const int added_colnum, const int added_rownum, const bool from_fathom, const bool force_delete)
The maximum number of violated valid inequalities that can be added per iteration.
None of the constraints are ever considered ineffective.
If true, BCP supports branching on cuts by providing potential branching candidates for the user...
int var_bound_changes_since_logical_fixing
void unchecked_erase_by_index(const BCP_vec< int > &positions)
Same as the previous method but without the sanity check.
void fint fint fint real fint real * x
This class holds a row in a compressed form.
const double * dj() const