Skip to content

Commit 2256aae

Browse files
committed
Stripped out type-specific MIP data; formatted
1 parent de18260 commit 2256aae

File tree

4 files changed

+72
-131
lines changed

4 files changed

+72
-131
lines changed

highs/mip/HighsMipSolver.cpp

Lines changed: 60 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void HighsMipSolver::run() {
154154
}
155155
// If the presolved problem is not suitable for Ines, then it's
156156
// recorded as "other"
157-
if (!mipdata_->mipIsInes()) mipdata_->mipIsOther();
157+
if (!mipdata_->mipIsInes()) mipdata_->mipIsOther();
158158

159159
analysis_.mipTimerStart(kMipClockSolve);
160160

@@ -890,101 +890,90 @@ void HighsMipSolver::cleanupSolve(const bool mip_logging) {
890890
(long long unsigned)mipdata_->sb_lp_iterations,
891891
(long long unsigned)mipdata_->sepa_lp_iterations,
892892
(long long unsigned)mipdata_->heuristic_lp_iterations);
893-
const HighsKnapsackData& knapsack_data = this->mipdata_->knapsack_data_;
894-
std::stringstream ss;
895-
ss.str(std::string());
896-
ss << highsFormatToString(" Knapsack MIPs %d",
897-
int(knapsack_data.num_problem));
898-
if (knapsack_data.num_problem > 0)
899-
ss << highsFormatToString(
900-
" (mean items %d; mean capacity %d)",
901-
int((1.0 * knapsack_data.sum_variables) / knapsack_data.num_problem),
902-
int((1.0 * knapsack_data.sum_capacity) / knapsack_data.num_problem));
903-
highsLogUser(options_mip_->log_options, HighsLogType::kInfo, "%s\n",
904-
ss.str().c_str());
905-
const HighsInesData& ines_data = this->mipdata_->ines_data_;
906-
ss.str(std::string());
907-
ss << highsFormatToString(" Ines MIPs %d",
908-
int(ines_data.num_problem));
909-
if (ines_data.num_problem > 0)
910-
ss << highsFormatToString(
911-
" (mean columns %d; mean rows %d)",
912-
int((1.0 * ines_data.sum_col) / ines_data.num_problem),
913-
int((1.0 * ines_data.sum_row) / ines_data.num_problem));
914-
highsLogUser(options_mip_->log_options, HighsLogType::kInfo, "%s\n",
915-
ss.str().c_str());
916893

