Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:659df3e8d3d6, committed 2015-12-04
- Comitter:
- Sarahi
- Date:
- Fri Dec 04 02:12:47 2015 +0000
- Parent:
- 0:9aa5f35f299c
- Commit message:
- Simulaciones proyecto3
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9aa5f35f299c -r 659df3e8d3d6 main.cpp
--- a/main.cpp Mon Nov 23 23:39:55 2015 +0000
+++ b/main.cpp Fri Dec 04 02:12:47 2015 +0000
@@ -12,17 +12,18 @@
#define M3 1
#define pQ3Q1 0.1 // probability of sending Q3 output to the Q1 input
#define pQ3Out 0.9 // probability of delivering Q3 output as system output
-#define tf 15
+#define tf 10000
#define lambda 10
#define pQ1I_Q2I 0.5
+#define sz_a 1000
-int Q1[20]= {0}; // initial Q1
-int Q2[20]= {0}; // initial Q2
-int Q3[20]= {0}; // initial Q3
+int Q1[sz_a]= {0}; // initial Q1
+int Q2[sz_a]= {0}; // initial Q2
+int Q3[sz_a]= {0}; // initial Q3
float t = 0; // initial simulation time
-float t_events_Q1[20] = {0}; // time stamps for the k events
-float t_events_Q2[20] = {0}; // time stamps for the k events
-float t_events_Q3[20]= {0}; // time stamps for the k events
+float t_events_Q1[sz_a] = {0}; // time stamps for the k events
+float t_events_Q2[sz_a] = {0}; // time stamps for the k events
+float t_events_Q3[sz_a]= {0}; // time stamps for the k events
int k=1; // event number
double SI = 0;
@@ -41,9 +42,9 @@
double SO = 0;
-float Q1_lambda [20]= {0};
-float Q2_lambda [20]= {0};
-float Q3_lambda [20]= {0};
+float Q1_lambda [sz_a]= {lambda*0.5};
+float Q2_lambda [sz_a]= {lambda*0.5};
+float Q3_lambda [sz_a]= {1/(u1*M1) + 1/(u2*M2)};
float t_Q1=0;
float t_Q2=0;
@@ -58,27 +59,32 @@
double min_3(double x, double y, double z);
int max_2(int x, int y);
double max_3(double x, double y, double z);
+float var_rand(float x);
+int Q1k;
+int Q2k;
+int Q3k;
+
+
+float x_i=0;
+float exprnd=0;
int i=0;
-int exprnd=1;
int main()
{
- Q1_lambda[0]= lambda*0.5;
- Q2_lambda[0]= lambda*0.5;
- Q3_lambda[0]= 1/(u1*M1) + 1/(u2*M2);
-
+
while( t <= tf ){
myled=0;
//exprnd(1/freq) simulate an exponential pdf with parameter = average time = 1 / arriving rate
- // System input
-
- SI = float(exprnd)*(1/float (lambda));
+ // System input
+
+ SI = var_rand(lambda);
+
// Q1
Q1I1 = Q3O/pQ3Q1;
Q1I2 = SI/0.5;
- //printf("Sl: %lf \n", SI);
+ printf("Sl: %lf \n", SI);
Q1_lambda [k]= (1/Q1I1 + 1/Q1I2);
//printf("Q1I1: %lf \n", Q1I1);
@@ -86,7 +92,8 @@
//printf("Q1_lambda: %f \n", Q1_lambda[k]);
if(Q1[k] > 0){
- Q1O = float(exprnd)*(1/(float(u1)*float (M1))); // service time in the queue
+ Q1O = float(u1)*float (M1); // service time in the queue
+ Q1O= var_rand(Q1O);
}
else{
Q1O= min_2(Q1I1,Q1I2)+1.0;
@@ -117,7 +124,8 @@
//printf("Q2_lambda :%f \n",Q2_lambda[k]);
if(Q2[k] > 0){
- Q2O = float(exprnd)*(1/(float(u2)*float(M2))); // service time in the queue
+ Q2O = float(u2)*float(M2); // service time in the queue
+ Q2O= var_rand(Q2O);
}
else{
Q2O = Q2I1 + 1.0;
@@ -150,7 +158,8 @@
//printf("Q3_lambda: %f \n",Q3_lambda[k]);
if(Q3[k] > 0){
- Q3O = float(exprnd)*(1/(float(u3)*float(M3))); // service time in the queue
+ Q3O = float(u3)*float(M3); // service time in the queue
+ Q3O= var_rand(Q3O);
}
else{
Q3O = min_2(Q1O, Q2O) + 1.0;
@@ -185,16 +194,65 @@
wait(0.5);
}
+
led_a=0;
-
+ wait(1);
+ pc.printf("k=");
+ pc.printf("%d\r\n",k);
+ wait(.5);
+
+ pc.printf("Q1\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%d, ",Q1[i]);
+
+ }
+
+ pc.printf("\n Q2\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%d, ",Q2[i]);
+
+ }
+
+ pc.printf("\n Q3\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%d, ",Q3[i]);
+
+ }
+
+ pc.printf("\n Q1_lambda\n");
for (i=0; i<=k; i++){
- pc.printf("%d",Q1[i]);
- pc.printf("%d",Q2[i]);
- pc.printf("%d",Q3[i]);
- pc.printf("%f",Q1_lambda[i]);
- pc.printf("%f",Q2_lambda[i]);
- pc.printf("%f",Q3_lambda[i]);
- }
+ pc.printf("%f, ",Q1_lambda[i]);
+
+ }
+
+ pc.printf("\n Q2_lambda\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%f, ",Q2_lambda[i]);
+
+ }
+ pc.printf("\n Q3_lambda\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%f, ",Q3_lambda[i]);
+
+ }
+
+ pc.printf("\n t_events_Q1\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%f, ",t_events_Q1[i]);
+
+ }
+ pc.printf("\n t_events_Q2\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%f, ",t_events_Q2[i]);
+
+ }
+
+ pc.printf("\n t_events_Q3\n");
+ for (i=0; i<=k; i++){
+ pc.printf("%f, ",t_events_Q3[i]);
+
+ }
+
led_a=1;
}
@@ -254,4 +312,12 @@
max=z;
}
return max;
+ }
+
+float var_rand(double x){
+ x_i= rand()%100;
+ x_i= x_i/float(100);
+ //pc.printf("x_i: %f\n",x_i);
+ exprnd=(-1.0)*float(x)*log(x_i);
+ return exprnd;
}
\ No newline at end of file