Load Optimization Problem

Dr. Tri Basuki Kurniawan
TheLorry Data, Tech & Product
19 min readNov 12, 2021

An exploration of a load optimization problem.

Photo by Alex Mecl on Unsplash

The purpose of packing problems is to determine the optimum way to pack a collection of items with varying sizes into containers with defined capacities. A typical application is efficiently putting boxes onto delivery vehicles. Due to capacity limits, it is frequently impossible to pack all of the products. In that case, the problem is to determine a subset of the items with the most significant overall size that will fit in the containers.

There are many types of packing problems. Knapsack problems and bin packing are two of the most common.

Knapsack Problem

The knapsack problem is a combinatorial optimization problem in which you must decide how many items should be included in a collection. The overall weight of the collections is determined whether it is less than or equal to a specific limit. Given a set of items, each weight and volume, the limitations are as broad as feasible. It gets its name from the difficulties someone faces, which is limited to a fixed-size knapsack, and must fill it with the most valuable items.

The issue frequently arises in resource allocation when decision-makers must choose among various non-divisible projects or tasks under a defined budget or time limit.

Bin Packing Problem

Similar to the knapsack problem, the bin packing issue is also an optimization problem. A finite number of bins or containers, each with a defined capacity, must be packed to minimize the total number of bins used.

Filling containers, loading vehicles with weight capacity limits, making file backups in media, technology mapping in FPGA semiconductor chip design, putting boxes onto delivery vehicles are all examples of the problem.

In The Lorry, as a transportation company, we have been facing both the knapsack and bin-packing problems, when we should deliver the parcel to our customer address.

OR-Tools Google Library

One of the best solutions available in the market nowadays is OR-Tools from Google. OR-Tools is open source software for combinatorial optimization, seeking to find the best solution to a problem out of an extensive set of possible solutions. Here are some examples of issues that OR-Tools solves:

  • Vehicle routing: Find optimal routes for vehicle fleets that pick up and deliver packages given constraints.
  • Scheduling: Find the optimal schedule for a complex set of tasks that need to be performed before others on a fixed set of machines or other resources.
  • Bin packing: Pack as many objects of various sizes as possible into a fixed number of bins with maximum capacities.

Problems like these typically have many viable solutions — too numerous for a computer to sort through. OR-Tools overcomes this by narrowing the search set with cutting-edge algorithms to obtain an optimal (or near-optimal) answer.

The Load Performance Problem (using Jupiter notebook)

Let's start writing our coding in Jupyter Notebook (the examples data and the Jupyter notebook coding are available here).

First, we need to open our example data, which has weight and volume for each item.

# Load the dataimport pandas as pd
pd.set_option("display.max_columns", None)
data_url = "dataset/examples.csv"
dataset = pd.read_csv(data_url)
display(dataset)

The result is shown below.

The data consist of the actual weight, width, height, and length of each item. There are 367 items in this example. The actual width, height, and length we will calculate to get the volume of the item. The Actual Weight is in unit kilogram (kg), and the other data are in unit centimetre (cm).

Let's add our code to get the volume of the items.

# Get the volume of itemsdataset['Volume'] = dataset['Actual Weight'] * dataset['Actual Height'] * dataset['Actual Length']display(dataset)

We will get a result similar to the picture.

The Volume data are in a unit centimetre cube (cm³).

Next, we need to calculate the total volume and weights of all items.

Let's write simple code to do that.

# Calculate the total weight and total volume of all itemstotal_volume = dataset['Volume'].sum()
total_weight = dataset['Actual Weight'].sum()
print('Total Volume: ', total_volume, 'cm3')
print('Total Weight: ', total_weight, ' kg')

Next, the result we obtain.

The total volume of all items is 46,254,303 cm³, and the total weight is 9,853 kg.

For that volume and weight, how many vehicles should be used?

After the data is ready, let's start defining the lorry we have to deliver all of our parcels.

# Define the lorriesFEET_TO_CM = 30.48
lorries = [
{
"code": "4x4",
"description": "4x4 Pickup",
"length": 4,
"height": 3,
"width": 3.5,
"max_weight": 500
},
{
"code": "VAN",
"description": "Van",
"length": 8,
"height": 3,
"width": 3.5,
"max_weight": 500
},
{
"code": "LORRY-S",
"description": "1-tonne lorry",
"length": 10,
"height": 5,
"width": 5,
"max_weight": 1000
},
{
"code": "LORRY-M",
"description": "3-tonne lorry",
"length": 14,
"height": 7.2,
"width": 7,
"max_weight": 3000
},
{
"code": "LORRY-L",
"description": "5-tonne lorry",
"length": 17,
"height": 7.2,
"width": 7,
"max_weight": 5000
}
]
for lorry in lorries:
volume = round((lorry['length'] * FEET_TO_CM) * (lorry['height'] * FEET_TO_CM) * (lorry['width'] * FEET_TO_CM), 2)
lorry['max_volume'] = volume
display(lorries)

