/********************************************************
Xpress-BCL C++ Example Problems
===============================
file xbrecurs.cxx
`````````````````
Recursion solving a non-linear financial planning problem
The problem is to solve
net(t) = Payments(t) - interest(t)
balance(t) = balance(t-1) - net(t)
interest(t) = (92/365) * balance(t) * interest_rate
where
balance(0) = 0
balance[T] = 0
for interest_rate
(c) 2008 Fair Isaac Corporation
author: S.Heipcke, 2001, rev. Mar. 2011
********************************************************/
#include
#include
#include "xprb_cpp.h"
#include "xprs.h"
using namespace std;
using namespace ::dashoptimization;
#define T 6
/****DATA****/
double X = 0.00; /* An INITIAL GUESS as to interest rate x */
double B[] = /* {796.35, 589.8918, 398.1351, 201.5451, 0.0, 0.0}; */
{1,1,1,1,1,1};
/* An INITIAL GUESS as to balances b(t) */
double P[] = {-1000, 0, 0, 0, 0, 0}; /* Payments */
double R[] = {206.6, 206.6, 206.6, 206.6, 206.6, 0}; /* " */
double V[] = {-2.95, 0, 0, 0, 0, 0}; /* " */
XPRBvar b[T]; /* Balance */
XPRBvar x; /* Interest rate */
XPRBvar dx; /* Change to x */
XPRBctr interest[T], ctrd;
XPRBprob p("Fin_nlp"); /* Initialize a new problem in BCL */
/***********************************************************************/
void modFinNLP()
{
XPRBvar i[T]; /* Interest */
XPRBvar n[T]; /* Net */
XPRBvar epl[T], emn[T]; /* + and - deviations */
XPRBexpr cobj, le;
int t;
/****VARIABLES****/
for(t=0;t0) p.newCtr("bal", b[t] == b[t-1]-n[t]);
else p.newCtr("bal", b[t] == -n[t]);
}
for(t=1;t0.000001)
{
ct++;
basis=p.saveBasis(); /* Save the current basis */
/* Get the solution values for b and x */
for(t=1;t |