Skip to main content

optiSLang MOPSolver API 2024 R1

mopsolver

Last update: 16.07.2025
1// $Id$
2
3#pragma once
4#ifndef _MOPSOLVER_HPP_
5#define _MOPSOLVER_HPP_
6
7#include "mopsolver_dlpublic.h"
8#include "typedef/base_types.hpp"
9#include "ok_math_types.hpp"
10#include "omdb.hpp"
11#include "surrogate_info.hpp"
12#include "mop_permissions.hpp"
13#include <mutex>
14
15namespace dynardo
16{
17 namespace integration
18 {
19 class FMOPSolver;
20 typedef boost::shared_ptr< FMOPSolver > FMOPSolver_ptr_type;
21 }
22
23 namespace mop
24 {
25 class CMOPCustomSolver;
26 typedef boost::shared_ptr< CMOPCustomSolver > mop_custom_solver_ptr_type;
27
28
29 DYNARDO_MOPSOLVER_INTERNAL_DLPUBLIC std::string GetVersion();
30
31 static inline const wchar_t* GetResourceFileName() { return L"mop_tenbar.omdb"; }
32
34 std::vector<double> responses;
35 std::vector<double> criteria_values;
36 };
37
38 class DYNARDO_MOPSOLVER_INTERNAL_DLPUBLIC MOPSolver
39 {
40 public:
41 typedef dynardo::algorithm::datatypes::SurrogateInfoContainer surrogate_info_container_type;
42 typedef dynardo::algorithm::datatypes::name_size_list_type responses_pair_type;
43 typedef std::vector< std::pair< bool, dynardo::string_type > > quality_usage_suffix_vector_type;
44 typedef std::pair< dynardo::string_list_type, dynardo::string_list_type > input_output_names_pair_type;
45 typedef std::map< dynardo::string_type, input_output_names_pair_type > external_solver_input_output_names_map_type;
46 typedef std::map< dynardo::string_type, dynardo::path_type > title_path_map_type;
47
48 MOPSolver( bool _signals_wanted = true );
49 MOPSolver( const dynardo::path_type& _omdb, bool _signals_wanted = true );
50 ~MOPSolver();
51
52 void SetWorkingDirectory( const dynardo::path_type& _wdir );
53 void SetInitializeNames( const dynardo::string_list_type& _initialize_responses, const dynardo::string_list_type& _initialize_errors );
54
55 bool InitializeSolver( const dynardo::path_type& );
56 bool InitializeSolver( const dynardo::algorithm::datatypes::OMDB&, const dynardo::path_type& = dynardo::path_type() );
57 bool InitializeSolver();
58
59 bool CanApproximateFMOP( const title_path_map_type& _title_path_map );
60 static bool CanInitializeFMOPSolver( const dynardo::algorithm::datatypes::OMDB&, dynardo::utils::log::LogBase_ptr_type );
61 void InitializeFMOPSolver();
62 void ReleaseFMOPSolver();
63
64 void InitializeMOPCustomSolvers();
65
66 bool BoundariesViolated(
67 const dynardo::design_type& _design,
68 dynardo::enums::eExtrapolationTypes _extrapolation_type,
69 bool _throw );
70
71 void SetLog( dynardo::utils::log::LogBase_ptr_type );
72 dynardo::utils::log::LogBase_ptr_type GetLog();
73 dynardo::utils::log::LogBase& GetLoggerRef();
74
75 void SetMOPSolverPermissions( const dynardo::mop::MOPSolverPermissions& _mopsolver_permissions )
76 {
77 mopsolver_permissions_ = _mopsolver_permissions;
78 }
79
80 const dynardo::algorithm::datatypes::OMDB& GetOMDB() const;
81 const surrogate_info_container_type& GetSurrogateInfos() const;
82
83 const dynardo::design_type& GetReferenceDesign();
84 const dynardo::string_list_type& GetParameterNames();
85 const dynardo::string_list_type& GetResponseNames();
86 const dynardo::string_list_type& GetCriteriaNames();
87 const dynardo::criterion_seq_type& GetAllCriteria();
88
89 external_solver_input_output_names_map_type GetExternalInputsOutputsNames();
90
91 dynardo::design_type GetDesignWithOnlyActiveParameter( const design_type& orig_design );
92
93 void RemoveCVValues();
94
95 // convenience
96 typedef std::vector< double > qualities_vector_type;
97 typedef std::vector< qualities_vector_type > collected_qualities_vector_type;
98 typedef boost::variant< qualities_vector_type, collected_qualities_vector_type > qualities_variant_type;
99 typedef std::map< dynardo::string_type, qualities_variant_type > qualities_map_type;
100 qualities_map_type ApproximateQualityValues(
101 const dynardo::design_type& _design,
102 dynardo::enums::eExtrapolationTypes _extrapolation_type );
103
104 // solve
105 dynardo::design_type Approximate(
106 const dynardo::design_type& _design,
107 bool _extrapolate );
108 dynardo::design_type Approximate(
109 const dynardo::design_type& _design,
110 dynardo::enums::eExtrapolationTypes _extrapolation_type,
111 const dynardo::optislang::typedefs::matrix_type& _request_matrix_oracle = dynardo::optislang::typedefs::matrix_type() );
112 dynardo::design_container_type Approximate(
113 const dynardo::design_container_type& _designs,
114 bool _with_criteria,
115 dynardo::enums::eExtrapolationTypes _extrapolation_type,
116 bool _throw,
117 const dynardo::optislang::typedefs::matrix_type& _request_matrix_oracle = dynardo::optislang::typedefs::matrix_type() );
118
120 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
121 bool _with_criteria,
122 bool _extrapolate,
123 bool _throw );
125 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
126 bool _with_criteria,
127 dynardo::enums::eExtrapolationTypes _extrapolation_type,
128 bool _throw );
129
130 // gradients
131 std::vector< double > ApproximateGradientsPerResponse(
132 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
133 const dynardo::string_type& _response_name,
134 bool _extrapolation_type,
135 bool _throw );
136 std::vector< double > ApproximateGradientsPerResponse(
137 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
138 const dynardo::string_type& _response_name,
139 dynardo::enums::eExtrapolationTypes _extrapolation_type,
140 bool _throw );
141 std::vector< double > ApproximateGradients(
142 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
143 bool _extrapolation_type,
144 bool _throw );
145 std::vector< double > ApproximateGradients(
146 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
147 dynardo::enums::eExtrapolationTypes _extrapolation_type,
148 bool _throw );
149
150 // errors
151 std::vector< double > ApproximateErrorsPerResponse(
152 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
153 const dynardo::string_type& _response_name,
154 bool _extrapolation_type,
155 bool _throw );
156 std::vector< double > ApproximateErrorsPerResponse(
157 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
158 const dynardo::string_type& _response_name,
159 dynardo::enums::eExtrapolationTypes _extrapolation_type,
160 bool _throw );
161 std::vector< double > ApproximateErrors(
162 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
163 bool _extrapolation_type,
164 bool _throw );
165 std::vector< double > ApproximateErrors(
166 const dynardo::optislang::typedefs::matrix_type& _request_matrix,
167 dynardo::enums::eExtrapolationTypes _extrapolation_type,
168 bool _throw );
169
170 // interface for mop_as_solver.exe
171 static void Calculate( const std::string& omdb_file, const std::string& in_file, const std::string& out_file,
172 const bool reference_flag, const bool _dont_check_bounds );
173
174 // serializes class
175 friend class boost::serialization::access;
176 template< class Archive > void serialize(Archive & ar, const unsigned int version);
177
178 private:
179 void InitializeLog();
180 void InitializeLogAsFileLog();
181 bool BoundariesViolated( const dynardo::optislang::typedefs::matrix_type& _request_matrix, dynardo::enums::eExtrapolationTypes _extrapolation_type, bool _throw );
182 dynardo::optislang::typedefs::matrix_type DesignsToRequestMatrix( const dynardo::design_container_type& _designs );
183
184 surrogate_info_container_type& GetNonConstSurrogateInfos();
185
186 typedef std::function<
187 dynardo::math::metamodel::matrix_type
188 ( const dynardo::algorithm::datatypes::OMDB&,
189 const dynardo::string_type&,
190 surrogate_info_container_type::surrogate_pointer_type,
191 const dynardo::optislang::typedefs::matrix_type& ) > current_surrogate_function_type;
192
193 std::vector< double > DoForAll(
194 current_surrogate_function_type,
195 const dynardo::optislang::typedefs::matrix_type&,
196 dynardo::enums::eExtrapolationTypes,
197 bool _throw );
198 std::vector< double > DoForOne(
199 const dynardo::string_type&,
200 current_surrogate_function_type,
201 const dynardo::optislang::typedefs::matrix_type&,
202 dynardo::enums::eExtrapolationTypes,
203 bool _throw );
204
205 responses_pair_type GetCleanedResponsesPair() const;
206
207 dynardo::utils::log::LogBase_ptr_type logger_;
208
209 dynardo::mop::MOPSolverPermissions mopsolver_permissions_;
210
211 dynardo::path_type omdb_path_;
212 dynardo::algorithm::datatypes::OMDB omdb_;
213
214 dynardo::string_list_type initialized_responses_;
215 dynardo::string_list_type initialized_errors_;
216
217 dynardo::criterion_seq_type all_criteria_;
218
219 dynardo::parameter_manager_type surrogate_parameters_;
220
221 bool signals_wanted_;
222 dynardo::path_type working_directory_;
223 dynardo::integration::FMOPSolver_ptr_type fmopsolver_;
224
225 std::list< dynardo::mop::mop_custom_solver_ptr_type > mop_custom_solvers_;
226
232 struct DYNARDO_MOPSOLVER_INTERNAL_DLPUBLIC DerivedState
233 {
234 std::mutex mutex_;
235
236 dynardo::string_list_type parameter_names_;
237 dynardo::string_list_type response_names_;
238 dynardo::string_list_type criteria_names_;
239
240 DerivedState() {}
241 DerivedState( const DerivedState& _other );
242 DerivedState( DerivedState&& _other );
243
244 DerivedState& operator=( const DerivedState& _other );
245 DerivedState& operator=( DerivedState&& _other );
246
247 void Clear();
248 };
249 DerivedState derived_;
250 };
251
252 } // mop
253} // dynardo
254
255DYNARDO_EXPORT_TYPE(dynardo::mop::MOPSolver, 0)
256BOOST_CLASS_TRACKING( dynardo::mop::MOPSolver, boost::serialization::track_always )
257
258#endif //_MOPSOLVER_HPP_
Definition: mopsolver.hpp:39
Definition: mopsolver.hpp:33

Connect with Ansys