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

Basic embedding tasks

Description
  • ugcomp.c: Compiling a model into a BIM file (requires burglar2.mos, burglar.dat)
  • ugcomptmp.c: Compiling a model into a BIM file saved in Mosel's temporary directory (requires burglar2.mos, burglar.dat)
  • ugexec.c: Execute (compile/load/run) a model (requires burglar2.mos, burglar.dat)
  • ugrun.c: Executing a BIM file (requires burglar2.bim, burglar.dat)
  • ugdefstream.c: Redirecting the model output (requires burglar2.mos, burglar.dat)
  • ugarray1.c, ugarray2.c: Accessing modeling objects: sparse arrays (requires transport.mos, transprt.dat)
  • ugcb.c: Retrieve model output via a callback (requires burglar2.mos, burglar.dat)
  • ugparam1.c, ugparam2.c: Passing parameters to a Mosel model (requires prime2.mos)
  • ugsol1.c, ugsol2.c: Accessing modeling objects and solution information (requires burglar3.mos, burglar.dat)


Source Files

Data Files





ugcb.c

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

   file ugcb.c
   ```````````
   Retrieve model output via a callback.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2006, rev. Feb. 2017
********************************************************/

#include <stdio.h>
#include "xprm_mc.h"

/**************************************/
/* Callback function to handle output */
/**************************************/
long XPRM_RTC cbmsg(XPRMmodel model, void *info, char *buf, unsigned long size)
{
/* Note: 'model' is NULL if the stream is used outside of an execution */
 printf("Mosel: %.*s", (int)size, buf);
 return 0;
}

int main()
{
 int result;
 char outfile_name[40];           /* File name of output stream */

 if(XPRMinit())                   /* Initialize Mosel */
  return 1;
                                  /* Using 'sysfd' driver:                   */
                                  /* Redirect error stream to default output */
 XPRMsetdefstream(NULL, XPRM_F_ERROR, "sysfd:1");

                                  /* Prepare file name for output stream   */
                                  /* using 'cb' driver:                    */
                                  /* "cb:function_pointer[/callback_data]" */
 sprintf(outfile_name, "cb:%p", cbmsg);

                                  /* Set default output stream to callback */
 XPRMsetdefstream(NULL, XPRM_F_WRITE, outfile_name);

                                  /* Execute = compile/load/run a model */
 if(XPRMexecmod(NULL, "burglar2.mos", NULL, &result, NULL))
  return 2;

 return 0;
}


Back to examples browserPrevious exampleNext example