What is optimization?
Imagine you have a $50 store coupon for groceries. For your diet you need to buy certain types of food – like
fruits,
vegetables, and dairy –. Ideally, you'd spend exactly $50. However, it
might not always be possible to spend the exact amount.
So, your goal is to buy the required groceries and spend
as little extra money as possible beyond the coupon's value.
This is a simple example of what we call
optimization.
Optimization is all about finding the best solution to a problem, given certain limitations or requirements. The "best" solution depends on what you're trying to achieve. In our grocery example, the "best" solution means spending as close to $50 as possible without spending too much more. We want to minimize the amount we have to pay out of pocket.
Let's say you just randomly pick items: 3 apples ($12), 2 carrots ($4), and 1 milk ($5). That's $21 total. You're far from using your full coupon! You could buy more, but what should you buy to get closer to $50 without spending a lot more than $50? Trying every possible combination of fruits, vegetables, and dairy could take a long time.
The Components of an Optimization Problem
Our grocery shopping scenario, though simple, contains all the essential elements of an optimization problem, which we will call a model. Let's break it down:
Decision Variables
These are the things we can choose or control. In our case, the decision variables are how many of each item we buy. We can represent these with variables:
- a = number of apples
- b = number of bananas
- ca = number of carrots
- s = number of spinach
- m = number of milk
- ch = number of cheese
For example, a = 3 means we buy 3 apples. These variables are what we'll be changing to find the best solution.
Objective Function
This is what we're trying to minimize (we can also maximise). In our case, we want to minimize the amount of money we spend beyond our $50 coupon. We can express this mathematically:
Total Cost = 4a + 3b + 2ca + 3s + 5m + 6ch
Extra Spending = Total Cost - 50
Our objective function is to minimize the "Extra Spending".
Constraints
These are the limitations or rules we must follow. We say that our model
is Subject to (s.t.) those constraints.
In our grocery example, we have a few constraints:
- Minimum Fruit: a + b ≥ 3 (We must buy at least 3 fruits)
- Minimum Vegetables: ca + s ≥ 2 (We must buy at least 2 vegetables)
- Minimum Dairy: m + ch ≥ 1 (We must buy at least 1 dairy product)
- Minimum Spending: 4a + 3b + 2ca + 3s + 5m + 6ch ≥ 50 (We must spend at least 50)
- Non-negative quantities: a, b, ca, s, m, ch ≥ 0 (We can't buy a negative number of items)
By defining these three components-decision variables, objective function, and constraints—we've turned our everyday grocery problem into a formal optimization model that can be solved using mathematical techniques.
Let's put everything together in a model using the ROOC syntax:
And using the solvers inside rooc, we are able to find a solution with cost 0, so we managed to spend
exactly $50
The food we picked are: apples = 10, carrots = 2, cheese = 1
Why is optimization useful?
Optimization helps us make better
decisions when we face limited resources, competing goals, or complex systems.
Here are some other examples:
- Logistics and Transportation: Companies like delivery services and airlines use optimization to plan routes, schedule deliveries, and manage fleets. The goal might be to minimize fuel consumption, delivery times, or overall costs.
- Manufacturing and Production: In manufacturing, optimization is used to determine the best production schedules, manage inventory levels, and design efficient production lines. The goal might be to maximize production output, minimize waste, or reduce production costs. For example, a factory might use optimization to determine the optimal mix of products to manufacture given limited resources like raw materials and machine time.
- Finance and Investment: Financial institutions use optimization to build investment portfolios that maximize returns while minimizing risk. Optimization techniques can help determine the best allocation of assets across different investment classes.
- Energy and Utilities: Power companies use optimization to manage the distribution of electricity, optimize energy production, and schedule maintenance. The goal might be to minimize energy losses, reduce costs, or ensure a reliable power supply.
These are just a few examples of how optimization is used across diverse fields. In essence, any situation where you're trying to make the "best" decision given certain constraints can potentially benefit from optimization techniques. By formulating the problem mathematically and using appropriate algorithms, we can find solutions that are proven to be the best.