24 #if defined(NAN_EQUALS_ZERO)
25 #define IsNonZero(d) ((d)!=0.0 || mxIsNaN(d))
27 #define IsNonZero(d) ((d)!=0.0)
35 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[] ) {
57 mexPrintf(
"BEGIN PROCESSING DATA\n");
59 mexErrMsgTxt(
"Fifteen input arguments are required.");
65 matlabModel->
numVar = (
int) mxGetScalar( prhs[ 0]) ;
67 matlabModel->
numCon = (
int) mxGetScalar( prhs[ 1]);
71 if (!(mxIsDouble(prhs[2 ]))){
72 mexErrMsgTxt(
"Constraint matrix A must be of type double.");
75 if ( (mxGetN(prhs[ 2]) != matlabModel->
numVar) || (mxGetM(prhs[2]) != matlabModel->
numCon) ){
76 mexErrMsgTxt(
" Constraint matrix A must have number of rows equal to number of constraints and columns equal number of variables \n");
83 if( !mxIsEmpty( prhs[ 3]) ){
84 if (mxGetN(prhs[3]) != matlabModel->
numCon ){
85 mexErrMsgTxt(
" Vector BL size must equal the number of rows\n");
87 matlabModel->
bl = mxGetPr( prhs[ 3]);
89 for(i = 0; i < matlabModel->
numCon; i++){
90 if( mxIsInf( -(matlabModel->
bl[i]) ) ) matlabModel->
bl[ i] = -
OSDBL_MAX;
95 if( !mxIsEmpty( prhs[ 4]) ){
96 if (mxGetN(prhs[4]) != matlabModel->
numCon ){
97 mexErrMsgTxt(
" Vector BU size must equal the number of rows\n");
99 matlabModel->
bu = mxGetPr( prhs[ 4]);
101 for(i = 0; i < matlabModel->
numCon; i++){
102 if( mxIsInf( matlabModel->
bu[i]) ) matlabModel->
bu[ i] =
OSDBL_MAX;
107 if (mxGetN(prhs[5]) != matlabModel->
numVar ){
108 mexErrMsgTxt(
" Vector OBJ size must equal the number of variables\n");
110 matlabModel->
obj = mxGetPr( prhs[ 5]);
113 if( !mxIsEmpty( prhs[ 6]) ){
114 if (mxGetN(prhs[6]) != matlabModel->
numVar ){
115 mexErrMsgTxt(
" Vector VL size must equal the number of variables\n");
117 matlabModel->
vl = mxGetPr( prhs[ 6]);
119 for(i = 0; i < matlabModel->
numVar; i++){
121 if( mxIsInf( -(matlabModel->
vl[i]) ) ) matlabModel->
vl[ i] = -
OSDBL_MAX;
126 if( !mxIsEmpty( prhs[ 7]) ){
127 if (mxGetN(prhs[7]) != matlabModel->
numVar ){
128 mexErrMsgTxt(
" Vector VU size must equal the number of variables\n");
130 matlabModel->
vu = mxGetPr( prhs[ 7]);
132 for(i = 0; i < matlabModel->
numVar; i++){
134 if( mxIsInf( matlabModel->
vu[i]) ) matlabModel->
vu[ i] =
OSDBL_MAX;
139 if ( (mxGetScalar( prhs[ 8]) != 0) && (mxGetScalar( prhs[ 8]) != 1)){
140 mexErrMsgTxt(
" The objective type must be either 1 (max) or 0 (min)\n");
142 mxGetScalar( prhs[ 8]) > 0 ? matlabModel->
objType = 1 : matlabModel->
objType = 0;
146 if(!mxIsChar( prhs[ 9])){
147 mexErrMsgTxt(
" Vector VarType must be a character array\n");
149 if (mxGetN(prhs[ 9]) != matlabModel->
numVar ){
150 mexErrMsgTxt(
" Vector VarType size must equal the number of variables\n");
152 buf = mxArrayToString( prhs[ 9]);
160 if( !mxIsEmpty( prhs[ 10]) ){
161 if( mxGetM( prhs[ 10]) != 4) mexErrMsgTxt(
" Vector Q Must have 4 rows\n");
162 int numQTerms = mxGetN( prhs[ 10]);
165 matlabModel->
qRows =
new int[ numQTerms];
166 matlabModel->
qIndex1 =
new int[ numQTerms];
167 matlabModel->
qIndex2 =
new int[ numQTerms];
168 matlabModel->
qVal =
new double[ numQTerms];
169 pr= mxGetPr( prhs[ 10]);
170 for(i = 0; i < numQTerms; i++){
171 for(j = 0; j <= 3; j++){
175 matlabModel->
qRows[ i] = (
int) pr[ k];
184 matlabModel->
qVal[ i] = pr[
k];
191 if( !mxIsEmpty( prhs[ 11]) ){
192 matlabModel->
instanceName = mxArrayToString( prhs[ 11]);
195 buf = mxArrayToString( prhs[ 12]);
200 matlabModel->
sSolverName = mxArrayToString( prhs[ 13]);
201 printf(
"WE ARE USING SOLVER %s\n", &matlabModel->
sSolverName[0]);
205 printf(
"WE ARE USING AGENT %s\n", &matlabModel->
sAgentAddress[0]);
208 mexPrintf(
"CREATE THE INSTANCE \n");
211 mexPrintf(
"CALL THE REMOTE SERVER \n");
212 sTest = matlabModel->
solve();
213 std::string osil = matlabModel->
osil;
215 printf(
"HERE IS THE INSTANCE %s\n", ch);
216 mexPrintf(
"DONE WITH THE REMOTE CALL \n");
217 mexPrintf(
"HERE IS THE SOLUTION \n");
218 mexPrintf(&sTest[0] );
225 str[ 0] = &sTest[0] ;
226 plhs[0]= mxCreateCharMatrixFromStrings( 1, (
const char **)str);
242 int *irs, *jcs,
j,
k;
244 double *pr, *
pi, *si, *sr;
250 cmplx = (pi==NULL ? 0 : 1);
252 plhs = mxCreateSparse(m, n, nzmax, (mxComplexity)cmplx);
255 irs = (
int*)mxGetIr( plhs);
256 jcs = (
int*)mxGetJc( plhs);
259 for (j=0; (j<
n); j++) {
262 for (i=0; (i<
m ); i++) {
277 for(j = 0; j <
n; j++){
279 for(km = jcs[ j]; km < jcs[ j+1]; km++ ){
bool isColumnMajor
isColumnMajor holds whether the coefMatrix (AMatrix) holding linear program data is stored by column...
bool objType
objType indicates whether or not we have a max (1) or a min (0)
double * qVal
qVal is a pointer to the coefficient value of each of the quadratic terms.
double * vl
vl is a pointer to the lower bounds on the varialbes
void createOSInstance()
Create an OSInstance.
SparseMatrix * sparseMat
sparseMat is a pointer to an OS Sprase Matrix data structure
double * vu
vu is a pointer to the upper bounds on the variables
int numCon
numCon is the number of constraints in the problem
std::string sAgentAddress
is the address of the solver service
int * qIndex2
qIndex2 is a pointer to the index of the second variable in each of the quadratic terms ...
static const CouNumber pi
int startSize
startSize is the dimension of the starts array
double * bl
bl is a pointer to the lower bounds on the constraints
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
std::string sSolverName
sSolverName is the name of the solver
int valueSize
valueSize is the dimension of the indexes and values arrays
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
a sparse matrix data structure
int numQTerms
numQTerms is the number of quadratic terms
std::string solve()
Solve the problem instance.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
int * qIndex1
qIndex1 is a pointer to the index of the first variable in each of the quadratic terms ...
int numVar
numVar is the number of variables in the problem
int * qRows
qRows is a pointer to the row index of each quadratic term
std::string instanceName
instanceName is the name of the problem instance
SparseMatrix * getConstraintMatrix(const mxArray *prhs)
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
char * varType
varType is a pointer to the variable type eg C, B, I
std::string osil
is the osil instance that gets created from the MATLAB data structures
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
double * bu
bu is a pointer to the upper bounds on the constraints
double * obj
obj is a pointer to the objective function coefficients