SIMLIB/C++  3.07
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 
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
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
62 p(new Param[n])
63 {
64  for (int i = 0; i < n; i++)
65  p[i] = a[i];
66 }
67 
68 // assignment
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 
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
98 {
99  for (int i = 0; i < n; i++)
100  ::Print("%g ", p[i].Value());
101 }
102 
104 {
105  for (int i = 0; i < n; i++)
106  p[i].Print();
107 }
108 
109 }
110 // end
int search(const char *name)
Definition: opt-param.cc:40
const char * name
Definition: optimize.h:19
ParameterVector & operator=(const ParameterVector &a)
Definition: opt-param.cc:69
friend bool operator==(const ParameterVector &p1, const ParameterVector &p2)
Definition: opt-param.cc:86
double min
Definition: optimize.h:20
const char * Name() const
Definition: optimize.h:48
Implementation of class CalendarList interface is static - using global functions in SQS namespace...
Definition: algloop.cc:32
void Print() const
Definition: opt-param.cc:21
Basic optimization framework + methods.
double value
Definition: optimize.h:22
Internal header file for SIMLIB/C++.
double max
Definition: optimize.h:21
Main SIMLIB/C++ interface.
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
ParameterVector(int sz, Param *a)
Definition: opt-param.cc:53
void PrintValues() const
Definition: opt-param.cc:97
Param & operator=(double x)
Definition: optimize.h:38