Пример #1
0
        public bool ReduceColumns(ref FuzzyTableau tableau, KeyValuePair <string, double> pivot, string minVar)
        {
            bool siCorrecto = false;

            if (tableau != null && !string.IsNullOrEmpty(pivot.Key) && !string.IsNullOrEmpty(minVar))
            {
                OperacionesVectoriales     op        = new OperacionesVectoriales();
                TRFNOperation              fop       = new TRFNOperation();
                List <FuzzyVectorEquation> resultado = new List <FuzzyVectorEquation>();

                FuzzyVectorEquation evreferencia = tableau.FuzzyStandardConstraint.Where(r => r.Name == pivot.Key).FirstOrDefault();
                evreferencia = new FuzzyVectorEquation(evreferencia.Name, evreferencia.Header, op.OperacionV1parametro(evreferencia.Numbers, "/", pivot.Value), fop.OperateConstant(evreferencia.IndependentTerm, Constantes.Division, pivot.Value));
                double varValue = evreferencia.Vector.Where(v => v.Key == minVar).FirstOrDefault().Value;

                foreach (FuzzyVectorEquation ev in tableau.FuzzyStandardConstraint)
                {
                    if (ev.Name == pivot.Key)
                    {
                        resultado.Add(evreferencia);
                    }
                    else if (ev.Name != pivot.Key)
                    {
                        double pivoteev = ev.Vector.Where(r => r.Key == minVar).FirstOrDefault().Value;
                        //string opPivot = (pivoteev > 0 && varValue > 0 || pivoteev < 0 && varValue < 0) ? "-" : "+";
                        if (pivoteev != 0)
                        {
                            resultado.Add(new FuzzyVectorEquation(ev.Name, ev.Header,
                                                                  op.OperacionV1parametroV2(ev.Numbers, "-", pivoteev, evreferencia.Numbers),
                                                                  fop.Subtraction(ev.IndependentTerm, fop.OperateConstant(evreferencia.IndependentTerm, Constantes.Multiplicacion, pivoteev))));
                        }
                        else
                        {
                            resultado.Add(ev);
                        }
                    }
                }

                TRFN pivotefo             = tableau.FuzzyZRow.FuzzyVector.Where(r => r.Key == minVar).FirstOrDefault().Value;
                FuzzyObjectiveFunction fo = null;

                if (!fop.IsZero(pivotefo))
                {
                    fo = new FuzzyObjectiveFunction(tableau.FuzzyZRow.Header, fop.ReduceFuzzyRows(tableau.FuzzyZRow.FuzzyNums, fop.OperateFuzzyConstant(evreferencia.Numbers, Constantes.Multiplicacion, pivotefo)), fop.Addition(tableau.FuzzyZRow.IndependentTerm, fop.Multiplication(fop.MakeNegative(pivotefo), evreferencia.IndependentTerm)), tableau.FuzzyZRow.IsMax);
                }
                else
                {
                    fo = tableau.FuzzyZRow;
                }

                //Actualizamos nombre pivote en ecuación
                tableau = new FuzzyTableau(resultado, fo, RefreshBase(tableau.Base, minVar, pivot.Key));

                tableau.FuzzyStandardConstraint.Where(c => c.Name.Contains(pivot.Key)).FirstOrDefault().Name = minVar;
                tableau.isSolution = true;
            }

            return(siCorrecto);
        }
Пример #2
0
        public void FuzzyOperationsBody()
        {
            TRFNOperation fop = new TRFNOperation();

            List <TRFN> L1 = new List <TRFN> {
                new TRFN(Constantes.NDType.AlfaBetaType, -15, -13, 2, 2),
                new TRFN(Constantes.NDType.AlfaBetaType, -14, -12, 3, 3),
                new TRFN(Constantes.NDType.AlfaBetaType, -17, -15, 2, 2)
            };

            List <double> L2 = new List <double> {
                1.076923077, 0, 1, 0, 0.07692307692, 0
            };

            TRFN referencia = new TRFN(Constantes.NDType.AlfaBetaType, -17, -15, 2, 2);

            List <TRFN> L3 = fop.OperateFuzzyConstant(L2, Constantes.Multiplicacion, referencia).ToList();

            List <TRFN> result = fop.ReduceFuzzyRows(L1, L3).ToList();
        }
Пример #3
0
        public FuzzyObjectiveFunction ReduceBaseVar(FuzzyObjectiveFunction foArtificial, IEnumerable <FuzzyVectorEquation> constraints)
        {
            FuzzyObjectiveFunction newFO = foArtificial;
            TRFNOperation          fop   = new TRFNOperation();

            if (foArtificial != null && foArtificial.FuzzyVector.Count() > 0)
            {
                foreach (string varName in constraints.Select(x => x.Name))
                {
                    FuzzyVectorEquation vectorRef = constraints.Where(c => c.Vector.Any(v => v.Key == varName && v.Value == 1)).FirstOrDefault();

                    TRFN pivotefo = foArtificial.FuzzyVector.Where(r => r.Key == varName).FirstOrDefault().Value;
                    if (!fop.IsZero(pivotefo))
                    {
                        newFO = new FuzzyObjectiveFunction(foArtificial.Header, fop.ReduceFuzzyRows(newFO.FuzzyNums, fop.OperateFuzzyConstant(vectorRef.Numbers, Constantes.Multiplicacion, pivotefo)), fop.Addition(newFO.IndependentTerm, fop.Multiplication(fop.MakeNegative(pivotefo), vectorRef.IndependentTerm)), newFO.IsMax);
                    }
                }
            }

            return(newFO);
        }