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

Folio - Embedding examples from 'Getting started'

Description
Simple embedding tasks for a portfolio optimization problem:
  • loading and running a BIM file (foliorun.java)
  • executing a Mosel model (folioexec.java)
  • parameterized model execution (folioparam.java)
  • exporting a matrix (foliomat.java)
  • accessing model results (folioobj.java)
  • data exchange in memory (runfolio.java,runfoliob.java,runfoliobd.java)
  • retrieving solution output from Optimizer callbacks in foliocbio.mos during optimization (runfoliocbio.java)

folioembedjava.zip[download all files]

Source Files

Data Files





folioobj.java

/********************************************************
  Mosel Library Example Problems
  ==============================

  file folioobj.java
  ``````````````````
  Accessing model results.

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, Mar. 2006
********************************************************/

import com.dashoptimization.*;

public class folioobj
{
 public static void main(String[] args) throws Exception
 {
  XPRM mosel;
  XPRMModel model;
  XPRMArray varr, darr;
  XPRMMPVar x;
  XPRMSet set;
  int[] indices;

  mosel = new XPRM();                        // Initialize Mosel

  mosel.compile("foliodata.mos");            // Compile the model
  model = mosel.loadModel("foliodata.bim");  // Load compiled model
  model.run();                               // Run the model
  
                                      // Test whether a solution is found
				      // and print the objective value
  if(model.getProblemStatus()==XPRMModel.PB_OPTIMAL)
    System.out.println("Objective value: " + model.getObjectiveValue());

                                      // Retrieve the decision variables
  varr=(XPRMArray)model.findIdentifier("frac"); // Get model object 'frac',
                                                // it must be an array

                                      // Retrieve the index names
  set=(XPRMSet)model.findIdentifier("SHARES");  // Get model object 'SHARES',
                                                // it must be a set

  indices = varr.getFirstIndex();     // Get the first entry of array varr
                                      // (we know that the array is dense)
  do
  {
   x = varr.get(indices).asMPVar();   // Get a variable from varr
   System.out.println(set.get(indices[0]) + ":\t" + x.getSolution()*100 + "%");
				      // Print the solution value
  } while(varr.nextIndex(indices));   // Get the next index

 }
}

Back to examples browserNext example