Transportation Problem
Step 1: Write proc optmodel;
proc optmodel;
That was easy.
Step 2: Create all your “assets”.
I call them assets, but you can call them whatever you want. Think of them as anything in the problem that we can assign attributes to. In this case, we have the Plants and the Regions. So we will create two sets, one for each. That’s why we use the command “set”.
set Plant={“Plant 1″,”Plant 2”};
set Region={“Region 1″,”Region 2”, “Region 3”};
I like calling things by their name, so I can remember them. Make sure to use {} for the sets, and to put each name inside quotes.
Step 3: Input all your data
This is all the information that in being shared in the problem. They will generally be attributes for each of the assets, or they can be constants. For all of these we use the command number:
number demand{Region} = [25 95 80];
number capacity{Plant} = [100 125];
number cost{Plant, Region} = [
250 325 445
275 260 460
];
The general nomenclature is that you give a name to the attribute, put what asset it describes inside {} and then put the values inside []. When writing tables in, make sure to write {rows,columns}. In the case of the cost, the plants would be the rows, and the regions would be the columns. Make sure that the order of the numbers you input matches the order of the items you defined in your set; SAS will assign the first number to the first item in the set, and so on. It also helps to space out tables to better read them and catch mistakes.
Step 4: Establish your variables
In this case, variables are the flows from the Plants to the Regions.
var flow{Plant, Region} >= 0;
Putting Plant,Region inside the {} means we will have a flow for each combination of Plant and Region. This means six variables will be created flow(Plant 1, Region 1), flow(Plant 1, Region 2), flow(Plant 1, Region 3), flow (Plant 2, Region 1), flow(Plant 2, Region 2), and flow(Plant 2, Region 3). Always remember to define what type of variable it is. In this case, we want our variables to be non-negative.
Step 5: Define your objective function
I called it z here, but you can call it anything you want, like TotalCost if you want to be more descriptive
minimize z = sum{i in Plant, j in Region}flow[i,j]*cost[i,j];
When you write sum {i in Plant, j in Region }, it’s the equivalent of doing a sumproduct in Excel. SAS will take every combination of Plant and Region and do the described calculation of flow times cost, and then add them all up. So in this case, it would take flow[Plant 1, Region 1]*cost[Plant 1, Region 1], then flow[Plant 1, Region 2]*cost[Plant 1, Region 2], do that for all the combinations, and then compute the sum.
I could’ve used p instead of i, and r intead of j, like sum {p in Plant, r in Region}flow[p,r]*cost[p,r]), or any other letter for that matter as long as I remain consistent and I haven’t used that letter to describe something else already.
Step 6: Establish your Constraints
In this case there are only two general contraints: capacity contraints for the plants, and demand constraints for the regions:
con capacitycon{i in Plant}: sum{j in Region}flow[i,j] <= capacity[i];
con demandcon{j in Region}: sum{i in Plant}flow[i,j] >= demand[j];
Let’s take as an example the first constraint. On the left side of the :, con capacitycon{i in Plant}, establishes the name of the constraint as capacitycon. The {I in Plant} means this is a constraint that applies individually to every Plant, so the constraint will be calculated individually for every item in the set Plant. This means this constraint really works as two constraints in this case, one using values for Plant 1, and another using values for Plant 2.
After the “:” we define the constraint itself. Here, SAS will take the flow and change the value j using every region, and add them up, and it will compare that to the capacity of the Plant. Since we established before the “:” that the constraint would be calculated separately for each Plant, the Plant remains constant for each iteration of the constraint calculation. In essence, it would take the flow(P1, R1) + flow(P1, R2) + flow(P1,R3) and make sure that is less that or equal to the capacity of (P1). Again notice that the Plant doesn’t change; instead, the constraint will do the calculations for Plant 2 as a separate comparison, because we established the {i in Plant} on the left of the “:”.
Step 7: Wrap it up
solve; print z flow; expand; quit;
Don’t forget to check the log for any error (the middle tab between you code and the results). SAS will highlight any mistakes you would’ve made there. Just scroll up to see where the first red line of text is, and that was your first mistake. You can follow these steps any time you are using SAS with this notation.
Transhipment Problem
Network Facility Location Problem
“transcost” was not used in the sas files, as it is not required when the transportation cost is $1. If it is any other value, will need to add that in.
Network Facility Location Problem w/ LOS
copy and paste matrix from spreadsheet…
to calculate the binary table dynamically, see below from page 12
97529_Using_Arrays_in_SAS_Programming.pdf
For the demand constraint “demandcon“, use an equality instead of inequality as otherwise the solution will create non-integer demand, just to meet the LOS constraint.
Advanced Supply Chain Network Design
Supply Chain Network Design Problem
Multi-Commidity Flow Problem:
Data tables come before “proc optmodel;”
INFILE Statement Options
DELIMITER= option—Specifies what character (other than the blank default character) to use as the delimiter in files that are being read. Common delimiters include comma (,), vertical pipe (|), semi-colon (;) , and the tab. For example, to specify a vertical pipe as the delimiter, the syntax is DLM=’|’, as shown here: infile ‘C:\mydata\test.dat’ dsd dlm=’|’ lrecl=1024;
A tab is specified by its hexadecimal value. For ASCII systems (UNIX, Windows, and Linux), the value is ’09’x. For EBCDIC systems (z/OS and MVS), the value is ‘05’x. As an example, the syntax to specify a tab delimiter on an ASCII system is DLM=’09’x. Note: The positioning of the quotation marks and the x in hexadecimal values is critical. No space is allowed between the x and the quotation marks, as shown in this example: infile ‘C:\mydata\test.txt’ dsd dlm=’09’x truncover;
In my case I have troubles with the ASCII so I used dlm=’,’; and I separated the data with , and it run.
/* Inputing values of multi-dimensional matrix incost in a table form first*/
Data incost;
infile datalines dsd delimiter=’09’x;
input Product $ Plant $ DC $ incost;
datalines;
P1 Chicago Atlanta 6
P1 Chicago Boston 5
P1 Dallas Atlanta 4
P1 Dallas Boston 7
P1 Miami Atlanta 6
P1 Miami Boston 9
P2 Chicago Atlanta 6
P2 Chicago Boston 5
P2 Dallas Atlanta 4
P2 Dallas Boston 7
P2 Miami Atlanta 6
P2 Miami Boston 9
P3 Chicago Atlanta 6
P3 Chicago Boston 5
P3 Dallas Atlanta 4
P3 Dallas Boston 7
P3 Miami Atlanta 4
P3 Miami Boston 7
;
Run;
/* Inputing values of multi-dimensional matrix outcost in a table form first*/
Data outcost;
infile datalines dsd delimiter=’09’x;
input Product $ DC $ Region $ outcost;
datalines;
P1 Atlanta NY 8
P1 Atlanta VA 5
P1 Atlanta PA 6
P1 Boston NY 9
P1 Boston VA 7
P1 Boston PA 6
P2 Atlanta NY 7
P2 Atlanta VA 8
P2 Atlanta PA 5
P2 Boston NY 3
P2 Boston VA 8
P2 Boston PA 6
P3 Atlanta NY 7
P3 Atlanta VA 4
P3 Atlanta PA 4
P3 Boston NY 4
P3 Boston VA 5
P3 Boston PA 4
;
Run;
Fixed Planning Horizon Problem
Aggregate Planning And Distribution Channel Strategies
Aggregate Planning (including numerous factors like hiring and firing, production levels, etc)
Aggregate Planning with Demand Elasticity (including factors like hiring and firing, production levels, discounts, etc)
Omni-channel Network Design
Reverse Logistics…for Batteries
Optimization Based Procurement
Simple Auctions
Capacity by Lane Constraint
Level of Service Constraint
Supplier Capacity Constraint
Minimum $$ Volume Constraint
Combinatorial Bids
Combinatorial Bids (Min 2 carriers) – Add the following constraint to the previous model.
SAS Files
SC2x_W1L1_Transhipment_SandyCo.sasSC2x_W1L1_Transportation_SandyCo.sasSC2x_W1L2_FacilityLocation_NERD2.sasSC2x_W1L2_FacilityLocation_NERD3.sasW2L1_NetworkDesignModels_NERD4.sasW2L2_AdvancedNetworkDesignModels_WUWU1.sasW3L1_FPH.sasW4L1_AggregatePlanning_DireWolf1.sasW4L1_AggregatePlanning_DireWolf2.sasW4L2_Omnichannel_Araz.sasW4L2_ReverseLogistics_Battery.sasW7L2_OBP_CapacityConstraints.sasW7L2_OBP_CapacityConstraintsSupplier.sasW7L2_OBP_CombinatorialBids.sasW7L2_OBP_CombinatorialBids2Carriers.sasW7L2_OBP_LevelOfService.sasW7L2_OBP_MinimumVolumeConstraints.sasW7L2_OBP_SimpleOptimization.sas