liveBook · Manning

Optimization

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

An algorithm that assigns values to decision variables to optimize an objective function subject to constraints.

Optimization assigns values to decision variables to find the best available solution to a problem. An objective function measures what “best” means, such as minimum cost or maximum profit. Constraints limit which assignments are acceptable. Searching for the best solution therefore means comparing candidates within a feasible search space, though a practical algorithm may settle for a near-optimal result. section 1.3 section 1.6

To formulate a problem, identify:

  • Decision variables: the inputs you can control, such as a ticket price or a selection of parcels. section 1.6 section 1.3.2
  • Objective functions: the quantities to minimize or maximize. A problem may have one objective or several competing objectives. section 1.3.2
  • Constraints: bounds and other restrictions. Hard constraints must hold; soft constraints express preferences and can be represented through rewards or penalties in the objective. section 1.3.3

Pricing one ticket

Suppose ticket price x must lie between $0 and $250, and profit is f(x) = −20x² + 6,200x − 350,000. Setting the derivative, −40x + 6,200, to zero gives x = $155 and profit of $130,500. This is a small problem with one decision variable and one objective; larger problems may require a search algorithm rather than a hand calculation. section 1.3.2 section 1.2

Constraints can change how candidates are judged. In cargo-bike loading, each parcel has a weight and profit, and an overweight load incurs a penalty. In timetabling, two lectures cannot occupy the same room at once, while placing consecutive lectures in nearby rooms is a preference. First decide which restrictions are inviolable; then decide how to score any preferences. section 1.3.3

An optimizer searches among candidate assignments. Exploration tests new regions; exploitation concentrates on a region that has already produced good results. Too much exploitation can leave the search near a local optimum, while too much exploration costs time. The required turnaround matters: a design decision may permit days of computation, whereas a repeatedly solved control problem may allow only milliseconds or seconds. The benefit must also justify implementation costs; elaborate routing changes may offer little value for a handful of deliveries. section 1.5 section 1.2 section 1.1

For a continuous objective, simulated annealing can generate neighboring values and sometimes accept a worse one while its temperature decreases. On f(x) = (x − 6)² with 0 ≤ x ≤ 31, a hand iteration accepts an improvement from x = 2 to x = 2.25, then rejects a worse candidate according to its acceptance probability. Python implementations can scale the experiment: define the objective and bounds, run the solver, inspect its result, and tune its parameters. Tabu search offers another approach to continuous function optimization; parameter tuning affects whether it finds an optimal or near-optimal solution. section 5.3 section 6.4

Listing 5.1 Function optimization using scipy.optimize.dual_annealing
#!pip install scipy
import numpy as np
from scipy.optimize import dual_annealing
  
def objective_function(solution):                                                 #1
    return solution[0]**2 +2*(solution[1]**2) - 0.3*np.cos(3*np.pi*solution[0]) –
 0.4*np.cos(4*np.pi*solution[1]) + 0.7
  
bounds = np.asarray([[-100, 100], [-100, 100]])                                   #2
  
res_dual = dual_annealing(objective_function, bounds=bounds, maxiter = 100)       #3
  
print('Dual Annealing Solution: f(%s) = %.5f' % (res_dual['x'], res_dual['fun'])) #4
#1 Define the objective function or functions (e.g., Bohachevsky function).
#2 Define the boundary constraints of the decision variables.
#3 Perform the dual annealing search.
#4 Print the dual annealing solution.

This Python listing shows the practical interface: define an objective, set variable bounds, run SciPy’s dual_annealing, and print the candidate solution and its objective value. section 5.3

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Develops variables, objectives, constraints, search trade-offs, hand iterations, and Python solver use; does not establish a single algorithm for every problem.
Examples
Uses ticket pricing, cargo-bike loading, timetabling, a bounded quadratic, and continuous-function test problems.
What it assumes
Starts with hand-solvable problems before moving to Python libraries, without requiring previous experience solving optimization problems.
What you can do after
Apply it via SciPy’s dual_annealing or a tabu-search solver by defining objectives and bounds, then inspecting and tuning results.
How it connects
Connects decision variables, objective functions, constraints, feasible search spaces, local optima, simulated annealing, and tabu search.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.