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

Looping over optimization runs (within a model, batch executions, and multiple models/submodel)

Description
This example shows different possibilities of looping over a series of optimization runs using different data sets.
  • In the first case (batch1.mos) the loop is implemented within a single Mosel model. At every loop execution a new data set is read and the model is redefined correspondingly.
  • The second model (batch2.mos) only defines and solves once the optimization problem. It is run either from a batch file (runbatch2), or from an application using the Mosel Libraries (batch2.c), or as a submodel from a second Mosel model (runbatch2.mos) and receives the name of the data set to be used through a runtime parameter.


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
batch1.mos[download]
batch2.mos[download]
batch2.c[download]
runbatch2[download]
runbatch2.mos[download]

Data Files





batch2.c

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

   file batch2.c
   `````````````
   Looping over program executions coupled with 
   parameterized data in- and output.
       
   (c) 2008 Fair Isaac Corporation
       author: S.Heipcke, Oct. 2002
*******************************************************/

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

int main()
{
 int i, result;
 char params[60];
 XPRMmodel mod;

 XPRMinit();                            /* Initialize Mosel */

 XPRMcompmod(NULL,"batch2.mos",NULL,"");/* Compile the model batch2.mos */
 mod=XPRMloadmod("batch2.bim",NULL);    /* Load the BIM file */
 XPRMrunmod(mod,&result,NULL);          /* Run the model */

 for(i=1;i<=2;i++)
 {
  sprintf(params,"INFILE=batchdata%d.dat, OUTFILE=batchdata%d.dat, LIM=%d",
    i,i+1, 100+i*10);
  XPRMrunmod(mod,&result,params);      /* Re-run the model with other data */
 }

 return 0;
}

Back to examples browserPrevious exampleNext example