Ipopt
3.11.4
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
contrib
MatlabInterface
src
iterate.hpp
Go to the documentation of this file.
1
// Copyright (C) 2008 Peter Carbonetto. All Rights Reserved.
2
// This code is published under the Eclipse Public License.
3
//
4
// Author: Peter Carbonetto
5
// Dept. of Computer Science
6
// University of British Columbia
7
// September 15, 2008
8
9
#ifndef INCLUDE_ITERATE
10
#define INCLUDE_ITERATE
11
12
#include "mex.h"
13
#include <string.h>
14
15
// Function definitions.
16
// ---------------------------------------------------------------
17
template
<
class
Type>
void
copymemory
(
const
Type* source, Type* dest,
int
n) {
18
memcpy(dest,source,
sizeof
(Type)*n);
19
}
20
21
// Class Iterate.
22
// -----------------------------------------------------------------
23
// An object of this class stores all the information we would like to
24
// keep track of regarding the variables in our optimization
25
// problem. An Iterate object is constructed from a MATLAB array,
26
// which is either an array in double precision, or a cell array with
27
// elements that are arrays in double precision. There are two methods
28
// of interest: a function that copies the elements from a source
29
// array to the Iterate object (inject), and a function that copies
30
// the Itereate to a destination array (copyto).
31
class
Iterate
{
32
public
:
33
34
// This constructor initializes the object basically by creating a
35
// duplicate of the specified MATLAB array. It is important to note
36
// that the Iterate object does *not* create an independent copy of
37
// the MATLAB array. As such, it will not destroy the MATLAB arrays
38
// when the object is destroyed.
39
explicit
Iterate
(mxArray*
ptr
);
40
41
// The destructor.
42
~Iterate
() { };
43
44
// Return the number of variables.
45
friend
int
numvars
(
const
Iterate
&
x
) {
return
x.
nv
; };
46
47
// Copy the elements from the source array.
48
void
inject
(
const
double
*
x
);
49
50
// Copy the elements to the location in memory pointed to by "dest".
51
// It is assumed that sufficient memory is allocated for the
52
// destination.
53
void
copyto
(
double
*
x
)
const
;
54
55
// Convert the Iterate object to a MATLAB array.
56
operator
mxArray*() {
return
ptr
; };
57
operator
const
mxArray*()
const
{
return
ptr
; };
58
59
// This function dynamically creates a new array containing all the
60
// information about the iterate as specified by the MATLAB
61
// array. It is up to the user to deallocate the memory associated
62
// with the newly allocated data array. The return value is the size
63
// of the array.
64
static
int
getMatlabData
(
const
mxArray* ptr,
double
*& data);
65
66
protected
:
67
int
nv
;
// The number of optimization variables.
68
mxArray*
ptr
;
// All the information is stored in a MATLAB array.
69
};
70
71
#endif
Generated on Mon Oct 21 2013 19:08:14 for Ipopt by
1.8.4