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





iodrvraw2.c

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

   file iodrvraw2.c
   ````````````````
   Using the IO drivers `raw' and `mem'.
   - Model source in separate .mos file -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Feb. 2007, rev. Feb. 2017
********************************************************/

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

const struct
{                                 /* Initial values for array 'data': */
 const char *ind;                 /*   index name */
 double val,wght;                 /*   value and weight data entries */
} data[]={{"camera",15,2}, {"necklace",100,20}, {"vase",90,20}, 
          {"picture",60,30}, {"tv",40,40}, {"video",15,30}, 
          {"chest",10,60}, {"brick",1,10}};

double solution[8];               /* Array for solution values */

/*****************/
/* Main function */
/*****************/
int main()
{
 XPRMmodel mod;
 XPRMalltypes rvalue, itemname;
 XPRMset set;
 int result,i;
 char data_name[40];              /* File name of initial values for 'data' */
 char solution_name[40];          /* File name of solution values */
 char params[96];                 /* Parameter string for model execution */

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

/* Prepare file names for 'initializations' using the 'raw' driver:         */
/*   "rawoption[,...],filename"                                             */
/*   (Here, 'filename' uses the 'mem' driver, data is stored in memory)     */
/* Options for 'raw':                                                       */
/* 'slength=0': strings are represented by pointers to null terminated      */
/*              arrays of characters (C-string) instead of fixed size arrays*/
/* 'noindex':   only array values are expected - no indices requested       */

 sprintf(data_name, "slength=0,mem:%p/%d", data, (int)sizeof(data));
 sprintf(solution_name, "noindex,mem:%p/%d", solution, (int)sizeof(solution));

                                   /* Pass file names as execution param.s */
 sprintf(params, "DATA='%s',SOL='%s'", data_name, solution_name);

 if(XPRMexecmod(NULL, "burglar2r.mos", params, &result, &mod))
  return 2;                        /* Execute a model file */

/* Display solutions values obtained from the model */
 printf("Objective: %g\n", XPRMgetobjval(mod));
 XPRMfindident(mod, "ITEMS", &rvalue);     /* Get the model object 'ITEMS' */
 set = rvalue.set;
 for(i=0;i<8;i++)
  printf(" take(%s): %g\n", XPRMgetelsetval(set, i+1, &itemname)->string,
         solution[i]);

 return 0;
}


Back to examples browserPrevious example