private void FactFlow(ILogicNode startNode) { if (startNode is ILiteralNode && _graph.OutDegree(startNode) == 1) { foreach (var node in _graph.Outgoing(startNode).Where(node => !node.Fact)) { if (node is ILiteralNode) { var negNode = _graph.GetNode(Negate(node.Id)); if (negNode.Fact) { throw new Exception("KB is inconsistent, " + node.Id + " and " + negNode.Id + " are both facts!"); } } node.Fact = true; FactFlow(node); } } foreach (var node in _graph.Incoming(startNode).Where(node => !node.Fact)) { if (node is IClauseNode) { if (_graph.Outgoing(node).All(dependency => dependency.Fact)) { node.Fact = true; FactFlow(node); } } else if (node is ILiteralNode && (_graph.OutDegree(node) == 1 || node.Id.Contains("|"))) { var negNode = _graph.GetNode(Negate(node.Id)); if (negNode.Fact) { throw new Exception("KB is inconsistent, " + node.Id + " and " + negNode.Id + " are both facts!"); } node.Fact = true; FactFlow(node); } } }