/********************************************************/
/* Xpress-BCL C# Example Problems */
/* ============================== */
/* */
/* file xbportf.cs */
/* ``````````````` */
/* Example for the use of Xpress-BCL */
/* (Quadratic portfolio model) */
/* */
/* (c) 2008 Fair Isaac Corporation */
/* authors: S.Heipcke, D.Brett. */
/********************************************************/
/* In this model, a choice has to be made which values are taken *
* into a portfolio in order to minimize the total cost. The costs *
* for some values are interrelated, introducing a quadratic part *
* to the objective function. Upper bounds are given on the total *
* number of values and the share of each value that may be taken. */
using System;
using System.Text;
using System.IO;
using Optimizer;
using BCL;
namespace Examples
{
public class TestPortfolio
{
int NVal = 30; /* Total number of values */
int LIMIT = 20; /* Maximum number to be chosen */
//Define your own XPRBDATAPATH
const string XPRBDATAPATH = "../../data";
string QFILE = XPRBDATAPATH + "/portf/pfqcost.dat"; /* Quadratic cost coeff.s */
string BFILE = XPRBDATAPATH + "/portf/pfubds.dat"; /* Upper bds. on percentages */
string CFILE = XPRBDATAPATH + "/portf/pflcost.dat"; /* Linear cost coefficients */
/**** DATA ****/
double[] Cost; /* Coeff. of lin. part of the obj. */
double[,] QCost; /* Coeff. of quad. part of the obj. */
double[] UBnd; /* Upper bound values */
XPRBprob p = new XPRBprob("Portfolio"); /* Initialize a new problem in BCL */
/***********************************************************************/
public void modFolio()
{
XPRBexpr le = new XPRBexpr();
XPRBexpr qobj = new XPRBexpr();
XPRBvar[] x = new XPRBvar[NVal]; /* Amount of a value taken into
the portfolio */
XPRBvar[] y = new XPRBvar[NVal]; /* 1 if value i is chosen, else 0 */
int i,j;
XPRSprob xprsp;
/**** VARIABLES ****/
for(i=0;i |