You are on page 1of 10

Optimization

Kashif Bilal
Optimization

– the action of making the best or most effective use of a situation or resource.
– Optimization is used everywhere
– "companies interested in the optimization of the business“
– In computing, optimization is the process of modifying a system to make some
features of it to
– work more efficiently
– or use fewer resources. For instance, a computer program may be optimized so that it runs
faster,
– or to run with less memory requirements or other resources
– or to consume less energy.
Greedy Algorithms or Heuristics

– Consider a knapsack problem


– We have items with value and weight/space consumption
– We have a constraint regarding knapsack capacity: 10 KG
– How to maximize the value of collected items?

– What greedy approaches we have ?


– Sort by weight
– Sort by value
– Find value per unit weight (value density)
– Can we improve further ???
Mathematical Presentation

– Given a set of items I


– Each items in I, 𝑖 ∈ 𝐼, characterized by
– Value vi
– Weight Wi

– Capacity of Knapsack K
Optimization Modeling

– Model tells what the problem is actually..


– Optimization modeling requires
– Decision variable
– Whether this item will be added to knapsack or not
– Xi = 1, if items is added, 0 otherwise

– Express the constraints


– In this case the only constraint is that total weight of items must be less than or equal to K
– σ𝑖∈𝐼 𝑤𝑖 ≤ 𝐾

– Express the objective function


– 𝑀𝑎𝑥𝑖𝑚𝑖𝑧𝑒 σ𝑖∈𝐼 𝑣𝑖 𝑥𝑖 , 𝑤ℎ𝑒𝑟𝑒 𝑥𝑖 ∈ {0,1}
Multiple choice Knapsack

– We have n different classes of items, exactly one item must be chosen from
each class ; or atleast one item must be chosen from each class
Multiple Knapsack Problem

– If we have n items and m knapsacks with capacities Wi, we get the multiple
knapsack problem:
Dynamic Programming

– dynamic programming (also known as dynamic optimization) is a method for solving


a complex problem by breaking it down into a collection of simpler sub problems,
solving each of those sub problems just once, and storing their solutions.
– Divide knapsack problem into subproblems
– Consider 0 items, 1 items … n items one by one
– Consider weights starting from 0 to K and calculate optimal placement for each of item

– Consider one item at a time


– If wi > W
– O(i-1,w)
– Else
– Max(O(i-1,w), vi + O(i-1),W-wi)
Knapsack using DP

– Table and memorization technique


– The bottom right corner of table is optimal value
– To choose the selected items
– Start traversing from bottom right
– If (I > i-1)
– Add I and find previous i-1, W-Wi

You might also like