We will get a result similar to this.

First, we define the array containing all the lorry, code, description, maximum weight capacity, and maximum volume capacity.

Based on the lorries array, we will estimate or get preference the optimum way, how many vehicles to deliver all of the items.

In this scenario, we assume we have a limited number of vehicles for each size, so we should define the number of vehicles in our coding totalLorry and we use the or-tools library to ensure the number of items that should be delivered is optimum.

Ok, first, we need to define the main process using OR-Tools.

# main processfrom ortools.linear_solver import pywraplp
import warnings
warnings.filterwarnings('ignore')
# create data model for knapsack problem
# paramter optimize are data to be packing into the available vehicle in totalLorry
def create_data_model(optimize, totalLorry):
"""Create the data for the example."""
data = {}
weights = optimize['Actual Weight'].to_list()
volumes = optimize['Volume'].to_list()

data['weights'] = weights
data['volumes'] = volumes

data['items'] = list(range(len(weights)))
data['num_items'] = len(weights)

max_volumes = []
max_weights = []
truck_types = []

# reserve totalLorry data to be starting from small vehicle first
totalLorry.reverse()
# resgister max_weight and max_volume for each available vehicle
for tL in totalLorry:
for i in range(tL['number']):
max_volumes.append(tL['max_volume'])
max_weights.append(tL['max_weight'])
truck_types.append(tL['code'])

data['max_volume'] = max_volumes
data['max_weight'] = max_weights
data['truck_types'] = truck_types

data['trucks'] = list(range(len(data['max_volume'])))

return data

First, we need to import our or-tools library, and then we define a function to create data that will use in or-tools later. In this code, we define two constraints are max_volume and max_weight, and we define our available truck types and the number of trucks for each type.

Ok, next, we need to start optimizing the number of vehicles that should use. First, we need to define what the lorry we have. We define totalLorry variables to use later in our algorithms.

# ===============================
# ==== Get Load Optimization ====
# ===============================
totalLorry = [{'code': 'LORRY-L',
'number': 1,
'max_weight': 5000,
'max_volume': 24261874.16},
{'code': 'LORRY-M',
'number': 2,
'max_weight': 3000,
'max_volume': 19980366.96},
{'code': 'LORRY-S',
'number': 3,
'max_weight': 1000,
'max_volume': 7079211.65},
{'code': 'VAN', 'number': 3, 'max_weight': 500, 'max_volume': 2378615.11},
{'code': '4x4', 'number': 6, 'max_weight': 500, 'max_volume': 1189307.56}]

Based on totalLorry’s variable, we have 1 LORRY-L with a maximum weight of 5,000 kg and a maximum volume of 24,261,874 cm³. We also have 2 LORRY-M , 3 LORRY-S , 3 Van and 6 4x4. Total the vehicles are 15 available.

Then, we start using the or-tools library to optimize our data.

data = create_data_model(dataset, totalLorry)# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
# Variables
# x[i, j] = 1 if item i is packed in bin j.
x = {}
for i in data['items']:
for j in data['trucks']:
x[(i, j)] = solver.IntVar(0, 1, 'x_%i_%i' % (i, j))
# Constraints
# Each item can be in at most one bin.
for i in data['items']:
solver.Add(sum(x[i, j] for j in data['trucks']) <= 1)
# The amount packed in each bin cannot exceed its max weight.
for j in data['trucks']:
solver.Add(
sum(x[(i, j)] * data['weights'][i]
for i in data['items']) <= data['max_weight'][j])
# The amount packed in each bin cannot exceed its max volume.
for j in data['trucks']:
solver.Add(
sum(x[(i, j)] * data['volumes'][i]
for i in data['items']) <= data['max_volume'][j])
# Add objectives
objective = solver.Objective()
for i in data['items']:
for j in data['trucks']:
objective.SetCoefficient(x[(i, j)], data['volumes'][i])
objective.SetMaximization()
status = solver.Solve()

In this coding, first, we create our data by calling our previous function create_data_model with passing dataset and totalLorry as variables. Next, we create an object of the bin-packing solver. In this sample we used SCIP.

The rest of the coding is to define variables, constraints, and objectives. The constraint in this coding is that one item should be in only one lorry, and the total weight of all items in one lorry should not be more than the maximum weight and volume of the lorry.

In this scenario, we try to optimize the maximum volume carried by the lorry with the limited capacity of weight and its volume.

The following coding will only execute if the status of optimization processing has a true value to show the result.

