Category: Chapter 7

Program 7.1

/***********************************************************************************
* 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 Printed Circuit Board (PCB) Assembly Line Assignment Problem;
option nodate ;
%let _title=’Example 7.1: A line assignment problem using PROC OPTMODEL’;
%let _dataC=’c:/sasor/Data7_1_C.txt’;
%let _dataT=’c:/sasor/Data7_1_T.txt’;
%let _nLine=4;
%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*****************************
****************************************************************************/

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

Program 7.2

/***********************************************************************************
* 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 Printed Circuit Board (PCB) Assembly Line Assignment Problem;
option nodate ;
%let _title=’Example 7.2: SMT placement machines or the component allocation problem using PROC OPTMODEL’;
%let _data=’c:/sasor/Data7_2.txt’;
%let _nMachine=3;
%let _nCompon=7;
%let _optimout=mysolution;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;
proc import
datafile=&_data
out=data12
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set MACHINES=1..&_nMachine;
set COMPONENTS=1..&_nCompon;

* Define variables;
var X{MACHINES, COMPONENTS} integer >=0;
var T;

* Define parameters;
number time{MACHINES, COMPONENTS};
number s{MACHINES};
number c{COMPONENTS};

* Load the time matrix;
read data data12 (where =(machine ne “demand”))
into [_N_]
{j in COMPONENTS} ;

* Load the component array;
read data data12 (where =(machine eq “demand”))
into
{j in COMPONENTS} ;

print c;
* Load the setup-time array;
read data data12 (where= (machine ne “demand”))
into [_N_] s[_N_]=col(“setup”);

* Define objective function;
min obj = T;

* Define constrains;

con Total{i in MACHINES}:
T- s[i] – sum{j in COMPONENTS: time[i,j] ne 1E10} time[i,j]*X[i,j] >=0;

con compon{j in COMPONENTS: j ne 0}: sum{i in MACHINES} X[i,j] =c[j];

con zero{i in MACHINES, j in COMPONENTS : time[i,j]=1E10}: x[i,j]=0;

* Solve the model;
solve with milp;
%put &_OROPTMODEL_;

expand;
* Create optimum values in a SAS dataset ‘optimout’;
create data &_optimout
from [MACHINES COMPONENTS]
={i in MACHINES, j in COMPONENTS: x[i,j]^=0}
amount=x ;

* End of OPTMODEL Procedure;
quit;

%mend model;

%macro report;
* Report the results in a tabulated form;
proc tabulate data=&_optimout;
title &_title;
class MACHINES COMPONENTS ;
var amount;
table MACHINES =” Machine”,
COMPONENTS*amount*sum
/ BOX=’Machines or the Component Allocation Problem’;
run;
%mend report;

%macro orcap;
%data;
%model;
%report;
%mend orcap;

%orcap;


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

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

Program 7.3

/***********************************************************************************
* 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.                                                                *
************************************************************************************/

* A SAS procedure for SMT placement machines or the component sequencing problem;
%let _title=’Example 7.3: SMT placement machines or the component sequencing problem’;
%let _dataC=’c:/sasor/Data7_3_C.txt’;
%let _dataF=’c:/sasor/Data7_3_F.txt’;
%let _nFeeder=4;
%let _nCompon=4;
%let _outprimal= outprimal;
%let _outdual= outdual;
%let _outtable= outtable;
option nodate;

* 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=&_dataF
out=dataF
dbms=tab
replace;
getnames=yes;
run;
%mend data;

* The model building macro;
%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set COMP=0..&_nCompon;
set Feed=0..&_nFeeder;

* Define variables;
var u{COMP} integer >=0;
var x{COMP,COMP} binary >=0 ;
var z;

* Define parameters;
number d{COMP,COMP};
number cx {COMP};
number cy {COMP};
number type {COMP};
number fx {FEED};
number fy {FEED};
number randfeeder {FEED};
number d1;
number d2;
number Distance{COMP,FEED};
number ds2{COMP,FEED};

* Load component data;
read data Datac into [_N_] type[_N_]=col(‘type’);
read data Datac into [_N_] cx[_N_]=col(‘cx’);
read data Datac into [_N_] cy[_N_]=col(‘cy’);

* Load feeder data;
read data Dataf into [_N_] fx[_N_]=col(‘fx’);
read data Dataf into [_N_] fy[_N_]=col(‘fy’);
read data Dataf into [_N_] randfeeder[_N_]=col(‘randfeeder’);

cx[0]=0; cy[0]=0; fx[0]=0; fy[0]=0;

for {i in FEED, j in COMP}
do;
if (i ne 0 & j ne 0)
then do; d1=(cx[i]-fx[j])**2; d2=(cy[i]-fy[j])**2; end;
else if (i=0 & j=0)
then do; d1=0; d2=0; end;
else if (i=0)
then do; d1=(cx[j]**2); d2=(cy[j]**2); end;
else if (j=0)
then do; d1=(fx[i]**2); d2=(fy[i]**2); end;

