Initializing help system before first use

Running a model with multiple data scenarios


Type: Transportation
Rating: 2
Description: Retrieve data and solution information from the model instances for solution aggregation and reporting by the calling program.
File(s): scenar.c, scenar.mos
Data file(s): dem1.dat, dem2.dat, dem3.dat, dem4.dat, dem5.dat, supply.dat


scenar.c
/*******************************************************
   Mosel Example Problems
   ====================== 

   file scenar.c
   `````````````
   Executing different scenarios.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2002
********************************************************/

#include 
#include 
#include "xprm_mc.h"

int execscenar(const char *FILENAME, double WEIGHT);

#define NSUP 6

double obj, capuse[NSUP], CAP[NSUP];
char SUPNAME[NSUP][64];

int main()
{
 int NSCENAR = 5;
 const char *DEMDATA[] = {"dem1.dat", "dem2.dat", "dem3.dat", "dem4.dat", 
                          "dem5.dat"};
 double WEIGHT[] = {0.4, 0.15, 0.1, 0.25, 0.1};
 int i,s;
 double fact = 0;

 if(XPRMinit())                         /* Initialize Mosel */
  return 1;
                                        /* Execute all scenarios */
 for(i=0;istring);
   XPRMgetarrval(darr, indices, &(CAP[indices[0]-1]));
  } while(!XPRMgetnextarrentry(darr, indices));  /* Get the next index tuple */
 }

/* At every execution: get the solution for variables 'x' */
 XPRMfindident(mod, "x", &rvalue);        /* Get the model object 'x' */
 varr = rvalue.array;
 XPRMgetfirstarrtruentry(varr, indices); /* Get the first entry of array varr
                                             (we know that the array is sparse 
                                             and has two dimensions) */
 do
 {
  XPRMgetarrval(varr, indices, &x);       /* Get the corresponding variable */
  capuse[indices[0]-1] += WEIGHT*XPRMgetvsol(mod,x);   /* Save the sol. value */
/*  printf("<%d,%d:%g>\n", indices[0], indices[1], XPRMgetvsol(mod,x)); */
 } while(!XPRMgetnextarrtruentry(varr, indices));  
                                          /* Get the next index tuple */
 return 1;
}

scenar.mos
(!*******************************************************
  Mosel Example Problems
  ======================

  file scenar.mos
  ```````````````
  Transportation example (multiple scenarios).

  (c) 2008 Fair Isaac Corporation
      author: S.Heipcke, 2002, rev. Dec. 2017
*********************************************************!)

model "Scenario"
 uses "mmxprs"

 parameters
  DEMFILE="Data/dem1.dat"
 end-parameters
 
 declarations
  Suppliers: set of string                  ! Set of suppliers
  Customers: set of string                  ! Set of customers
  COST: dynamic array(Suppliers,Customers) of real  ! Cost per supplier-customer pair
  CAP: array(Suppliers) of real             ! Production capacity
  DEM: array(Customers) of real             ! Demand by customers

  x: dynamic array(Suppliers,Customers) of mpvar    ! Transported quantities
 end-declarations
 
 initializations from "Data/supply.dat"
  COST CAP
 end-initializations
 
 initializations from DEMFILE
  DEM as "DEMAND"
 end-initializations  

 forall(s in Suppliers, c in Customers | exists(COST(s,c))) create(x(s,c))

! Objective: minimize total cost
 MinCost:= 
  sum(s in Suppliers, c in Customers | exists(COST(s,c))) COST(s,c) * x(s,c)

! Limits on production capacities
 forall(s in Suppliers) sum(c in Customers) x(s,c) <= CAP(s)

! Satisfy customer demands
 forall(c in Customers) sum(s in Suppliers) x(s,c) >= DEM(c) 

 minimize(MinCost)

 writeln("Demand scenario: ", DEMFILE)
 
(! 
 forall(s in Suppliers, c in Customers)
  if(getsol(x(s,c))>0) then
   writeln(s," (", CAP(s), ") -> ", c, " (", DEM(c), "): ", 
       getsol(x(s,c)) )
  end-if
!)

 if(getprobstat=XPRS_OPT) then
  writeln("Total cost: ", getobjval)
  forall(s in Suppliers) writeln(s, ": ", getsol(sum(c in Customers) x(s,c)) )
 end-if
 
end-model