简体   繁体   中英

How to apply conditional costs to objective function in Python PuLP?

I'm optimising transaction traffic to different banks, say between A and B. The cost of each transaction is fixed, but that fee is dependent on overall volume (eg Bank A: $1 if between 0-10m transactions, $0.9 if 10m+, and something different for Bank B).

I have a forecast of number of transactions I'll need to make, so my decision variables are number of transactions to each bank. But I'm struggling to formulate objective function to use the right costs as they depend on the values of the decision variables.

I'm new to PuLP and optimisation so struggling to understand how to implement such objective function.

That is often modeled as a piecewise linear function . This can be a bit intimidating for a beginner, but there are formulations for this. They typically use binary variables (or similar), so it is more difficult.

A collection of formulations is here: https://yetanothermathprogrammingconsultant.blogspot.com/2019/02/piecewise-linear-functions-and.html . You may want to focus first on method 2 as that is using binary variables. SOS1/SOS2 variables are only available in more high-end solvers. Sorry, this is not as simple as you may have expected.

In some cases, these piecewise linear functions don't need binary variables. Eg when things stay convex. This can be the case if larger amounts are always more expensive than smaller amounts (the opposite of a discount). Another issue is that the precise formulation of these discounts depends on the details, like if the discount is for everything or only for the part greater than $10m. Discount schemes can become quite complicated in practice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM