Computes a minimum-weight spanning tree

Assignment Help C/C++ Programming
Reference no: EM131750144

Assignment -

In Assignment 1, your program can successfully read in an input file that describes n = NUM_PT points in the two-dimensional plane, within the rectangular area [0, MAXA x [0, MAX_Y]. Your program for Assignment #2 computes a minimum-weight spanning tree (MST) for these n points. By executing the following command,

>myprogram - i instance10_001.txt

your program appends the edges of the MST to the input file instance10_001 txt , one in a line as: i i* d(i, i*)

where pi and pi* are the two end points of the edge, pi is the parent of pi., and d(i, e) is the weight of the edge (the distance between the two points).

The goal of Assignment #3 is to lay down the edges of the MST to achieve the maximum total overlap, and to conduct numerical experiments to collect the statistics (Lecture slide set #11 contains some illustration). The following list contains the specifications for Assignment #3 (10 marks in total):

1. Using the following command to run your program for Assignment #3,

>myprogram      instance10_002 txt          output10_002 txt]

Here the input file instance10_002 txt is in the format resulted from Assignment #2 (provided as the sample input in eClass), that is, it contains the edges of the MST.

The option "-o output10_002.txt" specifies a file to write the program output; if it is not there, your program writes output to stdout data stream.

2. The following data type is strongly recommended to be used in your program; the subsequent des¬cription is based on this struct:

struct point {

int index;                             /* the order in the instance file */

int x;                                      /* x coordinate */

int y;                                      /* y coordinate */

int parent;                           /* parent in the tree when added            */

int num_children;            /* has value 0 -- 8            */

int child[8];

int overlap_hv;                 /* total overlap when horizontal then vertical */

int overlap_vh;                 /* total overlap when the other way      */

};

Essentially, this new data type is for storing information associated with a point, which has a number of entries and their meanings. In particular, it is guaranteed that the number of child¬ren num_children one can have is at most 8; the member overlap_hv' records the total overlap of the subtree rooted at the edge (parent , index) when the edge (parent , index) is laid as an L-shape first horizontally out of parent then vertically to reach index (that is, parent is incident at the horizontal portion of the edge and i is incident at the vertical portion of the edge; in the degenerate case, the horizontal portion or the vertical portion of the edge has length 0).

When a variable of struct point is declared, all its members are initialized to -1, indicating invalid values, except .num_children initialized to 0.

In the sequel, assume you declare the following array to store the n points: struct point p [n];

3. Assume the first given point in the instance file has index/subscript 0 (that is, p [0] is the root of the MST). If n = 1, your program terminates without doing anything; otherwise (i.e., n > 1), your program prints to the output the values of all the members for the second point (i.e., p [1] ), one in a line. For the member array . child, you only need to print out the children that are > 0. These form the first set of lines in the output; print an empty line after them.

Using the sample input file in.stance10_002.txt, your program should print the following out:

p [1] . index = 1;

p [i] .x = 0;

p [1] .y = 90;

p [1] .parent = 5;

p [1] .num_children = 0;

p [1] . child 181 = {};

p [1] overlap_hv = 0;

p [1] . overlap_vh = 0;

4. Starting with the root of the MST, your program prints to the output the following members in one line:

. index, .num_children, . child [0] , . . . child [ .num_children - 1]

Then recursively prints the same information for each child. These form the second set of lines in the output; print an empty line after them.

(This is the depth-first-search order of the points, or the DFS order.)

Using the sample input file instance10_002 txt , your program should print the following out:

p [0] . index = 0,                .num_children = 1, . child [0] = 9                               

p [9] . index = 9 , .num_children = 1, . child [0] = 4                             

p [4] . index = 4,                .num_children = 1, . child [0] = 5                               

p [5] . index 5, .num_children = 2, . child [0] = 8, . child [1] = 1

p [8] . index = 8,                .num_children = 1, . child [0] = 7                               

p [7] . index = 7,                .num_children = 2, . child [0] = 3, . child [1] = 6

p [3] . index = 3,                .num_children = 0                                                                          

p E61 . index = 6, .nurn_children = 1, . child [0] =                2                             

p [2] . index = 2,                .num_children = 0                                                                          

p Eli . index = 1, .num_children = 0

5. Let O denote the reversed DFS order.

Using the sample input file instance10_002 txt , this order 0 (using the indices of the points) is 1, 2, 6, 3, 7, 8, 5, 4, 9, 0

Suppose point pi is at the head of the order 0. There are two possible cases (also refer to lecture slide set lecturell.pdf):

(a) pi has no children ( .num_children = 0). In this case, set both members . overlap_hv and . overlap_vh to 0, and pi is said processed and removed from 0.

