Differential Evolution on Bin Packing

Two numerical examples: standard random-key encoding, then a discrete configuration-difference adaptation.

Exam-safe one-liner: DE is naturally continuous. For bin packing, either use a continuous random-key vector and decode it into an item order, or define a custom discrete "difference" operator over configurations/features. The random-key method is simpler and was the HW-style approach; the configuration-difference method is more native but must be carefully repaired for feasibility.

Problem Instance

Bin capacity C = 10. Six items:

ItemABCDEF
Weight481427

Fitness for this example:

fitness = number_of_bins + 0.01 * slack_balance_penalty

The number of bins is the main objective. The small slack penalty breaks ties, like a smoother fitness surface.

Method 1: Random-Key DE

This is the most exam-safe adaptation. A DE individual is a real vector. Sort the keys to get an item order, then decode that order using First Fit.

Target vector and decoding

The current target individual is:

ItemABCDEF
Target key x_i0.620.150.870.310.440.73

Sort by ascending key:

B, D, E, A, F, C

First Fit decoding:

Bin 1 load 10
B8E2
Bin 2 load 9
D4A4C1
Bin 3 load 7
F7

Target uses 3 bins. Slack vector is [0, 1, 3].

DE mutation

Use DE/rand/1/bin with mutation factor F = 0.60.

v = x_r1 + F * (x_r2 - x_r3)
VectorABCDEF
x_r1 base0.200.800.350.650.100.55
x_r20.900.300.750.250.600.40
x_r30.400.700.100.500.200.95
x_r2 - x_r30.50-0.400.65-0.250.40-0.55
0.60 * diff0.30-0.240.39-0.150.24-0.33
Donor v0.500.560.740.500.340.22

Binomial crossover

Use crossover rate CR = 0.70. If random number <= CR, take donor key; otherwise keep target key. Force item D from donor as j_rand.

ItemABCDEF
Random number0.810.140.660.91*0.380.52
Take fromtargetdonordonordonor*donordonor
Trial u0.620.560.740.500.340.22

The star means D is forced by j_rand, even though 0.91 is greater than CR.

Decode the trial

Sort by ascending trial key:

F, E, D, B, A, C

First Fit decoding:

Bin 1 load 10
F7E2C1
Bin 2 load 8
D4A4
Bin 3 load 8
B8

Trial uses 3 bins. Slack vector is [0, 2, 2].

Selection: trial vs target

CandidateBin loadsBinsSlackSlack penaltyFitness
Target x_i10, 9, 730, 1, 34.673.0467
Trial u10, 8, 830, 2, 22.673.0267

Trial is accepted because it uses the same number of bins and has a better tie-breaker fitness.

Method 2: Configuration-Difference / Similarity DE

This is a custom discrete DE idea, not ordinary arithmetic DE. You cannot literally subtract two bin-packing configurations. Instead, define difference as a set of features or moves, then apply a fraction of those features to a base configuration and repair infeasibility.

Represent a configuration by co-location features

A feature means "item X and item Y are in the same bin." This is useful for bin packing because good packings often preserve good item pairings.

Base configuration R1

Bin 1 load 10
B8E2
Bin 2 load 9
A4D4C1
Bin 3 load 7
F7

Features: BE, AD, AC, DC

Configuration R2

Bin 1 load 9
B8C1
Bin 2 load 10
A4D4E2
Bin 3 load 7
F7

Features: BC, AD, AE, DE

Configuration R3

Bin 1 load 8
B8
Bin 2 load 10
F7E2C1
Bin 3 load 8
A4D4

Features: FE, FC, EC, AD

Define the discrete difference

Instead of arithmetic R2 - R3, use features present in R2 but not in R3:

R2 - R3 = {BC, AE, DE}

Let F = 2/3. Apply two of the three difference features to the base R1. Suppose we choose:

F * (R2 - R3) = {BC, AE}

Apply feature BC to the base

Base has B with E, and C with A,D. To enforce BC, move C into B's bin.

But B8 + E2 + C1 = 11, which violates capacity. Repair by ejecting E temporarily:

Bin 1 load 9
B8C1
Bin 2 load 8
A4D4
Bin 3 load 7
F7
Unplaced
E2

Apply feature AE and repair

Now enforce AE by placing E2 with A4. Bin 2 has load 8, so adding E gives load 10 and stays feasible.

Bin 1 load 9
B8C1
Bin 2 load 10
A4D4E2
Bin 3 load 7
F7

This donor configuration is valid and uses 3 bins.

What this means conceptually

This discrete version mimics DE:

Continuous DEConfiguration-difference DE
x_r2 - x_r3Features/moves present in R2 but not R3
F * differenceApply only a fraction of those features/moves
x_r1 + ...Start from base R1 and inject those selected features
Bounds/clippingRepair capacity violations and unplaced items
Greedy replacementAccept donor/trial only if it beats the target fitness

Which Answer Should You Use In The Exam?

If the question asks what you actually did in HW#5: use the random-key explanation.

If the question asks how to adapt DE more natively to bin packing: use the configuration-difference answer, but explicitly say you must define difference over moves/features and repair infeasible bins.

Doctor-style answer: "DE is continuous, so direct subtraction of two bin-packing configurations is meaningless. In HW#5 I used random keys: DE changes real numbers, sorting gives a permutation, and First Fit decodes it. The weakness is that the encoding dominates the search. A more native discrete DE would define difference as item-pair co-location features or moves, apply a fraction of those features to a base solution, then repair capacity violations."
← Hub