Commits

Arturo Hernandez  committed d34c977

Change the tabular data generation

Now that it reflects the use of a user defined value for alpha, in the
generateTabData method, refactor some variables.

Add accumulatedTime variable in the struct MvSimulationTable.

Split the variable poisson int poissonVar and poissonVarValue in the
same struct.

Add condition to test the very first variable/packet, so it's time of
arrival and accumulated time is effectively 0. Because.

Random changes in some comments. Also, add lotsa comments.

Add header definitions and QStandardItem generation in the showTabData
for the 'new' items to be shown.

  • Participants
  • Parent commits e16e1c0

Comments (0)

Files changed (2)

File mvGUIClient/mainwindow.cpp

 
 void MainWindow::on_btnGenerateTabData_clicked()
 {
-    // Instantiate all the objects we'll be using
+    // Instantiate all the objects we'll be using. Their names make clear what
+    // we are doing.
     MvLinearCongruential *mk = new MvLinearCongruential(
                 this->ui->inputDSB_X_Sim->value(),
                 this->ui->inputDSB_a_Sim->value(),
     MvPoissonRandVar *mprv = new MvPoissonRandVar(
                 this->ui->inputSB_LamdaSim->value());
 
-    MvExpoRandVar *mxrv = new MvExpoRandVar();
+    MvExpoRandVar *mxrv = new MvExpoRandVar(
+                this->ui->inputDSB_alpha_Sim->value());
 
     MvUniformRandVar *murv = new MvUniformRandVar(
                 this->ui->inputSB_limitBottom_Sim->value(),
                 this->ui->inputSB_limitUp_Sim->value());
 
-    // first, generate our Poisson Variables
+    // first, generate our Poisson Variables. This step is identical to the one
+    // in the on_btnPoissonVarGen_clicked method up there. In fact, it should be
+    // refactored
+    // TODO: refactor this loop into a function
     int spvars = this->ui->inputSB_VarQuantitySim->value();
     poissonVariables = new std::vector<int>();
     for (int i = 0; i < spvars; i++)
         mprv->resetVars();
     }
 
-    // Let's test if table exists, just in case something went wrong
+    // Let's test if table exists, just in case something went wrong. Not much
+    // as existing, as pointing to an existing object.
     if (table)
     {
         delete table;
     }
     table = new std::vector<MvSimulationTable>();
 
-    for (int i = 0; i < poissonVariables->size(); i++)
+    // Then a variable to accumulate time
+    double aT = 0.0;
+
+    // This loop first get the Poisson random variable, and using its value
+    // rolls another loop, for the number of packets that it represents.
+    // Then, in the inner loop, gets the values for its time and packet size,
+    // to then pass it to a variable of the structure type, so it is pushed into
+    // the array that hold the final table data (The one that is passed to the
+    // ui->tableView
+
+    for (unsigned int i = 0; i < poissonVariables->size(); i++)
     {
-        int alpha = poissonVariables->at(i);
-        for (int k = 0; k < alpha; k++)
+        unsigned int PoissonValue = poissonVariables->at(i);
+        for (unsigned int k = 0; k < PoissonValue; k++)
         {
-            double exp = mxrv->getExpoRandVar(alpha, ((float)mk->MvRand() / mk->m));
-            double uni = murv->getUniformRandVar(((float)mk->MvRand() / mk->m));
+            double exp = mxrv->getExpoRandVar( ((float)mk->MvRand() / mk->m) );
+            double uni = murv->getUniformRandVar( ((float)mk->MvRand() / mk->m) );
             struct MvSimulationTable t;
-            t.poisson = alpha;
+            t.poissonVar = (i + 1);
+            t.poissonVarValue = PoissonValue;
             t.packet = (k + 1);
-            t.time = exp;
-            t.size = uni;
+
+            // This little condition is for the very first 'packet' special case
+            // As the time is 'randomly' generated, it should not matter, as it
+            // does not affect posterior packets' times.
+
+            if (0 == i && 0 == k)
+            {
+                t.time = 0.0;
+            }
+            else
+            {
+                t.time = exp;
+            }
+
+            aT += t.time;
+            t.accumulatedTime = at;
+
+            t.size = (unsigned int) uni;
             table->push_back(t);
         }
     }
 
     // At this point, table shoud contain all the tabulated data.
-    // So let's clear all the objects, except, of course, the table.
+    // So let's clear all the objects, except, of course, the table one.
     delete mk;
     delete mprv;
     delete mxrv;
     // Now, let's initialize the pointer, with a literally "new" object
 
     simTableModel = new QStandardItemModel(this);
+
     simTableModel->setHorizontalHeaderItem(0,
                                            new QStandardItem(
-                                               QString("Variable Aleatoria Poisson")));
+                                               QString("V.A. de Possion #")));
     simTableModel->setHorizontalHeaderItem(1,
                                            new QStandardItem(
-                                               QString("Paquete en periodo de tiempo")));
+                                               QString("Valor de V.A. de Poisson")));
     simTableModel->setHorizontalHeaderItem(2,
                                            new QStandardItem(
-                                               QString("Tiempo entre arribo")));
+                                               QString("Paquete por valor de Poisson")));
     simTableModel->setHorizontalHeaderItem(3,
                                            new QStandardItem(
+                                               QString("Tiempo entre arribo")));
+    simTableModel->setHorizontalHeaderItem(4,
+                                           new QStandardItem(
+                                               QString("Tiempo acumulado")));
+    simTableModel->setHorizontalHeaderItem(5,
+                                           new QStandardItem(
                                                QString(
                                                    QString::fromUtf8("Tamaño de paquete"))));
 
     // having no way to output both data and index in the same sentence (as per
     // C++ 98), the 'old' way of doing it is used. That is, the (*). operator.
 
-    for (int i = 0; i < table->size(); i++)
+    for (unsigned int i = 0; i < table->size(); i++)
     {
         simTableModel->setItem(i, 0,
                                new QStandardItem(
-                                   QString::number( (*table)[i].poisson )));
+                                   QString::number( (*table)[i].poissonVar )));
         simTableModel->setItem(i, 1,
                                new QStandardItem(
-                                   QString::number( (*table)[i].packet )));
+                                   QString::number( (*table)[i].poissonVarValue )));
         simTableModel->setItem(i, 2,
                                new QStandardItem(
-                                   QString::number( (*table)[i].time )));
+                                   QString::number( (*table)[i].packet )));
         simTableModel->setItem(i, 3,
                                new QStandardItem(
+                                   QString::number( (*table)[i].time )));
+        simTableModel->setItem(i, 4,
+                               new QStandardItem(
+                                   QString::number( (*table)[i].accumulatedTime )));
+        simTableModel->setItem(i, 5,
+                               new QStandardItem(
                                    QString::number( (*table)[i].size )));
 
     }
     this->ui->tableView->resizeColumnsToContents();
     this->ui->tableView->resizeRowsToContents();
 
-    // And now, delete the table, because we have already graphicated it.
+    // And now, delete the "table", because we have already graphicated it.
     delete table;
     table = NULL;
 

File mvGUIClient/mainwindow.h

 }
 
 struct MvSimulationTable {
-    int poisson;
-    int packet;
+    unsigned int poissonVar;
+    unsigned int poissonVarValue;
+    unsigned int packet;
     double time;
-    double size;
+    double accumulatedTime;
+    unsigned int size;
 };
 
 class MainWindow : public QMainWindow