bpp-core  2.2.0
AutoParameter.cpp
Go to the documentation of this file.
1 //
2 // File: AutoParameter.cpp
3 // Created by: Julien Dutheil
4 // Created on: Tue Nov 11 22:15:16 2003
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for numerical calculus.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #include "AutoParameter.h"
41 #include "NumConstants.h"
42 
43 #include <iostream>
44 
45 using namespace std;
46 
47 // Utils:
48 #include "../Text/TextTools.h"
49 #include "../App/ApplicationTools.h"
50 
51 using namespace bpp;
52 
53 /******************************************************************************/
54 
55 string AutoParameter::CONSTRAINTS_AUTO = "auto";
56 string AutoParameter::CONSTRAINTS_IGNORE = "ignore";
57 string AutoParameter::CONSTRAINTS_KEEP = "keep";
58 
61 AutoParameter::AutoParameter(const std::string& name, double value, Constraint* constraint, bool attachConstraint) throw (ConstraintException):
62  Parameter(name, value, constraint, attachConstraint), messageHandler_(ApplicationTools::message) {}
63 
64 AutoParameter::AutoParameter(const Parameter& p): Parameter(p), messageHandler_(ApplicationTools::message) {}
65 
66 AutoParameter::AutoParameter(const AutoParameter& p): Parameter(p), messageHandler_(p.messageHandler_) {}
67 
69 {
72  return *this;
73 }
74 
75 /******************************************************************************/
76 
77 void AutoParameter::setValue(double value) throw (ConstraintException)
78 {
79  try
80  {
81  // First we try to assign this value:
82  Parameter::setValue(value);
83  }
84  catch (ConstraintException& ce)
85  {
86  // Aie, there's a pb here...
87  if (messageHandler_)
88  {
89  (*messageHandler_) << "Constraint match at parameter ";
90  (*messageHandler_) << name_;
91  (*messageHandler_) << ", badValue = ";
92  (*messageHandler_) << ce.getBadValue();
93  (*messageHandler_) << " ";
94  (*messageHandler_ << constraint_->getDescription()).endLine();
95  }
96  double limit = constraint_->getAcceptedLimit(value);
97  try
98  { // We try to assign the limit then.
99  Parameter::setValue(limit);
100  }
101  catch(ConstraintException& ce2)
102  {
103  // Aie, the limit is not reachable, so we perform a smaller step...
104  //Parameter::setValue((getValue() + limit) / 2);
105  try
106  {
107  // Try on the right:
109  }
110  catch(ConstraintException& ce3)
111  {
112  // Try on the left:
114  }
115  }
116  }
117 }
118 
119 /******************************************************************************/
120 
This class allows to perform a correspondence analysis.
AutoParameter & operator=(const AutoParameter &param)
Assignment operator.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:135
AutoParameter(const std::string &name="", double value=0, Constraint *constraint=0, bool attachConstraint=false)
Build a new AutoParameter.
virtual double getBadValue() const
Get the value that doesn&#39;t match the constraint.
This class provides some common tools for developping applications.
OutputStream * messageHandler_
Definition: AutoParameter.h:62
virtual void setValue(double value)
Set the value of this parameter.
Definition: Parameter.cpp:123
static double TINY()
Definition: NumConstants.h:81
The constraint interface.
Definition: Constraints.h:62
The AutoParameter class.
Definition: AutoParameter.h:58
Exception thrown when a value do not match a given constraint.
Parameter & operator=(const Parameter &param)
Assignment operator.
Definition: Parameter.cpp:93
virtual void setValue(double value)
Set the value of this parameter.