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

Burglar - Exchange of information with embedded models

Description
  • iodrvmem.c - working in memory ('mem' driver): compilation of a model held in memory to memory
  • iodrvmem2.c - working in memory ('mem' driver): compilation of a model file to memory (requires burglar2.mos, burglar.dat)
  • iodrvraw.c - binary data format ('raw' driver): compilation of a model held in memory to memory
  • iodrvraw2.c - binary data format ('raw' driver): working with physical model files (requires burglar2r.mos)
  • iodrvcb.c - output to callback functions ('cb' driver); working with system file descriptors ('sysfd' driver)
  • burgbindata.[c|java], - use of 'bin:' / BinDrv for reading and writing (requires burglar2m.mos)
For Java and .NET versions see the subdirectories C2 and D3 of the Mosel User Guide examples folder.

Further explanation of this example: Whitepaper 'Generalized file handling in Mosel', Sections 6 Exchange of information with embedded models, 7 bin: using Mosel's binary format


Source Files

Data Files





iodrvmem2.c

/*******************************************************
   Mosel Example Problems
   ====================== 

   file iodrvmem2.c
   ````````````````
   Using the IO driver `mem'.
   - Model source in separate .mos file -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2004, rev. Aug. 2023
********************************************************/

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


/*****************/
/* Main function */
/*****************/
int main()
{
 XPRMmodel mod;
 int result,i;
 char bimfile[2000];              /* Buffer to store BIM file */
 size_t bimfile_size;             /* Buffer to store actual size of BIM file */
 char bimfile_name[64];           /* File name of BIM file */

 i=XPRMinit();                    /* Initialize Mosel */
 if((i!=0)&&(i!=32))
  return 1;

/* Prepare file names for compilation using 'mem' driver: */
/*   "mem:base address/size[/actual size pointer]"        */
 bimfile_size=0;
 sprintf(bimfile_name, "mem:%p/%d/%p",
         bimfile, (int)sizeof(bimfile), &bimfile_size);

                                  /* Compile model file to memory */
 if(XPRMcompmod(NULL, "burglar2.mos", bimfile_name, "Knapsack example")) 
    return 2; 
 printf("BIM file uses %d bytes of memory.\n", (int)bimfile_size);

                                  /* Load a BIM file from memory */
 if((mod=XPRMloadmod(bimfile_name, NULL))==NULL)
  return 3;

 if(XPRMrunmod(mod, &result, NULL))  /* Run the model */
  return 4;

 return 0;
}


Back to examples browserPrevious example