idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
UniformlyRandom.h
1//
2// Created by henri on 17.10.23.
3//
4
5#ifndef IDOL_UNIFORMLYRANDOM_H
6#define IDOL_UNIFORMLYRANDOM_H
7
8#include "VariableBranching.h"
9#include "idol/mixed-integer/optimizers/branch-and-bound/branching-rules/impls/UniformlyRandom.h"
10
11namespace idol {
12 class UniformlyRandom;
13}
14
16 std::optional<unsigned int> m_seed;
17public:
18 UniformlyRandom() = default;
19
20 template<class IteratorT>
21 UniformlyRandom(IteratorT t_begin, IteratorT t_end) : idol::VariableBranching(t_begin, t_end) {}
22
23 template<class NodeInfoT>
24 class Strategy : public VariableBranching::Strategy<NodeInfoT> {
25 std::optional<unsigned int> m_seed;
26 public:
27 Strategy() = default;
28
29 explicit Strategy(const UniformlyRandom& t_parent)
31 m_seed(t_parent.m_seed) {}
32
34 operator()(const Optimizers::BranchAndBound<NodeInfoT> &t_parent) const override {
35
36 unsigned int seed = m_seed.has_value() ? m_seed.value() : (std::random_device())();
37
40 seed);
41 }
42
43 VariableBranching::Strategy<NodeInfoT> *clone() const override {
44 return new Strategy(*this);
45 }
46 };
47
48 UniformlyRandom& with_seed(unsigned int t_seed) {
49
50 if (m_seed.has_value()) {
51 throw Exception("A seed has already been configured.");
52 }
53
54 m_seed = t_seed;
55 }
56
57};
58
59#endif //IDOL_UNIFORMLYRANDOM_H