_totalLeftVolume = 0
_totalLeftWeight = 0
if status == pywraplp.Solver.OPTIMAL:
assign = []
total_weight = 0
total_items = 0
print('Total Lorry: ')
display(totalLorry)
print()
print('Total Items:', len(dataset))
print()
for j in data['trucks']:
bin_weight = 0
bin_volume = 0
print('Truck ', j, '[', data['truck_types'][j] ,'] - max_weight:[', "{:,.2f}".format(data['max_weight'][j]), '] - max volume:[', "{:,.2f}".format(data['max_volume'][j]), ']' )
for i in data['items']:
if x[i, j].solution_value() > 0:
assign.append(i)
total_items += 1
print('Item', i, '- weight:', data['weights'][i],
' volumes:', data['volumes'][i])
bin_weight += data['weights'][i]
bin_volume += data['volumes'][i]
print('Packed truck volume:', "{:,.2f}".format(bin_volume))
print('Packed truck weight:', "{:,.2f}".format(bin_weight))
print()
if (bin_volume > 0) & (bin_weight > 0):
leftVolume = data['max_volume'][j] - bin_volume
leftWeight = data['max_weight'][j] - bin_weight
else:
leftVolume = 0
leftWeight = 0
print('Left Volume', "{:,.2f}".format(leftVolume))
print('Left Weight', "{:,.2f}".format(leftWeight))
print()
print()
total_weight += bin_weight
_totalLeftVolume += leftVolume
_totalLeftWeight += leftWeight
print('Total packed weight:', "{:,.2f}".format(total_weight))
print('Total packed volume:', "{:,.2f}".format(objective.Value()))
print('Total item assigned:', "{:,.0f}".format(total_items))
print()
print("#" * 70)
print('Total Left Volume', "{:,.2f}".format(_totalLeftVolume))
print('Total Left Weight', "{:,.2f}".format(_totalLeftWeight))
print("#" * 70)
else:
print('The problem does not have an optimal solution.')
print()

The results are shown below.

Total Lorry:[{'code': '4x4', 'number': 6, 'max_weight': 500, 'max_volume': 1189307.56},
{'code': 'VAN', 'number': 3, 'max_weight': 500, 'max_volume': 2378615.11},
{'code': 'LORRY-S',
'number': 3,
'max_weight': 1000,
'max_volume': 7079211.65},
{'code': 'LORRY-M',
'number': 2,
'max_weight': 3000,
'max_volume': 19980366.96},
{'code': 'LORRY-L',
'number': 1,
'max_weight': 5000,
'max_volume': 24261874.16}]
Total Items: 367

Truck 0 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 0 - weight: 5.7 volumes: 461.7
Item 7 - weight: 13.9 volumes: 81871.0
Item 9 - weight: 2.5 volumes: 3375.0
Item 12 - weight: 6.8 volumes: 3046.4
Item 14 - weight: 25.0 volumes: 6000.0
Item 15 - weight: 1.35 volumes: 1012.5
Item 16 - weight: 7.0 volumes: 5264.0
Item 17 - weight: 6.7 volumes: 6700.0
Item 18 - weight: 3.0 volumes: 3240.0
Item 20 - weight: 4.0 volumes: 6660.0
Item 28 - weight: 2.4 volumes: 1495.2
Item 32 - weight: 10.0 volumes: 2600.0
Item 38 - weight: 5.0 volumes: 1800.0
Item 182 - weight: 24.4 volumes: 47630.508
Item 183 - weight: 13.0 volumes: 48633.0
Item 266 - weight: 0.3 volumes: 72.0
Item 285 - weight: 0.1 volumes: 48.0
Item 362 - weight: 177.0 volumes: 498432.0
Item 363 - weight: 8.795 volumes: 11266.395
Item 364 - weight: 45.0 volumes: 145530.0
Item 366 - weight: 51.0 volumes: 314160.0
Packed truck volume: 1,189,297.70
Packed truck weight: 412.94

Left Volume 9.86
Left Weight 87.06


Truck 1 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 6 - weight: 65.0 volumes: 715000.0
Item 8 - weight: 18.0 volumes: 45360.0
Item 10 - weight: 30.0 volumes: 72000.0
Item 11 - weight: 18.0 volumes: 69678.0
Item 19 - weight: 39.0 volumes: 237120.0
Item 24 - weight: 6.0 volumes: 11250.0
Item 26 - weight: 10.0 volumes: 24000.0
Item 35 - weight: 14.0 volumes: 14490.0
Item 268 - weight: 2.0 volumes: 256.0
Item 357 - weight: 18.0 volumes: 18.0
Packed truck volume: 1,189,172.00
Packed truck weight: 220.00

Left Volume 135.56
Left Weight 280.00


Truck 2 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 13 - weight: 55.0 volumes: 304920.0
Item 21 - weight: 69.0 volumes: 557175.0
Item 22 - weight: 30.0 volumes: 113400.0
Item 23 - weight: 15.0 volumes: 63000.0
Item 25 - weight: 29.9 volumes: 54597.399999999994
Item 27 - weight: 18.0 volumes: 25920.0
Item 29 - weight: 21.4 volumes: 54099.2
Item 41 - weight: 11.0 volumes: 2002.0
Item 49 - weight: 18.0 volumes: 13608.0
Item 180 - weight: 1.8 volumes: 437.40000000000003
Packed truck volume: 1,189,159.00
Packed truck weight: 269.10

