Computer Sciences Dept.

CS 838 Pervasive Parallelism Fall 2005 Section 3
Instructor Mark D. Hill
URL: http://www.cs.wisc.edu/~markhill/cs838/Fall2005/

Homework 4 // Due at Lecture Wednesday, October 5, 2005

WARNING: This is harder than earlier assignments!

Please direct questions to Dan Gibson (gibson[at]cs.wisc.edu) who helped create this assignment.

Perform this assignment on cabernet.cs.wisc.edu, a 16-processor Sun E6000, where we have activated a CS account for you. (Unless you already had an account, you should only use this machine only for 838-3 homework assignments or your course project. Unless you have a longer connection to CS, this account and its storage will be removed after the end of the semester.)

You should do this assignment alone. No late assignments.

Purpose

The purpose of this assignment is to consider how sequential programs can be parallelized with various parallel APIs, and to further understand the advantages and disadvantages of the APIs presented in class.

Programming Environments: MPI, P-Threads, OpenMP

See earlier homeworks for descriptions of programming environments.

Programming Task: Genetic Algorithm for the Traveling Salesperson Problem

The Traveling Salesperson problem (TSP) is a frequently-used computer science problem. The aim of TSP is to find a minimum-distance path between some number of cities that a salesperson might follow on a business trip. The best path is the path that has the shortest total round-trip distance--from an arbitrary starting city, though all other cities, and back to the starting city. Unfortunately, finding the best path is an NP-complete problem. In fact, the known (perfect) solutions are not much better than exhaustively testing all possible solutions. Exhaustive-search is bounded by O(N!), where N is the number of cities. Since we will be working on TSP of size N=1217 or more, we will use a heuristic-guided genetic search algorithm to find a good rather than optimal solution.

Genetic algorithms (GAs) are derived from the concept of natural selection. They are essentially random-search algorithms that maintain a (large) pool of potential solutions to the given problem (a population of solutions), from which new and better solutions are formed through crossover (the process by which two or more solutions are combined to form a new solution), similar to the recombination of DNA. At each time-step (commonly known as a generation), the pool of solutions is evaluated according to a fitness function. The least-fit solutions are removed from the population (as in natural selection), leaving the most-fit members of the population to "breed" the next generation of solutions.

GAs are susceptible to "getting stuck" in local minima of the fitness criteria, so it is vital to include mutations in the genetic process. After a crossover, the resulting solution (child) should be mutated with incidence rM (i.e. if rM=0.2 then 20% of the children should be mutated at random in a given time-step). Mutation usually involves drastic changes in solution structure to introduce new "genes" to the population that would not normally arise through crossover.

Genetic Alg. Pseudocode

For those unfamiliar with the implementation of genetic algorithms, a simple example of a GA is available here, with a pseudocode explanation of the genetic process in genetic.txt.

Problem 1: Write Sequential Genetic Algorithm to Approximately Solve TSP

Implementing a genetic algorithm for the TSP problem requires careful consideration of what constitutes a population, a fitness, a crossover, etc. Below, we provide definitions of these and other terms which you may choose to adopt for your implementation. You may choose not to adopt these definitions without penalty. The definitions are provided primarily for those who are not already familiar with the implementation of GAs.

Population Member: an array of integers, each representing one city. The array begins with zero, and the order in which other values appear defines the order that the traveling salesperson will visit the other cities. Since our version of TSP requires a complete circuit, all rotations of a given ordering are equivalent. (i.e. {0,1,2,3} is equivalent to {2,3,0,1})

Population: A (large) group of population members.

Fitness: A population member's fitness is defined as the total distance of travel represented by the order of cities. For the purposes of determining fitness, we will assume that 1) there are straight-line routes connecting all cities and 2) the Earth is flat, so given longitude and latitude of a location, the distance to another location is simply the Pythagorean distance.

Crossover: The process by which two parent population members are combined to form a child. Specifically, crossover must produce only valid solutions (i.e. no city may appear more than once, and each city must appear in the child solution). Many GAs operate on strings that must produce constrained solutions; example crossover operations may be found in literature, such as: K. Shahookar and P. Mazumder, A Genetic Approach to Standard Cell Placement Using Meta-Genetic Parameter Optimization, in: IEEE Trans. on Computer-Aided Design, Vol. 9, No. 5, May 1990. You are free to implement any crossover function that you wish, but keep in mind that crossover is the primary means by which solutions are improved. More on crossover functions here.

Mutation: A population member is mutated by swapping the positions of one to three randomly selected cities in the array.

Input files will be provided, defining names of cities and their respective longitudes and latitudes. Your implementation must be capable of parsing input files in the format provided. The first line of each file contains only a single integer--the number of entries that follow on subsequent lines. All other lines consist of a tuple: [latitude] [longitude] [name of city]. Note that [name of city] is a string and may contain spaces.

In some input files, cities are repeated with multiple longitude and latitude pairs. Consider these to represent multiple stops in the same locale for the traveling salesperson.

Link to input files

Your implementations' argument stream is defined as:

[input file] [population size] [number of generations] [crossover rate] [mutation rate] [number of threads] [random seed]

Population size and the number of generations are integers, which you may assume are greater than two. Crossover and mutation rates are floating-point values, on the range [0.0,1.0]. The number of threads is ignored for the sequential implementation, and may be considered to be a power of two for other implementations. Furthermore, you may assume population size * crossover rate, population size * (1+crossover rate), and population size are all evenly divisible by the number of threads.

Real genetic algorithms usually use heuristics to guide the generation of their initial populations. Since we wish to study parallelization, you need not implement this. If you are interested in tuning your algorithm for better solutions, you may wish to implement a more sophisticated method for generating initial populations.

Problem 2: Write Parallelized Genetic TSP Programs

You will implement two parallelized versions of your genetic solution to TSP. Parallelize your TSP implementation from Problem 1 using any two of the following: MPI, P-Threads, OpenMP.

There are many parallel implementations of genetic algorithms. For this assignment, you may use any parallelization techniques you prefer.

As an additional exercise, you may wish to parallelize your code using all three APIs. However, only two implementations will be graded, and no additional credit will be given for three implementations.

Problem 3: Analysis of Parallel Genetic TSP

In this section, we will analyze the performance of your three Genetic TSP implementations.

Modify your programs to measure the execution time of the parallel phase of execution. Use of Unix's gethrtime() is recommended. Do not use the time Built-in TCL command.

Plot the normalized (versus the serial version) speedups of the programs from Problem 2 on N=[1,2,4,8,16] using usa.in as the input file, a population size of 4096, and a crossover rate of 25% over 50 generations. You may select the mutation rate as you prefer to provide the best final solution.

Repeat for input file Wisconsin.in on a separate graph. The other input files are provided for testing purposes. We may run your code on other input files of the same format.

Tips and Tricks

Start early.

Make use of the demo programs provided.

You can use /usr/platform/sun4u/sbin/prtdiag -v on cabernet to learn many useful characteristics of your host machine.

What to Hand In

Please turn this homework in on paper at the beginning of lecture.

A description of your method of parallelization for Programs 2. Which parts of your program were easy to parallelize with each API? Which parts were not parallelized in your implementation? Which implementation performs best?

A printout of the parallel phase of Program 1.

A printout of the parallel phase of Programs 2.

Printout of a (good) TSP solution for Wisconsin.in.

The plots as described in Problem 3.

Important: Include your name on EVERY page.

 
Computer Sciences | UW Home