Ejemplo n.º 1
0
        private void RemoveClause(IClause clause)
        {
            var headNode = clause.Head != null?_graph.GetNode(clause.Head.Value) : null;

            if (headNode != null)
            {
                if (clause.Body.Count == 1)
                {
                    var literalNode = _graph.GetNode(clause.Body.First().Value);
                    var edge        = _graph.GetEdge(headNode, literalNode);
                    _graph.RemoveEdge(edge);

                    headNode    = _graph.GetNode(clause.Head.NegatedValue());
                    literalNode = _graph.GetNode(clause.Body.First().NegatedValue());
                    edge        = _graph.GetEdge(headNode, literalNode);
                    _graph.RemoveEdge(edge);
                }
                else if (clause.Body.Count > 1)
                {
                    var clauseNode = _graph.GetNode(ClauseKey(clause.Body));
                    var edge       = _graph.GetEdge(headNode, clauseNode);
                    _graph.RemoveEdge(edge);

                    if (_graph.InDegree(clauseNode) < 1)
                    {
                        _graph.RemoveNode(clauseNode);
                    }

                    headNode = _graph.GetNode(clause.Head.NegatedValue());
                    foreach (var literalNode in clause.Body.Select(dependency => _graph.GetNode(dependency.NegatedValue())))
                    {
                        edge = _graph.GetEdge(headNode, literalNode);
                        _graph.RemoveEdge(edge);
                    }
                }
            }
        }