## Multi-Commodity Transshipment Problem (lp14)

```/****************************************************************/
/*          S A S   S A M P L E   L I B R A R Y                 */
/*                                                              */
/*    NAME: LP14                                                */
/*   TITLE: Multi-Commodity Transshipment Problem (lp14)        */
/* PRODUCT: OR                                                  */
/*  SYSTEM: ALL                                                 */
/*    KEYS: LP                                                  */
/*   PROCS: LP                                                  */
/*    DATA:                                                     */
/*                                                              */
/* SUPPORT:                             UPDATE:                 */
/*     REF:                                                     */
/*    MISC:                                                     */
/*                                                              */
/****************************************************************/

title 'Multi-commodity Transshipment Problem with Fixed-Charges';
%macro dooversd;
_coef_=sd{_i_};
if sd{_i_}>0 then do;                /* the node is a supply node */
_row_=from||' commodity'||put(_i_,2.);
if from^=' ' then output;
end;
else if sd{_i_}<0 then do;           /* the node is a demand node */
_row_=to||' commodity'||put(_i_,2.);
if to^=' ' then output;
end;
else if from^=' ' & to^=' ' then do; /* a transshipment node      */
_coef_=0;
_row_=from||' commodity'||put(_i_,2.); output;
_row_=to  ||' commodity'||put(_i_,2.); output;
end;
%mend dooversd;

%macro dooverc;
_col_=arc||' commodity'||put(_i_,2.);
if from^=' ' & to^=' ' then do;  /* add node arc incidence matrix */
_type_='le'; _row_=from||' commodity'||put(_i_,2.);
_coef_=1;  output;
_row_=to  ||' commodity'||put(_i_,2.);
_coef_=-1; output;
_type_='  '; _row_='obj';
_coef_=c{_i_};  output;
/* add fixed charge variables   */
_type_='le'; _row_=arc;
_coef_=1;  output;
_col_='_rhs_';
_type_='  ';
_coef_=0;  output;
_col_=arc||'fx';
_coef_=-M; output;
_row_='int';
_coef_=1;  output;
_row_='obj';
_coef_=fx; output;
_row_='upper';
_coef_=1;  output;
end;
%mend dooverc;

data network;
retain M 1.0e6;
length _col_ \$ 22 _row_ \$ 22;
keep _type_ _col_ _row_ _coef_ ;
array sd sd1-sd4;
array c c1-c4;

input arc \$10. from \$ to \$ c1 c2 c3 c4 sd1 sd2 sd3 sd4 fx;

/* for the first observation define some of the rows */

if _n_=1 then do;
_type_='upperbd'; _row_='upper'; output;
_type_='lowerbd'; _row_='lower'; output;
_type_='min';     _row_='obj';   output;
_type_='integer'; _row_='int';   output;
end;

_col_='_rhs_';  _type_='le';

do _i_ = 1 to dim(sd);
%dooversd;
end;
do _i_ = 1 to dim(c);
%dooverc;
end;

datalines;
a-Chicago   farm-a  Chicago    20 15 17 22     100 100  40   .  100
b-Chicago   farm-b  Chicago    15 15 15 30     100 200  50  50   75
c-Chicago   farm-c  Chicago    30 30 10 10      40 100  75 100  100
a-StLouis   farm-a  StLouis    30 25 27 22       .   .   .   .  150
c-StLouis   farm-c  StLouis    10  9 11 10       .   .   .   .   75
Chicago-NY  Chicago NY         75 75 75 75    -150 -200 -50 -75 200
StLous-NY   StLouis NY         80 80 80 80       .   .   .   .  200
;

/* solve the model */

proc lp sparsedata pout=solution noprint;
run;

/* print the solution */

data;
set solution;
rename _var_=arc _value_=amount;
if _value_^=0 & _type_='NON-NEG';
run;

proc print;
id arc;
var amount;
run;

```