Skip to content

Commit 172ea1b

Browse files
authored
Merge pull request #343 from ds4dm/gasse-patch-2
2 parents c7f5a50 + 90c5c73 commit 172ea1b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

libecole/src/observation/khalil-2016.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ auto row_is_active(SCIP* const scip, SCIP_ROW* const row) noexcept -> bool {
357357
auto const activity = SCIPgetRowActivity(scip, row);
358358
auto const lhs = SCIProwGetLhs(row);
359359
auto const rhs = SCIProwGetRhs(row);
360-
return SCIPisEQ(scip, activity, rhs) || SCIPisEQ(scip, activity, lhs);
360+
return SCIProwIsInLP(row) && (SCIPisEQ(scip, activity, rhs) || SCIPisEQ(scip, activity, lhs));
361361
}
362362

363363
/**
@@ -437,7 +437,7 @@ void set_stats_for_active_constraint_coefficients(
437437
SCIP* const scip,
438438
nonstd::span<SCIP_ROW*> const rows,
439439
nonstd::span<SCIP_Real> const coefficients,
440-
xt::xtensor<value_type, 2> const& active_rows_weights) noexcept {
440+
xt::xtensor<value_type, 2> const& lp_rows_weights) noexcept {
441441

442442
auto weights_stats = std::array<utility::StatsFeatures<value_type>, 4>{};
443443
for (auto& stats : weights_stats) {
@@ -452,8 +452,10 @@ void set_stats_for_active_constraint_coefficients(
452452
if (row_is_active(scip, row)) {
453453
n_active_rows++;
454454

455+
assert(row_lp_idx >= 0);
456+
455457
for (std::size_t weight_idx = 0; weight_idx < weights_stats.size(); ++weight_idx) {
456-
auto const weight = active_rows_weights(row_lp_idx, weight_idx);
458+
auto const weight = lp_rows_weights(row_lp_idx, weight_idx);
457459
assert(!std::isnan(weight)); // If NaN likely hit a maked value
458460
auto const weighted_abs_coef = weight * std::abs(coef);
459461

@@ -475,7 +477,7 @@ void set_stats_for_active_constraint_coefficients(
475477
auto const row_lp_idx = SCIProwGetLPPos(row);
476478
if (row_is_active(scip, row)) {
477479
for (std::size_t weight_idx = 0; weight_idx < weights_stats.size(); ++weight_idx) {
478-
auto const weight = active_rows_weights(row_lp_idx, weight_idx);
480+
auto const weight = lp_rows_weights(row_lp_idx, weight_idx);
479481
assert(!std::isnan(weight)); // If NaN likely hit a maked value
480482
auto const weighted_abs_coef = weight * std::abs(coef);
481483

@@ -532,7 +534,7 @@ void set_dynamic_features(
532534
Tensor&& out,
533535
SCIP* const scip,
534536
SCIP_VAR* const var,
535-
xt::xtensor<value_type, 2> const& active_rows_weights) {
537+
xt::xtensor<value_type, 2> const& lp_rows_weights) {
536538
auto* const col = SCIPvarGetCol(var);
537539
auto const rows = scip::get_rows(col);
538540
auto const coefficients = scip::get_vals(col);
@@ -542,7 +544,7 @@ void set_dynamic_features(
542544
set_dynamic_stats_for_constraint_degree(out, rows);
543545
set_min_max_for_ratios_constraint_coeffs_rhs(out, scip, rows, coefficients);
544546
set_min_max_for_one_to_all_coefficient_ratios(out, rows, coefficients);
545-
set_stats_for_active_constraint_coefficients(out, scip, rows, coefficients, active_rows_weights);
547+
set_stats_for_active_constraint_coefficients(out, scip, rows, coefficients, lp_rows_weights);
546548
}
547549

548550
/**
@@ -566,14 +568,14 @@ auto extract_all_features(scip::Model& model, bool pseudo, xt::xtensor<value_typ
566568
auto observation = xt::xtensor<value_type, 2>{{model.variables().size(), Khalil2016Obs::n_features}, std::nan("")};
567569

568570
auto* const scip = model.get_scip_ptr();
569-
auto const active_rows_weights = stats_for_active_constraint_coefficients_weights(model);
571+
auto const lp_rows_weights = stats_for_active_constraint_coefficients_weights(model);
570572

571573
for (auto* var : branch_cands) {
572574
auto const var_idx = SCIPvarGetProbindex(var);
573575
auto var_features = xt::row(observation, var_idx);
574576
auto var_static_features = xt::row(static_features, var_idx);
575577
set_precomputed_static_features(var_features, var_static_features);
576-
set_dynamic_features(var_features, scip, var, active_rows_weights);
578+
set_dynamic_features(var_features, scip, var, lp_rows_weights);
577579
}
578580

579581
return observation;

0 commit comments

Comments
 (0)