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
11
namespace
idol {
12
class
UniformlyRandom;
13
}
14
15
class
idol::UniformlyRandom
:
public
idol::VariableBranching
{
16
std::optional<unsigned int> m_seed;
17
public
:
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)
30
:
VariableBranching::Strategy<NodeInfoT>
(t_parent),
31
m_seed(t_parent.m_seed) {}
32
33
BranchingRules::VariableBranching<NodeInfoT>
*
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
38
return
new
BranchingRules::UniformlyRandom<NodeInfoT>
(t_parent,
39
idol::VariableBranching::Strategy<NodeInfoT>::create_branching_candidates
(t_parent.parent()),
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
idol::BranchingRules::UniformlyRandom
Definition
UniformlyRandom.h:16
idol::BranchingRules::VariableBranching
Definition
VariableBranching.h:19
idol::Exception
Definition
Exception.h:14
idol::Optimizers::BranchAndBound
Definition
Optimizers_BranchAndBound.h:30
idol::UniformlyRandom::Strategy
Definition
UniformlyRandom.h:24
idol::UniformlyRandom
Definition
UniformlyRandom.h:15
idol::VariableBranching::Strategy
Definition
VariableBranching.h:33
idol::VariableBranching
Definition
VariableBranching.h:18
lib
include
idol
mixed-integer
optimizers
branch-and-bound
branching-rules
factories
UniformlyRandom.h
Generated by
1.9.8