Linear Assignment Problem for Minimizing Swim Times (netsle03)
/***************************************************************************/
/* */
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: netsle03 */
/* TITLE: Linear Assignment Problem for Minimizing Swim Times (netsle03) */
/* PRODUCT: OR */
/* SYSTEM: ALL */
/* KEYS: OR */
/* PROCS: OPTMODEL, CONTENTS, PRINT */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: Example 3 from the network solver documentation. */
/* */
/***************************************************************************/
data RelayTimes;
input name $ sex $ back breast fly free;
datalines;
Sue F 35.1 36.7 28.3 36.1
Karen F 34.6 32.6 26.9 26.2
Jan F 31.3 33.9 27.1 31.2
Andrea F 28.6 34.1 29.1 30.3
Carol F 32.9 32.2 26.6 24.0
Ellen F 27.8 32.5 27.8 27.0
Jim M 26.3 27.6 23.5 22.4
Mike M 29.0 24.0 27.9 25.4
Sam M 27.2 33.8 25.2 24.1
Clayton M 27.0 29.2 23.0 21.9
;
proc contents data=RelayTimes
out=stroke_data(rename=(name=stroke) where=(type=1));
run;
proc optmodel;
set <str> STROKES;
read data stroke_data into STROKES=[stroke];
set <str> SWIMMERS;
str sex {SWIMMERS};
num time {SWIMMERS, STROKES};
read data RelayTimes into SWIMMERS=[name] sex
{stroke in STROKES} <time[name,stroke]=col(stroke)>;
set FEMALES = {i in SWIMMERS: sex[i] = 'F'};
set FNODES = FEMALES union STROKES;
set MALES = {i in SWIMMERS: sex[i] = 'M'};
set MNODES = MALES union STROKES;
set <str,str> PAIRS;
solve with NETWORK /
graph_direction = directed
links = (weight=time)
subgraph = (nodes=FNODES)
lap
out = (assignments=PAIRS)
;
put PAIRS;
create data LinearAssignF from [name assign]=PAIRS sex[name] cost=time;
solve with NETWORK /
graph_direction = directed
links = (weight=time)
subgraph = (nodes=MNODES)
lap
out = (assignments=PAIRS)
;
put PAIRS;
create data LinearAssignM from [name assign]=PAIRS sex[name] cost=time;
quit;
proc print data=LinearAssignF noobs label;
sum cost;
run;
proc print data=LinearAssignM noobs label;
sum cost;
run;