Skip to content

Commit

Permalink
adding B&B tree size as a reward function
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrwnaguib committed Feb 16, 2023
1 parent 353a450 commit e6ebddf
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions libecole/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions libecole/include/ecole/reward/tree-size-estimate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <cstdint>

#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
16 changes: 16 additions & 0 deletions libecole/src/reward/tree-size-estimate.cpp
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions python/ecole/src/ecole/core/reward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_<TreeSizeEstimate>(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_<SolvingTime>(m, "SolvingTime", R"(
Solving time difference.
Expand Down

0 comments on commit e6ebddf

Please sign in to comment.