/***********************************************************************************
* 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. *
************************************************************************************/
* Using PROC OPTMODEL for Assignment problem;
option nodate ;
%let _title=’Assignment network: solution to exercise 2.2′;
%let _data=’c:\sasor\data2_2_exercise.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..4};
* 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} <costprofit[worker,t]=col(“task”||t)>;
* 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*****************************
****************************************************************************/