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 "opencmiss/zinc/optimisation.h"
13 #include "opencmiss/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 
220  Field getConditionalField(const Field& independentField)
221  {
222  return Field(cmzn_optimisation_get_conditional_field(id, independentField.getId()));
223  }
224 
241  int setConditionalField(const Field& independentField, const Field& conditionalField)
242  {
243  return cmzn_optimisation_set_conditional_field(id, independentField.getId(), conditionalField.getId());
244  }
245 
252  {
253  return static_cast<Method>(cmzn_optimisation_get_method(id));
254  }
255 
262  int setMethod(Method method)
263  {
264  return cmzn_optimisation_set_method(id,
265  static_cast<cmzn_optimisation_method>(method));
266  }
267 
275  {
276  return cmzn_optimisation_get_attribute_integer(id,
277  static_cast<cmzn_optimisation_attribute>(attribute));
278  }
279 
289  int setAttributeInteger(Attribute attribute, int value)
290  {
291  return cmzn_optimisation_set_attribute_integer(id,
292  static_cast<cmzn_optimisation_attribute>(attribute), value);
293  }
294 
301  double getAttributeReal(Attribute attribute)
302  {
303  return cmzn_optimisation_get_attribute_real(id,
304  static_cast<cmzn_optimisation_attribute>(attribute));
305  }
306 
315  int setAttributeReal(Attribute attribute, double value)
316  {
317  return cmzn_optimisation_set_attribute_real(id,
318  static_cast<cmzn_optimisation_attribute>(attribute), value);
319  }
320 
328  {
329  return Field(cmzn_optimisation_get_first_independent_field(id));
330  }
331 
350  {
351  return Field(cmzn_optimisation_get_next_independent_field(id, refField.getId()));
352  }
353 
367  int addIndependentField(const Field& field)
368  {
369  return (cmzn_optimisation_add_independent_field(id, field.getId()));
370  }
371 
379  int removeIndependentField(const Field& field)
380  {
381  return (cmzn_optimisation_remove_independent_field(id, field.getId()));
382  }
383 
391  {
392  return Field(cmzn_optimisation_get_first_objective_field(id));
393  }
394 
413  {
414  return Field(cmzn_optimisation_get_next_objective_field(id, refField.getId()));
415  }
416 
431  int addObjectiveField(const Field& field)
432  {
433  return (cmzn_optimisation_add_objective_field(id, field.getId()));
434  }
435 
443  int removeObjectiveField(const Field& field)
444  {
445  return (cmzn_optimisation_remove_objective_field(id, field.getId()));
446  }
447 
455  {
456  return cmzn_optimisation_get_solution_report(id);
457  }
458 
465  int optimise()
466  {
467  return cmzn_optimisation_optimise(id);
468  }
469 
470 };
471 
473 {
474  return Optimisation(cmzn_fieldmodule_create_optimisation(id));
475 }
476 
477 } // namespace Zinc
478 }
479 
480 #endif
A description of a non-linear optimisation problem.
Definition: optimisation.hpp:28
Field getNextIndependentField(const Field &refField)
Definition: optimisation.hpp:349
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:50
Method
Definition: optimisation.hpp:82
Optimisation createOptimisation()
Definition: optimisation.hpp:472
int removeObjectiveField(const Field &field)
Definition: optimisation.hpp:443
Field getNextObjectiveField(const Field &refField)
Definition: optimisation.hpp:412
int setMethod(Method method)
Definition: optimisation.hpp:262
int addIndependentField(const Field &field)
Definition: optimisation.hpp:367
int setAttributeReal(Attribute attribute, double value)
Definition: optimisation.hpp:315
int setConditionalField(const Field &independentField, const Field &conditionalField)
Definition: optimisation.hpp:241
Attribute
Definition: optimisation.hpp:107
cmzn_field_id getId() const
Definition: field.hpp:102
Field getFirstIndependentField()
Definition: optimisation.hpp:327
int setAttributeInteger(Attribute attribute, int value)
Definition: optimisation.hpp:289
Field getFirstObjectiveField()
Definition: optimisation.hpp:390
Method getMethod()
Definition: optimisation.hpp:251
Field getConditionalField(const Field &independentField)
Definition: optimisation.hpp:220
double getAttributeReal(Attribute attribute)
Definition: optimisation.hpp:301
int removeIndependentField(const Field &field)
Definition: optimisation.hpp:379
bool isValid() const
Definition: optimisation.hpp:71
cmzn_optimisation_id getId() const
Definition: optimisation.hpp:206
int getAttributeInteger(Attribute attribute)
Definition: optimisation.hpp:274
int optimise()
Definition: optimisation.hpp:465
char * getSolutionReport()
Definition: optimisation.hpp:454
Definition: optimisation.hpp:84
int addObjectiveField(const Field &field)
Definition: optimisation.hpp:431