Left Volume 148.56
Left Weight 230.90


Truck 3 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 30 - weight: 16.0 volumes: 216000.0
Item 31 - weight: 29.0 volumes: 103675.0
Item 33 - weight: 15.0 volumes: 87750.0
Item 34 - weight: 15.0 volumes: 28125.0
Item 36 - weight: 19.0 volumes: 46816.0
Item 39 - weight: 19.61 volumes: 59694.80100000001
Item 40 - weight: 5.08 volumes: 20929.6
Item 42 - weight: 36.0 volumes: 115200.0
Item 43 - weight: 31.0 volumes: 263500.0
Item 45 - weight: 65.0 volumes: 49335.0
Item 47 - weight: 31.0 volumes: 116622.0
Item 48 - weight: 16.0 volumes: 15360.0
Item 50 - weight: 2.0 volumes: 1610.0
Item 51 - weight: 5.0 volumes: 2795.0
Item 52 - weight: 4.9 volumes: 23289.7
Item 53 - weight: 6.6 volumes: 11668.8
Item 54 - weight: 8.3 volumes: 11387.600000000002
Item 61 - weight: 13.0 volumes: 11544.0
Item 65 - weight: 3.5 volumes: 2625.0
Item 99 - weight: 4.0 volumes: 1320.0
Packed truck volume: 1,189,247.50
Packed truck weight: 344.99

Left Volume 60.06
Left Weight 155.01


Truck 4 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 2 - weight: 20.0 volumes: 960.0
Item 37 - weight: 166.0 volumes: 741024.0
Item 44 - weight: 50.0 volumes: 425000.0
Item 56 - weight: 9.0 volumes: 19800.0
Item 70 - weight: 1.8 volumes: 1548.0
Item 316 - weight: 1.51 volumes: 859.5674999999999
Packed truck volume: 1,189,191.57
Packed truck weight: 248.31

Left Volume 115.99
Left Weight 251.69


Truck 5 [ 4x4 ] - max_weight:[ 500.00 ] - max volume:[ 1,189,307.56 ]
Item 46 - weight: 55.0 volumes: 412500.0
Item 55 - weight: 18.0 volumes: 23562.0
Item 57 - weight: 25.0 volumes: 50150.0
Item 58 - weight: 20.0 volumes: 36480.0
Item 59 - weight: 15.0 volumes: 49500.0
Item 60 - weight: 19.8 volumes: 21740.4
Item 62 - weight: 16.0 volumes: 43120.0
Item 63 - weight: 3.0 volumes: 26130.0
Item 64 - weight: 51.0 volumes: 328185.0
Item 66 - weight: 3.18 volumes: 7205.880000000001
Item 67 - weight: 5.0 volumes: 19355.0
Item 68 - weight: 30.0 volumes: 73500.0
Item 71 - weight: 5.0 volumes: 4320.0
Item 72 - weight: 20.0 volumes: 66360.0
Item 73 - weight: 15.0 volumes: 6750.0
Item 74 - weight: 21.0 volumes: 10500.0
Item 77 - weight: 20.0 volumes: 9680.0
Item 335 - weight: 0.7 volumes: 154.0
Packed truck volume: 1,189,192.28
Packed truck weight: 342.68

Left Volume 115.28
Left Weight 157.32


Truck 6 [ VAN ] - max_weight:[ 500.00 ] - max volume:[ 2,378,615.11 ]
Item 69 - weight: 40.0 volumes: 98000.0
Item 75 - weight: 25.0 volumes: 60000.0
Item 76 - weight: 34.8 volumes: 35495.99999999999
Item 78 - weight: 23.0 volumes: 36800.0
Item 79 - weight: 21.0 volumes: 23436.0
Item 80 - weight: 16.0 volumes: 18480.0
Item 81 - weight: 12.0 volumes: 19836.0
Item 82 - weight: 79.0 volumes: 505600.0
Item 83 - weight: 5.0 volumes: 4980.0
Item 84 - weight: 21.0 volumes: 53890.2
Item 85 - weight: 10.0 volumes: 3750.0
Item 86 - weight: 12.0 volumes: 9000.0
Item 87 - weight: 32.0 volumes: 64000.0
Item 88 - weight: 20.0 volumes: 15000.0
Item 89 - weight: 18.9 volumes: 49140.0
Item 90 - weight: 32.2 volumes: 33810.00000000001
Item 91 - weight: 30.0 volumes: 27000.0
Item 92 - weight: 21.0 volumes: 53890.2
Item 94 - weight: 20.0 volumes: 20300.0
Item 95 - weight: 4.0 volumes: 4944.0
Item 96 - weight: 17.2 volumes: 13244.0
Item 140 - weight: 5.13 volumes: 7695.0
Packed truck volume: 1,158,291.40
Packed truck weight: 499.23

