/*********************************************************************** Xpress Optimizer Examples ========================= file Polygon_userfunc.c ``````````````````````` Implement the polygon example using a user function. Maximize the area of polygon of N vertices and diameter of 1 The position of vertices is indicated as (rho,theta) coordinates where rho denotes the distance to the base point (vertex with number N) and theta the angle from the x-axis. A user (black box) function is used to implement the problem. (c) 2017 Fair Isaac Corporation ***********************************************************************/ #include #include #include #include #include "xprs.h" #include "xslp.h" #define MAXROW 20 #define MAXCOL 20 #define MAXELT 50 #define MAXTOKEN 200 #define MAXCOEF 20 void XPRS_CC XSLPMessage(XSLPprob my_prob, void *my_object, const char *msg, int len, int msg_type); double XPRS_CC MyFunc(double *Values, void *Context); int main(int argc, char *argv[]) { XPRSprob xprob = NULL; XSLPprob sprob = NULL; int nRow, nCol, nSide, nElement, nToken, nCoef, nRowName, nColName; int iRow, Sin, Cos; char RowType[MAXROW]; double RHS[MAXROW], OBJ[MAXCOL], Element[MAXELT], Lower[MAXCOL], Upper[MAXCOL]; int ColStart[MAXCOL+1], RowIndex[MAXELT]; int ColIndex[MAXCOEF], FormulaStart[MAXCOEF+1]; int Type[MAXTOKEN]; double Value[MAXTOKEN], Factor[MAXCOEF]; int VarType[MAXCOL]; double InitialValue[MAXCOL]; int functionID; int ReturnValue; int i, j; char RowNames[500], ColNames[500]; void *Func; int nMyFuncArguments; /* Initialisation */ if (ReturnValue=XPRSinit(NULL)) goto ErrorReturn; if (ReturnValue=XSLPinit()) goto ErrorReturn; if (ReturnValue=XPRScreateprob(&xprob)) goto ErrorReturn; if (ReturnValue=XSLPcreateprob(&sprob,&xprob)) goto ErrorReturn; /* XSLPsetcbmessage */ XSLPsetcbmessage(sprob,XSLPMessage,NULL); nSide = 5; nRowName = 0; /* Rows */ nRow = nSide-2 + (nSide-1)*(nSide-2)/2 + 1; for (i=0;i 1) { Element[nElement] = 1; RowIndex[nElement++] = iRow; } iRow++; } Upper[nCol-1] = 3,142; /* Equals column */ nColName = nColName + 1 + sprintf(&ColNames[nColName],"="); ColStart[nCol] = nElement; Lower[nCol] = Upper[nCol] = 1; /* fixed at 1 */ InitialValue[nCol] = 1; VarType[nCol] = 4 | 0x4000; nCol++; /* Remaining columns come later */ for (i=1;i0;i--) { Type[nToken] = XSLP_COL; Value[nToken++] = i; Type[nToken] = XSLP_COL; Value[nToken++] = nSide+i; } Type[nToken] = XSLP_FUN; Value[nToken++] = functionID; Type[nToken] = XSLP_EOF; Value[nToken++] = 0; /* Distances */ for (i=1;i