Distance[i,j]=round(sqrt( d1+d2),0.000001);
end;
print Distance;

for {i in FEED, j in COMP}
do;
if (i=j) then ds2[i,j]=0;
else if i=0 then ds2[j,i]=Distance[randfeeder[j],0]+Distance[j,randfeeder[j]];
else if j=0 then ds2[j,i]=Distance[j,i];
else ds2[j,i]=Distance[j,randfeeder[j]]+Distance[i,randfeeder[j]];
end;

* Define objective function ;
min obj = z;

* Define constrains;
con Objective: z= sum{i in FEED, j in COMP} ds2[j,i]*x[i,j];

con component_immediately_before1 {i in FEED}: sum{j in COMP: i ne j} x[j,i]=1;

con component_immediately_before2 {j in COMP}: sum{i in FEED: i ne j} x[j,i]=1;

con subtour_elimination {i in FEED, j in COMP : i ne 0 & j ne 0 & i ne j}: u[i]-u[j] + &_nCompon * x[i,j]<=&_nCompon-1;

solve with MILP;

expand;

%put &_OROPTMODEL_;

* Create optimum values of x in a SAS dataset ‘optimout1’;
create data optimout1
from [COMP FEED]
={i in COMP, j in FEED: x[i,j] ne 0}
amount=x ;

* Create optimum values of u in a SAS dataset ‘optimout2’;
create data optimout2
from [COMP]
={i in COMP: u[i]}
amount=u ;
*End of PROC OPTMODE;

quit;
%mend model;
* The report writing macro;
%macro report;
title &_title;

proc tabulate data=optimout1;
title &_title;
class COMP FEED ;
var amount;
table COMP =”COMP”,
FEED*amount*sum
/ BOX=’Component sequencing’;
run;

proc tabulate data=optimout2;
title &_title;
class COMP ;
var amount;
table COMP =”COMP”,
amount*sum
/ BOX=’Component sequencing’;
run;

%mend report;


* A SAS macro for SMT placement machines or the component sequencing problem;
%macro orcsp;
%data;
%model;
%report;
%mend orcsp;


%orcsp;


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

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

Exercise 7.1

/***********************************************************************************
* 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*****************************
****************************************************************************/

Permanent link to this article: http://sas-or.com/book/exercise-7-1

Exercise 7.2

/***********************************************************************************
* 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 Printed Circuit Board (PCB) Assembly Line Assignment Problem;
option nodate ;
%let _title=’Example 7.2: SMT placement machines or the component allocation problem using PROC OPTMODEL’;
%let _data=’c:/sasor/Data7_2_exercise.txt’;
%let _nMachine=4;
%let _nCompon=7;
%let _optimout=mysolution;

* The data handling macro;
%macro data;
* Import text tab delimited data file to SAS data file;
proc import
datafile=&_data
out=data12
dbms=tab
replace;
getnames=yes;
run;
%mend data;

%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set MACHINES=1..&_nMachine;
set COMPONENTS=1..&_nCompon;

* Define variables;
var X{MACHINES, COMPONENTS} integer >=0;
var T;

* Define parameters;
number time{MACHINES, COMPONENTS};
number s{MACHINES};
number c{COMPONENTS};

* Load the time matrix;
read data data12 (where =(machine ne “demand”))
into [_N_]
{j in COMPONENTS} <time[_N_,j]=col(‘compon’||j)>;

* Load the component array;
read data data12 (where =(machine eq “demand”))
into
{j in COMPONENTS} <c[j]=col(‘compon’||j)>;

print c;
* Load the setup-time array;
read data data12 (where= (machine ne “demand”))
into [_N_] s[_N_]=col(“setup”);

* Define objective function;
min obj = T;

* Define constrains;
con Total{i in MACHINES}:
T- s[i] – sum{j in COMPONENTS: time[i,j] ne 1E10} time[i,j]*X[i,j] >=0;
con compon{j in COMPONENTS: j ne 0}: sum{i in MACHINES} X[i,j] =c[j];

con zero{i in MACHINES, j in COMPONENTS : time[i,j]=1E10}: x[i,j]=0;

* Solve the model;
solve with milp;
%put &_OROPTMODEL_;
vexpand;
* Create optimum values in a SAS dataset ‘optimout’;
create data &_optimout
from [MACHINES COMPONENTS]
={i in MACHINES, j in COMPONENTS: x[i,j]^=0}
amount=x ;

* End of OPTMODEL Procedure;
quit;

%mend model;

%macro report;
* Report the results in a tabulated form;
proc tabulate data=&_optimout;
title &_title;
class MACHINES COMPONENTS ;
var amount;
table MACHINES =” Machine”,
COMPONENTS*amount*sum
/ BOX=’Machines or the Component Allocation Problem’;
run;
%mend report;

%macro orcap;
%data;
%model;
%report;
%mend orcap;

%orcap;


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

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

Exercise 7.3

/***********************************************************************************
* 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.                                                                *
************************************************************************************/