Left Volume 1,220,323.71
Left Weight 0.77


Truck 7 [ VAN ] - max_weight:[ 500.00 ] - max volume:[ 2,378,615.11 ]
Item 93 - weight: 63.0 volumes: 250425.0
Item 97 - weight: 10.0 volumes: 3750.0
Item 98 - weight: 37.0 volumes: 11100.0
Item 100 - weight: 25.0 volumes: 38000.0
Item 101 - weight: 26.0 volumes: 22464.0
Item 102 - weight: 30.0 volumes: 125400.0
Item 103 - weight: 12.0 volumes: 42000.0
Item 104 - weight: 13.9 volumes: 81871.0
Item 105 - weight: 15.0 volumes: 17760.0
Item 106 - weight: 17.5 volumes: 49000.0
Item 107 - weight: 42.0 volumes: 175560.0
Item 108 - weight: 20.0 volumes: 21700.0
Item 109 - weight: 50.0 volumes: 55900.0
Item 110 - weight: 21.0 volumes: 5313.0
Item 111 - weight: 32.2 volumes: 7245.000000000001
Item 112 - weight: 29.0 volumes: 121800.0
Item 113 - weight: 45.0 volumes: 75600.0
Item 136 - weight: 9.4 volumes: 60160.0
Item 217 - weight: 2.0 volumes: 3000.0
Packed truck volume: 1,168,048.00
Packed truck weight: 500.00

Left Volume 1,210,567.11
Left Weight 0.00


Truck 8 [ VAN ] - max_weight:[ 500.00 ] - max volume:[ 2,378,615.11 ]
Item 114 - weight: 12.0 volumes: 11808.0
Item 115 - weight: 45.0 volumes: 144540.0
Item 116 - weight: 30.0 volumes: 185250.0
Item 117 - weight: 28.0 volumes: 7700.0
Item 118 - weight: 31.0 volumes: 68355.0
Item 119 - weight: 39.7 volumes: 29219.2
Item 120 - weight: 33.0 volumes: 83490.0
Item 121 - weight: 35.0 volumes: 327250.0
Item 122 - weight: 12.58 volumes: 25160.0
Item 123 - weight: 60.0 volumes: 450000.0
Item 124 - weight: 16.0 volumes: 20800.0
Item 125 - weight: 33.0 volumes: 222453.0
Item 126 - weight: 18.0 volumes: 72000.0
Item 127 - weight: 17.0 volumes: 110925.0
Item 128 - weight: 50.0 volumes: 311550.0
Item 129 - weight: 18.0 volumes: 40500.0
Item 131 - weight: 20.0 volumes: 9520.0
Item 248 - weight: 1.0 volumes: 2000.0
Packed truck volume: 2,122,520.20
Packed truck weight: 499.28

Left Volume 256,094.91
Left Weight 0.72


Truck 9 [ LORRY-S ] - max_weight:[ 1,000.00 ] - max volume:[ 7,079,211.65 ]
Item 130 - weight: 40.0 volumes: 19040.0
Item 132 - weight: 20.0 volumes: 9520.0
Item 133 - weight: 20.0 volumes: 9520.0
Item 134 - weight: 45.0 volumes: 371250.0
Item 135 - weight: 120.0 volumes: 380160.0
Item 137 - weight: 38.0 volumes: 68400.0
Item 138 - weight: 23.0 volumes: 62560.0
Item 139 - weight: 18.0 volumes: 8064.0
Item 141 - weight: 9.0 volumes: 25863.3
Item 142 - weight: 28.0 volumes: 125440.0
Item 143 - weight: 20.0 volumes: 34860.0
Item 144 - weight: 16.0 volumes: 32000.0
Item 145 - weight: 11.0 volumes: 6655.0
Item 146 - weight: 5.0 volumes: 5325.0
Item 148 - weight: 13.3 volumes: 13832.0
Item 149 - weight: 15.0 volumes: 12000.0
Item 150 - weight: 5.5 volumes: 16005.0
Item 151 - weight: 47.0 volumes: 125631.0
Item 152 - weight: 31.0 volumes: 231880.0
Item 153 - weight: 30.0 volumes: 185250.0
Item 154 - weight: 47.0 volumes: 173979.9
Item 155 - weight: 41.0 volumes: 194832.0
Item 156 - weight: 30.0 volumes: 19200.0
Item 157 - weight: 45.0 volumes: 101250.0
Item 158 - weight: 35.0 volumes: 70000.0
Item 159 - weight: 30.0 volumes: 185250.0
Item 160 - weight: 12.3 volumes: 19680.0
Item 161 - weight: 13.0 volumes: 14560.0
Item 162 - weight: 69.0 volumes: 645150.0
Item 163 - weight: 26.0 volumes: 94848.0
Item 164 - weight: 12.3 volumes: 19680.0
Item 165 - weight: 47.0 volumes: 101778.5
Item 166 - weight: 10.0 volumes: 15200.0
Item 167 - weight: 18.0 volumes: 60030.0
Item 198 - weight: 5.3 volumes: 8108.999999999999
Item 213 - weight: 3.18 volumes: 4110.468
Item 273 - weight: 1.0 volumes: 10000.0
Packed truck volume: 3,480,913.17
Packed truck weight: 999.88

