/*********************************************************************** Xpress Optimizer Examples ========================= file Polygon_initialvalue.c `````````````````````````` Implement the polygon example using tokens and initial values 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. The nonlinear expressions are described using formula tokens, and providing initial values to the nonlinear variables. (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); 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 ReturnValue; int i, j; char RowNames[500], ColNames[500]; /* 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;i1) { Type[nToken] = XSLP_OP; Value[nToken++] = XSLP_PLUS; } } Type[nToken] = XSLP_EOF; Value[nToken++] = 0; /* Distances */ for (i=1;i