A 3 Social Network

download A 3 Social Network

of 3

Transcript of A 3 Social Network

  • 7/28/2019 A 3 Social Network

    1/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 tobeing 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, thenAlice 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 shouldthen 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 nby 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.

  • 7/28/2019 A 3 Social Network

    2/3

    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 nlines 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. Yourprogram should use this subroutine to multiply the friends array by itself and producethe array F2.

    Step 3: Define a subroutine which, given an n by n matrix, counts the number of howmany 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 thediagonal 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 networkis. 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 theone with 3 mutual friends. For this sample data your program should output suggested

    friends formembers 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 thegrader

    Submit only the source file (.f90) and name your file A3_123456789 where1234567898 is replaced by your student ID number.

  • 7/28/2019 A 3 Social Network

    3/3

    Sample Data

    27

    000000000000000000000010000000000000001000000000000000

    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