private bool GetResolvent(Expression first, Expression second, out Expression resolvent) { resolvent = null; //получаем множества дизъюнктов List <Expression> firstExp = eh.GetDisjunctCollection(first); List <Expression> secondExp = eh.GetDisjunctCollection(second); for (int i = 0; i < firstExp.Count; i++) { for (int j = 0; j < secondExp.Count; j++) //для всех пар { ProductionFact fact1 = firstExp[i].GetFact(); ProductionFact fact2 = secondExp[j].GetFact(); if (firstExp[i] is UnaryOperator) //если выражение имеет вид !(факт) { //если найдена контрарная пара if (IsContariesCouple(firstExp[i], secondExp[j])) { firstExp.RemoveAt(i); secondExp.RemoveAt(j); //если списки пусты, то получен пустой дизъюнкт, иначе строим резольвенту if (firstExp.Count != 0 && secondExp.Count != 0) { resolvent = eh.CreateDisjunction(firstExp.Union(secondExp).ToList()); } } } } } return(false); }
public override bool Equals(object obj) { ProductionFact fact = obj as ProductionFact; if (fact != null) { return(fact.name == this.name && fact.value == this.value); } return(false); }
public double Union(ProductionFact fact, OperationType type = OperationType.MinMax) { double x = this.GetConfidence(); double y = fact.GetConfidence(); int p = 2; switch (type) { case (OperationType.MinMax): return(Math.Max(x, y)); case (OperationType.Algebraic): return(x + y - x * y); case (OperationType.Conditional): if (y == 0) { return(x); } else if (x == 0) { return(y); } else { return(1); } case (OperationType.MinMaxAlternative): return(Math.Min(1, x + y)); case (OperationType.Exponential): return(Math.Min(1, Math.Pow(Math.Pow(x, p) + Math.Pow(y, p), 1.0 / p))); default: return(0); } }
private bool IsContariesCouple(Expression firstExp, Expression secondExp) { ProductionFact fact1 = firstExp is UnaryOperator? firstExp.Descendants[0].GetFact() :firstExp.GetFact(); ProductionFact fact2 = secondExp is UnaryOperator ? secondExp.Descendants[0].GetFact() : secondExp.GetFact(); if (firstExp is UnaryOperator) //если выражение имеет вид !(факт) { if (!(secondExp is UnaryOperator)) //если выражение имеет вид 'имя факта - значение' { //отрицание факта и факт if ((fact1.Name == fact2.Name) && (fact1.Value.Equals(fact2.Value))) { return(true); } } } else //выражение имеет вид 'имя факта - значение' { if (secondExp is UnaryOperator) { //факт и отрицание факта if ((fact1.Name == fact2.Name) && (fact1.Value.Equals(fact2.Value))) { return(true); } } else { //если имена фактов равны, а значения нет if ((fact1.Name == fact2.Name) && !(fact1.Value.Equals(fact2.Value))) { return(true); } } } return(false); }
/// <summary> /// инициализирует новый экземпляр <see cref="AddFactAction"/>. /// </summary> /// <param name="fact">Добавляемый факт.</param> public AddFactAction(ProductionFact fact) { this.fact = fact; }