FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Folio - Advanced modelling and solving tasks

Description
Advanced modelling and solving tasks for a portfolio optimization problem:
  • Automated solver tuning (foliolptune.mos)
  • Defining an integer solution callback (foliocb.mos)
  • Using the solution enumerator for multiple MIP solutions (folioenumsol.mos)
  • Handling infeasibility
    • handling infeasibility through deviation variables (folioinfeas.mos)
    • retrieving infeasible row/column from presolve (folioinfcause.mos)
    • retrieving IIS - LP or MIP infeasible (folioiis.mos, foliomiis.mos)
    • using the built-in infeasibility repair functionality (foliorep.mos)
    • same as foliorep, using an 'mpsol' object (foliorep_sol.mos)
  • Data transfer in memory
    • running foliomemio.mos with data transfer in memory (runfolio.mos)
    • same running foliomemio2.mos, grouping tables with identical index sets in "initializations" blocks (runfolio2.mos)
    • master model running several model instances in parallel (runfoliopar.mos)
  • Remote models on a distributed architecture
    • running foliomemio.mos on a remote instance of Mosel (runfoliodistr.mos)
    • master model running several model instances in parallel, each on a different (remote) instance of Mosel (runfoliopardistr.mos)
  • Remote execution via XPRD
    • See examples in the Mosel Whitepapers directory moselpar/XPRD
  • XML and JSON data formats
    • reading data from an XML file, solution output in XML format on screen and to a new file (folioxml.mos, folioxmlqp.mos)
    • generate HTML output file as an XML document (runfolioxml.mos)
    • using JSON-format data files, reading data from a JSON file, solution output in JSON format on screen and to a new file (foliojson.mos)
  • HTTP
    • starting an HTTP server managing requests from HTTP clients (foliohttpsrv.mos)
    • HTTP client exchanging XML data files with an HTTP server (foliohttpclient.mos)


Source Files

Data Files





foliohttpclient.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file foliohttpclient.mos
   ````````````````````````
   Sending HTTP requests for model runs with
   XML-format data to a server, retrieving and
   displaying the results.

   *** Before running this model, an HTTP server must be
   *** launched by running the file foliohttpsrv.mos.
   
  (c) 2013 Fair Isaac Corporation
      author: S.Heipcke, July 2013
*******************************************************!)

model "HTTP client launching portfolio model"
 uses "mmhttp"                       ! Use HTTP functions
 uses "mmxml"                        ! Use XML format

 parameters
  DATAFILE= "folio.xml"              ! File with problem data
  OUTFILE= "result.xml"              ! Output file
  MAXRISK = 1/3                      ! Max. investment into high-risk values
  MAXVAL = 0.3                       ! Max. investment per share
  MINAM = 0.5                        ! Min. investment into N.-American values

  SERVERNAME = "localhost"           ! Configure with the machine name/address
                                     ! that is running foliohttpsrv.mos
 end-parameters 

 declarations
  ResData: xmldoc                    ! XML document
  SList: list of integer             ! XML nodes
 end-declarations

 ! Create a temporary file with the configuration data
 TEMPDIR:=getparam("tmpdir")+"/tartemp"
 makedir(TEMPDIR)
 initializations to TEMPDIR+"/folioconfig.dat"
  MAXRISK
  MAXVAL
  MINAM
  DATAFILE
 end-initializations

 ! Create an archive with the configuration data + XML data file
 fcopy(DATAFILE, TEMPDIR)
 newtar(0, "zlib.gzip:tmp:folio.tgz", TEMPDIR, [DATAFILE, "folioconfig.dat"])

 ! Delete temporary files
 removefiles(SYS_RECURS, TEMPDIR, "*")
 removedir(TEMPDIR)

 ! Post the solving request (synchronous mode => waits for reply from server)
 status:=httppost("http://" + SERVERNAME + ":2533/runmodel", 
                  "tmp:folio.tgz", OUTFILE)

 ! Display the result
 if status/100=2 then
  load(ResData, OUTFILE)             ! Reading data from an XML file
  sol:=getnode(ResData, "result/solution") 
  writeln("Solution with value ", getattr(ResData, sol, "value"), ":")
  getnodes(ResData, sol, "share", SList)
  forall(s in SList)
   writeln("  ", getattr(ResData, s, "name"), ": ", getvalue(ResData, s))
 else
  writeln("Request failed with code: ", status, " (", httpreason(status), ")")
  fcopy(OUTFILE,"")                  ! Display output file contents (error msg)
 end-if
 
end-model

Back to examples browserPrevious exampleNext example