Program 2.2


/****************************************************************************
* This program is taken from the following book:                            *
* Emrouznejad, A. and Ho, W. (2010) Applied Operational Research with SAS,  *
* Chapman and Hall/CRC – 284 Pages.                                         *
* For details please visit: http://www.sas-or.com.                          *
****************************************************************************/


* Using PROC OPTMODEL for Assignment problem;
option nodate ;
%let _title=’Assignment network for five workers and five tasks.’;
%let _data=’c:\sasor\data2_2.txt’;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;

proc import
datafile=&_data
out= dataassign
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;

* Starting OPTMODEL Procedure;
proc optmodel;

* Define sets;
set WORKERS;
set TASKS={1..5};

* Define parameters;
number costprofit{WORKERS, TASKS};

* Define variables;
var X{WORKERS, TASKS} integer >= 0;

* Load the cost/profit matrix ;
read data dataassign
into WORKERS=[worker]
{t in TASKS} ;

* Define objective function;
min obj = sum{w in WORKERS, t in TASKS} costprofit[w,t]*x[w,t];

* Define constraints;
con req_supply{w in WORKERS}:
sum{t in TASKS} x[w,t] = 1;

con req_demand{t in TASKS}:
sum{w in WORKERS} x[w,t] = 1;

* Solve the model;
solve with milp;

* Create optimum values in a SAS dataset ‘optimout’;
create data optimout
from [WORKERS TASKS]
={w in WORKERS, t in TASKS: x[w,t]^=0}
amount=x cp= costprofit[w,t];

* End of OPTMODEL Procedure;
quit;

%mend model;

%macro report;
* Report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class WORKERS TASKS ;
var amount;
table WORKERS =” Workers”,
TASKS*amount*sum
/ BOX=’Assigning workers to each tasks’ ;
run;

* Report the results in a tabulated form;
proc tabulate data=optimout;
title &_title;
class WORKERS TASKS ;
var cp;
table WORKERS =” Workers”,
TASKS*cp*sum
/ BOX=’Cost-profit of workers to each tasks’ ;
run;
%mend report;

* The orassign macro for assignment problem;

%macro orassign;
%data;
%model;
%report;
%mend orassign;

%orassign;


/****************************************************************************
******************************END of the program*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/program-2-2

Leave a Reply