NetSim Source Code Help
Loading...
Searching...
No Matches
Distribution.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "Application.h"
15static long double ErrorFun(double p);
16/** This function is used to run the distributions */
17_declspec(dllexport) int fnDistribution(DISTRIBUTION nDistributionType, double *fDistOut,
18 unsigned long *uSeed, unsigned long *uSeed1,double* args)
19{
20 double fFirstArg = 0.0;
21 double fSecondArg = 0.0;
22 double fRand = 0.0;
23 double fRandomNumber = 0.0;
24 int nRandOut = 0;
25
26 switch (nDistributionType)
27 {
28 case Distribution_Exponential: /*Exponential Distribution Function*/
29 fFirstArg = args[0];
30 nRandOut = fnRandomNo(10000000, &fRand, uSeed, uSeed1);
31 fRandomNumber = (double) (fRand);
32 fFirstArg = 1 / fFirstArg;
33 *fDistOut = (double) -(1 / fFirstArg)
34 * (double) logl(1 - fRandomNumber);
35 break;
36 case Distribution_Uniform: /*Uniform distribution Function*/
37 fSecondArg = args[1];
38 fFirstArg = args[0];
39
40 nRandOut = fnRandomNo(10000000, &fRand, uSeed, uSeed1);
41 fRandomNumber = (double) (fRand);
42 *fDistOut = fFirstArg + (fSecondArg - fFirstArg) * fRandomNumber;
43 break;
44 case Distribution_Triangular: /*Triangular Distribution Function*/
45 fFirstArg = args[0];
46 fSecondArg = args[1];
47 nRandOut = fnRandomNo(10000000, &fRand, uSeed, uSeed1);
48 fRandomNumber = (double) (fRand);
49 if (0 <= fRandomNumber && fRandomNumber <= 0.5) {
50 *fDistOut = (double) sqrt(2 * (double) fRandomNumber);
51 } else if (fRandomNumber > 0.5 && fRandomNumber <= 1) {
52 *fDistOut = 2 - (double) sqrt(2 * (1 - (double) fRandomNumber));
53 }
54 break;
55 case Distribution_Weibull: /*Weibull Distribution Function*/
56 fFirstArg = args[0];
57 fSecondArg = args[1];
58 nRandOut = fnRandomNo(10000000, &fRand, uSeed, uSeed1);
59 fRandomNumber = (double) (fRand);
60 *fDistOut = (fFirstArg * (double) pow((-(double) logl(1 - (1
61 - fRandomNumber))), 1 / fSecondArg));
62 break;
63 case Distribution_Constant: /*Constant Distribution function*/
64 fFirstArg = args[0];
65 *fDistOut = fFirstArg;
66 break;
67 case Distribution_Backlog:/*BackLog Distribution. Not used as of NetSim v7 */
68 *fDistOut = 0.0;
69 break;
70
71 case Distribution_Normal:/*Normal Distribution Function on 25-12-2007 by Shashi kant*/
72 fFirstArg = args[0];
73 fSecondArg = args[1];
74 nRandOut = fnRandomNo(10000000, &fRand, uSeed, uSeed1);
75 fRandomNumber = (double) (fRand);
76 *fDistOut = (double) (fFirstArg + fSecondArg * sqrt(2) * ErrorFun(2
77 * fRandomNumber - 1));
78 break;
79 }
80 return 1;
81}
82/** Error inverse Function for Normal Distribution */
83static long double ErrorFun(double p)
84{
85 return (1.0968 * (sqrt(3.1415) * 0.5 * (p + (3.1415 * pow(p, 3)) / 12 + (7
86 * pow(3.1415, 2) * pow(p, 5)) / 480 + (127 * pow(3.1415, 3) * pow(
87 p, 7)) / 40320)));
88}
89
int fnRandomNo(long lm, double *fRandNo, unsigned long *uSeed, unsigned long *uSeed1)
Definition: RandomNumber.c:19
int fnDistribution(DISTRIBUTION nDistributionType, double *fDistOut, unsigned long *uSeed, unsigned long *uSeed1, double *args)
Definition: Distribution.c:17
static long double ErrorFun(double p)
Definition: Distribution.c:83
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
@ Distribution_Triangular
Definition: Packet.h:42
@ Distribution_Exponential
Definition: Packet.h:40
@ Distribution_Weibull
Definition: Packet.h:43
@ Distribution_Backlog
Definition: Packet.h:45
@ Distribution_Constant
Definition: Packet.h:44
@ Distribution_Normal
Definition: Packet.h:46
@ Distribution_Uniform
Definition: Packet.h:41
enum enum_Distribution DISTRIBUTION
Definition: main.h:122