Example #1
0
        public Reporte(List <Core.MiembroFuncionObjetivo> FO, List <Core.Restriction> Rest, int Objetivo, int totalOfertantes, int totalDemandantes, List <double> demandas, List <double> ofertas)
        {
            InitializeComponent();

            FuncionObjetivo  = FO;
            Restricciones    = Rest;
            TotalOfertantes  = totalOfertantes;
            TotalDemandantes = totalDemandantes;
            Demanda          = demandas;
            Oferta           = ofertas;

            Simplex = new Core.Simplex(FuncionObjetivo, Objetivo);
            Simplex.AddRestriction(Restricciones);
            ReporteModelo = new Core.Reporte(Simplex);

            // Solución óptima
            SolucionOptimaDT = new DataTable();

            SolucionOptimaDT.Columns.Add(new DataColumn("Ruta", typeof(string)));
            SolucionOptimaDT.Columns.Add(new DataColumn("Valor", typeof(double)));
            SolucionOptimaDT.Columns.Add(new DataColumn("Coeficiente", typeof(double)));
            SolucionOptimaDT.Columns.Add(new DataColumn("Aporte", typeof(double)));

            var Solucion = ReporteModelo.Solucion();

            for (int i = 0; i < FuncionObjetivo.Count; ++i)
            {
                DataRow newRow = SolucionOptimaDT.NewRow();
                newRow[0] = FuncionObjetivo[i].Nombre;
                newRow[1] = Solucion[i].ToDouble();
                newRow[2] = FuncionObjetivo[i].Coeficiente;
                newRow[3] = FuncionObjetivo[i].Coeficiente * Solucion[i].ToDouble();

                SolucionOptimaDT.Rows.Add(newRow);
            }

            // Ofertantes
            OfertantesDT = new DataTable();

            OfertantesDT.Columns.Add(new DataColumn("Ofertante", typeof(string)));
            OfertantesDT.Columns.Add(new DataColumn("Disponibilidad", typeof(double)));
            OfertantesDT.Columns.Add(new DataColumn("Enviado", typeof(double)));
            OfertantesDT.Columns.Add(new DataColumn("% Enviado", typeof(string)));

            for (int i = 0; i < TotalOfertantes; ++i)
            {
                DataRow newRow = OfertantesDT.NewRow();
                double  temp   = 0;
                newRow[0] = "Ofertante " + (i + 1).ToString();
                newRow[1] = Oferta[i];
                for (int j = 0; j < TotalDemandantes; ++j)
                {
                    temp += Solucion[j * TotalOfertantes + i].ToDouble();
                }
                newRow[2] = temp;
                newRow[3] = (Math.Round((temp * 100) / Oferta[i], 2)).ToString() + "%";

                OfertantesDT.Rows.Add(newRow);
            }

            // Demandantes
            DemandantesDT = new DataTable();

            DemandantesDT.Columns.Add(new DataColumn("Demandante", typeof(string)));
            DemandantesDT.Columns.Add(new DataColumn("Requerido", typeof(double)));
            DemandantesDT.Columns.Add(new DataColumn("Recibido", typeof(double)));
            DemandantesDT.Columns.Add(new DataColumn("% Recibido", typeof(string)));

            for (int i = 0; i < totalDemandantes; ++i)
            {
                DataRow newRow = DemandantesDT.NewRow();
                double  temp   = 0;

                newRow[0] = "Demandante " + (i + 1).ToString();
                newRow[1] = Demanda[i];
                for (int j = 0; j < TotalOfertantes; ++j)
                {
                    temp += Solucion[j + i * TotalOfertantes].ToDouble();
                }
                newRow[2] = temp;
                newRow[3] = (Math.Round((temp * 100) / Demanda[i], 2)).ToString() + "%";

                DemandantesDT.Rows.Add(newRow);
            }

            // Bindings
            DT_Demandantes.DataContext = DemandantesDT;
            DT_Ofertantes.DataContext  = OfertantesDT;
            DT_Solucion.DataContext    = SolucionOptimaDT;

            // Labels
            double recursosUsados = Solucion.Sum(x => x.ToDouble()), demandaTotal = Demanda.Sum(), ofertaTotal = Oferta.Sum();

            L_ValorObjetivo.Content  += " " + ReporteModelo.ObtenerZ().ToString();
            L_Disponibilidad.Content += (ofertaTotal - recursosUsados).ToString();
            L_Requerimiento.Content  += (demandaTotal - recursosUsados).ToString();

            // Ficticios, que son básicamente las variables de holgura/excedente.
            // Las cantidad de pende de la demanda y oferta total, el que tenga menos será al que le toque ser ficticio.
            if (ofertaTotal != demandaTotal)
            {
                var HolguraExcedente = ReporteModelo.HolguraExcedente();
                // HolgutaExcedente: 1.- Oferta || 2.- Demanda || 3.- Requisitos
                if (ofertaTotal > demandaTotal)
                {
                    for (int i = 0; i < totalOfertantes; ++i)
                    {
                        DataRow newRow = SolucionOptimaDT.NewRow();
                        newRow[0] = String.Format("Demandante Ficticio -> Ofertante {0}", (i + 1));
                        newRow[1] = Math.Abs(HolguraExcedente[i]);
                        newRow[2] = 0;
                        newRow[3] = 0;

                        SolucionOptimaDT.Rows.Add(newRow);
                    }
                }
                else if (demandaTotal > ofertaTotal)
                {
                    for (int i = 0; i < totalDemandantes; ++i)
                    {
                        DataRow newRow = SolucionOptimaDT.NewRow();
                        newRow[0] = String.Format("Ofertante Ficticio -> Demandante {0}", (i + 1));
                        newRow[1] = Math.Abs(HolguraExcedente[totalOfertantes + i]);
                        newRow[2] = 0;
                        newRow[3] = 0;

                        SolucionOptimaDT.Rows.Add(newRow);
                    }
                }
            }
        }
