Adding initial values
So far, Xpress NonLinear has started by using values which it estimates for itself. Because most of the variables are bounded, these initial values are fairly reasonable, and the model will solve. However, in general, you will need to provide initial values for at least some of the variables. Initial values, and other information for SLP variables, are provided using the XSLPloadvars function.
int VarType[MAXCOL]; double InitialValue[MAXCOL];
To load initial values using XSLPloadvars, we need an array (InitialValue) to hold the initial values, and a VarType array which is a bitmap to describe what information is being set for each variable.
for(i=1; i<nSide; i++) { ... InitialValue[nCol] = 3.14159*((double)i) / ((double)nSide); VarType[nCol] = 4; ... } ... for(i=1; i<nSide; i++) { InitialValue[nCol] = 1; VarType[nCol] = 4; }
These sections extend the loops for the columns in the earlier example. We set initial values for the thetas so that the vertices are spaced at equal angles; the rhos are all started at 1. We do not need to set a value for the equals column, because it is fixed at one. However, it is good practice to do so. In each case we set VarType to 4 because (as described in the Xpress NonLinear Reference Manual) Bit 2 of the type indicates that the initial value is being set.
for(i=0; i<nCol; i++) ColIndex[i] = i XSLPloadvars(sprob, nCol-1, &ColIndex[1], &VarType[1], NULL, NULL, NULL, &InitialValue[1], NULL);
XSLPloadvars can take several other arguments apart from the initial value. It is a general principle in Xpress NonLinear that using NULL for an argument means that there is no information being provided, and the current or default value will not be changed.
Because we built up the initial values as we went, the VarType and InitialValue arrays include column 0, which is OBJX and is not an SLP variable. As all the rest are SLP variables, we can simply start these arrays at the second item, and reduce the variable count by 1.