Cell phone tower capacity

Sorry this is long but I am almost finished with this assignment and just cannot finish the last part. I have all the signal strengths in an array such that:
The first set of 8 are signals from tower 1 to the 8 phones, and now i need to assign the phones to a tower based on the max occupancy that is given by the user but i am stuck. Here are the instructions and the code i have so far, thanks for any help.




You are an engineer at a wireless phone company that has just expanded its coverage. Given the
new tower configuration, you are tasked with writing a program that determines the best tower to serve
each customer’s mobile device. Ideally the tower with the strongest signal should be assigned to serve
each mobile device. However each tower can serve a limited number of mobile devices. Thus, if the
tower that has the strongest signal for mobile device X is already serving at its full capacity, then mobile
device X gets served by the tower with the next strongest signal that is not at full capacity.
For this assignment you are going to get the tower configuration from a file that contains the
tower ID, 2D coordinates and the cell tower mean radius separated by one space. Each line except the
first line describes a cell tower. The first line contains the number of towers in the file. The file has the
following structure:
File name: towers.txt
First line: Number of towers in the file
All other lines: Tower data (one tower per line, attributes separated
by space).
Tower attribute information:
1. Tower_ID
2. X_coordinate
3. Y_coordinate
4. Radius
The mobile devices list is given in another file, which contains their ID and the 2D coordinates.
Assume that the mobile devices given in the phones.txt file connect to the strongest tower in the
order given by the phones.txt file. . The phones.txt file has the following structure:
File name: phones.txt
First line: Number of phones in the file
All other lines: Phone data (one phone per line, attributes separated
by space).
Phone attribute information:
1. Phone_ID
2. X_coordinate
3. Y_coordinate
Example input files above can be found on ICON.
In both files the distance units are given in kilometers (km). Compute the estimated signal
strength (in decibels relative to milliwatts) between a phone and a tower using the following estimation
formula:
𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆 π‘†π‘†π‘†π‘†π‘†π‘†π‘†π‘†π‘›π‘›π‘›π‘›π‘›π‘›β„Ž = βˆ’113.0 βˆ’ 40.0 𝑙𝑙𝑙𝑙𝑙𝑙10(π‘Ÿπ‘Ÿ/𝑅𝑅)
Where r is the distance of the mobile device to the tower, and R is the radius of the tower. You
can compute the distance r between a mobile device and a tower using Pythagoras’s theorem and the
tower and mobile device coordinates.
All towers have the same service capacity (i.e. number of mobile devices it can serve). However
it can be changed when upgrades are made. Thus your program should take the tower capacity number
as an input from the user.
You should output to the screen a mapping of each mobile device ID to the tower ID that serves it. Also
include the signal strength, the distance to the tower, and whether or not this is the closest tower to the
device.
Here is an example of the output to be printed to the screen using the
inputs found on ICON and a tower capacity of 2:
Tower capacity: 2
Phone_ID Tower_ID Distance Signal_strength Closest_tower
0 1 4.24264 -74.0231 no
1 1 4.24264 -74.0231 no
2 0 1.41421 -79.0206 yes
3 0 1.41421 -79.0206 yes
4 2 7.07107 -106.979 no
5 2 7.07107 -106.979 no
6 3 9.89949 -112.825 no
7 3 9.89949 -112.825 no
For grading purposes, your program will be tested with a set of input files other than the one provided
to you.
You MAY assume that there will only be a maximum of 1000 towers and a maximum of 1000 phones.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
double idTower[1000];//array containing the ID# to each tower, up to 1000
double towerX[1000];//array containing the x-coordinates to each tower, up to 1000
double towerY[1000];//array containing the y-coordinate to each tower, up to 1000
double tRadius[1000];//array containing the radius to each tower, up to 1000

double idPhone[1000];//array containing the ID# to each phone, up to 1000
double phoneX[1000];//array containing x-coordinates of phones, up to 1000
double phoneY[1000];//array containing y-coordinates of phones, up to 1000

double phone[1000];//array that takes in data from phones.txt
double tower[1000];//array that takes in data from towers.txt
int maxCapacity;

int main()
{
    cout << "Enter a number for the capacity of each tower" << endl;//takes in number for max occupancy of each each tower
    cin >> maxCapacity;
    //cout << maxCapacity << endl;
    double distance[4000];
    double signalStrength[4000];
    ifstream phones;
    ifstream towers;

    phones.open("phones.txt");
    if ( phones.fail() ) //check if open failed
    {
        cerr << "File phones.txt could not be opened";
        return -1; //return an error code
    }
    for(int i=0; !phones.eof(); i++){
		phones >> phone[i];
		cout << phone[i] <<" ";
    }
    cout << endl;

    towers.open("towers.txt");
    if ( towers.fail() )
    {
        cerr << "File towers.txt could not be opened";
        return -1;
    }
    for(int i=0; !towers.eof(); i++){
		towers >> tower[i];
		cout << tower[i]<< " ";
    }
    cout << endl;
    int k = 0;


    for (int i = 1; i <= ((phone[0])*(3)); i = i+3){ //Puts the ID# of the phones into an array
        idPhone[k] =  0 + phone[i];
        cout << idPhone[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 2; i <= ((phone[0])*(3)); i = i+3){ //Puts the x-coordinate of the phones into an array
        phoneX[k] =  0 + phone[i];
        cout << phoneX[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 3; i <= ((phone[0])*(3)); i = i+3){ //Puts the y-coordinate of the phones into an array
        phoneY[k] =  0 + phone[i];
        cout << phoneY[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 1; i <= ((tower[0])*(4)); i = i+4){ //Puts the ID# of the towers into an array
        idTower[k] =  0 + tower[i];
        cout << idTower[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 2; i <= ((tower[0])*(4)); i = i+4){ //Puts the x-coordinate of the towers into an array
        towerX[k] =  0 + tower[i];
        cout << towerX[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 3; i <= ((tower[0])*(4)); i = i+4){ //Puts the y-coordinate of the towers into an array
        towerY[k] =  0 + tower[i];
        cout << towerY[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;

    for (int i = 4; i <= ((tower[0])*(4)); i = i+4){ //Puts the radius of the towers into an array
        tRadius[k] =  0 + tower[i];
        cout << tRadius[k] << " ";
        k++;
        }
    cout << endl;
    k = 0;
    int j = 0;



    cout << endl;


    while (j < tower[0]){// Finds the distance from tower to cell phones. Format:(first tower to all phones, second tower to all phones, etc)

        for (int i = 0; i < phone[0]; i++){
            distance[k] = 0 + ((towerX[j] - phoneX[i])*(towerX[j] - phoneX[i]))+((towerY[j] - phoneY[i])*(towerY[j] - phoneY[i]));
            distance[k] = 0 + sqrt(distance[k]);
                cout << distance[k]<< " ";
            k++;
        //j++;
        }
        cout << endl;

        j++;
    }

    j = 0;
    k = 0;

    while (j < tower[0]){

        for (int i = 0; i < phone[0]; i++){
            signalStrength[k] = ((-113.0)+((-40)*(log10((distance[k])/(tRadius[j])))));//finds the signal strength from tower
            // to phones. Format (first tower to all phones, second tower to all phones, etc.)
                cout << signalStrength[k] << " ";
                k++;
        }
        cout << endl;

        j++;
        }

    





    cout << endl;
    return 0;
}

Last edited on
Topic archived. No new replies allowed.