# This is a test file for your Julia extra credit project. You will only # need the section that corresponds to the problem you have chosen to do. # You'll have noticed that this is a .jl file, which is the same a .txt # file with a different file type that lets Julia know that this is a # Julia program. Lines that start with a '#' are called 'comments' are # are ignored by the program, so I can write instructions to you in the # comments without the program thinking that it is supposed to interpret # those lines. # Problem 1: Nearest neighbor implementation # I'll set an Int64 value vnum of vertices, # i.e. vnum, not necessarily 5, but some positive integer. vnum = 5 # I'll also give you the edges for the weights, an Array{Float64, 1}(enum) # (i.e. a 1 dimensional array of length enum, with Float64 values for # each element), where enum is the number of edges on a complete graph # with vnum vertices (Hint: you should know how to calculate this number # using binomial coefficients!). The weights will be in a list, so to # know which weights correspond to which edges you'll need to generate # the edges to be in order (see the example edges below). weights = [2.2, 4.2, 6.0, 5.4, 7.1, 3.1, 9.8, 9.1, 3.6, 0.3] # Then you can use the following code to make a list of vertices, where # each vertex is identified by a number. vertices = collect(1:vnum) # You will need to write your own code that will generate the edges for # the complete graph with vnum vertices. For vnum = 5, you should get: edges = Array{Array{Int64, 1}, 1}(10) edges[1] = [1, 2] edges[2] = [1, 3] edges[3] = [1, 4] edges[4] = [1, 5] edges[5] = [2, 3] edges[6] = [2, 4] edges[7] = [2, 5] edges[8] = [3, 4] edges[9] = [3, 5] edges[10] = [4, 5] # Just remember that you need to generate these edges JUST BY KNOWING THE # NUMBER OF VERTICES, so you can't just figure out what the edges should # be by doing it out by hand. I will enter the edges for you when I run # your program. Make sure as well that your edges are in order just like # for this example. # Now you just need to write your code that will calculate the nearest # neighbor circuit, starting and ending at vertex 1. Your code should # calculate the nearest neighbor path, nn_path, as an # array of the vertices traversed, in order, and the cost of traversing # this path, nn_cost. For this example, your result should be nn_cost = 13.4 nn_path = [1, 2, 4, 5, 3, 1] # Problem 2: Adjusted winner procedure implementation # I'll give you two lists of point values that each have the same length, # i.e. the number of items being divided, and each list of point values # will sum to 100. For example, you might get a_points = [20, 30, 25, 15, 10] b_ points = [15, 25, 20, 10, 30] # But remember that I might give you a pair of points-lists with a # different length and different values. # Now you'll write your own code to calculate which parties get which # items, where you'll refer to each item as its position in the two lists # of points, e.g. the item designated 1 was given 20 points by a and 15 # points by b. Your answer for this example should be a_whole_items = [1, 4] b_whole_items = [2, 5] shared_item = 3 x = 0.1111111111111111 # Problem 3: Jefferson method implementation # I'll give you a number of seats, seat_num, and an array of population # values, populations. For example: seat_num = 8 populations = [89, 30, 25] # So we have a house with 8 seats and three states with populations 89, # 30, and 25. Your program should then compute how many seats are given # to each state (referred to by their position in the populations list, # so the state 1 has population 89, state 2 has population 30, and state # 3 has population 25). # Your answer for this example should be apportionment = [5, 2, 1]