Introduction to mathematical optimization

Introduction to Optimization in Python

Jasmin Ludolf

Content Developer

Coming up...

 

You'll learn about...
  • Solving real-world optimization problems
  • Build a toolkit to tackle different problems

 

What you need to know beforehand...

 

What you don't need to know...
  • Calculus
  • Algorithms
Introduction to Optimization in Python

What is mathematical optimization?

 

  • Finding the ideal inputs for a specific problem

 

  • Examples:
    • Maximizing crop yields

Crops growing in a field.

  • Soil conditions, weather
  • Best crop quantity and quality
Introduction to Optimization in Python

What is mathematical optimization?

 

 

Vans driving a delivery route.

 

 

  • Optimal distribution routes
  • Distance and traffic
  • Improve delivery times and reduce costs
Introduction to Optimization in Python

The objective function

  • Describes the relationship between input variables and the result

 

Furniture manufacture:

  • Maximize profit, P
  • Quantity, q

 

$P = 40q - 0.5q^2$

  • Which value of q maximizes P?
Introduction to Optimization in Python

Optimize with Python

import numpy as np
import matplotlib.pyplot as plt

qs = np.arange(80)


def profit(q): return 40 * q - 0.5 * q**2
plt.plot(qs, profit(qs)) plt.xlabel('Quantity') plt.ylabel('Profit') plt.show()
Introduction to Optimization in Python

Optimization in manufacturing

 

  • Maximum value = optimum value

 

  • Possible reasons for the shape:
    • Not enough staff or equipment

 

Profit varying with quantity.

Introduction to Optimization in Python

Exhaustive search

  • "Brute force" method
  • Calculating the profit for a range of quantities
  • Select the one that produces the largest profit

 

A man holding binoculars sitting on a balloon with a dollar sign on it searching for profit.

Introduction to Optimization in Python

Exhaustive search in Python

import numpy as np

qs = np.arange(80)

def profit(q): 
  return 40 * q - 0.5 * q**2


profits = profit(qs) max_profit = profits.max()
max_ind = np.argmax(profits) q_opt = qs[max_ind]
print(f"The optimum is {q_opt} pieces of furniture, which makes ${max_profit} profit.")
The optimum is 40 pieces of furniture, which makes $800 profit.
Introduction to Optimization in Python

Exhaustive search advantages and disadvantages

 

  • Advantages
    • (+) Simple implementation
    • (+) No need for expensive software
    • (+) Minimal assumptions
  • Disadvantages
    • (-) Will not scale for complex cases
Introduction to Optimization in Python

Let's practice!

Introduction to Optimization in Python

Preparing Video For Download...