File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -46,14 +46,18 @@ bool HighsLp::isKnapsack(HighsInt& capacity) const {
4646 if (this ->row_lower_ [0 ] > -kHighsInf && this ->row_upper_ [0 ] < kHighsInf ) return false ;
4747 const bool upper = this ->row_upper_ [0 ] < kHighsInf ;
4848 const HighsInt constraint_sign = upper ? 1 : -1 ;
49- // Now check that all the (signed) coefficients are non-negative
50- for (HighsInt iEl = 0 ; iEl < this ->a_matrix_ .numNz (); iEl++)
51- if (constraint_sign * this ->a_matrix_ .value_ [iEl] < 0 ) return false ;
49+ // Now check that all the (signed) coefficients are integer and non-negative
50+ for (HighsInt iEl = 0 ; iEl < this ->a_matrix_ .numNz (); iEl++) {
51+ double coeff = constraint_sign * this ->a_matrix_ .value_ [iEl];
52+ if (coeff < 0 ) return false ;
53+ if (fractionality (coeff) > 0 ) return false ;
54+ }
55+ // Capacity must be integer, but OK to round down any fractional
56+ // values since activity of constraint is integer
57+ double double_capacity = upper ? this ->row_upper_ [0 ] : constraint_sign*this ->row_lower_ [0 ];
58+ const double capacity_margin = 1e-6 ;
59+ capacity = std::floor (double_capacity+capacity_margin);
5260 // Problem is knapsack!
53- //
54- // Get the capacity: if it is negative, then the problem is infeasible
55- capacity = upper ? this ->row_upper_ [0 ] : constraint_sign*this ->row_lower_ [0 ];
56- assert (capacity >= 0 );
5761 return true ;
5862}
5963
Original file line number Diff line number Diff line change @@ -1743,10 +1743,13 @@ HighsStatus HighsPrimalHeuristics::solveMipKnapsack() {
17431743 const HighsLogOptions& log_options = mipsolver.options_mip_ ->log_options ;
17441744 HighsInt capacity_;
17451745 assert (lp.isKnapsack (capacity_));
1746- const HighsInt capacity = capacity_;
17471746
17481747 const bool upper = lp.row_upper_ [0 ] < kHighsInf ;
17491748 const HighsInt constraint_sign = upper ? 1 : -1 ;
1749+ double double_capacity = upper ? lp.row_upper_ [0 ] : constraint_sign * lp.row_lower_ [0 ];
1750+ const double capacity_margin = 1e-6 ;
1751+ const HighsInt capacity = std::floor (double_capacity+capacity_margin);
1752+
17501753 if (capacity < 0 ) {
17511754 mipsolver.modelstatus_ = HighsModelStatus::kInfeasible ;
17521755 return solveMipKnapsackReturn (HighsStatus::kOk );
You can’t perform that action at this time.
0 commit comments