-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_func.c
107 lines (88 loc) · 3.34 KB
/
main_func.c
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
#include "code.h"
#include "main_func.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main_func(int length, int maxAttempt, int m, int C, int j, int T, int T1, int T2, int R){
float totalContending;
int raDuration = j;
//Allocating memory for UE status information
float** contendingUE_array = (float**) calloc(length+1,sizeof(float*));
for(int i=0;i<length+1;i++){
contendingUE_array[i]=(float*) calloc(maxAttempt+1,sizeof(float));
}
float** successUE_array = (float**) calloc(length+1,sizeof(float*));
for(int i=0;i<length+1;i++){
successUE_array[i]=(float*) calloc(maxAttempt+1,sizeof(float));
}
float** collidedUE_array = (float**) calloc(length+1,sizeof(float*));
for(int i=0;i<length+1;i++){
collidedUE_array[i]=(float*) calloc(maxAttempt+1,sizeof(float));
}
//Main Testing Program
//Initialize contending UE with m on the first attempt (one-shot arrival)
for(int i=0;i<length+1;i++){
for(int j=0;j<maxAttempt+1;j++){
if(i>=1 && i<=raDuration && j==1){
contendingUE_array[i][j]=(float)1000/raDuration;
successUE_array[i][j]=0;
collidedUE_array[i][j]=0;
}else{
contendingUE_array[i][j]=0;
successUE_array[i][j]=0;
collidedUE_array[i][j]=0;
}
}
}
//Calculating Mi, Mis, Mif for all i value
for(int i=0;i<length+1;i++){
if(i>1){
calculate_contending_UE(i,contendingUE_array[i],maxAttempt,collidedUE_array,C,j,T,T1,T2); //Calculate contending UE if i>1 (the first slot is the initial transmission of one-shot arrival process)
}
totalContending=total_contending_UE(contendingUE_array[i],maxAttempt);
calculate_success_UE(contendingUE_array[i],successUE_array[i],maxAttempt,totalContending,R); //calculate success UE in a particular slot
calculate_collided_UE(contendingUE_array[i],collidedUE_array[i],maxAttempt,totalContending,R); //calculate collided UE in a particular slot
contendingUE_array[i][0]=totalContending;
}
printf("======This is contending UE======\n\n");
for(int i=1;i<length+1;i++){
for(int j=1;j<maxAttempt+1;j++){
printf("%f",contendingUE_array[i][j]);
printf("\t");
}
printf("\n");
}
printf("======This is Success UE======\n\n");
for(int i=1;i<length+1;i++){
for(int j=1;j<maxAttempt+1;j++){
printf("%f",successUE_array[i][j]);
printf("\t");
}
printf("\n");
}
printf("======This is Collided UE======\n\n");
for(int i=1;i<length+1;i++){
for(int j=1;j<maxAttempt+1;j++){
printf("%f",collidedUE_array[i][j]);
printf("\t");
}
printf("\n");
}
writeToCSV(contendingUE_array,successUE_array,collidedUE_array,length,maxAttempt);
//Deallocating Memory
for(int i=0;i<length+1;i++){
free(contendingUE_array[i]);
}
free(contendingUE_array);
for(int i=0;i<length+1;i++){
free(successUE_array[i]);
}
free(successUE_array);
for(int i=0;i<length+1;i++){
free(collidedUE_array[i]);
}
free(collidedUE_array);
}
int main(){
main_func(180,2,1000,1,6,60,60,0,112);
}