[Cmpl] Error messages & some basic syntax questions

Mike Steglich mike.steglich at th-wildau.de
Thu Dec 27 08:59:13 EST 2012


Hi Richard,

CMPL is intended to formulate and solve linear programs. Therefore all objectives and constraints have to be formulated as linear expressions. 
The only nonlinear term that is allowed are products of variables if at least one of the factors is an integer variable.

Your model must fail because there a couple of nonlinear terms. 

e.g.:
spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} ->min; 

It is not permitted that variables are imbedded in brackets (at the moment). Therefore you have to reformulate your objective function into a polynomial of the second degree. 

sum{j: =1(1)count(coupon):   actualPrice[j]^2 +  2 * actualPrice[j] * linApproxPrice[j] + linApproxPrice[j] * linApproxPrice[j]   } ->min;

This polynomial contains the products linApproxPrice[j]*linApproxPrice[j] that can be used if the variables linApproxPrice[j] are integers and lower and upper bounds have been specified. To avoid accuracy problems it would make sense to scale the variables linApproxPrice[j] (e.g. by a factor 100). But this leads to a increased amount of artificial variables which are automatically generated by CMPL for the reformulation of the products of variables. 

It seems that is is possible to formulate your problem in form of a MIP but you have to "pay" it with a huge amount of variables or a lack in the accuracy.

We are planning to support nonlinear programs but this will be a long-term process.

Thanks,

Mike






Am 27.12.2012 um 07:37 schrieb Richard Baverstock:

> Hi,
> 
> I'm trying to learn how to use cmpl by writing a small model that approximates a polynomial to bond spot rates. 
> 
> Things are looking good, but calculation of some intermediate variables seems to be causing problems. I'm placing these calculations in the constraints section, as is done in the quadratic-assignment.cmpl example. The errors I see & the .cmpl file I am using are at the end of the email. The SYMBOL_VAR seems related to s[j], but I'm not fluent enough in the language yet to see what the issue is ...
> 
> I'm also curious - on page 31 of http://www.coliop.org/download/CMPL.pdf, the constaints and objective sections need to be in linear forms. Is non-linear optimization not supported in the CMPL language?
> 
> Thanks,
> Richard
> 
> Errors:
> 
> -bash-3.2$ cmpl immunize.cmpl 
> CMPL model generation - running
> 
> CMPL version: 1.7.1
> Authors: Thomas Schleiff, Mike Steglich
> Distributed under the GPLv3 
> 
> create model instance ...
> error (compiler): file immunize.cmpl line 35: syntax error, unexpected SYMBOL_VAR
> error (compiler): file immunize.cmpl line 42: syntax error, unexpected DEFS_TMP_ASSIGN, expecting ':'
> error (compiler): file immunize.cmpl line 42: syntax error, unexpected '}', expecting end of file
> CMPL model generation - failed
> 
> 
> CMPL file immunize.cmpl:
> 
> parameters:
>   # Car lease payments, 36 month term
>   nPayments  := 36;
>   payments[] := (3927, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, );
> 
>   # Bonds. Assumes face value of 100, and 2 bonds at each maturity date (to
>   # create a zero-coupon bond)
>   daysSinceLastCoupon := 131;
>   daysInCurrentPeriod := 184;
>   nBonds        := 6;
>   coupon[]      := (0.0388, 0.0063, 0.0075, 0.0313, 0.0400, 0.0125);
>   askPrice[]    := (101.531, 100.219, 100.531, 102.781, 105.313, 101.469);
>   couponsLeft[] := (1, 1, 2, 2, 3, 3);
> 
>   aiMultiplier := daysSinceLastCoupon / daysInCurrentPeriod;
> 
>   {j:=1(1)dim(coupon):  ai[j]          := aiMultiplier * coupon[j]/2; }
>   {j:=1(1)dim(coupon):  actualPrice[j] := askPrice[j] + ai[j] * 100; }
> 
>   # Create zero-coupon bonds. Assumes all have face values of 100.
>   {j:=1(1)dim(coupon)/2: zeroPrice[j] := ( -coupon[2*j]/(coupon[2*j-1] - coupon[2*j]) * actualPrice[2*j-1] + (1-( -coupon[2*j]/(coupon[2*j-1] - coupon[2*j]))) * actualPrice[2*j]); }
> 
>   # Spot rates for zero-coupon bonds
>   {j:=1(1)dim(zeroPrice): zeroSpot[j] := -ln(100/zeroPrice[j]); }
> 
> 
> variables:
>   a[1..5]: real;
>   s[1(1)dim(coupon)/2]: real;
>   linApproxPrice[1..dim(coupon)]: real;
>   d[1(1)dim(coupon)/2]: real;
> 
> objectives:
>   # Find a linear approximation to the spot rates
>   spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} ->min;
> 
> 
> constraints:
>   -20 <= a[] <= 20;
> 
>   # Calculate intermediate variables
>   {j:=1(1)dim(coupon)/2:  s[j] = a[1] + a[2] * ((1 - j)/2) + a[3] * (((1-j)/2)^2) + a[4] * (((1-j)/2)^3) + a[5] * (((1-j)/2)^4); }
>   {j:=1(1)dim(coupon)/2:  d[j] = (1 / ((1 + (s[j]/2))^couponsLeft[j])); }
>   {j:=1(1)dim(coupon)/2:  facePV[j] = d[j] * 100; }
>   {j:=1(1)dim(coupon):    cPaymentLeft[j] = coupon[j] * 100 * (1 - d[j]) / s[floor((j + 1)/2)]; }
>   {j:=1(1)dim(coupon):    linApproxPrice[j] = facePV[floor((j+1)/2)] + cPaymentLeft[j]; }
> 
> _______________________________________________
> Cmpl mailing list
> Cmpl at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cmpl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20121227/182cd99e/attachment.html>


More information about the Cmpl mailing list