@@ -13,34 +13,32 @@ namespace ecole {
1313namespace observation {
1414
1515nonstd::optional<xt::xtensor<double , 1 >> Pseudocosts::obtain_observation (scip::Model& model) {
16+ if (model.get_stage () != SCIP_STAGE_SOLVING) {
17+ return {};
18+ }
1619
17- if (model.get_stage () == SCIP_STAGE_SOLVING) {
18-
19- SCIP* scip = model.get_scip_ptr ();
20-
21- SCIP_VAR** cands;
22- SCIP_Real* cands_lp_values;
23- int nb_cands;
20+ auto * const scip = model.get_scip_ptr ();
2421
25- /* get branching candidates */
26- SCIPgetLPBranchCands (scip, &cands, &cands_lp_values, NULL , NULL , &nb_cands, NULL );
27- assert (nb_cands > 0 );
22+ /* get branching candidates */
23+ SCIP_VAR** cands;
24+ SCIP_Real* cands_lp_values;
25+ int nb_cands;
2826
29- /* Store pseudocosts in tensor */
30- auto const nb_lp_columns = static_cast <std::size_t >(SCIPgetNLPCols (scip));
31- xt::xtensor<double , 1 > pseudocosts ({nb_lp_columns}, std::nan (" " ));
27+ SCIPgetLPBranchCands (scip, &cands, &cands_lp_values, NULL , NULL , &nb_cands, NULL );
28+ assert (nb_cands > 0 );
3229
33- for (int i = 0 ; i < nb_cands; i++) {
34- auto * const col = SCIPvarGetCol (cands[i]);
35- auto const lp_index = SCIPcolGetLPPos (col);
36- auto const score = SCIPgetVarPseudocostScore (scip, cands[i], cands_lp_values[i]);
37- pseudocosts (lp_index) = static_cast <double >(score);
38- }
39- return pseudocosts;
30+ /* Store pseudocosts in tensor */
31+ auto const nb_lp_columns = static_cast <std::size_t >(SCIPgetNLPCols (scip));
32+ xt::xtensor<double , 1 > pseudocosts ({nb_lp_columns}, std::nan (" " ));
4033
41- } else {
42- return {};
34+ for (std::size_t i = 0 ; i < static_cast <std::size_t >(nb_cands); i++) {
35+ auto * const col = SCIPvarGetCol (cands[i]);
36+ auto const lp_index = static_cast <std::size_t >(SCIPcolGetLPPos (col));
37+ auto const score = SCIPgetVarPseudocostScore (scip, cands[i], cands_lp_values[i]);
38+ pseudocosts[lp_index] = static_cast <double >(score);
4339 }
40+
41+ return pseudocosts;
4442}
4543
4644} // namespace observation
0 commit comments