[Ipopt] Defining a Global Variable in IPOPT and Using This Global Variable From IPOPT Matlab Interface
Senses,Begum
bgmsenses at ufl.edu
Thu May 29 10:02:57 EDT 2014
Good morning!!
Ok I am trying this once again I typed everything this time. Hopefully
it will work.
Hello everyone,
I am using IPOPT with MATLAB interface. I am trying to send an array
from IPOPT Matlab interface to the MA57 interface. In order to be able
to do that first I edited option.cpp file in the
../CoinIpopt/Ipopt/contrib/MatlabInterface/src directory. In the
options.cpp file I added the following code under Options::Options(const
Iterate& x, Ipopt::IpoptApplication& app, const mxArray* ptr)
Options::Options(const Iterate& x, Ipopt::IpoptApplication& app, const
mxArray* ptr)
{
.
. There are some other ipopt mexhfile code here
.
// I want to use gpops_descriptor in MA57 interface and I want to
obtain this array of integers from IPOPT Matlab interface.
gpops_descriptor = NULL;
const mxArray* gpops_mxArray = mxGetField(ptr, 0, "gpops_descriptor");
if (gpops_mxArray)
{
\\ The MATLAB options.gpops_descriptor exists and has been passed
into the IPOPT mex function interface
\\ It is a double vector of length gpops_len.
int gpops_len = mxGetNumberOfElements(gpops_mxArray);
if (gpops_len>0)
{
// Allocate an extern int array for IPOPT's copy of
options.gpops_descriptor.
// Note that this array is not explicitly freed (yet),
since we are trying to minimize the changes
// to the IPOPT mexFunction. Matlab will free it for us
when this mexFunction returns to Matlab.
gpops_descriptor = (int*) mxMalloc(gpops_len *
sizeof(int));
// Copy the Matlab options.gpops_descriptor into the IPOPT
options object
double *gpops_double = mxGetPr(gpops_mxArray);
for (int 0; i< gpops_len; i++)
{
gpops_descriptor[i] = (int) gpops_double[i];
// Print out gpops_descriptor for test purposes
printf("gpops[%d]: %d\n, i, gpops_descriptor[i]);
}
}
}
if (gpops_descriptor == NULL)
{
printf("options.gpops_descriptor is not present\n");
}
}
I did not change anything in options.hpp file. Maybe I need to change
something in that file too???
Following this step, I wanted to declare the global variable in a .hpp
and .cpp file that can be seen by both Ipopt and ipopt matlab interface.
When I check ipopt.cpp file in the
../CoinIpopt/Ipopt/contrib/MatlabInterface/src directory I realized that
it includes "IpJournalist.hpp". This file is also included in the main
IPOPT files. Therefore, I edited IpJournalist.hpp and IpJournalist.cpp
files which are in the ../CoinIpopt/Ipopt/src/Common directory. I added
a line of code for global variable decleration in IpJournalist.hpp file
right before namespace Ipopt.
extern int*gpops_descriptor
namespace Ipopt
{
.
.
.
}
Next, I added a line of code in IpJournalist.cpp file again right
before namespace Ipopt.
int *gpops_descriptor;
namespace Ipopt
{
.
.
.
}
After all these configure, make and make install commands worked in the
CoinIpopt main directory but when I try to compile the mexFile by using
the make command in the CoinIpopt/Ipopt/contrib/MatlabInterface/src
directory it gave me the following error.
Undefined symbolds for architecture x86_64:
"_gpops_descriptor", referenced from:
Options::Options(const Iterate& x, Ipopt::IpoptApplication&,
mxArray_tag const*) in options.o
ld: symbol(s) not found for architecture x86_64:
clang: error: linker command failed with exit code 1(use -v to see
invocation)
mex: link of "ipopt.mexmaci64" failed.
make: ***[ipopt.mexmaci64] Error 1
Does anyone have any suggestions to fix this error? In case somebody
wants to see what happens in my terminal after I run the make command
you can find it in the attachments.
Thank you
Begum
More information about the Ipopt
mailing list