Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Some Standard Problems - Computer Architecture | CPSC 5155U, Study notes of Computer Architecture and Organization

Material Type: Notes; Professor: Bosworth; Class: Computer Architecture; Subject: Computer Science; University: Columbus State University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/04/2009

koofers-user-b1z
koofers-user-b1z 🇺🇸

10 documents

1 / 33

Toggle sidebar

Related documents


Partial preview of the text

Download Some Standard Problems - Computer Architecture | CPSC 5155U and more Study notes Computer Architecture and Organization in PDF only on Docsity! Some Standard Problems Here, we present the brute–force solution to a number of small instances of standard problems (and a few oddball ones). 1) TSP. 2) Knapsack. 3) Job Shop Scheduling. 4) Dogs, Cats, and Mice (an “oddball”). 5) Evaluating Standard Trigonometric Functions. As we undertake the brute–force solutions of the standard problems, we shall take notice of a number of “short cuts” that we shall later develop. A Didactic Issue There is an issue with the presentation of any of the standard problems in the class called “NP Hard”. This has to do with the size of the problem instance. Rather than give a precise definition of “instance size”, we go with intuitive definitions specific to each problem; the number of cities, the item count, etc. The standard didactic goal is to teach methods that can be used to speed up significantly the solution of a large instance of a standard problem. As an example, consider a tour of 50 cities with each city visited exactly once. The difficulty with solving such monster problems is that a complete solution might take quite a few class periods to develop, and would not contribute much to the student’s understanding of either the problem or the solution method. As a result, we elect to illustrate these “industrial strength” solution strategies by use of “toy sized” problems, which could more easily be solved by more primitive methods. The advantage is that the strategies are obvious. TSP: Is a Hamiltonian Cycle Possible? Yes. One such cycle: SEA  DFW  MEX  MIA  ATL  SEA. The total cost of this Hamiltonian cycle is given by 1020 + 319 + 439 + 125 + 715 = $2618. One suspects that this is not the lowest cost tour. However, we do know that any tour with higher cost is not optimal. TSP: The Small Problem Modified The existence problem is almost never considered. We formulate standard problems with direct connections between each pair of cities. Those city pairs for which there is no real direct connection get a direct connection with an absurdly high cost, such as the sum of all of the costs for existing connections. Here is the modification of the problem above. Given five cities and the fact that the start city can be chosen arbitrarily, we have 4! = 24 different solutions to check in order to find the optimal. Our solution will assume that Seattle is the start city. TSP: Some Standard Observations on the Solution While we shall solve this problem instance by a direct approach, it is important to note that there are a number of tricks that allow one to obtain a solution more quickly. None of these are of theoretical importance, but they are convenient. We begin with the observation that any Hamiltonian cycle in a graph on N vertices requires N distinct edges. This gives a lower bound on the total cost. The five lowest cost edges have cost (107, 125, 319, 344, 439). The total cost for this collection of edges would be $1334. No cycle can have less cost. The five edges associated with this smallest possible cost are shown highlighted in the graph at left. Note that they do not form a cycle, much less a Hamiltonian cycle. On the rare occasions in which the N edges of smallest cost do form a Hamiltonian cycle, the problem is quickly solved. TSP: Start At Seattle (Page 3) Again, the answers found were SEA – ATL – DFW – MEX – MIA – SEA and its reverse SEA – MIA – MEX – DFW – ATL – SEA Here is the solution. For this problem instance, it is unique. Knapsack Problem Given a knapsack of capacity W and a list of N > 0 items with weights (W1, W2, …, WN) and values (V1, V2, …, VN). There are a few implied assumptions to the problem. 1. W1 + W2 + … + WN > W. Otherwise, just put everything in. 2. For each item we have both and VJ > 0 and 0 < WJ  W. Any single item too big for the knapsack can be disregarded. Select the variables: (X1, X2, …, XN), 0.0  XJ  1.0, such that V = X1V1 + X2V2 + … + XNVN is maximized, subject to X1W1 + X2W2 + …. + XNWN  W. The variable XJ represents the amount of item J placed into the knapsack. We shall develop a strategy for the knapsack problem that is occasionally useful and never gives rise to complications in the solution. We define an auxiliary variable J = VJ / WJ, which is the value density. Knapsack: Ordering by Value Density Given a knapsack of capacity W and a list of N > 0 items with weights (W1, W2, …, WN) and values (V1, V2, …, VN). Define the value density as J = VJ / WJ. Here the requirement that WJ > 0 immediately leads to the conclusion that each value density is well defined. Reorder the sets in non–increasing order of value density: 1  2  …  J  … N-1  N . The textbook’s example of Knapsack Problem. Item 1 2 3 4 Value 42 12 40 25 Weight 7 3 4 5 Value Density 6.0 4.0 10.0 5.0 Knapsack: One Observation on Brute Force The brute force approach calls for generation of all sets in the powerset. But note that the subset {1, 2} yields a weight that is too large. This implies that any set of which {1, 2} is a subset will also be too large. Based on this simple observation, we could rule out the following trial solutions. {1, 2} {1, 2, 3} {1, 2, 4} {1, 2, 3, 4} We also note that the set {2, 3} yields a weight that is too large. In addition to the above, this rules out {2, 3, 4}. More on this later. Knapsack: First Two Decisions This slide illustrates a decision tree approach that is often applied to such problems. Here we see that the partial solution {1, 2} should be abandoned; with it go one quarter of the twenty–four possible solutions. Job Shop Scheduling This is also called the assignment problem. The simplest form of the problem calls for N workers to be assigned to an equal number of jobs, with N  2. We are given an N–by–N matrix of costs, with entries C[I, J] being the cost to assign worker I to job J. We want to minimize the total costs of the assignments. The feasibility constraints are obvious: 1. Each worker is to be given exactly one job. 2. Each job is to be assigned to exactly one worker. In terms of the cost matrix, the translation of the requirements is also obvious: 1. Each row is to have exactly one element selected. 2. Each column is to have exactly one element selected. The answer is a total cost and either an array assigning jobs to workers or an array assigning workers to jobs; each will be a permutation of the set of integers {1, 2, …, N}. The Brute Force Solution Continues (3, 1, 2, 4) 7 + 6 + 8 + 4 = 25 (3, 1, 4, 2) 7 + 6 + 8 + 6 = 27 (3, 2, 1, 4) 7 + 4 + 5 + 4 = 20 (3, 2, 4, 1) 7 + 4 + 8 + 7 = 26 (3, 4, 1, 2) 7 + 7 + 5 + 6 = 25 (3, 4, 2, 1) 7 + 7 + 8 + 7 = 29 (4, 1, 2, 3) 8 + 6 + 8 + 9 = 31 (4, 1, 3, 2) 8 + 6 + 1 + 6 = 21 (4, 2, 1, 3) 8 + 4 + 5 + 9 = 26 (4, 2, 3, 1) 8 + 4 + 1 + 7 = 20 (4, 3, 1, 2) 8 + 3 + 5 + 6 = 22 (4, 3, 2, 1) 8 + 3 + 8 + 7 = 26 The winner is (2, 1, 3, 4) with a total cost of 13. Assignment Problem: The Winner The winner is (2, 1, 3, 4) with a total cost of 13. Worker A gets job 2. Worker B gets job 1. Worker C gets job 3. Worker D gets job 4. 1 2 3 4 A 9 2 7 8 B 6 4 3 7 C 5 8 1 8 D 7 6 9 4 Once again we are done with a brute–force solution that, due to the small size of the problem instance, is the easiest way to solve the problem. We now consider a few tricks that will facilitate solution of larger and more realistic instances of this and similar problems. Generating the Bounding Solutions The bounding solution will determine a lower bound on the costs. It will be generated without any regard to row or column constraints. Row Minimum: [Give each worker the cheapest job. Forget constraints.] Column Minimum: [Assign to each job the cheapest worker. Forget constraints.] Dogs, Cats, and Mice “And now for something completely different.” You're given a hundred dollars You are to spend it all purchasing exactly a hundred animals at the pet store. Dogs cost $15.00 each, Cats cost $1.00 each, and Mice are 25 cents each. You must buy at least one of each animal. You must spend exactly $100.00. How many of each type of animal do you buy? Formulation of the Problem Let D = the number of dogs C = the number of cats M = the number of mice There are two equations. 15D + C + 0.25M = 100 the cost equation D + C + M = 100 the number of animals equation Standard algebra requires three equations for a solution involving three unknowns. It is also the fact that standard algebra cannot easily restrict solutions to positive integers. We can solve this problem by exhaustive search, supplemented by a few observations about the problem. Dogs, Cats, and Mice: Observations 1 & 2 Observation 1 The counts of dogs, cats, and mice must be positive integers. Remember that you are required to buy at least one of each. Observation 2 The number of mice bought must be a multiple of 4. The sum 15D + C + 0.25M must be an integer, more specifically it is the integer 100. This implies that 0.25M must be an integer, hence M is an integer multiple of 4. As a corollary used in later work, we conclude that 0.75M must be an integer multiple of 3. Dogs, Cats, and Mice: More Cases Let D = 4. Then the equations become C + 0.25M = 40 C + M = 96 or 0.75M = 56, not a multiple of 3. Let D = 5. Then the equations become C + 0.25M = 25 C + M = 95 or 0.75M = 70, not a multiple of 3. Let D = 6. Then the equations become C + 0.25M = 10 C + M = 94 or 0.75M = 84 or M = 112, too many mice. The unique solution is thus D = 3, C = 41, and M = 56; three dogs, forty one cats, and fifty six mice. Algorithms for Evaluation of Trig Functions We now consider the problem of evaluating trigonometric functions for specified angles. At this point, we are not interested in: 1. The exact structure of the algorithm. 2. The fact that angles have to be expressed in radians, not degrees. 1 radian  57.2958 degrees One of the basic requirements for an algorithm is that it terminate. Given an arbitrary input, we must have a guarantee that, after a finite amount of time, the algorithm will stop and produce the correct answer. The mere fact that a complete algorithmic solution of a 50–city instance of TSP would require 1.931043 years on a 1–teraflop machine such as the Cray MT–5, does not negate the claim that we have an algorithm. Here the algorithm is guaranteed to terminate. Trig Functions: Terminating the Algorithm The problem with algorithms for evaluating the trigonometric functions is any algorithm that can be implemented on a digital computer is based on an infinite series. The details can be examined in any intermediate calculus course. Each term in the series can be computed by a finite application of basic operations, such as multiplication and division. There is no problem here. However, the series is infinite. There is no amount of time, however large, that will allow the complete evaluation of such a series. We must look for another termination criterion. There are only a very few angles for which the sine and cosine can be exactly evaluated. We all know these values. Our termination criterion thus becomes the accuracy required for the computation. Do we need 7–digit accuracy, 14–digit accuracy? The accuracy criterion is easily applied. There are formal mathematical models that indicate the number of terms needed for a given accuracy.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved