OpenCMISS-Zinc C++ API Documentation
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 "opencmiss/zinc/optimisation.h"
13 #include "opencmiss/zinc/fieldassignment.hpp"
14 #include "opencmiss/zinc/fieldmodule.hpp"
15 
16 namespace OpenCMISS
17 {
18 namespace Zinc
19 {
20 
30 {
31 protected:
32  cmzn_optimisation_id id;
33 
34 public:
35 
36  Optimisation() : id(0)
37  { }
38 
39  // takes ownership of C handle, responsibility for destroying it
40  explicit Optimisation(cmzn_optimisation_id in_optimisation_id) :
41  id(in_optimisation_id)
42  { }
43 
44  Optimisation(const Optimisation& optimisation) :
45  id(cmzn_optimisation_access(optimisation.id))
46  { }
47 
48  Optimisation& operator=(const Optimisation& optimisation)
49  {
50  cmzn_optimisation_id temp_id = cmzn_optimisation_access(optimisation.id);
51  if (0 != id)
52  {
53  cmzn_optimisation_destroy(&id);
54  }
55  id = temp_id;
56  return *this;
57  }
58 
59  ~Optimisation()
60  {
61  if (0 != id)
62  {
63  cmzn_optimisation_destroy(&id);
64  }
65  }
66 
72  bool isValid() const
73  {
74  return (0 != id);
75  }
76 
83  enum Method
84  {
85  METHOD_INVALID = CMZN_OPTIMISATION_METHOD_INVALID,
88  METHOD_QUASI_NEWTON = CMZN_OPTIMISATION_METHOD_QUASI_NEWTON,
95  METHOD_LEAST_SQUARES_QUASI_NEWTON = CMZN_OPTIMISATION_METHOD_LEAST_SQUARES_QUASI_NEWTON
102  };
103 
109  {
110  ATTRIBUTE_FUNCTION_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_FUNCTION_TOLERANCE ,
118  ATTRIBUTE_GRADIENT_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_GRADIENT_TOLERANCE,
126  ATTRIBUTE_STEP_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_STEP_TOLERANCE,
134  ATTRIBUTE_MAXIMUM_ITERATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_ITERATIONS,
144  ATTRIBUTE_MAXIMUM_FUNCTION_EVALUATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_FUNCTION_EVALUATIONS,
154  ATTRIBUTE_MAXIMUM_STEP = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_STEP,
163  ATTRIBUTE_MINIMUM_STEP = CMZN_OPTIMISATION_ATTRIBUTE_MINIMUM_STEP,
172  ATTRIBUTE_LINESEARCH_TOLERANCE = CMZN_OPTIMISATION_ATTRIBUTE_LINESEARCH_TOLERANCE,
179  ATTRIBUTE_MAXIMUM_BACKTRACK_ITERATIONS = CMZN_OPTIMISATION_ATTRIBUTE_MAXIMUM_BACKTRACK_ITERATIONS,
189  ATTRIBUTE_TRUST_REGION_SIZE = CMZN_OPTIMISATION_ATTRIBUTE_TRUST_REGION_SIZE
200  };
201 
207  cmzn_optimisation_id getId() const
208  {
209  return id;
210  }
211 
221  Field getConditionalField(const Field& independentField)
222  {
223  return Field(cmzn_optimisation_get_conditional_field(id, independentField.getId()));
224  }
225 
242  int setConditionalField(const Field& independentField, const Field& conditionalField)
243  {
244  return cmzn_optimisation_set_conditional_field(id, independentField.getId(), conditionalField.getId());
245  }
246 
268  int addFieldassignment(const Fieldassignment& fieldassignment)
269  {
270  return cmzn_optimisation_add_fieldassignment(this->id, fieldassignment.getId());
271  }
272 
279  {
280  return static_cast<Method>(cmzn_optimisation_get_method(id));
281  }
282 
289  int setMethod(Method method)
290  {
291  return cmzn_optimisation_set_method(id,
292  static_cast<cmzn_optimisation_method>(method));
293  }
294 
302  {
303  return cmzn_optimisation_get_attribute_integer(id,
304  static_cast<cmzn_optimisation_attribute>(attribute));
305  }
306 
316  int setAttributeInteger(Attribute attribute, int value)
317  {
318  return cmzn_optimisation_set_attribute_integer(id,
319  static_cast<cmzn_optimisation_attribute>(attribute), value);
320  }
321 
328  double getAttributeReal(Attribute attribute)
329  {
330  return cmzn_optimisation_get_attribute_real(id,
331  static_cast<cmzn_optimisation_attribute>(attribute));
332  }
333 
342  int setAttributeReal(Attribute attribute, double value)
343  {
344  return cmzn_optimisation_set_attribute_real(id,
345  static_cast<cmzn_optimisation_attribute>(attribute), value);
346  }
347 
355  {
356  return Field(cmzn_optimisation_get_first_independent_field(id));
357  }
358 
377  {
378  return Field(cmzn_optimisation_get_next_independent_field(id, refField.getId()));
379  }
380 
394  int addIndependentField(const Field& field)
395  {
396  return (cmzn_optimisation_add_independent_field(id, field.getId()));
397  }
398 
406  int removeIndependentField(const Field& field)
407  {
408  return (cmzn_optimisation_remove_independent_field(id, field.getId()));
409  }
410 
418  {
419  return Field(cmzn_optimisation_get_first_objective_field(id));
420  }
421 
440  {
441  return Field(cmzn_optimisation_get_next_objective_field(id, refField.getId()));
442  }
443 
458  int addObjectiveField(const Field& field)
459  {
460  return (cmzn_optimisation_add_objective_field(id, field.getId()));
461  }
462 
470  int removeObjectiveField(const Field& field)
471  {
472  return (cmzn_optimisation_remove_objective_field(id, field.getId()));
473  }
474 
482  {
483  return cmzn_optimisation_get_solution_report(id);
484  }
485 
492  int optimise()
493  {
494  return cmzn_optimisation_optimise(id);
495  }
496 
497 };
498 
500 {
501  return Optimisation(cmzn_fieldmodule_create_optimisation(id));
502 }
503 
504 } // namespace Zinc
505 }
506 
507 #endif
A description of a non-linear optimisation problem.
Definition: optimisation.hpp:29
Field getNextIndependentField(const Field &refField)
Definition: optimisation.hpp:376
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:51
Method
Definition: optimisation.hpp:83
Optimisation createOptimisation()
Definition: optimisation.hpp:499
int removeObjectiveField(const Field &field)
Definition: optimisation.hpp:470
Field getNextObjectiveField(const Field &refField)
Definition: optimisation.hpp:439
int setMethod(Method method)
Definition: optimisation.hpp:289
cmzn_fieldassignment_id getId() const
Definition: fieldassignment.hpp:101
int addIndependentField(const Field &field)
Definition: optimisation.hpp:394
Object for assigning values of a field from a source field.
Definition: fieldassignment.hpp:44
int setAttributeReal(Attribute attribute, double value)
Definition: optimisation.hpp:342
int setConditionalField(const Field &independentField, const Field &conditionalField)
Definition: optimisation.hpp:242
Attribute
Definition: optimisation.hpp:108
cmzn_field_id getId() const
Definition: field.hpp:103
Field getFirstIndependentField()
Definition: optimisation.hpp:354
int setAttributeInteger(Attribute attribute, int value)
Definition: optimisation.hpp:316
Field getFirstObjectiveField()
Definition: optimisation.hpp:417
Method getMethod()
Definition: optimisation.hpp:278
Field getConditionalField(const Field &independentField)
Definition: optimisation.hpp:221
double getAttributeReal(Attribute attribute)
Definition: optimisation.hpp:328
int removeIndependentField(const Field &field)
Definition: optimisation.hpp:406
bool isValid() const
Definition: optimisation.hpp:72
cmzn_optimisation_id getId() const
Definition: optimisation.hpp:207
int getAttributeInteger(Attribute attribute)
Definition: optimisation.hpp:301
int optimise()
Definition: optimisation.hpp:492
char * getSolutionReport()
Definition: optimisation.hpp:481
The OpenCMISS namespace.
Definition: context.hpp:20
Definition: optimisation.hpp:85
int addFieldassignment(const Fieldassignment &fieldassignment)
Definition: optimisation.hpp:268
int addObjectiveField(const Field &field)
Definition: optimisation.hpp:458