Example #2
0
        public Reporte(List <Core.MiembroFuncionObjetivo> FO, List <Core.Restriction> Rest, int Objetivo)
        {
            InitializeComponent();

            FuncionObjetivo = FO;
            Restricciones   = Rest;

            Simplex = new Core.Simplex(FuncionObjetivo, Objetivo);
            Simplex.AddRestriction(Restricciones);
            ReporteModelo = new Core.Reporte(Simplex);

            // Informacion básica
            L_ValorObjetivo.Content += " " + ReporteModelo.ObtenerZ().ToString();
            L_Restricciones.Content += " " + Rest.Count;
            L_Variables.Content     += " " + FO.Count;

            // Variables
            DataTable VariablesDT = new DataTable();

            VariablesDT.Columns.Add(new DataColumn(String.Format("Nombre"), typeof(string)));       // 0
            VariablesDT.Columns.Add(new DataColumn(String.Format("Valor"), typeof(double)));        // 1
            VariablesDT.Columns.Add(new DataColumn(String.Format("Coeficiente"), typeof(double)));  // 2
            VariablesDT.Columns.Add(new DataColumn(String.Format("Contribución"), typeof(double))); // 3
            VariablesDT.Columns.Add(new DataColumn(String.Format("Minimo"), typeof(string)));       // 4
            VariablesDT.Columns.Add(new DataColumn(String.Format("Maximo"), typeof(string)));       // 5

            var Solucion         = ReporteModelo.Solucion();
            var LimitesVariables = ReporteModelo.LimitesCoeficientesObjetivo();

            for (int i = 0; i < FuncionObjetivo.Count; ++i)
            {
                DataRow newRow = VariablesDT.NewRow();
                newRow[0] = FuncionObjetivo[i].Nombre;
                newRow[1] = Solucion[i].ToDouble();
                newRow[2] = FuncionObjetivo[i].Coeficiente;
                newRow[3] = FuncionObjetivo[i].Coeficiente * Solucion[i].ToDouble();
                newRow[4] = LimitesVariables[i].Item1.ToString();
                newRow[5] = LimitesVariables[i].Item2.ToString();

                VariablesDT.Rows.Add(newRow);
            }

            // Restricciones
            DataTable RestriccionesDT = new DataTable();

            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Nombre"), typeof(string)));              // 0
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Signo"), typeof(string)));               // 1
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Lado B"), typeof(double)));              // 2
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Holgura o Excedente"), typeof(double))); // 3
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Dual"), typeof(double)));                // 4
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Minimo"), typeof(string)));              // 5
            RestriccionesDT.Columns.Add(new DataColumn(String.Format("Maximo"), typeof(string)));              // 6

            var HolguraExcedente     = ReporteModelo.HolguraExcedente();
            var Duales               = ReporteModelo.DualRestricciones();
            var LimitesRestricciones = ReporteModelo.LimitesRestriccion();

            for (int i = 0; i < Restricciones.Count; ++i)
            {
                DataRow newRow = RestriccionesDT.NewRow();
                newRow[0] = Restricciones[i].Nombre;
                newRow[1] = Core.Signos.IdSignoDictionary[Restricciones[i].Signo];
                newRow[2] = Restricciones[i].LadoB;
                Double temp = new Double();
                temp      = HolguraExcedente[i];
                newRow[3] = temp;
                newRow[4] = Duales[i];
                newRow[5] = LimitesRestricciones[i].Item1.ToString();
                newRow[6] = LimitesRestricciones[i].Item2.ToString();

                RestriccionesDT.Rows.Add(newRow);
            }

            // Bindings
            DG_Variables.ItemsSource     = VariablesDT.AsDataView();
            DG_Restricciones.ItemsSource = RestriccionesDT.AsDataView();
        }