FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Folio - Introductory examples from 'Getting Started'

Description
Simple tasks for formulating and solving a portfolio optimization problem:
  • loading an LP problem via matrix input (folioinput.c)
  • inputting an LP problem from data arrays (foliolp.c)
  • inputting a MIP problem - binary variables (foliomip1.c)
  • inputting a MIP problem - semicontinuous variables (foliomip2.c)
  • inputting a QP problem (folioqp.c)
  • using the MIP solution enumerator (foliomatenumsol.c)
  • using the MIP solution pool (foliomatsolpool.c)


Source Files

Data Files





folioinput.c

/********************************************************
  Xpress Optimizer Example Problems
  =================================

  file folioinput.c
  `````````````````
  Loading an LP problem via matrix input.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Aug. 2003, rev. Feb. 2023
********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "xprs.h"

int main(int argc, char **argv)
{
 XPRSprob prob;
 int s, status, ncol;
 double objval, *sol;

 /* Initialize Xpress */
 if (XPRSinit(NULL)) {
   char message[512];
   XPRSgetlicerrmsg(message,512);
   printf("%s\n", message);
   return -1;
 }

 XPRScreateprob(&prob);                  /* Create a new problem */
                                
 XPRSreadprob(prob, "Folio","");         /* Read the problem matrix */

 XPRSchgobjsense(prob, XPRS_OBJ_MAXIMIZE);  /* Set sense to maximization */
 XPRSlpoptimize(prob, "");               /* Solve the problem */

 XPRSwriteprtsol(prob, "Folio.prt", ""); /* Write results to file `Folio.prt' */
 
/* 
 XPRSgetintattrib(prob, XPRS_LPSTATUS, &status);  / * Get LP sol. status * /

 if(status == XPRS_LP_OPTIMAL)
 {
  XPRSgetdblattrib(prob, XPRS_LPOBJVAL, &objval); / * Get objective value * /
  printf("Total return: %g\n", objval);
 
  XPRSgetintattrib(prob, XPRS_ORIGINALCOLS, &ncol);  / * Get total no. of rows * /
  sol = (double *)malloc(ncol*sizeof(double));
  XPRSgetlpsol(prob, sol, NULL, NULL, NULL);      / * Get primal solution * /
  for(s=0;s<ncol;s++) printf("%d: %g%%\n", s+1, sol[s]*100);   
 }
*/

 XPRSdestroyprob(prob);                  /* Delete the problem */
 XPRSfree();                             /* Terminate Xpress */
  
 return 0;
} 

Back to examples browserNext example