SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
opt-param.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file opt-param.cc Optimization parameters
3
//
4
// Copyright (c) 2000-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
// EXPERIMENTAL
10
// parameters for optimization purposes
11
12
#include "
simlib.h
"
13
#include "
internal.h
"
14
#include "
optimize.h
"
15
#include <cstring>
// strcmp()
16
17
namespace
simlib3
{
18
19
SIMLIB_IMPLEMENTATION
;
20
21
void
Param::Print
()
const
22
{
23
::Print
(
"#Parameter %s: value=%g (min=%g, max=%g)\n"
,
name
,
value
,
min
,
24
max
);
25
}
26
27
#if 0
28
Param
&
Param::operator =
(
double
x) {
29
if
(x >
max
)
30
x =
max
;
31
if
(x <
min
)
32
x =
min
;
33
value
= x;
34
}
35
#endif
36
37
////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
int
ParameterVector::search
(
const
char
*name)
41
{
42
for
(
int
i = 0; i <
n
; i++)
43
if
(std::strcmp(
p
[i].Name(), name) == 0)
44
return
i;
45
return
-1;
46
}
47
48
// ParameterVector(): n(0), p(0) {}
49
// void Add(const Param&p) { add to the end }
50
// pp.Add(Param("x",1,5));
51
52
// initialize by array
53
ParameterVector::ParameterVector
(
int
sz,
Param
* a):
54
n
(sz),
p
(new
Param
[
n
])
55
{
56
for
(
int
i = 0; i <
n
; i++)
57
p
[i] = a[i];
58
}
59
60
// copy constructor
61
ParameterVector::ParameterVector
(
const
ParameterVector
& a):
n
(a.
n
),
62
p
(new
Param
[
n
])
63
{
64
for
(
int
i = 0; i <
n
; i++)
65
p
[i] = a[i];
66
}
67
68
// assignment
69
ParameterVector
&
ParameterVector::operator =
(
const
ParameterVector
& a) {
70
if
(
this
== &a)
71
return
*
this
;
// a=a
72
n
= a.
n
;
73
delete
[]
p
;
// TODO add exception-safety
74
p
=
new
Param
[
n
];
75
for
(
int
i = 0; i <
n
; i++)
76
p
[i] = a[i];
// copy objects
77
return
*
this
;
78
}
79
80
ParameterVector::~ParameterVector
()
81
{
82
delete
[]
p
;
83
}
84
85
// PROTOTYPE, values only !!!!!!!#########
86
bool
operator ==
(
const
ParameterVector
& p1,
const
ParameterVector
& p2) {
87
int
n
= p1.
size
();
88
if
(
n
!= p2.
size
())
89
return
false
;
90
for
(
int
i = 0; i <
n
; i++)
91
if
(p1[i].Value() != p2[i].Value())
92
return
false
;
93
return
true
;
94
}
95
96
// print
97
void
ParameterVector::PrintValues
()
const
98
{
99
for
(
int
i = 0; i <
n
; i++)
100
::Print
(
"%g "
,
p
[i].Value());
101
}
102
103
void
ParameterVector::Print
()
const
104
{
105
for
(
int
i = 0; i <
n
; i++)
106
p
[i].
Print
();
107
}
108
109
}
110
// end
simlib3::Param
Definition
optimize.h:18
simlib3::Param::value
double value
Definition
optimize.h:22
simlib3::Param::min
double min
Definition
optimize.h:20
simlib3::Param::operator=
Param & operator=(double x)
Definition
optimize.h:38
simlib3::Param::max
double max
Definition
optimize.h:21
simlib3::Param::Print
void Print() const
Definition
opt-param.cc:21
simlib3::Param::name
const char * name
Definition
optimize.h:19
simlib3::ParameterVector::PrintValues
void PrintValues() const
Definition
opt-param.cc:97
simlib3::ParameterVector::size
int size() const
Definition
optimize.h:71
simlib3::ParameterVector::ParameterVector
ParameterVector(int sz, Param *a)
Definition
opt-param.cc:53
simlib3::ParameterVector::operator=
ParameterVector & operator=(const ParameterVector &a)
Definition
opt-param.cc:69
simlib3::ParameterVector::n
int n
Definition
optimize.h:59
simlib3::ParameterVector::Print
void Print() const
Definition
opt-param.cc:103
simlib3::ParameterVector::~ParameterVector
~ParameterVector()
Definition
opt-param.cc:80
simlib3::ParameterVector::p
Param * p
Definition
optimize.h:60
simlib3::ParameterVector::search
int search(const char *name)
Definition
opt-param.cc:40
internal.h
Internal header file for SIMLIB/C++.
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::operator==
bool operator==(const ParameterVector &p1, const ParameterVector &p2)
Definition
opt-param.cc:86
simlib3::min
double min(double a, double b)
Definition
internal.h:285
simlib3::max
double max(double a, double b)
Definition
internal.h:286
optimize.h
Basic optimization framework + methods.
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0