Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reference points for comparison and measurement. Brute Force.

Similar presentations


Presentation on theme: "Reference points for comparison and measurement. Brute Force."— Presentation transcript:

1 Reference points for comparison and measurement

2 Brute Force

3

4 #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)

5 How Did O(1) Emerge?

6 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

7 Brute Force Common elements: Enumeration of outcomes? What is the O(a brute force algorithm)?

8 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

9 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 satisfaction problem.

10 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”?

11 TSP Continued

12 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)

13 TSP: Integer Programming Problem An alternative formulation of TSP may be found at http://en.wikipedia.org/wiki/Travelling_salesman_pro blem http://en.wikipedia.org/wiki/Travelling_salesman_pro blem 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 x ij is introduced. (The 0/1 are the integer options in this integer programming problem. It is sometimes called a 0/1 IPP)

14 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?


Download ppt "Reference points for comparison and measurement. Brute Force."

Similar presentations


Ads by Google