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

Folio - Embedding examples from 'Getting started'

Simple embedding tasks for a portfolio optimization problem:
  • loading and running a BIM file (
  • executing a Mosel model (
  • parameterized model execution (
  • exporting a matrix (
  • accessing model results (
  • data exchange in memory (,,
  • retrieving solution output from Optimizer callbacks in foliocbio.mos during optimization ([download all files]

Source Files

Data Files

  Mosel Library Example Problems

  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;                               // Run the model
                                      // Test whether a solution is found
				      // and print the objective value
    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)
   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