Python代写-BUAI 492
时间:2021-10-03

BUAI 492 Individual Homework #3 INSTRUCTIONS: For all programs, you are expected to use good programming style (including good variable names and some data validation). Before class on the due date listed in the syllabus, upload to Canvas ONE Jupyter Notebook file with your solutions to the following exercises. The solution to each exercise should be stored, in order, in a separate cell whose first line is a comment with the exercise number (for example, #EXERCISE 1) and is followed by your solution). For any exercise whose solution is not a computer program, write your answer as a comment. For any program that involves writing a function, validate the inputs in the function and also include a main program that calls the function and displays the results. Failing to follow these instructions will result in a loss of points. DO NOT COPY SOMEONE ELSE’S ANSWERS! Exercise 1. A network consists of a collection of p circles, called nodes that represent objects in solving certain problems. The network also has q lines, called arcs that connect pairs of nodes to express a relationship between the objects represented by the connected nodes, for example: Write functions to perform each of the following tasks. a. Write a function called GetDataAL to get the data for a network from an EXCEL file in which values of p and q are given in cells A1 and B1. Then get the “arc list” starting in row 2 of the file, in which each arc’s two connected nodes are in given in column A and B (see the file ArcList.xlsx with the data of the network above). The arc list should be returned to main program as a list of lists with element 0 being the list [p, q]. (10 points) b. Write a function called IsInAL that determines if a given arc is, or is not, in the network (for example, the arc 2 – 4 is not in the network above). (5 points) c. Write a function called DegreesAL that returns a list of the “degrees” of all the nodes, where the degree of a node is the number of arcs coming out of that node (for the example above, the degree of Node 1 is 1 and the degree of Node 3 is 2). (10 points) d. Write a function called DeleteNodeAL that deletes a node from a network that is stored as an arc list, Of course you must also delete the all of the arcs coming out of the deleted node and reduce the number of all nodes greater than the number of the node being deleted. Return the new arc list to the calling program. (10 points) Exercise 2. Write the four functions in Exercise 1, but this time, the data for the network are stored in an “adjacency matrix”, say A, in which Aij = 1 if i – j is an arc in the network, and 0 otherwise. For example, the (5 x 5) adjacency matrix for the network in Exercise 1 is given in the file AdjacencyMatrix.xlsx (an empty cell indicates a value of 0 for the adjacency matrix). (Hint: Use the numpy method “delete” to delete a row and column of A.) (35 points) 2 4 3 1 0 3 Exercise 3. Perform each of the following tasks. a. Write a function called GetAMatrix that creates a (p x n) matrix A of random real numbers between –10 and 10 in the form of a numpy array, where p < n are both obtained from the user. (5 points) b. Write a function called GetBasics that, given the integers p and n, returns a list, say basics, of p different randomly-chosen values from 0, 1, …, n – 1 with the remaining values in 0, 1, …, n – 1 being stored in the list nonbasics. Do this by starting with basics = [ ] and nonbaiscs = [0, 1, …, n – 1]. Then sequentially use the “pop” method to move a random element of nonbasics to basics exactly p times. (5 points) c. Given the lists basics and nonbasics from part(b), write a function called GetBandN that returns the submatrix B consisting of the columns of A indexed by the list basics together with the submatrix N consisting of the remaining columns of A. (5 points) d. Write a function called inverse that determines whether the B matrix has an inverse and, if so, returns that inverse matrix. The function should also return a Boolean variable indicating whether the B matrix has an inverse (True) or not (False). (Hint: Use the subpackage linalg of numpy.) (5 points.) Exercise 4. The United Nations has N volunteers, each of who speaks exactly one of L foreign languages fluently. The individuals will be formed into a number of teams. Write the following functions, returning all outputs to the calling program and displaying the results of each function. (Hint: Think carefully about what type of data structures to use by working through some examples before you write any code.) a. Write a function call GetData that asks the user for the number of volunteers, N, the number of teams, T, number of languages, L, and the names of the languages (these languages are to be entered on a single line). For each volunteer, generate one random language that person speaks fluently. Return all of this information to the calling program. (10 points) b. Write a function called CreateTeams that puts the first T volunteers on teams 1, …, T and then assigns the remaining people randomly to the T teams. (10 points) c. Write a function called GetTeamLanguages that returns the languages spoken by each team. (10 points) d. Write a function called FindTeam that, given a collection of some languages, returns the number of the first team that speaks all of those languages or else returns -1 if there is no team that speaks all of those languages and displays a message. Test your function by getting a collection of some languages from the user in the main program. (10 points) e. Write a function called MovePerson that moves a given person from one given team to another given team and changes the languages spoken by the two teams. Call this function from the main program to move the first person on team 0 to the last team and display the new teams. (10 points) Exercise 5. Fill out the course evaluations at https://weatherhead.case.edu/courseevaluations/.






















































































学霸联盟


essay、essay代写