Hello,
A question related to this example
How to define the supply details & constraints related to it, if the supply is on the farm level across all commodities not for each indvidual one. for example farm-a in total can supply 200 and farm-b in total can supply 100, where the demand from NY remains the same for each commodity. or vice versa where capacity in DC is across allo commodities not for each
Thanks
Hi,
There are multiple ways of modeling this. One is to add a new constraint on the outflow of the nodes (i.e. the sum over all DC and commodities from farm a must be less than the total capacity)
To achieve this with the code in the example I have changed the supply_data dataset by adding all nodes (i.e. add the DCs here) and adding an extra variable indicating the max flow through the node. In the optmodel code I have added a new "num" statement to hold the new capacity data and added it to the 'read data' statement. Finally, I've added a new constraint 'flow_cap' that sums over all flow out of a node (the constraint is defined over all nodes 'i' but the sum is only done over the arcs that start in 'i').
I've attached the modified program. With the data I've added you should see the overall (flow) capacity constraints on farm b and through the Chicago DC kick in and make the overall optmial flow more expensive
Hi,
There are multiple ways of modeling this. One is to add a new constraint on the outflow of the nodes (i.e. the sum over all DC and commodities from farm a must be less than the total capacity)
To achieve this with the code in the example I have changed the supply_data dataset by adding all nodes (i.e. add the DCs here) and adding an extra variable indicating the max flow through the node. In the optmodel code I have added a new "num" statement to hold the new capacity data and added it to the 'read data' statement. Finally, I've added a new constraint 'flow_cap' that sums over all flow out of a node (the constraint is defined over all nodes 'i' but the sum is only done over the arcs that start in 'i').
I've attached the modified program. With the data I've added you should see the overall (flow) capacity constraints on farm b and through the Chicago DC kick in and make the overall optmial flow more expensive
Great Thanks, I assume DATA NODE_CAP; is there for testing? as it's not refered in the body .
Another question, How to print total quanity/cost for each product ?
on a different note, If I don't want to define a dataset and do it in the matrix way. so, if I have a variably number DCProduct {dc,product}= [
4 | 5 | 6 | 7 |
5 | 2 | 2.4 | 2.8 |
6 | 7.5 | 9 | 10.5 |
]
and Where there are 2 products through these 3 DCs, and I want to some the first two columns and put it in avariable ProductA and the last 2 and put it in another variable product b. how to write this one.
I am not quite sure I understand what you are trying to achieve. You can easily have a variable number of DCs using a dataset as an input. Likewise, you can do any data manipulation with the grouping of commodities. Are you hinting at restricting the number of types of commodities flowing through a DC? E.g. there are 4 types but any one DC can only handle 2 of them?
Please elaborate
Yes, I want to force specific commodities to flow from certain farms as you said. and want to calculate the total quantity/cost flowing from plant to dc, to be able to know the unit cost of each commodity, where further I can add a constraint on the unit cost.
ok, so the idea is to add a new binary decision variable controlling which commodities are supplied from which node (i.e. 1=supplied, 0=not supplied). From here two new constraints are added. One limiting the number of commodities supplied from each node and one that binds this new variable to the flow (no supply infers no flow). The limits of commodities for each node (incl. DC and sink node for simplicity) have been added to the supply_data dataset.
I've attached the modified program
Thanks a ton! what about the total quantity/ total unit cost for each product
was missing the sql part, will see how to incorperate than that in the code. In the latest version with cap and limit, can we inforce product capacity on chicago with respecting the overal capacity. for example Chicago capacity for C3 shouldn't exceed 30 it still can process the other numer of items without exceeding the total capacity. I tried inforcing it by enering the required capacity in chicago and St but it didn't go, it works fine for the farms.
farm-a 100 100 40 . 240 4
farm-b 100 200 50 50 160 2
farm-c 40 100 75 100 250 4
Chicago 0 0 30 0 300 4
StLouis 0 0 0 0 1000 4
NY -150 -200 -50 -75 . .
By changing the supply_data dataset you are specifying that Chicago can provide 30 units of commodity 3, which is not what your want.
The specific example you provide can be solved by adding the following constraint to your model
con restrict_C3_Chicago: AmountShipped["Chicago","NY",3]<=30;
what is does is that is restricts the flow from Chicago to NY to 30, which solves what you need as long as NY is the only sink node in the network.
that's how I understand it, the supply dataset contains the supply and demand data, identified by +/- . so when I mention that chicago can supply 30, that part of the code will prevent chicago from supplying more than the mentioned amount, that's how it worked for farms, please clarify ?
con flow_balance {i in NODES, c in COMMODITIES}:
sum {<(i),j> in ARCS} AmountShipped[i,j,c] -
sum {<j,(i)> in ARCS} AmountShipped[j,i,c] <= supply[i,c];
if the above is not the right way and it's required to restrict multiple Nodes, do I need to create another data set specifying the the limit for each node?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.