I am trying to solve this problem using linear programming using Pulp in python.

We have mango packs with each having different number of mangoes.
We should be able to serve the demand using the minimum number of packets and if possible serve the whole bag.

```
# Packet Names and the count of mangoes in each packet.
mangoe_packs = {
    "pack_1": 2,
    "pack_2": 3,
    "pack_3": 3,
    "pack_4": 2
}

```

For example,

Based on the demand we should get the correct packets. Ie., if the demand is 2, we give the packet with 2 mangoes. If the demand is 5, we serve packets with 2 and 3 mangoes. If your demand is 2 and we don't have any packet with 2 mangoes we can serve packet with 3 mangoes. In this case, we will have one remnant mango. Our purpose is to have the least number of remnant mangoes while serving the demand.

```
# Packet Names and the count of mangoes in each packet.
mangoe_packs = {
    "pack_1": 2,
    "pack_2": 3,
    "pack_3": 3,
    "pack_4": 2
    }

```

Based on the data provided above,

> 
> If the demand is 2, The solution is pack\_2 (can be pack\_4 also).
> 
> 
> If the demand is 4, The solution is pack\_2 + pack\_4.
> 
> 
> If the demand is 5, The solution is pack\_1 + pack\_2
> 
> 
> 

I am new to Linear programming and stuck at the problem. Tried few solutions and they are not working.

I am unable to come up with the correct objective function and constraints to solve this problem. Need help with that. Thank you.

Here is the code I tried.

```
from pulp import *
prob = LpProblem("MangoPacks", LpMinimize)

# Number of Mangoes in each packet.
mangoe_packs = {
    "pack_1": 2,
    "pack_2": 3,
    "pack_3": 3,
    "pack_4": 2
}

# Define demand variable.
demand = LpVariable("Demand", lowBound=2, HighBound=2, cat="Integer")

pack_count =  LpVariable.dicts("Packet Count",
                                     ((i, j) for i in mangoe_packs.values() for j in ingredients),
                                     lowBound=0,
                                     cat='Integer')

pulp += (
    lpSum([
        pack_count[(pack)]
        for pack, mango_count in mangoe_packs.iteritems()])
)

pulp += lpSum([j], for pack, j in mangoe_packs.iteritems()]) == 350 * 0.05

status = prob.solve()

```

Thank you.