* A SAS procedure for SMT placement machines or the component sequencing problem;
%let _title=’Example 7.3: SMT placement machines or the component sequencing problem’;
%let _dataC=’c:/sasor/Data7_3_C_exercise.txt’;
%let _dataF=’c:/sasor/Data7_3_F_exercise.txt’;
%let _nFeeder=6;
%let _nCompon=6;
%let _outprimal= outprimal;
%let _outdual= outdual;
%let _outtable= outtable;
option nodate;

* 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=&_dataF
out=dataF
dbms=tab
replace;
getnames=yes;
run;
%mend data;
* The model building macro;
%macro model;
* Starting OPTMODEL Procedure;
proc optmodel;
* Define sets;
set COMP=0..&_nCompon;
set Feed=0..&_nFeeder;

* Define variables;
var u{COMP} integer >=0;
var x{COMP,COMP} binary >=0 ;
var z;

* Define parameters;
number d{COMP,COMP};
number cx {COMP};
number cy {COMP};
number type {COMP};
number fx {FEED};
number fy {FEED};
number randfeeder {FEED};
number d1;
number d2;
number Distance{COMP,FEED};
number ds2{COMP,FEED};

* Load component data;
read data Datac into [_N_] type[_N_]=col(‘type’);
read data Datac into [_N_] cx[_N_]=col(‘cx’);
read data Datac into [_N_] cy[_N_]=col(‘cy’);

* Load feeder data;
read data Dataf into [_N_] fx[_N_]=col(‘fx’);
read data Dataf into [_N_] fy[_N_]=col(‘fy’);
read data Dataf into [_N_] randfeeder[_N_]=col(‘randfeeder’);

cx[0]=0; cy[0]=0; fx[0]=0; fy[0]=0;

for {i in FEED, j in COMP}
do;
if (i ne 0 & j ne 0)
then do; d1=(cx[i]-fx[j])**2; d2=(cy[i]-fy[j])**2; end;
else if (i=0 & j=0)
then do; d1=0; d2=0; end;
else if (i=0)
then do; d1=(cx[j]**2); d2=(cy[j]**2); end;
else if (j=0)
then do; d1=(fx[i]**2); d2=(fy[i]**2); end;

Distance[i,j]=round(sqrt( d1+d2),0.000001);
end;
print Distance;
for {i in FEED, j in COMP}
do;
if (i=j) then ds2[i,j]=0;
else if i=0 then ds2[j,i]=Distance[randfeeder[j],0]+Distance[j,randfeeder[j]];
else if j=0 then ds2[j,i]=Distance[j,i];
else ds2[j,i]=Distance[j,randfeeder[j]]+Distance[i,randfeeder[j]];
end;

* Define objective function ;
min obj = z;

* Define constrains;
con Objective: z= sum{i in FEED, j in COMP} ds2[j,i]*x[i,j];

con component_immediately_before1 {i in FEED}: sum{j in COMP: i ne j} x[j,i]=1;
con component_immediately_before2 {j in COMP}: sum{i in FEED: i ne j} x[j,i]=1;
con subtour_elimination {i in FEED, j in COMP : i ne 0 & j ne 0 & i ne j}: u[i]-u[j] + &_nCompon * x[i,j]<=&_nCompon-1;

solve with MILP;

expand;

%put &_OROPTMODEL_;

* Create optimum values of x in a SAS dataset ‘optimout1’;
create data optimout1
from [COMP FEED]
={i in COMP, j in FEED: x[i,j] ne 0}
amount=x ;

* Create optimum values of u in a SAS dataset ‘optimout2’;
create data optimout2
from [COMP]
={i in COMP: u[i]}
amount=u ;
*End of PROC OPTMODE;
vquit;
%mend model;
* The report writing macro;
%macro report;
title &_title;

proc tabulate data=optimout1;
title &_title;
class COMP FEED ;
var amount;
table COMP =”COMP”,
FEED*amount*sum
/ BOX=’Component sequencing’;
run;

proc tabulate data=optimout2;
title &_title;
class COMP ;
var amount;
table COMP =”COMP”,
amount*sum
/ BOX=’Component sequencing’;
run;

%mend report;

* A SAS macro for SMT placement machines or the component sequencing problem;
%macro orcsp;
%data;
%model;
%report;
%mend orcsp;

%orcsp;


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

Permanent link to this article: http://sas-or.com/book/exercise-7-3

Chapter 7: Printed Circuit Board Production Planning

  • Printed Circuit Boards (PCB) Assembly Line Assignment Problem
  • PCB Component Allocation Problem
  • PCB Component-Sequencing Problem for PAP Machines

Chapter 7 - Programs

Permanent link to this article: http://sas-or.com/book/exercise-7-3