OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
optimisation.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_OPTIMISATION_HPP__
10 #define CMZN_OPTIMISATION_HPP__
11 
12 #include "zinc/optimisation.h"
13 #include "zinc/fieldmodule.hpp"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
29 {
30 protected:
31  cmzn_optimisation_id id;
32 
33 public:
34 
35  Optimisation() : id(0)
36  { }
37 
38  // takes ownership of C handle, responsibility for destroying it
39  explicit Optimisation(cmzn_optimisation_id in_optimisation_id) :
40  id(in_optimisation_id)
41  { }
42 
43  Optimisation(const Optimisation& optimisation) :
44  id(cmzn_optimisation_access(optimisation.id))
45  { }
46 
47  Optimisation& operator=(const Optimisation& optimisation)
48  {
49  cmzn_optimisation_id temp_id = cmzn_optimisation_access(optimisation.id);
50  if (0 != id)
51  {
52  cmzn_optimisation_destroy(&id);
53  }
54  id = temp_id;
55  return *this;
56  }
57 
58  ~Optimisation()
59  {
60  if (0 != id)
61  {
62  cmzn_optimisation_destroy(&id);
63  }
64  }
65 
71  bool isValid() const
72  {
73  return (0 != id);
74  }
75 
82  enum Method
83  {
84  METHOD_INVALID = CMZN_OPTIMISATION_METHOD_INVALID,
87  METHOD_QUASI_NEWTON = CMZN_OPTIMISATION_METHOD_QUASI_NEWTON,
94  METHOD_LEAST_SQUARES_QUASI_NEWTON = CMZN_OPTIMISATION_METHOD_LEAST_SQUARES_QUASI_NEWTON
101  };
102 
108  {
109  ATTRIBUTE_FUNCTION_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_FUNCTION_TOLERANCE ,
117  ATTRIBUTE_GRADIENT_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_GRADIENT_TOLERANCE,
125  ATTRIBUTE_STEP_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_STEP_TOLERANCE,
133  ATTRIBUTE_MAXIMUM_ITERATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_ITERATIONS,
143  ATTRIBUTE_MAXIMUM_FUNCTION_EVALUATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_FUNCTION_EVALUATIONS,
153  ATTRIBUTE_MAXIMUM_STEP = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_STEP,
162  ATTRIBUTE_MINIMUM_STEP = CMZN_OPTIMISATION_ATTRIBUTE_MINIMUM_STEP,
171  ATTRIBUTE_LINESEARCH_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_LINESEARCH_TOLERANCE,
178  ATTRIBUTE_MAXIMUM_BACKTRACK_ITERATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_BACKTRACK_ITERATIONS,
188  ATTRIBUTE_TRUST_REGION_SIZE = CMZN_OPTIMISATION_ATTRIBUTE_TRUST_REGION_SIZE
199  };
200 
206  cmzn_optimisation_id getId() const
207  {
208  return id;
209  }
210 
217  {
218  return static_cast<Method>(cmzn_optimisation_get_method(id));
219  }
220 
227  int setMethod(Method method)
228  {
229  return cmzn_optimisation_set_method(id,
230  static_cast<cmzn_optimisation_method>(method));
231  }
232 
240  {
241  return cmzn_optimisation_get_attribute_integer(id,
242  static_cast<cmzn_optimisation_attribute>(attribute));
243  }
244 
254  int setAttributeInteger(Attribute attribute, int value)
255  {
256  return cmzn_optimisation_set_attribute_integer(id,
257  static_cast<cmzn_optimisation_attribute>(attribute), value);
258  }
259 
266  double getAttributeReal(Attribute attribute)
267  {
268  return cmzn_optimisation_get_attribute_real(id,
269  static_cast<cmzn_optimisation_attribute>(attribute));
270  }
271 
280  int setAttributeReal(Attribute attribute, double value)
281  {
282  return cmzn_optimisation_set_attribute_real(id,
283  static_cast<cmzn_optimisation_attribute>(attribute), value);
284  }
285 
293  {
294  return Field(cmzn_optimisation_get_first_independent_field(id));
295  }
296 
315  {
316  return Field(cmzn_optimisation_get_next_independent_field(id, refField.getId()));
317  }
318 
332  int addIndependentField(const Field& field)
333  {
334  return (cmzn_optimisation_add_independent_field(id, field.getId()));
335  }
336 
344  int removeIndependentField(const Field& field)
345  {
346  return (cmzn_optimisation_remove_independent_field(id, field.getId()));
347  }
348 
356  {
357  return Field(cmzn_optimisation_get_first_objective_field(id));
358  }
359 
378  {
379  return Field(cmzn_optimisation_get_next_objective_field(id, refField.getId()));
380  }
381 
396  int addObjectiveField(const Field& field)
397  {
398  return (cmzn_optimisation_add_objective_field(id, field.getId()));
399  }
400 
408  int removeObjectiveField(const Field& field)
409  {
410  return (cmzn_optimisation_remove_independent_field(id, field.getId()));
411  }
412 
420  {
421  return cmzn_optimisation_get_solution_report(id);
422  }
423 
430  int optimise()
431  {
432  return cmzn_optimisation_optimise(id);
433  }
434 
435 };
436 
438 {
439  return Optimisation(cmzn_fieldmodule_create_optimisation(id));
440 }
441 
442 } // namespace Zinc
443 }
444 
445 #endif
A description of a non-linear optimisation problem.
Definition: optimisation.hpp:28
Field getNextIndependentField(const Field &refField)
Definition: optimisation.hpp:314
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
Method
Definition: optimisation.hpp:82
Optimisation createOptimisation()
Definition: optimisation.hpp:437
int removeObjectiveField(const Field &field)
Definition: optimisation.hpp:408
Field getNextObjectiveField(const Field &refField)
Definition: optimisation.hpp:377
int setMethod(Method method)
Definition: optimisation.hpp:227
int addIndependentField(const Field &field)
Definition: optimisation.hpp:332
int setAttributeReal(Attribute attribute, double value)
Definition: optimisation.hpp:280
Attribute
Definition: optimisation.hpp:107
cmzn_field_id getId() const
Definition: field.hpp:98
Field getFirstIndependentField()
Definition: optimisation.hpp:292
int setAttributeInteger(Attribute attribute, int value)
Definition: optimisation.hpp:254
Field getFirstObjectiveField()
Definition: optimisation.hpp:355
Method getMethod()
Definition: optimisation.hpp:216
double getAttributeReal(Attribute attribute)
Definition: optimisation.hpp:266
int removeIndependentField(const Field &field)
Definition: optimisation.hpp:344
bool isValid() const
Definition: optimisation.hpp:71
cmzn_optimisation_id getId() const
Definition: optimisation.hpp:206
int getAttributeInteger(Attribute attribute)
Definition: optimisation.hpp:239
int optimise()
Definition: optimisation.hpp:430
char * getSolutionReport()
Definition: optimisation.hpp:419
Definition: optimisation.hpp:84
int addObjectiveField(const Field &field)
Definition: optimisation.hpp:396