| |||||||||||||||||
Coco - A full production planning example Description The Coco productional planning problem: multi-item,
multi-period, multi-site production planning. A sequence
of model versions show how the model
was developed, to (a) use more sophisticated modeling features
and (b) to extend the model, taking it from a simple linear model
to one with fixed prices and logical decisions.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
Data Files xbcoco2.c /******************************************************** BCL Example Problems ==================== file xbcoco2.c `````````````` Coco Problem Phase 2. Use parameters, data tables and subscripted variables to separate the model structure from the data. Read data tables in from text data files. (c) 2008-2024 Fair Isaac Corporation author: S.Heipcke, Jan. 2000, rev. Mar. 2011 ********************************************************/ #include <stdio.h> #include "xprb.h" #define NP 2 /* Number of products (p) */ #define NF 2 /* factories (f) */ #define NR 2 /* raw materials (r) */ #define REVFILE XPRBDATAPATH "/coco/rev.dat" #define CMAKEFILE XPRBDATAPATH "/coco/cmake.dat" #define CBUYFILE XPRBDATAPATH "/coco/cbuy.dat" #define REQFILE XPRBDATAPATH "/coco/req.dat" #define MXSELLFILE XPRBDATAPATH "/coco/maxsell.dat" #define MXMAKEFILE XPRBDATAPATH "/coco/mxmake.dat" /****TABLES****/ double REV[NP]; /* Unit selling price of product p */ double CMAK[NP][NF]; /* Unit cost to make product p at factory f */ double CBUY[NR]; /* Unit cost to buy raw material r */ double REQ[NP][NR]; /* Requirement by unit of prod. p for raw material r */ double MXSELL[NP]; /* Max. amount of p that can be sold */ double MXMAKE[NF]; /* Max. amount factory f can make over all products */ double PROFIT[NP][NF]; /* Profit contribution of product p at factory f */ /***********************************************************************/ void modcoco2(XPRBprob prob) { XPRBvar make[NP][NF]; XPRBctr ctr; int p,f; /****VARIABLES****/ for(p=0;p<NP;p++) for(f=0;f<NF;f++) make[p][f]= /* Amount of prod. p to make at factory f */ XPRBnewvar(prob,XPRB_PL,XPRBnewname("make_p%df%d",p+1,f+1),0,XPRB_INFINITY); /****OBJECTIVE****/ ctr = XPRBnewctr(prob,"OBJ",XPRB_N); /* Objective: maximize total profit */ for(p=0;p<NP;p++) for(f=0;f<NF;f++) XPRBaddterm(ctr,make[p][f],PROFIT[p][f]); XPRBsetobj(prob,ctr); /* Select objective function */ /****CONSTRAINTS****/ /* Limit on the amount of product p to be sold */ for(p=0;p<NP;p++) { ctr = XPRBnewctr(prob,"MxSell",XPRB_L); for(f=0;f<NF;f++) XPRBaddterm(ctr,make[p][f],1); XPRBaddterm(ctr,NULL,MXSELL[p]); } /* Capacity limit at factory f */ for(f=0;f<NF;f++) { ctr=XPRBnewctr(prob,"MxMake",XPRB_L); for(p=0;p<NP;p++) XPRBaddterm(ctr, make[p][f], 1); XPRBaddterm(ctr, NULL, MXMAKE[f]); } /****SOLVING + OUTPUT****/ XPRBsetsense(prob,XPRB_MAXIM); /* Choose the sense of optimization */ XPRBlpoptimize(prob, ""); /* Solve the LP-problem */ printf("Objective: %g\n", XPRBgetobjval(prob)); /* Get objective value */ for(p=0;p<NP;p++) for(f=0;f<NF;f++) { XPRBprintvar(make[p][f]); printf(" "); } /* Print the solution values */ printf("\n"); } /***********************************************************************/ /**** Read data from files ****/ void readdata(void) { FILE *datafile; int p,f,r; /* Read the revenu data file */ datafile=fopen(REVFILE,"r"); XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", REV, NP); fclose(datafile); /* Read the production cost data file */ datafile=fopen(CMAKEFILE,"r"); for(p=0;p<NP;p++) XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", CMAK[p], NF); fclose(datafile); /* Read the raw material cost data file */ datafile=fopen(CBUYFILE,"r"); XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", CBUY, NR); fclose(datafile); /* Read the resource requirement data file */ datafile=fopen(REQFILE,"r"); for(p=0;p<NP;p++) XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", REQ[p], NR); fclose(datafile); /* read the max. sales quantities data file */ datafile=fopen(MXSELLFILE,"r"); XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", MXSELL, NP); fclose(datafile); /* Read the production capacities data file */ datafile=fopen(MXMAKEFILE,"r"); XPRBreadarrlinecb(XPRB_FGETS, datafile, 200, "g,", MXMAKE, NF); fclose(datafile); /* Calculate the table PROFIT */ for(p=0;p<NP;p++) for(f=0;f<NF;f++) { PROFIT[p][f] = REV[p] - CMAK[p][f]; for(r=0;r<NR;r++) PROFIT[p][f] -= (REQ[p][r]*CBUY[r]); } } /***********************************************************************/ int main(int argc, char **argv) { XPRBprob prob; prob=XPRBnewprob("Coco2"); /* Initialize a new problem in BCL */ readdata(); /* Data input from file */ modcoco2(prob); /* Model and solve the problem */ return 0; } | |||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |