CEE 509/COM S 574 Heuristic Methods for Optimization Professors: C. Shoemaker, B. Selman Assignment 4: SA for Traveling Salesman Problem & Finite Capacity Scheduling Date assigned: Friday, February 21, 2003 Date due: Monday, March 3, 2003 TA: Abbas Kermani, Office hours: Wednesday 1-2pm, 328C Upson Hall NOTE: check the newsgroup and website regularly for hints or corrections, if any. website: http://www.cs.cornell.edu/courses/cs572/ newsgroup: cornell.class.cs572 1. (14 points) The Traveling Salesman Problem: Nearly all the heuristic methods that you learn about in this course have been widely applied to TSP. We would like to discover the shortest tour that visits each of n given locations exactly once. We will be using a standard benchmark problem called att48, which consists of 48 U.S. cities. i) ii) We can represent each possible solution as a permutation. Let us say we have n = 4, and the cities are numbered 1, 2, 3, and 4; then the only distinct solutions are [1 2 3 4], [1 2 4 3], and [1 3 2 4]. Note that all other permutations correspond to one of these three distinct tours. How many distinct tours are there when n = 48? (1 pt.) From the course homepage, download the following files into the directory where you will be working: R.txt, locations.txt, opt.txt, cost.m, and plotlocation.m. The description of these files is as follows: R.txt: This is an ASCII file that can be loaded using the "load" command in MATLAB. It defines a matrix R of size 48x48 describing the inter-city distances. You must declare R to be a global variable so that the cost function can access it. locations.txt: This is also an ASCII file that can be loaded into the MATLAB workspace. It defines a matrix locations of size 48x2, and consists of the x and y locations of the 48 cities. opt.txt: This is also an ASCII file. It defines a vector opt of size 1x48, which is the permutation corresponding to the optimal solution for this problem. You can compare your results with this data. cost.m: This MATLAB function computes the total length of a given tour (expressed as a permutation of numbers from 1 to 48). Before you call this function you must load the matrix of inter-city distances R. Test this function out in the MATLAB command window with the following commands: >> load R.txt %this loads R into the workspace >> global R %make R global >> load opt.txt %this loads opt into the workspace >> cost(opt) plotlocation.m: This function accepts as input a possible tour (represented by a vector of size 1x48) and plots the tour in blue, along with the optimal tour in red. Test it out by trying the following on the command window: >> load opt.txt % not needed if opt is already loaded into the workspace >> plotlocation(opt) %this will plot the optimal tour (in blue, dotted lines) iii) Explain how you can generate a vector sinitial of size 1x48 that contains a random permutation of the numbers from 1 to 48 using a single MATLAB statement. (Hint: this can be done using the MATLAB commands sort and rand). (1 pt.) iv) Write a MATLAB function neighbor.m with the header line function snew = neighbor(s, Ntype) that returns the neighbor of the input s ( a vector of size 1x48), based on the neighborhood type Ntype. The following are the neighborhood types: Ntype = 1: Adjacent Pairwise Interchange - In the given permutation randomly pick any position & exchange the number in that position with its neighbor to the right Ntype = 2: k-neighborhood with k = 2 - Take any two links in the existing tour and cut them, now reconnect the two disconnected paths so that they form a tour different from the original one. Recall from the lecture that this is equivalent to choosing a certain subsequence from the permutation and reversing it, while keeping all other elements of the permutation intact. Consider an example where the permutation is of size 6: scurrent = [1 3 5 6 4 2]. One possible 2-neighbor of this permutation (that is generated by reversing the underlined subsequence) is snew = [1 3 4 6 5 2]. (3 pt.) v) Run Random Sampling (Greedy Search) on this problem, using the neighbor.m file you wrote in part iv, the cost.m file provided, and your RS.m file from assignment 1 (with such minor modifications as may be needed. Determine empirically if this greedy random-sampling search tends to settle down in local / global minima within 10,000 iterations (note: 10,000 iterations take about 20 seconds on a Pentium II 450 MHz machine. Each call to cost.m is approximately 95 flops). If so, how many iterations on average does it take to reach a local/global minimum? You will need to run GS.m several times (at least 30 runs with a random sinitial each time) to get reasonable statistics. Do this for both Neighborhood types. Which neighborhood type works better with Greedy Search? Submit plots for each neighborhood type showing average Jbest with respect to iterations. Use plotlocation.m to obtain plots of the best final solution obtained for each of the neighborhoods and indicate their cost. (2 pts.) vi) Run Simulated Annealing on this problem, using SA.m. Assume beta = 1. For both neighborhoods, determine good values for Tinitial and Tfinal via experimentation using at least 5000 iterations on each run. Describe these experiments in brief & indicate which parameter values you chose for each neighborhood type & why. (3 pts.) vii) Now with the best initial and final temperatures you found in vi, and an appropriate value of alpha, run SA.m at least 10 times for 100,000 iterations for each of the two neighborhoods. Submit plots for each neighborhood type showing average Jbest with respect to iterations. Compute and submit the average and standard deviation of Jbest at the final iteration for each neighborhood type. Which neighborhood type works better with SA? Submit a plot of the single best solution to the TSP obtained in all these SA runs using plotlocation.m and indicate its cost. Were you able to find the optimal solution (if so, how often and on which iteration(s) )? Remark briefly on your results and how they compare with the answer in part i. (4 pts.) 2. (6 points) Finite Capacity Scheduling Consider the Job Shop Scheduling problem described by the data in the tables below. There are two machines and two jobs. Job 1 has 3 operations, and job 2 has 2 operations Machine for given operations and given jobs Job 1 2 Job Machine the Operation is done on Operation 1 Operation 2 Operation 3 1 2 1 2 1 n.a. 1 2 Processing Time of the Operation Operation 1 Operation 2 Operation 3 4 1 3 2 5 n.a. Job 1 2 Due Date for the Job 8 11 a. Draw a Disjunctive Arc Representation for the Sequencing Constraints, containing both conjunctive and disjunctive arcs, similar in structure to the graph on the right half of the 4th page of the handout. (Recall that conjunctive arcs are standard arcs, drawn as solid lines.) (Hint: There are 5 nodes, 3 conjunctive arcs, and 4 disjunctive arcs.) Now assume that we have decided to use the following sequences for the two machines: Machine 1: Operations 11, 22, 13. Machine 2: Operations 12, 21. Note: Operation 13 corresponds to job 1, operation 3. b. Draw a Network Arc Representation for this system, by orienting the disjunctive arcs in your previous diagram. c. Using your Network Arc Representation for this system, compute start times for each node as we did in class, using a longest-path computation. d. Draw a Gantt Chart for the schedule you computed in the previous part of this problem. What is the objective function value for this schedule? e. You would need a set of candidate solutions (sequences) that you want to search over (see VI.A.1 in the lecture notes). Identify them. (Hint: there are 3!·2!=12 of them, corresponding to all of the ways in which you can chose a permutation of the jobs on machine 1, and a permutation of the jobs on machine 2.) f. If you were to use Tabu Search or Simulated Annealing for this problem, in addition to a set of candidate solutions that you want to search over, you also need a neighborhood structure (see VI.C in the lecture notes). Identify the API neighborhood structure. Create a graph in which all of the nodes you identified in the pervious problem are the nodes, and the arcs represent the neighborhood structure. (Hint: there are 12 nodes, and 18 arcs.)