public FuzzyObjectiveFunction ReduceArtificialVar(FuzzyObjectiveFunction foArtificial, IEnumerable <FuzzyVectorEquation> constraints) { FuzzyObjectiveFunction newFO = foArtificial; TRFN pivotefo = new TRFN(Constantes.NDType.AlfaBetaType, 1, 1, 0, 0); TRFNOperation fop = new TRFNOperation(); if (foArtificial != null && foArtificial.FuzzyVector.Count() > 0) { foreach (string varName in foArtificial.Header) { FuzzyVectorEquation vectorRef = null; if (varName.Contains("A")) { vectorRef = constraints.Where(c => c.Vector.Any(v => v.Key == varName && v.Value == 1)).FirstOrDefault(); } if (vectorRef != null && vectorRef.Vector.Count() > 0) { newFO = new FuzzyObjectiveFunction(foArtificial.Header, fop.AdditionFuzzyRows(newFO.FuzzyNums, fop.OperateFuzzyConstant(vectorRef.Numbers, Constantes.Multiplicacion, pivotefo)), fop.Addition(newFO.IndependentTerm, fop.Multiplication(pivotefo, vectorRef.IndependentTerm)), foArtificial.IsMax); } } } return(newFO); }
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); }
public FuzzyVectorEquation OrderDictionaryByVariable(FuzzyVectorEquation equation) { if (equation.Vector != null) { return(new FuzzyVectorEquation(equation.Name, OrderDictionaryByVariable(equation.Vector), equation.IndependentTerm)); } else { return(new FuzzyVectorEquation(equation.Name, OrderDictionaryByVariable(equation.FuzzyVector), equation.IndependentTerm)); } }
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); }