Left Volume 3,598,298.48
Left Weight 0.12


Truck 10 [ LORRY-S ] - max_weight:[ 1,000.00 ] - max volume:[ 7,079,211.65 ]
Item 1 - weight: 19.0 volumes: 62985.0
Item 168 - weight: 18.0 volumes: 2970.0
Item 169 - weight: 45.0 volumes: 90675.0
Item 170 - weight: 25.0 volumes: 116850.0
Item 171 - weight: 68.2 volumes: 891033.0
Item 172 - weight: 30.0 volumes: 59250.0
Item 173 - weight: 31.9 volumes: 307292.69999999995
Item 174 - weight: 50.0 volumes: 325000.0
Item 175 - weight: 12.3 volumes: 19680.0
Item 176 - weight: 12.3 volumes: 19680.0
Item 177 - weight: 12.3 volumes: 19680.0
Item 178 - weight: 12.3 volumes: 19680.0
Item 179 - weight: 120.0 volumes: 624000.0
Item 181 - weight: 21.0 volumes: 52416.0
Item 184 - weight: 25.0 volumes: 20000.0
Item 185 - weight: 48.0 volumes: 194400.0
Item 186 - weight: 60.0 volumes: 370500.0
Item 187 - weight: 40.0 volumes: 247000.0
Item 188 - weight: 12.3 volumes: 19680.0
Item 189 - weight: 40.0 volumes: 247000.0
Item 190 - weight: 61.0 volumes: 375760.0
Item 191 - weight: 21.0 volumes: 79002.0
Item 193 - weight: 65.0 volumes: 146250.0
Item 194 - weight: 12.0 volumes: 92964.0
Item 196 - weight: 10.7 volumes: 22373.699999999997
Item 197 - weight: 12.0 volumes: 114300.0
Item 199 - weight: 16.0 volumes: 12672.0
Item 200 - weight: 21.0 volumes: 61194.0
Item 201 - weight: 20.0 volumes: 261000.0
Item 202 - weight: 13.5 volumes: 23490.0
Item 245 - weight: 1.9 volumes: 2462.3999999999996
Item 317 - weight: 1.49 volumes: 1043.0
Item 361 - weight: 15.0 volumes: 21000.0
Item 365 - weight: 26.0 volumes: 80080.0
Packed truck volume: 5,003,362.80
Packed truck weight: 999.19

Left Volume 2,075,848.85
Left Weight 0.81


Truck 11 [ LORRY-S ] - max_weight:[ 1,000.00 ] - max volume:[ 7,079,211.65 ]
Item 195 - weight: 100.0 volumes: 228000.0
Item 203 - weight: 13.5 volumes: 23490.0
Item 204 - weight: 57.2 volumes: 277477.2
Item 205 - weight: 13.5 volumes: 23490.0
Item 206 - weight: 5.0 volumes: 3120.0
Item 207 - weight: 17.0 volumes: 146217.0
Item 208 - weight: 39.0 volumes: 250965.0
Item 209 - weight: 5.86 volumes: 11649.68
Item 210 - weight: 79.0 volumes: 538780.0
Item 211 - weight: 19.0 volumes: 91694.0
Item 212 - weight: 19.0 volumes: 91694.0
Item 214 - weight: 18.0 volumes: 31050.0
Item 215 - weight: 75.0 volumes: 486000.0
Item 216 - weight: 19.0 volumes: 91694.0
Item 218 - weight: 17.0 volumes: 16575.0
Item 219 - weight: 19.8 volumes: 21740.4
Item 220 - weight: 10.0 volumes: 15770.0
Item 221 - weight: 21.0 volumes: 33117.0
Item 222 - weight: 10.5 volumes: 29400.0
Item 223 - weight: 6.0 volumes: 9462.0
Item 224 - weight: 20.0 volumes: 71920.0
Item 225 - weight: 7.0 volumes: 25172.0
Item 226 - weight: 15.0 volumes: 80925.0
Item 227 - weight: 20.0 volumes: 31540.0
Item 228 - weight: 27.0 volumes: 118125.0
Item 229 - weight: 5.5 volumes: 2255.0
Item 230 - weight: 32.0 volumes: 168480.0
Item 231 - weight: 30.0 volumes: 145080.0
Item 232 - weight: 7.0 volumes: 25172.0
Item 233 - weight: 45.0 volumes: 340200.0
Item 234 - weight: 20.0 volumes: 7500.0
Item 235 - weight: 20.0 volumes: 41760.0
Item 236 - weight: 14.0 volumes: 11900.0
Item 237 - weight: 32.0 volumes: 133760.0
Item 238 - weight: 100.0 volumes: 605000.0
Item 240 - weight: 10.0 volumes: 71500.0
Item 242 - weight: 16.0 volumes: 34000.0
Item 243 - weight: 10.5 volumes: 22050.0
Item 327 - weight: 0.981 volumes: 391.9095
Item 338 - weight: 1.132 volumes: 475.43999999999994
Item 349 - weight: 1.395 volumes: 748.4175
Packed truck volume: 4,359,340.05
Packed truck weight: 998.87

