140 likes | 261 Views
Benchmarks. Reference points for comparison and measurement. Brute Force. A definition: Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. What is the complexity of finding ? What algorithm would you use?.
E N D
Benchmarks Reference points for comparison and measurement
Brute Force • A definition:Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. • What is the complexity of finding ? • What algorithm would you use?
Brute Force • A definition:Employing an algorithm that expresses a naïve or direct implementation of an algorithm based upon the statement of a problem. • What is the complexity of finding ? • What algorithm would you use? • Could it be done faster?
Find Two Ways • #Find a^n in two ways • import math • import time • a = 2 • n = 1000 • m = 100000 • starttime = time.time() • for j in range (m): • p = 1 • for i in range (n): • p *= a • endtime = time.time() • elapsedtime1 = endtime - starttime • print (p, elapsedtime1) • starttime = time.time() • for j in range (m): • lg = math.log(a) • ex = n * lg • p = math.exp(ex) • endtime = time.time() • elapsedtime2 = endtime - starttime • print (p, elapsedtime2) • print(elapsedtime1/elapsedtime2)
How Did O(1) Emerge? • Table look-up • Power series expansion using a fixed number of terms • , x>0 • , for all real values of x, and • Is this brute force?
Brute Force • Examples: • Sorting • O(n!) or O(2^(n^2)) • O(n^2) • O(n log n) Under what circumstances c/would you call such an algorithm brute force? • O(n) Under what circumstances c/would you call such an algorithm brute force? • Others? • Searching
Brute Force • Common elements: • Enumeration of outcomes? • What is the O(a brute force algorithm)?
Exhaustive Search • Enumerating all possible outcomes in order to identify a compliant or best solution • Often arises from a direct interpretation of a problem statement • May exist as the only method of finding compliant or optimal solutions
Optimization versus Constraint Satisfaction • For a function f, defined on a set S, if s* ε S such that f(s*) ≤ f(s) for all s ε S, then s* is said to be a minimum of f on S. The function f may be used as an objective function. • An optimization problem is a minimization problem subject to constraints: • g(s) ≤ 0 ; inequality constraints • h(s) = 0 ; equality constraints • If there is no objective function, the problem is a constraint satisfactionproblem.
Example Formulation: TSP • Natural language: Find the shortest round trip to visit some number of cities so that each of the cities is visited exactly once. • Can we tighten and clarify this statement? • How will “shortest” be measured? • What is a “round trip”? • What is “exactly once”?
TSP Continued • Given a set of n cities, label each with a distinct counting number from the set S = {0, …, n-1}. • Let p:S->S be a bijective (one-to-one and onto) function. The function p is a permutation of the city labels and may be used to represent a trip, where p(i) for i=0,…,n-1 is the city to visit at the ith step of the trip. • The cost of a trip can be determined by:
TSP Constraints (cont’d) • The constraints are: • Visit each city • Only visit once • They are satisfied or enforced implicitly by the choice of a candidate solution as a permutation of the label set: • Each city label must be used (onto) • A city label may only be used once (one-to-one)
TSP: Integer Programming Problem • An alternative formulation of TSP may be found at http://en.wikipedia.org/wiki/Travelling_salesman_problem • Note some of the key differences: • Cost function appears as a double summation (or is it?). • Constraints are explicitly expressed as equalities. • A 0/1 decision variable xij is introduced. (The 0/1 are the integer options in this integer programming problem. It is sometimes called a 0/1 IPP)
For Your Course Project • Identify your group. • State the problem you will tackle using natural language. • Restate the problem formally. Employ the language of analysis to formulate the objective and any constraints • Identify several of the algorithms you will apply to the problem. • What will be the bases for assessing the relative merits of the alternative algorithms? Benchmarks should appear. here, as well as measurements you plan to employ. (By the due date) • What are your empirical results? • Interpret and analyze your findings. • With respect to the algorithms, what would you do differently next time?