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

Basic embedding tasks

Description
  • ugcomptmp.cs: Compiling a model into a BIM file saved in Mosel's temporary directory (requires burglar2.mos, burglar.dat)
  • ugrun.cs: Compiling a model into a BIM file, then load and run it (requires burglar2.bim, burglar.dat)
  • ugdefstream.cs: Redirecting the model output (requires burglar2.mos, burglar.dat)
  • ugarray.cs: Accessing modeling objects: sparse arrays (requires transport.mos, transprt.dat)
  • ugcb.cs: Retrieve model output via a callback into a custom TextWriter (requires burglar2.mos, burglar.dat)
  • ugcb2.cs: Retrieve model output via a callback into a string (requires burglar2.mos, burglar.dat)
  • ugparam.cs: Passing parameters to a Mosel model (requires prime.mos)
  • ugsol.java: Accessing modeling objects and solution information (requires burglar3.mos, burglar.dat)


Source Files

Data Files





ugparam.cs

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

   file ugparam.cs
   ```````````````
   Passing parameters to a Mosel program
   Accessing modeling objects (sets).
   
   (c) 2013 Fair Isaac Corporation
       author: S.Heipcke, Apr. 2013 
********************************************************/


using System;
using System.IO;
using Mosel;


namespace ugparam.cs {

  public class ugparam {
    /// <summary>
    /// Main entry point for the application
    /// </summary>
    [STAThread]
    static void Main(string[] args) {
      XPRMSet set;
      int LIM=500, first, last;

      // Initialize Mosel
      XPRM mosel = XPRM.Init();

      // Compile and load a model
      XPRMModel model = mosel.CompileAndLoad("prime.mos");

      // Run the model
      model.ExecParams = "LIMIT=" + LIM;
      model.Run();
      Console.WriteLine("`prime' returned: " + model.Result);

      // Get model object 'SPrime', it must be a set
      set=(XPRMSet)model.FindIdentifier("SPrime");                              

      // Enumerate the set elements
      if (!set.IsEmpty)
      {
        first = set.FirstIndex;         // Get the number of the first index
        last = set.LastIndex;           // Get the number of the last index
    Console.WriteLine("Prime numbers from 2 to " + LIM);
        for (int i=first;i<=last;i++)   // Print all set elements
          Console.Write(" {0},", set.GetAsInteger(i));
        Console.WriteLine();
      }
    }
  }
}

Back to examples browserPrevious exampleNext example