Left Volume 2,719,871.60
Left Weight 1.13


Truck 12 [ LORRY-M ] - max_weight:[ 3,000.00 ] - max volume:[ 19,980,366.96 ]
Item 3 - weight: 36.0 volumes: 164160.0
Item 4 - weight: 10.0 volumes: 12300.0
Item 5 - weight: 40.0 volumes: 51000.0
Item 147 - weight: 55.0 volumes: 1650000.0
Item 239 - weight: 151.0 volumes: 1434500.0
Item 246 - weight: 72.6 volumes: 540579.6
Item 247 - weight: 61.0 volumes: 338184.0
Item 249 - weight: 15.0 volumes: 21600.0
Item 250 - weight: 36.0 volumes: 257400.0
Item 251 - weight: 40.0 volumes: 112800.0
Item 252 - weight: 11.4 volumes: 53283.600000000006
Item 253 - weight: 8.0 volumes: 8320.0
Item 254 - weight: 40.0 volumes: 235600.0
Item 255 - weight: 43.0 volumes: 202272.0
Item 256 - weight: 5.0 volumes: 4000.0
Item 257 - weight: 34.5 volumes: 161287.5
Item 258 - weight: 34.5 volumes: 161287.5
Item 259 - weight: 25.0 volumes: 85250.0
Item 260 - weight: 40.0 volumes: 223560.0
Item 261 - weight: 18.0 volumes: 74700.0
Item 262 - weight: 10.0 volumes: 16000.0
Item 263 - weight: 23.5 volumes: 37224.0
Item 264 - weight: 10.0 volumes: 10270.0
Item 265 - weight: 8.0 volumes: 23556.0
Item 267 - weight: 6.0 volumes: 25896.0
Item 269 - weight: 50.0 volumes: 178750.0
Item 270 - weight: 60.0 volumes: 270000.0
Item 271 - weight: 20.0 volumes: 76260.0
Item 272 - weight: 47.0 volumes: 108570.0
Item 274 - weight: 41.0 volumes: 273552.0
Item 275 - weight: 8.0 volumes: 12800.0
Item 276 - weight: 24.0 volumes: 29952.0
Item 277 - weight: 10.5 volumes: 15498.0
Item 278 - weight: 12.0 volumes: 64800.0
Item 279 - weight: 28.0 volumes: 54880.0
Item 280 - weight: 5.0 volumes: 18000.0
Item 281 - weight: 50.0 volumes: 200000.0
Item 282 - weight: 20.0 volumes: 30000.0
Item 283 - weight: 17.0 volumes: 27166.0
Item 284 - weight: 30.0 volumes: 213750.0
Item 286 - weight: 60.0 volumes: 411840.0
Item 287 - weight: 10.0 volumes: 5000.0
Item 288 - weight: 42.2 volumes: 76213.20000000001
Item 289 - weight: 43.2 volumes: 78019.20000000001
Item 290 - weight: 13.7 volumes: 36442.0
Item 291 - weight: 46.2 volumes: 164887.80000000002
Item 292 - weight: 18.0 volumes: 82044.0
Item 293 - weight: 6.0 volumes: 12000.0
Item 294 - weight: 5.0 volumes: 1250.0
Item 295 - weight: 28.0 volumes: 78960.0
Item 296 - weight: 17.0 volumes: 11220.0
Item 297 - weight: 14.0 volumes: 58800.0
Item 298 - weight: 12.0 volumes: 92964.0
Item 299 - weight: 12.0 volumes: 92964.0
Item 300 - weight: 12.0 volumes: 92964.0
Item 301 - weight: 20.0 volumes: 40260.0
Item 302 - weight: 14.0 volumes: 22946.0
Item 303 - weight: 12.0 volumes: 92964.0
Item 304 - weight: 7.2 volumes: 5616.0
Item 305 - weight: 35.0 volumes: 1260.0
Item 306 - weight: 45.0 volumes: 85500.0
Item 307 - weight: 20.0 volumes: 39600.0
Item 308 - weight: 12.8 volumes: 40550.4
Item 309 - weight: 41.0 volumes: 171380.0
Item 310 - weight: 15.0 volumes: 45000.0
Item 311 - weight: 19.0 volumes: 91694.0
Item 312 - weight: 19.8 volumes: 21740.4
Item 313 - weight: 29.0 volumes: 36975.0
Item 314 - weight: 35.0 volumes: 44625.0
Item 315 - weight: 46.7 volumes: 208468.80000000002
Item 318 - weight: 19.0 volumes: 35644.0
Item 319 - weight: 21.0 volumes: 30324.0
Item 320 - weight: 5.433 volumes: 6084.96
Item 321 - weight: 24.29 volumes: 874.44
Item 322 - weight: 7.272 volumes: 9162.72
Item 323 - weight: 10.0 volumes: 1500.0
Item 324 - weight: 18.0 volumes: 10800.0
Item 325 - weight: 12.0 volumes: 13500.0
Item 326 - weight: 26.0 volumes: 72800.0
Item 328 - weight: 16.0 volumes: 22000.0
Item 329 - weight: 30.0 volumes: 12397.5
Item 330 - weight: 10.0 volumes: 60000.0
Item 331 - weight: 25.0 volumes: 29700.0
Item 332 - weight: 50.0 volumes: 96250.0
Item 333 - weight: 18.0 volumes: 13095.0
Item 334 - weight: 16.0 volumes: 3520.0
Item 336 - weight: 22.0 volumes: 104720.0
Item 337 - weight: 20.0 volumes: 49500.0
Item 339 - weight: 18.0 volumes: 8316.0
Item 340 - weight: 41.0 volumes: 173225.0
Item 341 - weight: 18.0 volumes: 7020.0
Item 342 - weight: 30.0 volumes: 22500.0
Item 343 - weight: 20.0 volumes: 17500.0
Item 344 - weight: 18.0 volumes: 12096.0
Item 345 - weight: 35.0 volumes: 94325.0
Item 346 - weight: 52.0 volumes: 491244.0
Item 347 - weight: 21.0 volumes: 62475.0
Item 348 - weight: 12.289 volumes: 24578.0
Item 350 - weight: 15.0 volumes: 17640.0
Item 351 - weight: 25.0 volumes: 74375.0
Item 352 - weight: 17.0 volumes: 33235.0
Item 353 - weight: 28.0 volumes: 36400.0
Item 354 - weight: 99.0 volumes: 928125.0
Item 355 - weight: 18.0 volumes: 12879.0
Item 356 - weight: 73.0 volumes: 1351814.0
Item 358 - weight: 23.0 volumes: 60605.0
Item 359 - weight: 3.133 volumes: 2757.04
Item 360 - weight: 23.0 volumes: 60605.0
Packed truck volume: 13,786,742.66
Packed truck weight: 2,906.22

