Ejemplo n.º 1
0
        public bool ExecuteFuzzyPrimalSimplex(string sheetName)
        {
            bool                          isCorrect = false;
            ConectorDatosApp              conector  = new ConectorDatosApp();
            FuzzyPrimalSimplexService     service   = new FuzzyPrimalSimplexService();
            InitialFuzzyBasicSolution     initial   = new InitialFuzzyBasicSolution();
            KeyValuePair <string, double> minVar    = new KeyValuePair <string, double>();
            KeyValuePair <string, double> pivot     = new KeyValuePair <string, double>();

            if (!string.IsNullOrWhiteSpace(sheetName) && conector.GetFuzzyDataSimplex(Path, sheetName, out FuzzyTableau tableau) && initial.Check(ref tableau))
            {
                while (!service.CheckEnd(tableau))
                {
                    service.Pivoting(ref tableau, out minVar, out pivot);
                    service.ReduceColumns(ref tableau, pivot, minVar.Key);
                }

                if (tableau != null && tableau.isSolution)
                {
                    Trace.TrazaTextoConFecha(Constantes.TextoSiSolucion);
                    Trace.TrazaSolution(service.GetSolution(tableau));
                    isCorrect = true;
                }
            }
            else
            {
                Trace.TrazaTextoConFecha(Constantes.TextoNoSolucion);
            }

            return(isCorrect);
        }
Ejemplo n.º 2
0
        public bool GetFuzzyDataSimplex(string path, string NombreHoja, out FuzzyTableau tableau)
        {
            bool isCorrect = false;

            tableau = null;
            List <string> cabeceraFila    = new List <string>();
            List <string> cabeceraColumna = new List <string>();

            if (!string.IsNullOrWhiteSpace(path) && !string.IsNullOrWhiteSpace(NombreHoja))
            {
                UsoExcel helperExcel = new UsoExcel(path);
                FuzzyPrimalSimplexService fpsService = new FuzzyPrimalSimplexService();

                if (helperExcel.SiProcesoCorrecto && helperExcel.ComprobarSiExisteHoja(NombreHoja, out int indiceHoja) &&
                    helperExcel.ObtenerDimensionesHoja(indiceHoja, out int countFila, out int countCol))
                {
                    string[,] data = helperExcel.ObtenerDatosHoja(NombreHoja);
                    if (GetEquations(path, data, countFila - 1, countCol - 1, out List <string> header, out List <FuzzyConstraint> fuzzyEquations, out FuzzyObjectiveFunction fuzzyObjectiveFunction, out List <Constraint> equations, out ObjectiveFunction objectiveFunction) && fuzzyEquations.Count > 0)
                    {
                        List <FuzzyVectorEquation> constraints = fpsService.StandardizeConstraints(fuzzyEquations).ToList();
                        if (fpsService.StandardizeObjectiveFunction(fuzzyEquations, ref fuzzyObjectiveFunction))
                        {
                            tableau = new FuzzyTableau(constraints, fuzzyObjectiveFunction); isCorrect = true;
                        }
                    }
                }

                helperExcel.CerrarLibroExcel();
            }

            return(isCorrect);
        }