Sie sind auf Seite 1von 3

COMP 208: Computers in Engineering Winter, 2013 Assignment 3: Friends and More Friends

Due Date
Assignment 3 is due on Friday, February 22 at midnight. The cutoff is automated and is exactly at this time. Assignments submitted within the next hour will be considered late. After that time they will not be accepted at all. The assignment is to be done individually. You can collaborate on understanding the problem but you must write the solutions independently. Submissions might be subject to being checked by plagiarism detection software.

Introduction
On a social network site (Facebook, LinkedIn, etc..) pairs of people can be friends. If Alice is friends with Bob and Carol and David is also friends with Bob and Carol, then Alice and David have two mutual friends. If Alice and David are not friends, the site might suggest to each of them that they might want to become friends (since they have at least two mutual friends). The purpose of this assignment is to examine the set of friends in a social network and discover pairs of people who are not friends but have mutual friends.

Assignment
Your program should read a file containing a description of a social network. It should then output a list of suggested new friends for each pair of members of the network who have the most mutual friends.

Analysis
Suppose the social network has n members. The set of friends can be represented by an n by n two dimensional matrix. The entry F(i,j) equals 0 if member i and member j are not friends and equals 1 if they are friends. We also require that the diagonal elements (F(i, i)) be equal to 0 since a person cannot be friends with him or herself in the network. We note that the matrix is symmetric since if members i and j are friends, then F(i,j) = F(j,i) = 1.

Now consider the result of multiplying F by itself to produce the matrix F2. The values in this matrix are defined (using matrix multiplication) as . In the sum, the non-zero terms will be exactly those terms where F(i,k) and F(k,j) are both 1. That means that members i and j have member k as a mutual friend. In short, the sum counts the number of mutual friends that i and j have.

Methodology
Step 1: Read a data file describing a social network into a two dimensional array, say F. The file will consist of a line with the number of members of the array, n, followed by n lines which describe the friends of the corresponding member. A sample of data for a network with 27 members is provided below. You will be provided with more sets of data on MyCourses for testing your program. Your program should not make assumptions about the size of the data set other than to assume a maximum size such as 1000. Step 2: Define a subroutine to compute the product of two square n by n matrices. Your program should use this subroutine to multiply the friends array by itself and produce the array F2. Step 3: Define a subroutine which, given an n by n matrix, counts the number of how many members have 0, 1, 2, 3, 4, 5 or more than 5 mutual friends. In the sample data there is only one pair with 3 mutual friends but several with 2 mutual friends. Be careful not to double-count pairs of members. The matrix is symmetric so F2(i,j) and F2(j,i) will have the same values but should only be counted once. Also be careful not to count the diagonal entries since a member cannot be friends with him or herself. The subroutine should generate and return an array of length 7 with the counts for each category. Your program should use this subroutine to determine how interconnected the social network is. It should output the results of this search. Step 4: Output a list of suggested friends. The suggested friends are those in the top two non-zero categories. In the sample data provided below, the top non-zero entry is the one with 3 mutual friends. For this sample data your program should output suggested friends for members are not already friends and have 2 or 3 mutual friends. Again, do not output the same pair twice.

Requirements
The programs must be written in Fortran Define and use the subroutines as described above. Use meaningful variable names Comment and indent your code. It is your responsibility to make it readable to the grader Submit only the source file (.f90) and name your file A3_123456789 where 1234567898 is replaced by your student ID number.

Sample Data
27 000000000000000000000010000 000000000001000000000000000 000000000001000000100001000 000000000000000010100000000 000000001001100000000000000 000000000100000000000000101 000000001010001010100010001 000000000000000000000000100 000010100010000000101100010 000001000001100000001000000 000000101000000000000000000 011010000100000000000000000 000010000100010010001001000 000000000000101100000000010 000000100000010000000001000 000000000000010000000000000 000100100000100001010000100 000000000000000010000001000 001100101000000000000001100 000000000000000010001000000 000000001100100000010010001 000000001000000000000000100 100000100000000000001000000 001000000000101001100000000 000001010000000010100100000 000000001000010000000000000 000001100000000000001000000

Das könnte Ihnen auch gefallen