<commit_before>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005-2007 <NAME>
 * Copyright (C) 2006-2015 <NAME>
 * Copyright (C) 2009-2015 <NAME>
 * Copyright (C) 2011-2015 <NAME>
 *
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file UnfoundedSetCheckHeuristicsInterface.cpp
 * @author <NAME>
 *
 * @brief  Base class for
 *         unfounded set checks in genuine G&C model generators.
 */

#include "dlvhex2/UnfoundedSetCheckHeuristicsInterface.h"
#include "dlvhex2/Interpretation.h"
#include "dlvhex2/Printer.h"

#include <boost/foreach.hpp>

DLVHEX_NAMESPACE_BEGIN

// ============================== Base ==============================

UnfoundedSetCheckHeuristics::UnfoundedSetCheckHeuristics(const AnnotatedGroundProgram& groundProgram, RegistryPtr reg) : groundProgram(groundProgram), reg(reg)
{

    // prepare data structures for maintaining the skip program
    previouslyAssignedAndVerifiedAtoms = InterpretationPtr(new Interpretation(reg));
    notYetVerifiedExternalAtoms = InterpretationPtr(new Interpretation(reg));

    // make an index of ID addresses to rules
    atomsInRule.resize(groundProgram.getGroundProgram().idb.size(), 0);
    assignedAndVerifiedAtomsInRule.resize(groundProgram.getGroundProgram().idb.size(), 0);
    int ruleNr = 0;
    InterpretationPtr nodupAtom(new Interpretation(reg));
    InterpretationPtr nodupRule(new Interpretation(reg));

    #ifndef NDEBUG
    std::stringstream programstring;
    #endif
    BOOST_FOREACH (ID ruleID, groundProgram.getGroundProgram().idb) {
        const Rule& rule = reg->rules.getByID(ruleID);
        if (rule.isEAGuessingRule() || nodupRule->getFact(ruleID.address)) {
            ruleNr++;
            continue;
        }
        else {
            BOOST_FOREACH (ID h, rule.head) {
                if (!nodupAtom->getFact(h.address)) {
                    rulesOfAtom[h.address].insert(ruleNr);
                    nodupAtom->setFact(h.address);
                }
            }
            BOOST_FOREACH (ID b, rule.body) {
                if (!nodupAtom->getFact(b.address)) {
                    rulesOfAtom[b.address].insert(ruleNr);
                    nodupAtom->setFact(b.address);
                }
                //				if (b.isExternalAuxiliary()){
                //					notYetVerifiedExternalAtoms->setFact(b.address);
                //				}
            }
            atomsInRule[ruleNr] = nodupAtom->getStorage().count();
            nodupAtom->clear();

            // at the beginning, skipProgram is the whole program
            skipProgram.insert(ruleID);
            nodupRule->setFact(ruleID.address);
            ruleNr++;
        }
        #ifndef NDEBUG
        programstring << std::endl << RawPrinter::toString(reg, ruleID);
        #endif
    }<commit_msg>fix in partial UFS checker<commit_after>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005-2007 <NAME>
 * Copyright (C) 2006-2015 <NAME>
 * Copyright (C) 2009-2015 <NAME>
 * Copyright (C) 2011-2015 <NAME>
 *
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file UnfoundedSetCheckHeuristicsInterface.cpp
 * @author <NAME>
 *
 * @brief  Base class for
 *         unfounded set checks in genuine G&C model generators.
 */

#include "dlvhex2/UnfoundedSetCheckHeuristicsInterface.h"
#include "dlvhex2/Interpretation.h"
#include "dlvhex2/Printer.h"

#include <boost/foreach.hpp>

DLVHEX_NAMESPACE_BEGIN

// ============================== Base ==============================

UnfoundedSetCheckHeuristics::UnfoundedSetCheckHeuristics(const AnnotatedGroundProgram& groundProgram, RegistryPtr reg) : groundProgram(groundProgram), reg(reg)
{

    // prepare data structures for maintaining the skip program
    previouslyAssignedAndVerifiedAtoms = InterpretationPtr(new Interpretation(reg));
    notYetVerifiedExternalAtoms = InterpretationPtr(new Interpretation(reg));

    // make an index of ID addresses to rules
    atomsInRule.resize(groundProgram.getGroundProgram().idb.size(), 0);
    assignedAndVerifiedAtomsInRule.resize(groundProgram.getGroundProgram().idb.size(), 0);
    int ruleNr = 0;
    InterpretationPtr nodupAtom(new Interpretation(reg));
    InterpretationPtr nodupRule(new Interpretation(reg));

    #ifndef NDEBUG
    std::stringstream programstring;
    #endif
    BOOST_FOREACH (ID ruleID, groundProgram.getGroundProgram().idb) {
        const Rule& rule = reg->rules.getByID(ruleID);
        if (rule.isEAGuessingRule() || nodupRule->getFact(ruleID.address)) {
            ruleNr++;
            continue;
        }
        else {
            BOOST_FOREACH (ID h, rule.head) {
                if (!nodupAtom->getFact(h.address)) {
                    rulesOfAtom[h.address].insert(ruleNr);
                    nodupAtom->setFact(h.address);
                }
            }
            BOOST_FOREACH (ID b, rule.body) {
                if (!nodupAtom->getFact(b.address)) {
                    rulesOfAtom[b.address].insert(ruleNr);
                    nodupAtom->setFact(b.address);
                }
		if (b.isExternalAuxiliary()){
		    notYetVerifiedExternalAtoms->setFact(b.address);
		}
            }
            atomsInRule[ruleNr] = nodupAtom->getStorage().count();
            nodupAtom->clear();

            // at the beginning, skipProgram is the whole program
            skipProgram.insert(ruleID);
            nodupRule->setFact(ruleID.address);
            ruleNr++;
        }
        #ifndef NDEBUG
        programstring << std::endl << RawPrinter::toString(reg, ruleID);
        #endif
    }
{'fraction_non_alphanumeric': 0.11498855835240275, 'fraction_numerical': 0.014588100686498856, 'mean_word_length': 2.872093023255814, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6261747', 'n_tokens_mistral': 2140, 'n_tokens_neox': 1976, 'n_words': 542}