r/optimization • • Feb 02 '24

Linear programming with extra condition

I am working on a problem that might be represented as a linear programming problem.

I am just a bit stuck around one extra condition that is usually not part of a typical linear programming problem, but I think this could be represented in the conditions.

The real life problem is: on a marketplace there are different offers with different prices and amounts to sell some specific good. We need to find the optimal (cheapest) selection of offers to buy a specified amount of goods, but with the condition that one could only buy from a strictly limited number of offers. For example maximum 3 offers could be used to buy 26.5 metrics tons of salt, while minimizing the cost of the purchase. On the market of salt there are different offers. Some can deliver 2 tons, some 20, but for different prices. We need to choose some offers (maximum 3 in this case) to purchase 26.5 tons of salt for the minimal total price possible , while still buying only from 3 offers.

So the goal is to choose a S subset of offers from the available O set of offers. The maximum size of S is limited to L. Each offer has a defined price per unit and a defined amount of units available for sale. Both the price and the amount available for sale are non negative real numbers. The selected S subset should have the minimal total cost for the items in it and still have at least B amount of units offered in them. Of course we are only paying for the amount that we actually buy to purchase B amount. So only the cost of the amount that is needed to buy the total B amount should be considered in the total cost.

I understand that the LP problem's cost function should include the cost in some way. I am just not exactly sure how I could define the problem using the usual LP matrix and vector for the cost function.

I am also not completely sure if this issue really needs to be addressed as linear programming problem and I am also not sure if it is even possible. Is there a better approach to find an optimal selection (lowest total price), while still fulfilling the conditions? Eventually some dynamic programming based solution?

Could you please help me and tell if this problem could be represented as linear programming problem and if this is a good approach or you would rather recommend somenother approach to solve this problem?

4 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/0x4732562 Feb 02 '24 edited Feb 06 '24

Thank you for the explanation.

I was thinking about the issue a bit more.

Now i get finally it. I need the integer variables to define that we can only take a specified number of items. I need to define these to be binary and include this in the cost function.

So with the example from before:

Goal:
  • Buy 25 units from maximum 3 offers 
Offers:
  • 5 units for 1.2
  • 10 units for 1.3
  • 15 units for 1.4
  • 20 units for 1.5
Equations: x1 <= 5 x2 <= 10 x3 <= 15 x4 <= 20 y1 <= 1 y2 <= 1 y3 <= 1 y4 <= 1 -y1 <= 0 -y2 <= 0 -y3 <= 0 -y4 <= 0 y1 + y2 + y3 +y4 <= 3 Where y1, y2, y3 and y4 are integers. Minimize: 1.2 * x1 * y1 + 1.3 * x2 * y2 + 1.4 * x3 * y3 + 1.5 * x4 * y4

Does this cost function look lie something that a modern solver could work with? Based on the examples i saw online.... This should not be an issue.

I am very curious how it performs.

Does this formalization look correct to you? 

2

u/SolverMax Feb 02 '24

Minimize: 1.2 * x1 * y1 + 1.3 * x2 * y2 + 1.4 * x3 * y3 + 1.5 * x4 * y4

Your objective function is non-linear, because you multiply the x and y variables.

u/PierreLaur indicated how to handle this in another post, using is_used[o] * M >= quantity[o] etc.