/*********************************************************************** Xpress Optimizer Examples ========================= file Polygon_textformula.c `````````````````````````` Implement the polygon example using text formulas 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 text based input. (c) 2017 Fair Isaac Corporation ***********************************************************************/ #include #include #include #include #include "xprs.h" #include "xslp.h" #define MAXROW 20 #define MAXCOL 20 #define MAXELT 50 void XPRS_CC XSLPMessage(XSLPprob my_prob, void *my_object, char *msg, int len, int msg_type); int main(int argc, char *argv[]) { XPRSprob xprob = NULL; XSLPprob sprob = NULL; int nRow, nCol, nSide, nElement, nRowName, nColName; int iRow; char RowType[MAXROW]; double RHS[MAXROW], OBJ[MAXCOL], Element[MAXELT], Lower[MAXCOL], Upper[MAXCOL]; int ColStart[MAXCOL+1], RowIndex[MAXELT]; double Factor; int ReturnValue; int i, j; char RowNames[500], ColNames[500]; char *CoefBuffer; int BufferPos; /* Initialisation */ CoefBuffer = NULL; 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 */ nCol++; /* Remaining columns come later */ for (i=1;i 1) { BufferPos = BufferPos + sprintf(&CoefBuffer[BufferPos]," + "); } BufferPos = BufferPos + sprintf(&CoefBuffer[BufferPos], "RHO%d * RHO%d * SIN ( THETA%d - THETA%d )",i+1,i,i+1,i); } XSLPchgccoef(sprob,0,nSide,&Factor,CoefBuffer); /* Distances */ Factor = 1; for (i=1;i