Changeset 61e2bc2 in mmcs for mainwindow.C


Ignore:
Timestamp:
Jul 26, 2016, 10:17:16 AM (8 years ago)
Author:
rudmanmrrod <rudman22@…>
Branches:
master
Children:
588814f
Parents:
4d3d740
Message:

Agregados cambios alas matrices Ma, Mb, An y Bn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mainwindow.C

    r4d3d740 r61e2bc2  
    944944
    945945            QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
     946            TotalPrincipalTable(tw,PrincipalTable,2);
    946947            bool iguales = true;
    947948            CalcularTotales(tw,2,iguales);//Se llama a la funcion que agregue una nueva fila y columna con los totales respectivos
     
    965966            QMessageBox::warning(this,"Alerta","Debe llenar correctamente y agregar todas las cuentas");
    966967        }
     968    }
     969}
     970
     971/*
     972    Función que almacena los valores de la tabla principal en una matriz
     973    Autor: Rodrigo Boet
     974    Fecha: 21/06/2016
     975    @param <QTableWidget> *tw -> Recibe como parametro una widget de tabla de qt
     976*/
     977void MainWindow::TotalPrincipalTable(QTableWidget *tw,MatrixXd &Matriz,int init)
     978{
     979    int cantidad=tw->rowCount();
     980    Matriz.resize(cantidad-1,cantidad-1);
     981    for(int i=init;i<cantidad;i++)
     982    {
     983        double totalFila = 0;
     984        double totalColumna = 0;
     985        for(int j=init;j<cantidad;j++)
     986        {
     987            QString itemf=Separador(tw->item(i,j),true);
     988            double thisFila=itemf.toDouble();
     989            QString itemc=Separador(tw->item(j,i),true);
     990            double thisCol=itemc.toDouble();
     991            Matriz(i-init,j-init) = thisFila;
     992            Matriz(j-init,i-init) = thisCol;
     993            totalFila += Matriz(i-init,j-init);
     994            totalColumna += Matriz(j-init,i-init);
     995        }
     996        Matriz(i-init,cantidad-init) = totalFila;
     997        Matriz(cantidad-init,i-init) = totalColumna;
     998
    967999    }
    9681000}
     
    10231055    Valor->setFlags(Valor->flags() ^ Qt::ItemIsEditable);
    10241056    tableWidget->setItem(filas,columnas,Valor);
    1025     //
    10261057    int cantidad = tableWidget->rowCount();
    10271058    ItemsNoEditable(tableWidget,0,inicio-1,cantidad-1);
     
    11511182void MainWindow::CalcularAn(QTableWidget *tw,QTableWidget *nuevaTabla,QTableWidget *tablaOriginal,int count,bool endogena)//Funcion para calcular el Coeficiente Tecnico Horizontal (An)
    11521183{
     1184    if(endogena)
     1185    {
     1186        An.resize(count-3,count-3);
     1187    }
    11531188    for(int i=0;i<count-1;i++)
    11541189    {
     
    11681203                else
    11691204                {
    1170                     value = Separador(tw->item(count-1,i),true);
    1171                     value = QString::number(value.toDouble(),'f',precission);
    1172                     total=value.toDouble();
     1205                    total = PrincipalTable(count-3,i-2);
    11731206                }
    1174                 QString values = Separador(tw->item(j,i),true);
    1175                 values = QString::number(values.toDouble(),'f',precission);
    1176                 double valor=values.toDouble();
     1207                double valor=PrincipalTable(j-2,i-2);
    11771208                if(total==0)//Se comprueba en caso de que el total sea zero
    11781209                {
     
    11901221                ValoraInsertar->setTextAlignment(Qt::AlignCenter);
    11911222                nuevaTabla->setItem(j,i,ValoraInsertar);
     1223                if(endogena)
     1224                {
     1225                    An(j-2,i-2) = valor;
     1226                }
    11921227            }
    11931228            /****           En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/
     
    15321567    for(int i=0;i<count-1;i++)
    15331568    {
    1534         QString STotal = Separador(tw->item(i,count-1),true);
    1535         double total=STotal.toDouble();//Se obtiene el total de esa columna
     1569        //Se obtiene el total de esa columna
     1570        double total = PrincipalTable(i,count-3);
    15361571        for(int j=0;j<count-1;j++)
    15371572        {
    15381573            if(i!=0 && j!=0)
    15391574            {
    1540                 QString value = Separador(tw->item(i,j),true);
    1541                 double valor=value.toDouble();
     1575                double valor = PrincipalTable(i-1,j-1);
    15421576                if(total==0)//Se comprueba en caso de que el total sea zero
    15431577                {
     
    15511585                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
    15521586                ValoraInsertar->setTextAlignment(Qt::AlignCenter);
    1553                 value = Separador(ValoraInsertar,false);
     1587                QString value = Separador(ValoraInsertar,false);
    15541588                ValoraInsertar->setText(value);
    15551589                CT_HorizontalTW->setItem(i,j,ValoraInsertar);
     
    17621796                if(i>=2 && j>=2)
    17631797                {
    1764                     QString value = Separador(tablaPPAL->item(i,j),true);
    1765                     double valor=value.toDouble();
     1798                    QString value;
     1799                    double valor=PrincipalTable(i-2,j-2);
    17661800                    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',precission));
    17671801                    value = Separador(ValoraInsertar,false);
     
    17911825                    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem;
    17921826                    ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
     1827                    ValoraInsertar->setTextAlignment(Qt::AlignCenter);
    17931828                    tablaEE->setItem(i,j,ValoraInsertar);
    17941829                }
     
    17961831             }
    17971832        }
    1798 
    17991833        /***                    Se acomodan los componentes de las cuentas exogenas                 ***/
    18001834        int cantidad = tablaEE->rowCount()-elementos;
     
    18591893        CalcularTotales(matrizEndogena,2,var);
    18601894
     1895        TotalPrincipalTable(tablaEE,EndogenasyExogenas,2);
    18611896        CalcularTotales(tablaEE,2,var);
    18621897        setEndogenaExogenaCell(tablaEE,inicioExogena,elementos,true);
     
    19722007    spanEndogenaCell(tablaAn,2,0,false);//Se juntan los espacios de las cuentas
    19732008    tabWidget->removeTab(indice);
    1974     crearMatrizEndogena(tablaAn);
    19752009}
    19762010
     
    19812015}
    19822016
    1983 
    1984 void MainWindow::loadMatrizExogena()
    1985 {
    1986 
    1987 }
    19882017
    19892018/***     Funcion para retornar todos los componentes en una lista     ***/
     
    21092138}
    21102139
    2111 /*              Funcion que crea la matriz endogena-endogena        */
    2112 void MainWindow::crearMatrizEndogena(QTableWidget *tw)
    2113 {
    2114     int cantidad=tw->rowCount();
    2115     MatrixXd ident = MatrixXd::Identity(cantidad-1,cantidad-1);
    2116     MatrizEndogenaEndogena = ident;
    2117     for(int i=0;i<cantidad;i++)
    2118     {
    2119         for(int j=0;j<cantidad;j++)
    2120         {
    2121             if(i>=2 && j>=2)
    2122             {
    2123                 double valor=tw->item(i,j)->text().toDouble();
    2124                 MatrizEndogenaEndogena(i-2,j-2) = valor;
    2125             }
    2126 
    2127          }
    2128     }
    2129 }
    2130 
    21312140/*          Funcion que determina los Multiplicadores de Leontief       */
    21322141void MainWindow::restarIdentidadAn(QTableWidget *tw)
     
    21392148        for(int j=0;j<cantidad-1;j++)
    21402149        {
    2141             A(i,j) = ident(i,j)-MatrizEndogenaEndogena(i,j);
     2150            A(i,j) = ident(i,j)-An(i,j);
    21422151        }
    21432152    }
     
    24192428        QString cuenta = tw->item(i,1)->text();
    24202429        QString value = Separador(tw->item(i,cantidad-1),true);
    2421         double total = value.toDouble();
    24222430        if(totalCuentas.contains(cuenta))
    24232431        {
    2424             totalCuentas[cuenta] += total;
     2432            totalCuentas[cuenta] += EndogenasyExogenas(i-3,cantidad-4);
    24252433        }
    24262434        else
    24272435        {
    2428             totalCuentas.insert(cuenta,total);
     2436            totalCuentas.insert(cuenta,EndogenasyExogenas(i-3,cantidad-4));
    24292437        }
    24302438    }
     
    36383646
    36393647    crearMatrizExgEnd(MatrizEndogenaExogena,MatrizExgEnd,elementos,inicioExogena);
     3648    TotalEndoExoTable(elementos,inicioExogena);
    36403649    calcularMatrizExgEnd(MatrizExgEnd);
    36413650    ctvMatrizExgEnd(MatrizExgEnd,Bn);
     
    36803689}
    36813690
     3691/*
     3692    Función que almacena los valores del fragmento exogeno/endogeno la tabla Tipo de variables
     3693    Autor: Rodrigo Boet
     3694    Fecha: 22/06/2016
     3695    @param <int> elementos -> Recibe como párametro la cantidad de elemntos que tiene esa sección
     3696    @param <int> cantidad -> Recibe como parametro el inicio de del fragmento exogeno/endogeno
     3697*/
     3698void MainWindow::TotalEndoExoTable(int elementos, int cantidad)
     3699{
     3700    ExoEndo.resize(elementos,cantidad-3);
     3701    for(int i = 0;i<elementos;i++)
     3702    {
     3703        for(int j=0;j<cantidad-3;j++)
     3704        {
     3705            int value = (cantidad-3)+i;
     3706            ExoEndo(i,j) = EndogenasyExogenas(value,j);
     3707        }
     3708    }
     3709}
     3710
    36823711/*      Funcion para calcular los totales de la matriz Exógena-Endógena     */
    36833712void MainWindow::calcularMatrizExgEnd(QTableWidget *MatrizExgEnd)
     
    37093738    int fila = MatrizExgEnd->rowCount()-1;
    37103739    int columna = MatrizExgEnd->columnCount();
     3740    MBn.resize(fila-2,columna-2);
    37113741    QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
    37123742    int totalLocal = tw->rowCount()-1;
    37133743    for(int i = 0; i<columna; i++)
    37143744    {
    3715 
    3716         QString value;
    37173745        double total;
    37183746        for(int j = 0;j<fila;j++)
     
    37203748            if(i>=2 and j>=2)
    37213749            {
    3722                 value = Separador(tw->item(totalLocal,i),true);
    3723                 total = value.toDouble();
     3750                total = PrincipalTable(totalLocal-2,i-2);
    37243751                double valoraInsertar;
    37253752                if(total==0)
     
    37293756                else
    37303757                {
    3731                     QString valor = Separador(MatrizExgEnd->item(j,i),true);
    3732                     valoraInsertar = valor.toDouble();
     3758                    valoraInsertar = ExoEndo(j-2,i-2);
    37333759                    valoraInsertar /= total;
    37343760                }
     3761                MBn(j-2,i-2) = valoraInsertar;
    37353762                QTableWidgetItem *item = new QTableWidgetItem(QString::number(valoraInsertar,'f',precission));
    37363763                QString value = Separador(item,false);
     
    38243851    int fila = Bn->rowCount();
    38253852    int columna = Bn->columnCount();
    3826     QTableWidget *Ma = findChild<QTableWidget *>("MatrizMa");
    3827     int count = Ma->rowCount();
    3828     MatrixXd Mbn(fila-2,columna-2);
    3829     MatrixXd Mma(count-2,count-2);
    3830     for(int i=2;i<columna;i++)
    3831     {
    3832         for(int j=2;j<fila;j++)
    3833         {
    3834             QString valueb = Separador(Bn->item(j,i),true);
    3835             double doubleb = valueb.toDouble();
    3836             Mbn(j-2,i-2) = doubleb;
    3837         }
    3838     }
    3839     for(int i=2;i<count;i++)
    3840     {
    3841         for(int j=2;j<count;j++)
    3842         {
    3843             QString valuem = Separador(Ma->item(i,j),true);
    3844             double doublem = valuem.toDouble();
    3845             Mma(i-2,j-2) = doublem;
    3846         }
    3847     }
    3848     MatrixMb = Mbn*Mma;
     3853    MatrixMb = MBn*MatrixMa;
    38493854    for(int i=0;i<columna;i++)
    38503855    {
Note: See TracChangeset for help on using the changeset viewer.