Get startedGet started for free

Common constraint mistakes

1. Common constraint mistakes

Let's discuss how to avoid common mistakes for two types of constraints.

2. Dependent demand constraint

To start, let's imagine that we are planning the production for two items, A and B, over the course of 3 months. Product A is used as an input for the production of product B. Product B is sold directly to customers. We must define a constraint that for each unit of B produced, we also produce at least 3 units of A. This is called dependent demand. The demand for A is dependent on the demand for B.

3. Dependent demand constraint

The correct form of this constraint is 3B less than or equal to A. Common incorrect versions of this include, B less than or greater than 3A or B equal to 3A. One way to check that we have the correct form is by plugging a value into B. If we plug in 2 for B then A must be greater than or equal to 6.

4. Code example

Here we model the production planning problem. We work through the steps of the common modeling process you have seen in previous lessons. The demand for A is zero because it is not being sold to a customer.

5. Code example continued

Here is the code for our constraint. We iterate over the months with a for loop. For each month we multiply 3 times the production of B and make it less than or equal to the production of A. This ensures for each unit of B we produce at least 3 units of A.

6. Extended constraint

We can extend the idea of this constraint. If we also sell product A directly to customers, we can modify the constraint to account for that additional demand.

7. Combination constraint

Let us look at a different situation. Imagine we are working on a monthly warehouse distribution plan. There are 2 warehouses in our network that can each ship two different products, A and B. One of the warehouses is small and can only ship 12 A's or 15 B's per week. Now because this is a monthly plan we will assume that 1 month equals 4 weeks, and we want to know what combination of A, or B can be shipped in 4 weeks.

8. Combination constraint

First imagine that our constraint was only for 1 week instead of 4. It would look like 1/12 times A plus 1/15 times B, less than or equal to to 1. We are multiplying A and B by the inverse of their maximum. In this version, notice if we ship 12 A's or 15 B's or some combination it sum must be less than or equal to to 1. Modifying this constraint to 4 weeks we change the 1 on the right hand side to a 4. We could also check our constraint by plugging a value for A and B. Finally, here are some common mistakes of this type of constraint.

9. Code example

Again, this code example models the warehouse problem by loading data into a Pandas DataFrame

10. Code example continued

and going through the steps of the common modeling process.

11. Code example continued

Here is our constraint. In this example we are using lpSum to sum all the shipments from WH1 for product A for all customers. Then we multiply it by 1/12. We are doing the same for product B. Finally, we set the summed total less than or equal to 4.

12. Extend constraint

We can also extend the idea of this constraint. If we need to add more products we simply add them to the constraint following the same pattern. We can add as many of these as needed.

13. Summary

In this lesson we looked at common mistakes when working on dependent demand and combination selection constraints. We also reviewed how to extend and modify those constraints. Always remember you can check a constraint by plugging in a value.

14. Let's practice

Let's practice now.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.