Folio - Examples from 'Getting Started'
Description
Different versions of a portfolio optimization problem.
Basic modelling and solving tasks:
- modeling and solving a small LP problem (foliolp)
- performing explicit initialization (folioini*)
- data input from file, index sets (foliodata, requires foliocpplp.dat)
- modeling and solving a small MIP problem with binary variables (foliomip1)
- modeling and solving a small MIP problem with semi-continuous variables (foliomip2)
- modeling and solving QP and MIQP problems (folioqp, requires foliocppqp.dat)
- modeling and solving QCQP problems (folioqc, requires foliocppqp.dat)
- heuristic solution of a MIP problem (folioheur)
Advanced modeling and solving tasks:
- enlarged version of the basic MIP model (foliomip3 with include file readfoliodata.c_, to be used with data set folio10.cdat)
- defining an integer solution callback (foliocb)
- using the MIP solution pool (foliosolpool)
- using the solution enumerator (folioenumsol)
- handling infeasibility through deviation variables (folioinfeas)
- retrieving IIS (folioiis)
- using the built-in infeasibility repair functionality (foliorep)
Further explanation of this example:
'Getting Started with BCL' for the basic modelling and solving tasks; 'Advanced Evaluators Guide' for solution enumeration and infeasibilit handling
Source Files
By clicking on a file name, a preview is opened at the bottom of this page. Data Files
readfoliodata.c_
/********************************************************
Xpress-BCL C Example Problems
=============================
file readfoliodata.c_
`````````````````````
Include file reading data for model foliomip3
from a text file.
(c) 2009-2024 Fair Isaac Corporation
author: Y.Colombani, May 2009
********************************************************/
/****************************************************/
/* Skip empty lines & comments and find next record */
/****************************************************/
int nextrec(FILE *f,char *rec)
{
int c;
do
{
c=fgetc(f);
if(c==EOF) return 0;
else
if(c=='!')
{
do
{
c=fgetc(f);
if(c==EOF) return 0;
}
while(c!='\n');
}
} while (isspace(c));
rec[0]=c;
return fscanf(f,"%128s",rec+1);
}
/***************************/
/* Input a list of strings */
/***************************/
int read_str_list(FILE *f,char ***list,int *size)
{
int n;
char word[128];
char *buf[MAXENTRIES];
n=0;
while(fscanf(f,"%128s",word)>0)
if(strcmp(word,";")==0) break;
else
if(word[strlen(word)-1]==';')
{
word[strlen(word)-1]='\0';
buf[n++]=strdup(word);
break;
}
else
buf[n++]=strdup(word);
*size=n;
*list=(char **)malloc(sizeof(char *)*n);
memcpy(*list,buf,sizeof(char *)*n);
return 0;
}
/************************/
/* Input a list of ints */
/************************/
int read_int_list(FILE *f,int **list,int *size)
{
int n,c;
int word;
int buf[MAXENTRIES];
n=0;
while(fscanf(f,"%d",&word)>0)
buf[n++]=word;
do
{
c=fgetc(f);
} while(isspace(c));
*size=n;
*list=(int *)malloc(sizeof(int)*n);
memcpy(*list,buf,sizeof(int)*n);
return 0;
}
/****************************/
/* Input a table of doubles */
/****************************/
int read_dbl_table(FILE *f,double **table,int size)
{
int n,c;
*table=(double *)malloc(sizeof(double)*size);
for(n=0;n0) tbl[r]=tbl[r-1]+ncol;
while(fscanf(f,"%d",&i)>0)
tbl[r][i]=1;
do
{
c=fgetc(f);
} while(isspace(c));
}
return 0;
}
int readdata(const char *filename)
{
FILE *f;
char rec[128];
f=fopen(filename,"r");
if(f==NULL) return 1;
while(nextrec(f,rec)>0)
{
if(strcmp(rec,"SHARES:")==0 && NSHARES==0)
read_str_list(f,&SHARES_n,&NSHARES);
else
if(strcmp(rec,"REGIONS:")==0 && NREGIONS==0)
read_str_list(f,®IONS_n,&NREGIONS);
else
if(strcmp(rec,"TYPES:")==0 && NTYPES==0)
read_str_list(f,&TYPES_n,&NTYPES);
else
if(strcmp(rec,"RISK:")==0 && NRISK==0)
read_int_list(f,&RISK,&NRISK);
else
if(strcmp(rec,"RET:")==0 && NSHARES>0)
read_dbl_table(f,&RET,NSHARES);
else
if(strcmp(rec,"LOC:")==0 && NSHARES>0 && NREGIONS>0)
read_bool_table(f,&LOC,NREGIONS,NSHARES);
else
if(strcmp(rec,"SEC:")==0 && NSHARES>0 && NTYPES>0)
read_bool_table(f,&SECT,NTYPES,NSHARES);
else
break;
}
fclose(f);
return NSHARES<1 || NRISK<1 || NREGIONS<1 || NTYPES<1 ||
RET==NULL || RISK==NULL || LOC==NULL || SECT==NULL;
}
void testprintout(void)
{
int i,j;
printf("Shares(%d):",NSHARES);
for(i=0;i
|