Left Volume 6,193,624.30
Left Weight 93.78


Truck 13 [ LORRY-M ] - max_weight:[ 3,000.00 ] - max volume:[ 19,980,366.96 ]
Item 192 - weight: 250.0 volumes: 4062500.0
Item 241 - weight: 168.0 volumes: 2734200.0
Item 244 - weight: 195.0 volumes: 1243125.0
Packed truck volume: 8,039,825.00
Packed truck weight: 613.00

Left Volume 11,940,541.96
Left Weight 2,387.00


Truck 14 [ LORRY-L ] - max_weight:[ 5,000.00 ] - max volume:[ 24,261,874.16 ]
Packed truck volume: 0.00
Packed truck weight: 0.00

Left Volume 0.00
Left Weight 0.00


Total packed weight: 9,853.69
Total packed volume: 46,254,303.33
Total item assigned: 367

####################################################################
Total Left Volume 29,215,756.23
Total Left Weight 3,646.31
####################################################################

The result show, first we display the available lorry in this scenario. Next, for each lorry, we try to put a few items or parcels to optimize it. We also show the id, weight, and volume for each item in that lorry. At the end of each lorry, we display how much-left volume and weight are not used or the free space available on each lorry after packing the items.

Later, at the end of the result, we summary total packed weight and volume and total items assigned and also show the total left weight and volume space of the lorry.

Conclusion

We’ve already talked about load performance at a glance in this tutorial. We talk a little bit about the bin packing and knapsack problems, as well as the differences between the two.

We also talk about OR-Tools and demonstrate how to use them to solve our problem. We offer our example data and construct coding step by step to arrive at a solution to the problem.

The results suggest that by using this library, we can attempt to efficiently and effectively solve the load performance problem.

I hope you enjoyed this tutorial.

--

--

Dr. Tri Basuki Kurniawan
TheLorry Data, Tech & Product

Loves artificial intelligence learning including optimization, data science and programming