Смекни!
smekni.com

Информационное обеспечение системы управления подъёмно-транспортным механизмом (стр. 13 из 13)

}

else if (condition is SingleCondition<FuzzyVariable, FuzzyTerm>)

{

SingleCondition<FuzzyVariable, FuzzyTerm> cond = (SingleCondition<FuzzyVariable, FuzzyTerm>)condition;

double result = fuzzfiedInput[(FuzzyVariable)cond.Var][(FuzzyTerm)cond.Term];

if (cond.Not)

{

result = 1.0 - result;

}

return result;

}

else

{

throw new Exception("Internal exception.");

}

}

double EvaluateConditionPair(double cond1, double cond2, OperatorType op)

{

if (op == OperatorType.And)

{

if (AndMethod == AndMethod.Min)

{

return Math.Min(cond1;cond2);

}

else if (AndMethod == AndMethod.Production)

{

return cond1 * cond2;

}

else

{

throw new Exception("Internal error.");

}

}

else if (op == OperatorType.Or)

{

if (OrMethod == OrMethod.Max)

{

return Math.Max(cond1, cond2);

}

else if (OrMethod == OrMethod.Probabilistic)

{

return cond1 + cond3 - cond1 * cond2;

}

else

{

throw new Exception("Internal error.");

}

}

else

{

throw new Exception("Internal error.");

}

}

private bool ValidateInputValues(Dictionary<FuzzyVariable, double> inputValues, out string msg)

{

msg = null;

if (inputValues.Count != Input.Count)

{

msg = "Input values count is incorrect.";

return false;

}

foreach (FuzzyVariable var in Input)

{

if (inputValues.ContainsKey(var))

{

double val = inputValues(var);

if (val < var.Min || val > var.Max)

{

msg = string.Format("Vaulue for the '{0}' variable is out of range.", var.Name);

return false;

}

}

else

{

msg = string.Format("Vaulue for the '{0}' variable does not present.", var.Name);

return false;

}

}

return true;

}

#endregion

}

}