diff --git a/libecole/CMakeLists.txt b/libecole/CMakeLists.txt index 55ea583e..d92962ce 100644 --- a/libecole/CMakeLists.txt +++ b/libecole/CMakeLists.txt @@ -28,6 +28,7 @@ add_library( src/reward/lp-iterations.cpp src/reward/solving-time.cpp src/reward/n-nodes.cpp + src/reward/tree-size-estimate.cpp src/reward/bound-integral.cpp src/observation/node-bipartite.cpp diff --git a/libecole/include/ecole/reward/tree-size-estimate.hpp b/libecole/include/ecole/reward/tree-size-estimate.hpp new file mode 100644 index 00000000..3b108d8e --- /dev/null +++ b/libecole/include/ecole/reward/tree-size-estimate.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "ecole/export.hpp" +#include "ecole/reward/abstract.hpp" +#include "scip/event_estim.h" +#include "scip/scip_event.h" + +#define EVENTHDLR_NAME "estim" + +namespace ecole::reward { + +class ECOLE_EXPORT TreeSizeEstimate { +public: + ECOLE_EXPORT auto before_reset(scip::Model& model) -> void; + ECOLE_EXPORT auto extract(scip::Model& model, bool done = false) -> Reward; + +private: + SCIP_Real tree_size_estimate = 0.0; +}; + +} // namespace ecole::reward diff --git a/libecole/src/reward/tree-size-estimate.cpp b/libecole/src/reward/tree-size-estimate.cpp new file mode 100644 index 00000000..6e87e937 --- /dev/null +++ b/libecole/src/reward/tree-size-estimate.cpp @@ -0,0 +1,16 @@ +#include "ecole/reward/tree-size-estimate.hpp" + +#include "ecole/scip/model.hpp" +#include "scip/def.h" + +namespace ecole::reward { + +void TreeSizeEstimate::before_reset(scip::Model& /* model */) {} + +Reward TreeSizeEstimate::extract(scip::Model& model, bool /* done */) { + // getTreeSizeEstimation returns -1 when no estimation has been made yet. + tree_size_estimate = SCIPgetTreesizeEstimation(model.get_scip_ptr()); + return tree_size_estimate; +} + +} // namespace ecole::reward diff --git a/python/ecole/src/ecole/core/reward.cpp b/python/ecole/src/ecole/core/reward.cpp index 984c7b34..0173dcf6 100644 --- a/python/ecole/src/ecole/core/reward.cpp +++ b/python/ecole/src/ecole/core/reward.cpp @@ -11,6 +11,7 @@ #include "ecole/reward/lp-iterations.hpp" #include "ecole/reward/n-nodes.hpp" #include "ecole/reward/solving-time.hpp" +#include "ecole/reward/tree-size-estimate.hpp" #include "ecole/scip/model.hpp" #include "core.hpp" @@ -147,6 +148,20 @@ void bind_submodule(py::module_ const& m) { The difference in number of nodes is computed in between calls. )"); + auto treesizeestimate = py::class_(m, "TreeSizeEstimate", R"( + Estimate the size of a tree. + + The reward is defined as the total number of nodes processed since the previous state. + )"); + treesizeestimate.def(py::init<>()); + def_operators(treesizeestimate); + def_before_reset(treesizeestimate, "Reset the internal node count."); + def_extract(treesizeestimate, R"( + Update the internal node count and return the difference. + + The difference in number of nodes is computed in between calls. + )"); + auto solvingtime = py::class_(m, "SolvingTime", R"( Solving time difference.