alpaqa
1.0.0a10
Nonconvex constrained optimization
Toggle main menu visibility
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
i
l
m
n
o
p
r
s
t
u
v
w
Functions
a
b
c
d
e
f
i
m
n
o
p
r
s
t
u
w
Variables
Typedefs
c
d
f
i
l
m
p
r
t
u
v
Enumerations
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
û
α
γ
δ
ε
λ
ρ
σ
τ
φ
ψ
ϵ
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
û
α
ρ
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
α
γ
δ
ε
λ
ρ
σ
τ
φ
ψ
ϵ
Typedefs
a
b
c
d
e
f
h
i
l
m
n
o
p
r
s
t
v
w
Enumerations
Enumerator
Related Functions
Files
File List
File Members
All
a
c
d
e
f
g
l
m
p
r
s
t
u
w
Functions
a
c
d
e
f
g
l
m
p
r
s
t
w
Typedefs
Macros
a
c
e
p
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
src
alpaqa
include
alpaqa
util
max-history.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <algorithm>
4
#include <cstddef>
5
#include <vector>
6
7
namespace
alpaqa
{
8
9
/// Keep track of the maximum value over a specified horizon length.
10
template
<
class
T>
11
class
MaxHistory
{
12
public
:
13
MaxHistory
(
size_t
memory) :
buffer
(std::vector<T>(memory)) {}
14
15
void
add
(T newt) {
16
if
(
full
) {
17
T oldt = std::move(*
it
);
18
*
it
= std::move(newt);
19
if
(*
it
>
max_
)
20
max_
= *
it
;
21
else
if
(oldt ==
max_
)
22
max_
= *std::max_element(
buffer
.begin(),
buffer
.end());
23
++
it
;
24
if
(
it
==
buffer
.end())
25
it
=
buffer
.begin();
26
}
else
{
27
if
(
it
==
buffer
.begin() || newt >
max_
)
28
max_
= newt;
29
*
it
= std::move(newt);
30
++
it
;
31
if
(
it
==
buffer
.end()) {
32
it
=
buffer
.begin();
33
full
=
true
;
34
}
35
}
36
}
37
38
const
T &
max
()
const
{
return
max_
; }
39
40
private
:
41
std::vector<T>
buffer
;
42
bool
full
=
false
;
43
decltype
(
buffer
.begin())
it
=
buffer
.begin();
44
T
max_
{};
45
};
46
47
}
// namespace alpaqa
alpaqa::MaxHistory
Keep track of the maximum value over a specified horizon length.
Definition:
max-history.hpp:11
alpaqa::MaxHistory::MaxHistory
MaxHistory(size_t memory)
Definition:
max-history.hpp:13
alpaqa::MaxHistory::full
bool full
Definition:
max-history.hpp:42
alpaqa::MaxHistory::add
void add(T newt)
Definition:
max-history.hpp:15
alpaqa::MaxHistory::buffer
std::vector< T > buffer
Definition:
max-history.hpp:41
alpaqa::MaxHistory::it
decltype(buffer.begin()) it
Definition:
max-history.hpp:43
alpaqa::MaxHistory::max_
T max_
Definition:
max-history.hpp:44
alpaqa::MaxHistory::max
const T & max() const
Definition:
max-history.hpp:38
alpaqa
Definition:
anderson.hpp:10
Generated by
1.9.6