public FuzzyVectorEquation(string name, IEnumerable <string> header, IEnumerable <double> vector, TRFN terminoIndepe) { Name = name; Vector = header.Zip(vector, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v); Vector = dataManagement.OrderDictionaryByVariable(Vector); IndependentTerm = terminoIndepe; }
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 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); }
private bool GetFuzzyNumber(string data, out TRFN FuzzyNumber) { bool isCorrect = false; FuzzyNumber = null; string[] numbers = data.Replace("'", "").Split(Constantes.Separator); if (numbers.Length == 4 && double.TryParse(numbers[0], out double L) && double.TryParse(numbers[1], out double U) && double.TryParse(numbers[2], out double alfa) && double.TryParse(numbers[3], out double beta)) { FuzzyNumber = new TRFN(Constantes.NDType.AlfaBetaType, L, U, alfa, beta); isCorrect = true; } return(isCorrect); }
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(); }
public bool GetFuzzyParameter(string path, string sheetName, out List <FuzzyParameter> fuzzyParameters) { bool isCorrect = false; fuzzyParameters = new List <FuzzyParameter>(); if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(sheetName)) { UsoExcel helperExcel = new UsoExcel(path); if (helperExcel.SiProcesoCorrecto && helperExcel.ComprobarSiExisteHoja(sheetName, out int index) && helperExcel.ObtenerDimensionesHoja(index, out int countRow, out int countCol)) { string[,] data = helperExcel.ObtenerDatosHoja(sheetName); for (int i = 0; i < countRow - 1; i++) { TRFN numT = null; string parName = string.Empty; bool isNamePass = false; for (int j = 0; j < countCol - 1; j++) { if (!GetFuzzyNumber(data[i, j], out numT) && !isNamePass) { parName = data[i, j]; isNamePass = true; } } if (!string.IsNullOrEmpty(parName) && numT != null) { fuzzyParameters.Add(new FuzzyParameter(parName, numT)); } } } helperExcel.CerrarLibroExcel(); } return(isCorrect); }
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); }
public FuzzyVectorEquation(string name, IDictionary <string, double> vector, TRFN termindepe) { Name = name; Vector = vector; IndependentTerm = termindepe; }
public FuzzyVectorEquation(IDictionary <string, double> cuerpoVector, TRFN termindepe) { Vector = dataManagement.OrderDictionaryByVariable(cuerpoVector); IndependentTerm = termindepe; }
public FuzzyObjectiveFunction(string nombre, IEnumerable <string> Cabecera, IEnumerable <TRFN> vector, TRFN terminoIndepe, bool ismax) : base(nombre, Cabecera, vector, terminoIndepe) { IsMax = ismax; }
public FuzzyConstraint(string nombre, IEnumerable <string> Cabecera, IEnumerable <double> vector, string oper, TRFN terminoIndepe) : base(nombre, Cabecera, vector, terminoIndepe) { Operator = oper; }
public FuzzyConstraint(string nombre, IDictionary <string, double> cuerpoVector, string oper, TRFN termindepe) : base(nombre, cuerpoVector, termindepe) { Operator = oper; }
public FuzzyConstraint(IEnumerable <string> Cabecera, IEnumerable <TRFN> vector, string oper, TRFN terminoIndepe) : base(Cabecera, vector, terminoIndepe) { Operator = oper; }
public FuzzyConstraint(IDictionary <string, TRFN> cuerpoVector, string oper, TRFN termindepe) : base(cuerpoVector, termindepe) { Operator = oper; }
public bool GetEquations(string path, string[,] data, int numRow, int numCol, out List <string> header, out List <FuzzyConstraint> fuzzyEquations, out FuzzyObjectiveFunction fuzzyObjectiveFunction, out List <Constraint> equations, out ObjectiveFunction objectiveFunction) { equations = new List <Constraint>(); fuzzyEquations = new List <FuzzyConstraint>(); header = new List <string>(); fuzzyObjectiveFunction = null; objectiveFunction = null; Config _config = new Config(); if (data != null && !Decimal.TryParse(data[0, 0], out decimal num)) { for (int i = 0; i < numRow; i++) { bool ifPassOperator = false; bool isMax = false; string nameEV = string.Empty; string op = string.Empty; List <double> valuesN = new List <double>(); List <TRFN> valuesFuzzy = new List <TRFN>(); double terminoIndepe = Double.NaN; TRFN fuzzyIndependtTerm = null; if (i == 0) { for (int j = 1; j < numCol; j++) { header.Add(data[i, j]); } } else { for (int j = 0; j < numCol; j++) { double numA = Double.NaN; TRFN numT = null; if (j == 0) { nameEV = data[i, j]; } else if (Double.TryParse(data[i, j], out numA) && !ifPassOperator) { valuesN.Add(numA); } else if (!Double.TryParse(data[i, j], out numA) && !GetFuzzyNumber(data[i, j], out numT) && !ifPassOperator) { op = data[i, j]; ifPassOperator = true; } else if (Double.TryParse(data[i, j], out numA) && ifPassOperator) { terminoIndepe = numA; } else if (!Double.TryParse(data[i, j], out numA) && !GetFuzzyNumber(data[i, j], out numT) && ifPassOperator) { if (data[i, j] == Constantes.Maximizar) { isMax = true; } } else if (GetFuzzyNumber(data[i, j], out numT) && !ifPassOperator) { valuesFuzzy.Add(numT); } else if (GetFuzzyNumber(data[i, j], out numT) && ifPassOperator) { fuzzyIndependtTerm = numT; } } if (op != Constantes.IgualQue && fuzzyIndependtTerm == null) { equations.Add(new Constraint(nameEV, header, valuesN, op, terminoIndepe)); } if (op != Constantes.IgualQue && fuzzyIndependtTerm != null && valuesFuzzy.Count == 0) { fuzzyEquations.Add(new FuzzyConstraint(nameEV, header, valuesN, op, fuzzyIndependtTerm)); } if (op != Constantes.IgualQue && fuzzyIndependtTerm != null && valuesFuzzy.Count > 0) { fuzzyEquations.Add(new FuzzyConstraint(nameEV, header, valuesFuzzy, op, fuzzyIndependtTerm)); } else if (op == Constantes.IgualQue && valuesFuzzy.Count == 0) { objectiveFunction = new ObjectiveFunction(header, valuesN, isMax); } else if (op == Constantes.IgualQue && valuesFuzzy.Count > 0) { fuzzyObjectiveFunction = new FuzzyObjectiveFunction(header, valuesFuzzy, new TRFN(0), isMax); } } } if (_config.AnyFuzzyParameter && fuzzyObjectiveFunction != null && GetFuzzyParameter(path, _config.FuzzyParameterName, out List <FuzzyParameter> parameters)) { TRFNOperation fuzzyOperation = new TRFNOperation(); fuzzyObjectiveFunction = new FuzzyObjectiveFunction(fuzzyObjectiveFunction.Header, fuzzyOperation.MultiplicationFuzzyConstant(fuzzyObjectiveFunction.FuzzyNums, parameters.Select(p => p.Value).ToList()), fuzzyObjectiveFunction.IndependentTerm, fuzzyObjectiveFunction.IsMax); } } return((header.Count > 0 && fuzzyEquations.Count > 0 && fuzzyObjectiveFunction != null) || (header.Count > 0 && equations.Count > 0 && objectiveFunction != null)); }
public FuzzyObjectiveFunction(string nombre, IDictionary <string, TRFN> cuerpoVector, TRFN termindepe, bool ismax) : base(nombre, cuerpoVector, termindepe) { IsMax = ismax; }
public FuzzyVectorEquation(IEnumerable <string> header, IEnumerable <TRFN> vector, TRFN terminoIndepe) { FuzzyVector = dataManagement.OrderDictionaryByVariable(header.Zip(vector, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v)); IndependentTerm = terminoIndepe; }
public FuzzySimplexSolution(IDictionary <string, TRFN> varValue, TRFN solution) { this.VarValue = varValue; this.OptimalSolution = solution; }
public FuzzyVectorEquation(string name, IDictionary <string, TRFN> vector, TRFN termindepe) { Name = name; FuzzyVector = dataManagement.OrderDictionaryByVariable(vector); IndependentTerm = termindepe; }