Top Banner
Telerik Software Academy academy.telerik.com Other Algorithms
22

Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Dec 28, 2015

Download

Documents

Grant Francis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Telerik Software Academyacademy.telerik.com

Other Algorithms

Page 2: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Table of Contents1. Heuristics

2. Greedy

3. Genetic algorithms

4. Randomization

5. Geometry

2

Page 3: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Heuristics

Page 4: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Heuristics Solving problem more quickly than classic methods

Finding approximate solution When optimal solution is complex and hard to find (requires time and memory)

Heuristics give simple solution (not optimal!)

Quickly produce solution that is good enough vs finding optimal solution very very slow (mostly NP-complete problems)

4

Page 5: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Heuristics

Usage anti-virus scanners A* - Dijkstra + some cool stuff

Computes path quickly but the path might not be the shortest

5

Page 6: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Greedy

Page 7: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Greedy Locally optimal choice at each stage

Finds local extremum (not always global)

Much faster than always finding optimal solution

Example: Knapsack

Travelling salesman

Prim and Kruskal

Etc.

7

Page 8: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Greedy

What do we need: Candidate set

Selection function

Feasibility function

Objective function

Solution function

The result is NOT

the optimal solution

8

Page 9: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

GreedyLive Demo

Page 10: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Genetic Algorithms

Page 11: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Genetic Algorithm

Part of Artificial Intelligence Mimics the process of natural evolution

Terminology Population

Fitness

Operators Crossover

Mutation11

Page 12: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Genetic Algorithm

Crossover

Mutation

12

2 3 1 5 4 8 0 7 9 6

0 7 6 5 1 4 3 2 9 8

2 3 1 5 4 0 7 6 9 8

2 3 1 5 4 0 7 6 9 8

2 3 1 5 0 4 7 6 9 8

Page 13: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Genetic Algorithm - Steps

Create population Do many times (at least for 100 generations)

1. Determine fitness of each individual

2. Select next generation

3. Crossover

4. Mutation

5. Back to 1

Display results13

Page 14: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Genetic AlgorithmLive Demo

Page 15: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Randomization

Page 16: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Randomization Process of making something random

Monte Carlo and Las Vegas algorithms

Examples: Generate random permutation of a

sequence

Select a random sample of population

Generate random numbers16

Page 17: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Geometry

Page 18: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Geometry Vectors

Sum

Subtract

Normalization

Dot product

Cross product

18

Page 19: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Geometry Distance between two points Line equation Intersection of two lines Used very much in computer games and raytracing

19

Page 20: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Questions?

Other Algorithms

http://academy.telerik.com

Page 21: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Exercises1. You are given a set of infinite number

of coins (1, 2 and 5) and end value – N. Write an algorithm that gives the number of coins needed so that the sum of the coins equals N. Example: N = 33 => 6 coins x 5 + 1 coin x 2 + 1 coin x 1

2. You are given 3 points A, B and C, forming triangle, and a point P. Check if the point P is in the triangle or not.

21

Page 22: Telerik Software Academy academy.telerik.com. 1. Heuristics 2. Greedy 3. Genetic algorithms 4. Randomization 5. Geometry 2.

Free Trainings @ Telerik Academy

C# Programming @ Telerik Academy csharpfundamentals.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com