/***********************************************************************************
* This program is taken from the following book. If using please cite it as: *
* Emrouznejad, A. and W. Ho (2012). Applied Operations Research with SAS, *
* CRC Press: Taylor Francis Ltd, ISBN: 9781439841303. *
* For details please visit: http://www.sas-or.com. *
************************************************************************************/
* SAS macro for line assignment problem: solution to exercise 3.11.;
%let _title=’A line assignment problem using PROC OPTMODEL: solution to exercise 7.1.’;
option nodate ;
%let _dataC=’c:/sasor/Data7_1_C_exercise.txt’;
%let _dataT=’c:/sasor/Data7_1_T_exercise.txt’;
%let _nLine=3;
%let _nBoard=5;
%let _optimout=mysolution;
* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;
proc import
datafile=&_dataC
out=dataC
dbms=tab
replace;
getnames=yes;
run;
proc import
datafile=&_dataT
out=dataT
dbms=tab
replace;
getnames=yes;
run;
%mend data;
%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set LINES=1..&_nLine;
set BOARDS=1..&_nBoard;
* Define variables;
var X{LINES, BOARDS} integer >=0;
* Define parameters;
number cost{LINES, BOARDS};
number time{LINES, BOARDS};
number s{LINES};
number d{BOARDS};
* Load the time matrix;
read data dataT
into [_N_]
{j in BOARDS} <time[_N_,j]=col(‘board’||j)>;
* Load the cost matrix;
read data dataC (where =(line ne “demand”))
into [_N_]
{j in BOARDS} <cost[_N_,j]=col(‘board’||j)>;
* Load the demand array;
read data dataC (where =(line eq “demand”))
into
{j in BOARDS} <d[j]=col(‘board’||j)>;
* Load the supply array;
read data dataC (where= (line ne “demand”))
into [_N_] s[_N_]=col(“supply”);
* Define objective function;
min obj = sum{i in LINES, j in BOARDS} cost[i,j]*X[i,j];
* Define constrains;
con supply_line{i in LINES}:
sum{j in BOARDS} time[i,j]*X[i,j] <=s[i];
con demand_board{j in BOARDS}:
sum{i in LINES} X[i,j] =d[j];
* Solve the model;
solve with milp;
%put &_OROPTMODEL_;
* Exdpand the model;
expand;
* Create optimum values in a SAS dataset ‘optimout’;
create data &_optimout
from [LINES BOARDS]
={i in LINES, j in BOARDS: x[i,j]^=0}
amount=x ;
* Report the results in a tabulated form;
proc tabulate data=&_optimout;
title &_title;
class LINES BOARDS ;
var amount;
table LINES =” from City”,
BOARDS*amount*sum
/ BOX=’Assigning of Board to Line’;
run;
* End of OPTMODEL Procedure;
quit;
%mend model;
%macro report;
* Report the results in a tabulated form;
proc tabulate data=&_optimout;
title &_title;
class LINES BOARDS ;
var amount;
table LINES =” Line”,
BOARDS*amount*sum
/ BOX=’Assigning of Boards to Lines’ ;
run;
%mend report;
%macro orala;
%data;
%model;
%report;
%mend orala;
%orala;
/****************************************************************************
******************************END of the program*****************************
****************************************************************************/