PaGMO  1.1.5
set_get_params.cpp
1 /*****************************************************************************
2  * Copyright (C) 2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * http://apps.sourceforge.net/mediawiki/pagmo *
5  * http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Developers *
6  * http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Credits *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 #include <string>
25 #include <vector>
26 
27 #include "../worhp.h"
28 
29 namespace pagmo { namespace algorithm {
30 
31 void worhp::define_param_map() {
32  m_param_map["AcceptTolFeas"] = 1;
33  m_param_map["AcceptTolOpti"] = 2;
34  m_param_map["TolFeas"] = 3;
35  m_param_map["TolComp"] = 4;
36  m_param_map["TolOpti"] = 5;
37  m_param_map["NLPprint"] = 6;
38  m_param_map["InitialLMest"] = 7;
39  m_param_map["MaxIter"] = 8;
40 }
41 
42 void worhp::set_param(const std::string name, const double value)
43 {
44  // We check that the key exists
45  auto el = m_param_map.find(name);
46  if (el == m_param_map.end()) {
47  pagmo_throw(value_error,"Unknown parameter name, cannot set it.");
48  }
49  // According to the input we set the appropriate parameter
50  switch ( m_param_map[name] ) {
51  case 1:
52  m_params.AcceptTolFeas = value;
53  break;
54  case 2:
55  m_params.AcceptTolOpti = value;
56  break;
57  case 3:
58  m_params.TolFeas = value;
59  break;
60  case 4:
61  m_params.TolComp = value;
62  break;
63  case 5:
64  m_params.TolOpti = value;
65  break;
66  case 6:
67  m_params.NLPprint = value;
68  break;
69  case 7:
70  m_params.InitialLMest = value;
71  break;
72  case 8:
73  m_params.MaxIter = value;
74  break;
75  default:
76  pagmo_throw(value_error,"You should not be here!!");
77  }
78 }
79 
80 double worhp::get_param(const std::string name) const
81 {
82  // We check that the key exists
83  auto el = m_param_map.find(name);
84  if (el == m_param_map.end()) {
85  pagmo_throw(value_error,"Unknown parameter name, cannot get it.");
86  }
87 
88  // We make a copy for const correctness
89  std::map<std::string, int> map_copy = m_param_map;
90 
91  double retval = 0;
92 
93  // According to the input we return the appropriate parameter
94  switch ( map_copy[name] ) {
95  case 1:
96  retval = m_params.AcceptTolFeas;
97  break;
98  case 2:
99  retval = m_params.AcceptTolOpti;
100  break;
101  case 3:
102  retval = m_params.TolFeas;
103  break;
104  case 4:
105  retval = m_params.TolComp;
106  break;
107  case 5:
108  retval = m_params.TolOpti;
109  break;
110  case 6:
111  retval = m_params.NLPprint;
112  break;
113  case 7:
114  retval = m_params.InitialLMest;
115  break;
116  case 8:
117  retval = m_params.MaxIter;
118  break;
119  default:
120  pagmo_throw(value_error,"You should not be here!!");
121  }
122  return retval;
123 }
124 
125 std::vector<std::string> worhp::get_available_parameters() const
126 {
127  std::vector<std::string> retval;
128  for(auto it = m_param_map.begin(); it != m_param_map.end(); ++it) {
129  retval.push_back(it->first);
130  }
131  return retval;
132 }
133 
134 }} // namespaces
Root PaGMO namespace.