During optimization, the inverse planning system changes the weight of the beamlets by one intensity level (one level higher or lower), one beamlet at a time. After each change, a 3D dose matrix is calculated, and DVHs are generated for the target and critical structures. If the DVHs come closer to satisfying the planning goals, the change is accepted. Otherwise, it is rejected. To avoid local minima, the simulated annealing algorithm initially accepts some changes that make the dose distribution worse.