1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include "mps_option_parser.h"
#include <string.h>
_mps_matlab_options
mps_parse_matlab_options (const mxArray * optionStruct)
{
_mps_matlab_options options = {
MPS_ALGORITHM_SECULAR_GA,
MPS_OUTPUT_GOAL_APPROXIMATE,
16,
false,
false
};
if (!optionStruct)
return options;
if (mxIsChar (optionStruct))
{
mxChar * value = mxGetChars (optionStruct);
if (strcmp ((char*) value, "s") == 0)
options.algorithm = MPS_ALGORITHM_SECULAR_GA;
else if (strcmp ((char*) value, "u") == 0)
options.algorithm = MPS_ALGORITHM_STANDARD_MPSOLVE;
else
mexErrMsgTxt ("Invalid value specified for the algorithm. Only 'u' or 's' are allowed.\n");
}
else if (! mxIsStruct (optionStruct))
mexErrMsgTxt ("Only chars and struct values are allowed as MPSolve options\n");
if (optionStruct)
{
int nFields = mxGetNumberOfFields (optionStruct);
int i;
for (i = 0; i < nFields; i++)
{
const char * optionName = mxGetFieldNameByNumber (optionStruct, i);
mxArray * field = mxGetFieldByNumber (optionStruct, 0, i);
if (strcmp (optionName, "algorithm") == 0)
{
if (! mxIsChar (field))
mexErrMsgTxt ("Please specify only 'u' or 's' for the algorithm property\n");
else
{
mxChar * value = mxGetChars (field);
if (strcmp ((char*) value, "s") == 0)
options.algorithm = MPS_ALGORITHM_SECULAR_GA;
else if (strcmp ((char*) value, "u") == 0)
options.algorithm = MPS_ALGORITHM_STANDARD_MPSOLVE;
else
mexErrMsgTxt ("Invalid value specified for the property: 'algorithm'. Only 'u' or 's' are allowed.\n");
}
}
else if (strcmp (optionName, "digits") == 0)
{
if (! mxIsNumeric (field))
mexErrMsgTxt ("Please specify a positive integer for the digits property\n");
else
{
double digits = mxGetScalar (field);
if (digits <= 0)
mexErrMsgTxt ("Please specify a positive integer for the digits property\n");
else
options.digits = (int) digits;
}
}
else if (strcmp (optionName, "goal") == 0)
{
if (! mxIsChar (field))
mexErrMsgTxt ("Please specify only 'a' or 'i' as value for the goal property\n");
else
{
mxChar * value = mxGetChars (field);
if (strcmp ((char*) value, "i") == 0)
options.goal = MPS_OUTPUT_GOAL_ISOLATE;
else if (strcmp ((char*) value, "a") == 0)
options.goal = MPS_OUTPUT_GOAL_APPROXIMATE;
else
mexErrMsgTxt ("Please specify only 'a' or 'i' as value for the goal property\n");
}
}
else if (strcmp (optionName, "radius") == 0)
{
if (! mxIsLogicalScalar (field))
mexErrMsgTxt ("Please specify 'true' or 'false' as a value for the radius property\n");
else
{
options.radius = *mxGetLogicals (field);
}
}
else if (strcmp (optionName, "chebyshev") == 0)
{
if (! mxIsLogicalScalar (field))
mexErrMsgTxt ("Please specify 'true' or 'false' as a value for the chebyshev property\n");
else
{
options.chebyshev = *mxGetLogicals (field);
}
}
else
{
char * buffer = (char*) mxMalloc (sizeof (char) * (strlen ("The property '' is invalid\n") + strlen ((char*) optionName) + 1));
sprintf (buffer, "The property '%s' is invalid\n", optionName);
mexErrMsgTxt (buffer);
mxFree (buffer);
}
}
}
return options;
}
|