917-
if (knapsack_data.num_problem > 0 || ines_data.num_problem > 0)
918-
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
919-
"grep-knapsack-ines,%s,%s,%d,%" PRId64 ",%" PRId64
920-
",%d,%" PRId64 ",%" PRId64 "\n",
921-
model_->model_name_.c_str(), options_mip_->presolve.c_str(),
922-
knapsack_data.num_problem, knapsack_data.sum_variables,
923-
knapsack_data.sum_capacity, ines_data.num_problem,
924-
ines_data.sum_col, ines_data.sum_row);
925-
926-
const std::vector<HighsMipProblemData>& mip_problem_data = this->mipdata_->mip_problem_data_;
894+
const std::vector<HighsMipProblemData>& mip_problem_data =
895+
this->mipdata_->mip_problem_data_;
927896
HighsInt num_mip = static_cast<HighsInt>(mip_problem_data.size());
928897
HighsInt num_knapsack_mip = 0;
929898
size_t sum_knapsack_num_col = 0;
930899
HighsInt num_ines_mip = 0;
931900
size_t sum_ines_num_col = 0;
932901
size_t sum_ines_num_row = 0;
933902
HighsInt lc_max_submip_level = -1;
903+
HighsInt min_submip_sum_dim = kHighsIInf;
934904
HighsInt min_submip_num_col = kHighsIInf;
935905
HighsInt min_submip_num_row = kHighsIInf;
906+
const bool full_submip_logging = true;
936907
for (HighsInt iMip = 0; iMip < num_mip; iMip++) {
937908
switch (mip_problem_data[iMip].type) {
938-
case HighsMipProblemType::kKnapsack:
939-
num_knapsack_mip++;
940-
sum_knapsack_num_col += mip_problem_data[iMip].num_binary;
941-
break;
942-
case HighsMipProblemType::kInes:
943-
num_ines_mip++;
944-
sum_ines_num_col += mip_problem_data[iMip].num_binary;
945-
sum_ines_num_row += mip_problem_data[iMip].num_row;
946-
break;
947-
case HighsMipProblemType::kOther:
948-
default:
949-
break;
909+
case HighsMipProblemType::kKnapsack:
910+
num_knapsack_mip++;
911+
sum_knapsack_num_col += mip_problem_data[iMip].num_binary;
912+
break;
913+
case HighsMipProblemType::kInes:
914+
num_ines_mip++;
915+
sum_ines_num_col += mip_problem_data[iMip].num_binary;
916+
sum_ines_num_row += mip_problem_data[iMip].num_row;
917+
break;
918+
case HighsMipProblemType::kOther:
919+
default:
920+
break;
921+
}
922+
HighsInt lc_submip_level = mip_problem_data[iMip].submip_level;
923+
924+
lc_max_submip_level = std::max(lc_submip_level, lc_max_submip_level);
925+
HighsInt submip_num_col = mip_problem_data[iMip].num_continuous +
926+
mip_problem_data[iMip].num_binary +
927+
mip_problem_data[iMip].num_general_integer +
928+
mip_problem_data[iMip].num_implied_integer;
929+
HighsInt submip_num_row = mip_problem_data[iMip].num_row;
930+
HighsInt submip_sum_dim = submip_num_col + submip_num_row;
931+
if (min_submip_sum_dim > submip_sum_dim) {
932+
min_submip_sum_dim = submip_sum_dim;
933+
min_submip_num_col = submip_num_col;
934+
min_submip_num_row = submip_num_row;
950935
}
951-
lc_max_submip_level = std::max(mip_problem_data[iMip].submip_level, lc_max_submip_level);
952-
HighsInt submip_num_col =
953-
mip_problem_data[iMip].num_continuous +
954-
mip_problem_data[iMip].num_binary +
955-
mip_problem_data[iMip].num_general_integer +
956-
mip_problem_data[iMip].num_implied_integer;
957-
958-
min_submip_num_col = std::min(submip_num_col, min_submip_num_col);
959-
min_submip_num_row = std::min(mip_problem_data[iMip].num_row, min_submip_num_row);
936+
if (full_submip_logging)
937+
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
938+
" MIP %3d (level = %2d; %3d conts; %3d bin; "
939+
"%3d gen; %3d impl; cols / rows: %3d / %3d; type %s)\n",
940+
int(iMip), int(lc_submip_level),
941+
int(mip_problem_data[iMip].num_continuous),
942+
int(mip_problem_data[iMip].num_binary),
943+
int(mip_problem_data[iMip].num_general_integer),
944+
int(mip_problem_data[iMip].num_implied_integer),
945+
int(submip_num_col), int(submip_num_row),
946+
mip_problem_data[iMip].type == HighsMipProblemType::kKnapsack
947+
? "Knapsack"
948+
: mip_problem_data[iMip].type == HighsMipProblemType::kInes
949+
? "Ines"
950+
: "Other");
960951
}
961952
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
962-
" MIPs %d (%d knapsack; %d Ines)\n",
963-
int(num_mip),
964-
int(num_knapsack_mip),
965-
int(num_ines_mip));
966-
953+
" MIPs %d (%d knapsack; %d Ines)\n", int(num_mip),
954+
int(num_knapsack_mip), int(num_ines_mip));
955+
956+
std::stringstream ss;
967957
ss.str(std::string());
968958
ss << highsFormatToString(" Max sub-MIP depth %d", int(max_submip_level));
969-
if (max_submip_level > 0)
970-
ss << highsFormatToString(" min cols/rows = %d/%d\n");
959+
if (max_submip_level > 0)
960+
ss << highsFormatToString(" (min cols/rows: %d/%d)\n",
961+
int(min_submip_num_col), int(min_submip_num_row));
971962
highsLogUser(options_mip_->log_options, HighsLogType::kInfo, "%s\n",
972-
ss.str().c_str());
963+
ss.str().c_str(), int(min_submip_num_col),
964+
int(min_submip_num_row));
973965