(b) pi has . num_children > 0 children. In this case, all the children must have been processed. When the edge ( . parent, 1) is laid as first horizontally out of . parent then vertically to reach for each combination of how the edges (i, . child [j )'s for j = 0, 1,        , .num_children -1 are laid, compute the overlap of these .num_children +1 edges and add the .overlap_xx's of all its children. (Here xx corresponds to how the edge (i, . child [j] ) is laid out.) This is the total overlap for the combination. Among all combinations, the maximum total overlap is set for the member . overlap_hv of point pi.

In the same way, compute . overlap_vh for point pi.

Afterwards, pi is said processed and removed from O.

Note: when pi is the root (that is, the last point in 0), which has no parent, only the combinations of the child edges are examined to compute . overlap_hv for point pi, and we certainly have .overlap_vh = .overlap_hv.

6. Your program prints to the output the following lines (the last/third set of lines):

The total overlap is .overlap_hv (%d)

The reduction rate is ...(%.2f) and appends to the instance file the following comment lines: #The total overlap is .overlap_hv (%d)

#The reduction rate is ...(%.2f) where . overlap_hv is replaced by its value for the root, and the reduction rate is calculated as .overlap_hv divided by the length of the MST.

1. Use your program for Assignment #1 to generate 100 random instances for each of n = 100, 200,300, 400, 600, 800,1000 (7 values), with the fixed circuit board area [0,1000] x [0,1000].

The instance files are "instanceXXX_YYY.txt", where XXX is the number n of points, and YYY ranges from 001 to 100.

2. For each n, run your programs (for Assignment #2 and Assignment #3) on the 100 instances, to obtain the average reduction rate, the average execution time (in minutes and seconds) of your program for Assignment #2, and the average execution time (in minutes and seconds) of your program for Assignment #3.

3. Print these values in the following way (as a text file named result_yourCCID.txt): n, reduction rate, running time for A2, running time for A3 one row for each n.

4. Submit this file together with your C program for Assignment #3.

Attachment:- Assignment File.rar

Reference no: EM131750144

Questions Cloud

Develop three to four-page analysis on the projected return : Develop a three to four-page analysis on the projected return on investment for your college education and projected future employment
Discuss enjoy the benefits of benchmarking : Suppose you were a manager for Delta Airlines. Your company wishes to enjoy the benefits of benchmarking
Select an industry or firm : Select an industry or firm. State its market structure (pure competition, monopoly, monopolistic, or oligopoly). Next, please define the characteristics
Compute the impact of various subscription prices : If, after the offering, total after-tax earnings for the coming year are expected to be $20,000,000, and dividends of $0.72 per share are to be maintained.
Computes a minimum-weight spanning tree : our program for Assignment #2 computes a minimum-weight spanning tree (MST) for these n points. By executing the following command,
Explain in detail the meaning of substitute goods : Assume that Big Mac hamburgers and Whopper hamburgers are substitutes for each other. If the price of only Big Macs drops, what will likely happen.
Compute the roi of the teen division : Compute the ROI of the Teen division if the embroidery machine is purchased
Calculate the percentage change in the warrants floor value : Calculate the percentage change in the warrants' floor value for a ± 1 5-percent change in the market price of the shares.
Examine the extent to which two issues are occurring : Some of the most serious abuses taking place in developing countries deal with child labor, human slavery, sweatshops, bad governance.

Reviews

len1750144

12/5/2017 1:05:18 AM

Topic: C program. The above specifications on your program for Assignment #3 worth 8 marks. The second task in this assignment is as follows, and worths 2 marks. For each n, run your programs (for Assignment #2 and Assignment #3) on the 100 instances, to obtain the average reduction rate, the average execution time (in minutes and seconds) of your program for Assignment #2, and the average execution time (in minutes and seconds) of your program for Assignment #3. Print these values in the following way (as a text file named result_yourCCID.txt): n, reduction rate, running time for A2, running time for A3 one row for each n. Submit this file together with your C program for Assignment #3.

Write a Review

C/C++ Programming Questions & Answers

  Prepare a program to add the specific numbers

Write a program that will read in 5 numbers and add 10 to the first number, 20 to the second number, and 30 to the third number, 40 to the fourth and 50 to the 50th.

  Consider implementing subnetting to support three department

Consider implementing subnetting to support three departments within an organization. The three departments P, Q and R need support for 30, 40 and 60 hosts.

  Solution to the quadratic equation

The program should allow the user to input the particular integer coefficients of the quadratic equation and properly output either real or complex number solutions for the roots of the equation

  Discuss the differences concerning how a program would acces

Discuss the differences concerning how a program would access the members of objects that have been declared as an array of objects

  Describe an example application of polymorphism

Provide and describe an example application of polymorphism that could be used in a program solution. List and describe the class relationships.

  That reads ten numbers from input and prints

Write a C program that reads ten numbers from input and prints them in reverse order. We assume that the data consists of integers. The program should conform to the following format

  Program that would display a letter to a friend

Writing a c++ program that would display a letter to a friend? It should have a proper format like name, friends name, address.....etc

  Reads from the external file input.txt

Program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.tx

  What does the return statement do

What is the purpose of the function header?How may you identify the body of a function?  What does the return statement do?

  Write a program for a palindrome

Write a program for A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindromes with minimum number of character replacements..

  Program that evaluates a infix expression

Program that evaluates a infix expression using stacks terminated by an equal sign. for example: (4-2)-5)/(2+1)-2))=the expression will contain single digit and the operators +, -, *,/. Make sure to consider the operator precedence.

  Roles of human resource professionals

"I would like to discuss how IS has positively impacted the roles of human resource professionals.  Specifically, I would like to look at data storing and how having this information stored in an HRIS system helps human resource professionals beco..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd