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

Compilation to/from memory

Description
  • ugcompfrmem.mos, ugcompfrmemcs.cs: Compiling a model held in memory
  • ugcompmem.mos, ugcompmemcs.cs: Compiling a model to memory (requires burglar2.mos, burglar.dat)
Further explanation of this example: 'Mosel User Guide', Section 17.1 Generalized file handling

ugcompmemcs.zip[download all files]

Source Files

Data Files





ugcompmemcs.cs

/********************************************************
   Mosel User Guide Example Problems
   ================================= 

   file ugcompmem.cs
   `````````````````
   Compiling a model to memory.
   
   (c) 2013 Fair Isaac Corporation
       author: S.Heipcke, Mar. 2013 
               J.Farmer, Jul. 2019, rev. May. 2021
********************************************************/


using System;
using System.IO;
using Mosel;


namespace ugcompmem.cs {

  public class ugcompmem {
    /// <summary>
    /// Main entry point for the application
    /// </summary>
    [STAThread]
    static void Main(string[] args) {
      // Initialize Mosel
      XPRM mosel = XPRM.Init();
      // Set Mosel work directory to folder containing our example files
      mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;

      // Compile the Mosel model to a MemoryStream
      MemoryStream bimStream = new MemoryStream();
      mosel.Compile("",mosel.WorkDir+"/burglar2.mos",bimStream);

      // Reset stream pointer to beginning so we can read the bytes we've just written
      bimStream.Seek(0,SeekOrigin.Begin);

      // Load the Mosel model
      XPRMModel model;
      mosel.Bind("bimblk", bimStream);
      try {
        model = mosel.LoadModel("dotnet:bimblk");
      } finally {
        mosel.Unbind("bimblk");
      }
      
      // Run the model
      model.Run();
    }
  }

}

Back to examples browserPrevious example