974966
if (num_knapsack_mip > 0 || num_ines_mip > 0)
975967
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
976-
"grep-knapsack-ines,%s,%s,%d,%" PRId64 "%d,%" PRId64 ",%" PRId64 "\n",
968+
"grep-knapsack-ines,%s,%s,%d,%" PRId64 ",%d,%" PRId64
969+
",%" PRId64 "\n",
977970
model_->model_name_.c_str(), options_mip_->presolve.c_str(),
978-
num_knapsack_mip, sum_knapsack_num_col,
979-
num_ines_mip, sum_ines_num_col, sum_ines_num_row);
971+
num_knapsack_mip, sum_knapsack_num_col, num_ines_mip,
972+
sum_ines_num_col, sum_ines_num_row);
980973

981974
if (max_submip_level > 0) {
982975
}
983-
984-
985-
986-
987-
976+
988977
if (!timeless_log) analysis_.reportMipTimer();
989978

990979
assert(modelstatus_ != HighsModelStatus::kNotset);

highs/mip/HighsMipSolverData.cpp

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,8 @@ void HighsMipSolverData::init() {
684684
upper_limit = mipsolver.options_mip_->objective_bound;
685685
optimality_limit = mipsolver.options_mip_->objective_bound;
686686
primal_dual_integral.initialise();
687-
knapsack_data_.initialise();
688687
knapsack_capacity_ = 0;
689688
knapsack_integral_scale_ = 0;
690-
ines_data_.initialise();
691689
mip_problem_data_.clear();
692690

693691
if (mipsolver.options_mip_->mip_report_level == 0)
@@ -2688,9 +2686,6 @@ bool HighsMipSolverData::mipIsKnapsack(const bool silent) {
26882686
this->knapsack_capacity_ = std::floor(double_capacity + capacity_margin);
26892687
// Problem is knapsack!
26902688
if (!silent) {
2691-
this->knapsack_data_.num_problem++;
2692-
this->knapsack_data_.sum_variables += lp.num_col_;
2693-
this->knapsack_data_.sum_capacity += this->knapsack_capacity_;
26942689
HighsMipProblemData mip_problem_data;
26952690
mip_problem_data.clear();
26962691
mip_problem_data.submip_level = mipsolver.submip_level;
@@ -2720,9 +2715,6 @@ bool HighsMipSolverData::mipIsInes(const bool silent) {
27202715
if (!silent) {
27212716
highsLogUser(mipsolver.options_mip_->log_options, HighsLogType::kInfo,
27222717
"MIP is an Ines problem\n");
2723-
this->ines_data_.num_problem++;
2724-
this->ines_data_.sum_col += lp.num_col_;
2725-
this->ines_data_.sum_row += lp.num_row_;
27262718
HighsMipProblemData mip_problem_data;
27272719
mip_problem_data.clear();
27282720
mip_problem_data.submip_level = mipsolver.submip_level;
@@ -2744,14 +2736,14 @@ void HighsMipSolverData::mipIsOther() {
27442736
mip_problem_data.num_continuous++;
27452737
} else if (lp.integrality_[iCol] == HighsVarType::kInteger) {
27462738
if (lp.col_lower_[iCol] == 0 && lp.col_upper_[iCol] == 1) {
2747-
mip_problem_data.num_binary++;
2739+
mip_problem_data.num_binary++;
27482740
} else {
2749-
mip_problem_data.num_general_integer++;
2741+
mip_problem_data.num_general_integer++;
27502742
}
27512743
} else if (lp.integrality_[iCol] == HighsVarType::kImplicitInteger) {
27522744
mip_problem_data.num_implied_integer++;
27532745
} else {
2754-
assert(111==234);
2746+
assert(111 == 234);
27552747
}
27562748
}
27572749
mip_problem_data.num_row = lp.num_row_;
@@ -2904,27 +2896,3 @@ void HighsMipProblemData::clear() {
29042896
this->num_row = 0;
29052897
this->type = HighsMipProblemType::kOther;
29062898
}
2907-
2908-
void HighsKnapsackData::initialise() {
2909-
num_problem = 0;
2910-
sum_variables = 0;
2911-
sum_capacity = 0;
2912-
}
2913-
2914-
void HighsKnapsackData::add(const HighsKnapsackData& knapsack_data) {
2915-
this->num_problem += knapsack_data.num_problem;
2916-
this->sum_variables += knapsack_data.sum_variables;
2917-
this->sum_capacity += knapsack_data.sum_capacity;
2918-
}
2919-
2920-
void HighsInesData::initialise() {
2921-
num_problem = 0;
2922-
sum_col = 0;
2923-
sum_row = 0;
2924-
}
2925-
2926-
void HighsInesData::add(const HighsInesData& ines_data) {
2927-
this->num_problem += ines_data.num_problem;
2928-
this->sum_col += ines_data.sum_col;
2929-
this->sum_row += ines_data.sum_row;
2930-
}

highs/mip/HighsMipSolverData.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,6 @@ struct HighsMipProblemData {
4343
void clear();
4444
};
4545

46-
struct HighsKnapsackData {
47-
HighsInt num_problem;
48-
int64_t sum_variables;
49-
int64_t sum_capacity;
50-
void initialise();
51-
void add(const HighsKnapsackData& knapsack_data);
52-
};
53-
54-
struct HighsInesData {
55-
HighsInt num_problem;
56-
int64_t sum_col;
57-
int64_t sum_row;
58-
void initialise();
59-
void add(const HighsInesData& ines_data);
60-
};
61-
6246
struct HighsPrimaDualIntegral {
6347
double value;
6448
double prev_lb;
@@ -182,12 +166,9 @@ struct HighsMipSolverData {
182166

183167
HighsDebugSol debugSolution;
184168

185-
HighsKnapsackData knapsack_data_;
186169
HighsInt knapsack_capacity_;
187170
HighsInt knapsack_integral_scale_;
188171

189-
HighsInesData ines_data_;
190-
191172
std::vector<HighsMipProblemData> mip_problem_data_;
192173

193174
HighsMipSolverData(HighsMipSolver& mipsolver)

highs/mip/HighsPrimalHeuristics.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,17 @@ bool HighsPrimalHeuristics::solveSubMip(
152152
submipsolver.run();
153153
mipsolver.max_submip_level =
154154
std::max(submipsolver.max_submip_level + 1, mipsolver.max_submip_level);
155-
156-
mipsolver.mipdata_->knapsack_data_.add(submipsolver.mipdata_->knapsack_data_);
157-
mipsolver.mipdata_->ines_data_.add(submipsolver.mipdata_->ines_data_);
158155

159156
// Append the sub-MIP problem data to this MIP problem data
160-
mipsolver.mipdata_->mip_problem_data_.insert(mipsolver.mipdata_->mip_problem_data_.end(),
161-
submipsolver.mipdata_->mip_problem_data_.begin(),
162-
submipsolver.mipdata_->mip_problem_data_.end());
157+
std::vector<HighsMipProblemData> mipsolver_mip_data =
158+
mipsolver.mipdata_->mip_problem_data_;
159+
std::vector<HighsMipProblemData> submipsolver_mip_data =
160+
submipsolver.mipdata_->mip_problem_data_;
161+
mipsolver.mipdata_->mip_problem_data_.insert(
162+
mipsolver.mipdata_->mip_problem_data_.end(),
163+
submipsolver.mipdata_->mip_problem_data_.begin(),
164+
submipsolver.mipdata_->mip_problem_data_.end());
165+
mipsolver_mip_data = mipsolver.mipdata_->mip_problem_data_;
163166

164167
if (!mipsolver.submip) mipsolver.analysis_.mipTimerStop(kMipClockSubMipSolve);
165168
if (submipsolver.mipdata_) {

0 commit comments

Comments
 (0)