artificial intelligence (cscu9ye ) lecture 4: optimisation … · 2016-09-28 · strategies to...

14
9/28/2016 1 ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION AND SEARCH (LOCAL SEARCH) Gabriela Ochoa http://www.cs.stir.ac.uk/~goc/ OUTLINE 1. Optimisation problems Optimisation & search Two Examples The Knapsack Problem The Traveling Salesman Problem TSP (next lecture) 2. Optimisation methods Heuristics and metaheuristcis Single point algorithms Population-based algorithms, such as genetic and other evolutionary algorithms (next lecture 2

Upload: others

Post on 21-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

1

ARTIFICIAL INTELLIGENCE (CSCU9YE )

LECTURE 4: OPTIMISATION AND

SEARCH (LOCAL SEARCH)

Gabriela Ochoa

http://www.cs.stir.ac.uk/~goc/

OUTLINE

1. Optimisation problems

Optimisation & search

Two Examples

The Knapsack Problem

The Traveling Salesman Problem TSP (next lecture)

2. Optimisation methods

Heuristics and metaheuristcis

Single point algorithms

Population-based algorithms, such as genetic and other

evolutionary algorithms (next lecture

2

Page 2: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

2

PRELIMINARIES

More AI demos: Knightscope K5 An autonomous robot that provides a physical security

presence

Gathers important real-time, on-site data through its numerous sensors

Data is is then processed through a predictive analytics engine

Combine with business, government and social data sets to determine if there is a concern or threat in the area.

If so, a notification is sent is sent to the community and authorities

Dictionary definition of Optimisation The act of making something as good as possible

The action of making the best or most effective use of a situation or resource.

3

OPTIMISATION PROBLEMS

Wide variety of applications across industry, commerce,

science and government

Optimisation occurs in the minimisation of time, cost and

risk, or the maximisation of profit, quality, and efficiency

Examples

Finding shortest round trips in graphs (TSP)

Finding models of propositional formulae (SAT)

Determining the 3D-structure of proteins

Planning, scheduling, cutting & packing, logistics,

transportation, communications, timetabling, resource

allocation, genome sequencing

Software engineering: test case minimisation and prioritisation,

requirements analysis, code design and repair, etc.

4

Page 3: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

3

SEARCH IN COMPUTING SCIENCE

1. Search for stored data

• Finding information stored in disc

or memory.

• Examples: Sequential search,

Binary search

2. Search for web documents

• Finding information on the world

wide web

• Results are presented as a list of

results

3. Search for paths or routes

• Finding a set of actions that will

bring us from an initial stat to a

goal stat

• Relevant to AI

• Examples: depth first search, breath

first search, branch and bound, A*,

Monte Carlo tree search.

4. Search for solutions

• Find a solution in a large space of

candidate solutions

• Relevant to AI, Optimisation, OR

• Examples: evolutionary algorithms,

Tabu search, simulated annealing,

ant colony optimisation, etc.

At least 4 meanings of the word search in CS

5

OTPIMISATION AND SEARCH

In many optimisation problems, the path to the goal is irrelevant; the goal state itself is the solution

State space = set of "complete" configurations

Find configuration satisfying constraints, e.g., n-queens

In such cases, we can use local search algorithms

Keep a single "current" state, try to improve it

6

Page 4: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

4

OPTIMISATION PROBLEMS ARE EVERYWHERE!

Logistics, transportation,

supply change

management

Manufacturing, production

lines

Timetabling

Cutting & packing Computer networks

and

Telecommunications

Software - SBSE 7

OPTIMISATION PROBLEMS

General constrained

optimisation problem: Optimisation through search

Iteratively generate and evaluate

candidate solutions.

• Systematic search

• (Stochastic) local search

Search Space: set of

candidate solutions. All

possible combinations of the

decision variables.

Min/Max f( )

x

Subject to:

0)( xgi

0)( xhj

i = 1,…,p

j = 1,…,n

8

Page 5: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

5

OPTIMISATION PROBLEMS: TWO CATEGORIES

Continuous

Continuous variables

Looking for a set (vector) of

real numbers [45.78, 8.91, 3.36]

Objective function has a

mathematical expression

Special cases studied in

mathematics and OR:

Convex, Linear

Combinatorial

Discrete variables

Looking for an object from a

finite set

Binary digits [1011101010]

Integer [1, 53, 4, 67, 39]

Permutation [3,5,1,2,4]

Graph

• Generally different flavours and methods for solving them

• Have become divergent 9

OPTIMISATION/SEARCH ALGORITHMS

Optimisation algorithms

Exact

Special purpose

Generate bounds: dual ascent,

Langrangean relax

General purpose

Branch and bound

Cutting planes

Approximate

Special purpose

Approximation Greedy /

Constructive Heuristics

Meta and Hyper heuristics

Single point Population based

• Guarantee finding optimal solution

• Useful when problems can be solved in

Polynomial time, or for small instances

• Do not Guarantee finding optimal solution

• For most interesting optimisation problems no

polynomial methods are known

Approximation algorithms:

• An attempt to formalise heuristics (emerged from the field of theoretical computer science)

• Polynomial time heuristics that provide some sort of guarantee on the quality of the solution 10

Page 6: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

6

THE KNAPSACK PROBLEM

Given a knapsack of capacity W, and a number n of items, each with

a weight and value. The objective is to maximise the total value of

the items in the knapsack

maximise

4x1+2x2+x3+10x4 +2x5

subject to

12x1+2x2+x3+4x4+x5 15

x1,x2,x3,x4,x5 {0, 1}

Xi = 1 If we select item i

0 Otherwise

• Binary representation [11010]

Maximise Subject

to

• Search space size = 2n

• n = 100, 2100 ≈ 1030

11

REAL-WORLD EXAMPLE OF THE KNAPSACK

PROBLEM

Consider a cargo company, that has an airplane

and need to carry packages.

Customers state the weight of the cargo item

they would like delivered, and the amount they

are prepared to pay.

The airline is constrained by the total amount of

weight the plane is allowed to carry.

The company must choose a subset of the

packages (bids) to carry in order to make the

maximum possible profit, given the weight limit

that they must respect. 12

Page 7: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

7

LOCAL SEARCH METHODS FOR

OPTIMISATION

Exhaustive enumeration, only possible for small

problems

Random search

Hill-climbing

Steepest (Best) ascent

First (Next)ascent

Multi-start hill-climbing

Iterated local search

Simulated annealing

13

EXHAUSTIVE ENUMERATION

Try out all possible ways of packing/leaving out the items

For each way, it is easy to calculate the total weight carried and the total value carried

Consider the following knapsack problem instance: 3

1 5 4

2 12 10

3 8 5

11

Where: The first line gives the number of items. The last line gives the capacity of the knapsack. The remaining lines give the index, value and weight of each item.

14

Page 8: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

8

KNAPSACK, FULL ENUMERATION

Items Value Weight Feasible?

000 0 0 Yes

001 8 5 Yes

010 12 10 Yes

011 20 15 No

100 5 4 Yes

101 13 9 Yes

110 17 14 No

111 25 19 No

15

Optimal!!

THE NOTION OF NEIGHBOURHOOD

S x

N(x)

A search space S, a potential

solution x, and its neighbourhood

N(x)

Region of the search space that is “near” to some particular

point in that space

Define a distance function dist on the search space S

Dist: S x S → R

N(x) = {y Є S: dist(x,y) ≤ ε }

Examples: • Euclidean distance, for search spaces

defined over continuous variables

• Hamming distance, for search spaces

defined over binary strings

• Hamming distance between two strings is

the number of positions at which the

corresponding symbols are different. 16

Page 9: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

9

DEFINING NEIGHBOURHOODS: BINARY

REPRESENTATION

1-flip mutation: flipping a single bit in the given bit

string

For strings of length n, every solution has n neighbours

Example: 1 1 0 0 1 → 0 1 0 0 1,

Python implementation

17

HILL-CLIMBING SEARCH

Like climbing a mountain in thick fog with amnesia

18

Best Improvement (gradient descent, greedy hill-climbing): Choose maximally

improving neighbour

First Improvement: Choose the first found improving move.

Local optimum: No other solution in the neighbourhood has better fitness

Page 10: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

10

HILL-CLIMBING SEARCH IN PYTHON

19

HILL-CLIMBING SEARCH

Problem: depending on initial state, can get stuck in local maxima

20

Page 11: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

11

TERMINOLOGY AND DATES

Heuristic: Greek word heuriskein, the art of discovering new

strategies to solve problems

Heuristics for solving optimization problems, G. Poyla (1945)

A method for helping in solving of a problem, commonly informal

“rules of thumb”, educated guesses, or simply common sense

Prefix meta: Greek for “upper level methodology”

Metaheuristics: term was introduced by Fred Glover (1986).

Other terms: modern heuristics, heuristic optimisation, stochastic

local search

21

WHAT IS A METAHEURISTIC?

Extended variants of local search

General-purpose solvers, usually applicable to a large

variety of problems

Use two phases during search

Intensification (exploitation): focus the applications of

operators on high-quality solutions

Diversification (exploration): systematically modifies

existing solutions such as new areas of the search space are

explored

22

Page 12: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

12

ITERATED LOCAL SEARCH

Procedure Iterated Local Search (ILS)

s = initislise(s)

s = hill-climbing (s)

while NOT termination_criterion {

r = s

s = perturbation(s)

s = hill-climbing (s)

if s < r

s = r

}

Key idea: use two stages

Local search for reaching local optima (intensification)

Perturbation stage, for escaping local optima (diversification)

Acceptance criterion: to control diversification vs. intensificaction

23

SIMULATED ANNEALING

Key idea: provides a mechanism to escape local

optima by allowing moves that worsen the

objective function value

Annealing: the physical process of heating up a

solid and then cooling it down (slowly) until it

crystallizes

candidate solutions → states of physical system

objective function → thermodynamic energy

globally optimal solutions → ground states

parameter T → physical temperature

24

Page 13: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

13

SIMULATED ANNEALING – ALGORITHM

1. Start with a random solution s

2. Choose some “nearby” solution s’

3. If the new solution is better (i.e. f(s’) ≤ f(s)) , take it as the

current solution (= accept it)

4. If it is worse, accept it with a probability that depends on

the deterioration f(s)-f(s’) and a global parameter T (the

temperature)

Metropolis acceptance criterion

Cooling schedule: a

mechanism for reducing

the temperature

25

PRACTICAL EXERCISE

In the programming language of your choice

implement:

1. A random search method

2. A first improvement (random mutation) hill-

climbing method

Apply the algorithms to the two instances

given: ‘easy20.txt’ and ‘hard200.txt’

Which algorithm is best for this problem and

why?

26

Page 14: ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 4: OPTIMISATION … · 2016-09-28 · strategies to solve problems Heuristics for solving optimization problems, G. Poyla (1945) A method

9/28/2016

14

SUMMARY

What is optimisation?

Relationship between optimisation and search

The knapsack problem

Local search algorithms

Hill-climbing

Multi-start hill-climbing

Iterated local search

Simulated annealing

Next lecture

Travelling salesman problem

Evolutionary algorithms 27