Example #1
0
        public void FuzzyOperationsFO()
        {
            TRFNOperation fop = new TRFNOperation();

            TRFN n1 = new TRFN(Constantes.NDType.AlfaBetaType, 15, 17, 2, 2);
            TRFN n2 = new TRFN(Constantes.NDType.AlfaBetaType, 460, 480, 8, 8);

            n2 = fop.OperateConstant(n2, Constantes.Division, 13);
            //n2 = fop.MakeNegative(n2);

            TRFN result = fop.Multiplication(n1, n2);
            //result = fop.OperateConstant(result, Constantes.Division, 13);
            //result = fop.MakeNegative(result);
        }
        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);
        }