OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
Loading...
Searching...
No Matches
Constraint.hpp
Go to the documentation of this file.
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5
6
This file is part of QuantLib, a free-software/open-source library
7
for financial quantitative analysts and developers - http://quantlib.org/
8
9
QuantLib is free software: you can redistribute it and/or modify it
10
under the terms of the QuantLib license. You should have received a
11
copy of the license along with this program; if not, please email
12
<quantlib-dev@lists.sf.net>. The license is also available online at
13
<http://quantlib.org/license.shtml>.
14
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the license for more details.
18
*/
19
20
/*! \file constraint.hpp
21
\brief Abstract constraint class
22
*/
23
24
#ifndef quantlib_optimization_constraint_h
25
#define quantlib_optimization_constraint_h
26
27
#include <config.h>
28
29
#include "
math/DynamicVector.hpp
"
30
31
using namespace
OpenMD
;
32
namespace
QuantLib {
33
34
//! Base constraint class
35
class
Constraint {
36
protected
:
37
//! Base class for constraint implementations
38
class
Impl
{
39
public
:
40
virtual
~Impl
() {}
41
//! Tests if params satisfy the constraint
42
virtual
bool
test
(
const
DynamicVector<RealType>
& params)
const
= 0;
43
};
44
Impl
* impl_;
45
46
public
:
47
bool
empty()
const
{
return
!impl_; }
48
bool
test(
const
DynamicVector<RealType>
& p)
const
{
return
impl_->
test
(p); }
49
RealType update(
DynamicVector<RealType>
& p,
50
const
DynamicVector<RealType>
& direction, RealType beta);
51
Constraint(Impl* impl = NULL);
52
virtual
~Constraint() {
delete
impl_; }
53
};
54
55
//! No constraint
56
class
NoConstraint :
public
Constraint {
57
private
:
58
class
Impl :
public
Constraint::Impl
{
59
public
:
60
bool
test(
const
DynamicVector<RealType>
&)
const
{
return
true
; }
61
};
62
63
public
:
64
NoConstraint() : Constraint(
new
NoConstraint::Impl()) {}
65
};
66
67
//! %Constraint imposing positivity to all arguments
68
class
PositiveConstraint :
public
Constraint {
69
private
:
70
class
Impl :
public
Constraint::Impl
{
71
public
:
72
bool
test(
const
DynamicVector<RealType>
& params)
const
{
73
for
(
size_t
i = 0; i < params.size(); ++i) {
74
if
(params[i] <= 0.0)
return
false
;
75
}
76
return
true
;
77
}
78
};
79
80
public
:
81
PositiveConstraint() : Constraint(
new
PositiveConstraint::Impl) {}
82
};
83
84
//! %Constraint imposing all arguments to be in [low,high]
85
class
BoundaryConstraint :
public
Constraint {
86
private
:
87
class
Impl :
public
Constraint::Impl
{
88
public
:
89
Impl(RealType low, RealType high) : low_(low), high_(high) {}
90
bool
test(
const
DynamicVector<RealType>
& params)
const
{
91
for
(
size_t
i = 0; i < params.size(); i++) {
92
if
((params[i] < low_) || (params[i] > high_))
return
false
;
93
}
94
return
true
;
95
}
96
97
private
:
98
RealType low_, high_;
99
};
100
101
public
:
102
BoundaryConstraint(RealType low, RealType high) :
103
Constraint(
new
BoundaryConstraint::Impl(low, high)) {}
104
};
105
106
//! %Constraint enforcing both given sub-constraints
107
class
CompositeConstraint :
public
Constraint {
108
private
:
109
class
Impl :
public
Constraint::Impl
{
110
public
:
111
Impl(
const
Constraint& c1,
const
Constraint& c2) : c1_(c1), c2_(c2) {}
112
bool
test(
const
DynamicVector<RealType>
& params)
const
{
113
return
c1_.test(params) && c2_.test(params);
114
}
115
116
private
:
117
Constraint c1_, c2_;
118
};
119
120
public
:
121
CompositeConstraint(
const
Constraint& c1,
const
Constraint& c2) :
122
Constraint(
new
CompositeConstraint::Impl(c1, c2)) {}
123
};
124
125
}
// namespace QuantLib
126
127
#endif
DynamicVector.hpp
OpenMD::DynamicVector
Dynamically-sized vector class.
Definition
DynamicVector.hpp:74
QuantLib::Constraint::Impl
Base class for constraint implementations.
Definition
Constraint.hpp:38
QuantLib::Constraint::Impl::test
virtual bool test(const DynamicVector< RealType > ¶ms) const =0
Tests if params satisfy the constraint.
OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Definition
ActionCorrFunc.cpp:63
optimization
Constraint.hpp
Generated on
for OpenMD by
1.17.0