Вы находитесь на странице: 1из 2

proj3-page 1 of 2

ECE 3331 Project 3 Fall 2011


(due 10/10/11 5 pm)
All fields of engineering involve situations where the proper allocation of resources is a critical problem. Consider for example a situation in which four kinds of resources--labor, metals, plastics, and electronic components--are required to produce each unit of four different types of computers. This information may be summarized in a "resource" matrix A as shown below: Product Charlie Snoopy Lucy Linus | | | | | Labor 3 4 7 20 Metals 20 25 40 50 Plastics 10 15 20 22 Electronics 10 8 10 15

The total number of each computer produced is constrained by the total resources available. If R is the vector showing the total amounts of each resource available, and we assume that all resources are to be used, then the system of linear equations ATX = R determines the amount of each product that can be produced. Now suppose that we have the option of increasing any one of the available resources. The linear system then becomes ATY = R+E where E is zero except for the particular resource to be increased. If A is invertible, then Y =(AT)-1R+(AT)-1E = X+(A-1)TE so that Y-X = (A-1)TE. Since E has only one non-zero entry, we see that the impact of a unit increase in a specific resource can be seen by examining the inverse of the resource matrix: . . . . 0 0817 0 1066 0 1368 0 0888 . . . . 0 2256 0 1728 0 0213 1 = 0 0396 A 0 1465 0 4085 0 1909 0 0071 . . . . . . . . 0 1918 0 0107 0 1137 0 0089 Each element of the inverse refers to the effect of increasing resource i on product j. The rows of the inverse correspond to resources while the columns correspond to products. For example, the (2,1) element specifies that an increase of 0.0396 unit of Charlie will result from an additional unit of metal. Notice that some of the entries are negative, signifying that a unit increase in some resources will actually decrease the production of certain of the computers. The profit per unit of each computer is summarized in a profit vector: Product Profit Charlie | 1000 Snoopy | 700 Lucy | 1100 Linus | 400 To evaluate the benefit to be gained by increasing each resource, multiply the resource inverse by the vector giving . 12204 63 24 . the profit per product to get the expected change in profit due to a unit increase in each resource: 67 70 . . 77 78 Thus an increase in electronics(j=4) will yield the greatest increase in profit, followed closely by an increase in the amount of metals, while increases in labor or plastics will result in profit decreases. You are to write a C program that will do the following: (1)Input from a data file named cp3.dat a sequence of resource and profit arrays together with the names of the resources and products. The first line of the file contains a single integer which should be stored in a variable named num, the number of resources and products. The second line contains the names of the individual resources, separated by semicolons. These should be stored in a character array reslbl, one name per row. The third line contains the names of the individual products, separated by semicolons. These should be stored in a character array prdlbl, one name per row. The next num lines contain the rows of the resource matrix. These should be stored in a matrix named resource. The next line contains the profit vector. This should be stored as a row vector named profit, of course. Your program should be designed to read one set, perform the analysis described below, and then loop back to read another set until all data has been processed. You may assume that the maximum number of resources and products is 10, and that the maximum number of characters in a name is 8. Thus you should #define the constants MAXNUM as 10 and MAXLEN as 9 (which allows for the null at the end of the names).

proj3-page 2 of 2

(2)Output to a file named <cougarnet username>cp3.out (e.g. brshethcp3.out) the resource matrix and the profit vector with neatly labeled row and column headings as illustrated above. This should be done by invoking, for both the resource matrix and the profit vector, a function whose prototype is void tablewrite(int nrow,int ncol, double mat[][MAXNUM],char rowlbl[][9],char collbl[][9],char title[30],char rowtitle[9],FILE *fout) The input arguments are nrow, the number of rows; ncol, the number of columns; mat, the nrowncol matrix; rowlbl, the character array containing the labels for the rows of the matrix, one label per row; collbl, the character array containing the labels for the columns of the matrix, one label per row; title, a string containing a title for the table; and rowtitle, a string containing a label to appear over the individual row labels, and a pointer to the output file. . (3)Invoke a function to invert the resource matrix. This function, whose prototype is int matinv(int n,double a[ ][MAXNUM],ainv[ ][MAXNUM]), will be available for you to copy from the course website. It should be included in your source file when you test your program and when you turn it in. The function returns the integer 1 if the inversion succeeded and the integer 0 if it did notpresumably because the input matrix was singular. The arguments are n=size of matrix, a=matrix to be inverted, and ainv=inverse matrix, to be found. (4)Use tablewrite to output the inverse, remembering that the rows of the inverse correspond to resources while the columns correspond to products. (5)Locate the negative elements of the inverse and for each, output a statement to the effect that "A unit increase in resource XXXXX will result in a decrease of ZZZZZ in product YYYYYYY". (6)Invoke a function to multiply the inverse times the profit vector to determine the profit change vector. This function should have a prototype of void matvec(int n, double mat[ ][MAXNUM],double rowvec[ ][MAXNUM],double prodvec[ ][MAXNUM]). The function should be designed to multiply the nn matrix mat times the transpose of the 1n vector rowvec to get the n1 product and then transpose it to get the 1n prodvec (7)Use tablewrite to output the profit change vector. (8)Find the largest component of the profit change vector and output a statement of the form "The greatest increase in profit will result from an increase in resource XXXXXX", or, if all of the components of the profit change vector are negative, output a statement that no resources should be increased. No global variables are allowed! A sample data file, cp3.dat will be available on the web site.

Вам также может понравиться