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

Preprocessing Mosel code

It is possible to use standard C preprocessors such as cpp or m4 with Mosel. Mosel treats the preprocessor symbol '#' at the beginning of lines like a comment sign, with the exception of line numbers/positioning markers that are handled to obtain the original line numbers (see the discussion in Section 2.5.3 Line control directives of the Mosel Language Reference Manual).
  • Using a C preprocessor as prefix in compilation:
    mosel comp "mmsystem.pipe:cpp preproc.mos -DA=1 -DDEBUG" -o preprocout.bim
    mosel run preprocout
  • Using a C preprocessor to output model source:
    cpp preproc.mos -DA=1 -DDEBUG -o preprocout.mos
    mosel preprocout.mos

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.


   Mosel Example Problems

   file preproc.mos
   Example of using preprocessor definitions within a Mosel model

   !!! The C preprocessor 'cpp' must be available in order     
   !!! to process this file before running it with Mosel 

   Compile and run the resulting BIM file with:
mosel comp "mmsystem.pipe:cpp preproc.mos -DA=1 -DDEBUG" -o preproc.bim
mosel run preproc

   Produce the prepocessed source via cpp:
cpp preproc.mos -DA=1 -DDEBUG -o preprocA1.mos

   (c) 2020-2022 Fair Isaac Corporation
       author: S. Heipcke, Aug. 2020, rev. Oct. 2022
model "preprocess via cpp"

#ifdef A
writeln("A defined")
#if A==1
writeln("A is 1")
writeln("A not defined")

!writeln("Uncommenting this line produces a syntax error",,)

#ifdef DEBUG
writeln_("This is a debug message.")



Back to examples browserPrevious example