<commit_before>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 <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 DependencyGraph.cpp
 * @author <NAME>
 * @date Mon Sep 19 12:19:38 CEST 2005
 *
 * @brief Classes for the dependency graph class and its subparts.
 *
 *
 */

#include "dlvhex/DependencyGraph.h"

#include "dlvhex/Error.h"
#include "dlvhex/globals.h"
#include "dlvhex/ProgramCtx.h"
#include "dlvhex/PluginContainer.h"
#include "dlvhex/PluginInterface.h"

#include <sstream>
//#include <iostream>

DLVHEX_NAMESPACE_BEGIN

/*
DependencyGraph::DependencyGraph()
{
}
*/


DependencyGraph::DependencyGraph(ComponentFinder* cf, const ProgramCtx& ctx)

  : nodegraph(*ctx.getNodeGraph()), componentFinder(cf), programCtx(ctx)
{
    const std::vector<AtomNodePtr> allnodes = nodegraph.getNodes();

    Subgraph* subgraph = new Subgraph;

    std::vector<std::vector<AtomNodePtr> > strongComponents;

    //
    // keep track of the nodes that belong to a SCC
    //
    std::vector<AtomNodePtr> visited;

    //
    // find all strong components
    //
    getStrongComponents(allnodes, strongComponents);

    //
    // go through strong components
    //
    for (std::vector<std::vector<AtomNodePtr> >::const_iterator scc = strongComponents.begin();
        scc != strongComponents.end();
        ++scc)
    {
        //
        // we need a component object for each component that needs a special
        // evaluation procedure:
        // (i) stratified SCC with external atoms: fixpoint iteration
        // (ii) unstratified SCC with external atoms: guess&check
        //
        if (isExternal(*scc))
        {
            ModelGenerator* mg;

            //
            // if we have a negated edge in this nodeset, we have an
            // unstratifed component (because the nodeset is already a
            // SCC!).
	    //
	    // This is also true for cycles through a disjunction.
            //
            if (hasNegEdgeOrNonmonotonicExtatom(*scc))
            {
                //std::cerr << "using guess check" << std::endl;
                mg = new GuessCheckModelGenerator(ctx);
            }
            else
            {
                //std::cerr << "using fixpoint" << std::endl;
                mg = new FixpointModelGenerator(ctx);
            }

	    ///@todo another memory leak *sigh*
            Component* comp = new ProgramComponent(*scc, mg);

            //
            // component-object is finished, add it to the dependency graph
            //
            components.push_back(comp);

            //
            // add it also to the current subgraph
            //
            subgraph->addComponent(comp);

            //
            // mark these scc nodes as visited
            //
            for (std::vector<AtomNodePtr>::const_iterator ni = (*scc).begin();
                ni != (*scc).end();
                ++ni)
            {
	      ///@todo marking scc nodes as visited this is not so nice here
                visited.push_back(*ni);
            }
        }
    }

    //<commit_msg>removed some debugging code<commit_after>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 <NAME>uer
 * 
 * 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 DependencyGraph.cpp
 * @author <NAME>
 * @date Mon Sep 19 12:19:38 CEST 2005
 *
 * @brief Classes for the dependency graph class and its subparts.
 *
 *
 */

#include "dlvhex/DependencyGraph.h"

#include "dlvhex/Error.h"
#include "dlvhex/globals.h"
#include "dlvhex/ProgramCtx.h"
#include "dlvhex/PluginContainer.h"
#include "dlvhex/PluginInterface.h"

#include <sstream>

DLVHEX_NAMESPACE_BEGIN

/*
DependencyGraph::DependencyGraph()
{
}
*/


DependencyGraph::DependencyGraph(ComponentFinder* cf, const ProgramCtx& ctx)

  : nodegraph(*ctx.getNodeGraph()), componentFinder(cf), programCtx(ctx)
{
    const std::vector<AtomNodePtr> allnodes = nodegraph.getNodes();

    Subgraph* subgraph = new Subgraph;

    std::vector<std::vector<AtomNodePtr> > strongComponents;

    //
    // keep track of the nodes that belong to a SCC
    //
    std::vector<AtomNodePtr> visited;

    //
    // find all strong components
    //
    getStrongComponents(allnodes, strongComponents);

    //
    // go through strong components
    //
    for (std::vector<std::vector<AtomNodePtr> >::const_iterator scc = strongComponents.begin();
        scc != strongComponents.end();
        ++scc)
    {
        //
        // we need a component object for each component that needs a special
        // evaluation procedure:
        // (i) stratified SCC with external atoms: fixpoint iteration
        // (ii) unstratified SCC with external atoms: guess&check
        //
        if (isExternal(*scc))
        {
            ModelGenerator* mg;

            //
            // if we have a negated edge in this nodeset, we have an
            // unstratifed component (because the nodeset is already a
            // SCC!).
	    //
	    // This is also true for cycles through a disjunction.
            //
            if (hasNegEdgeOrNonmonotonicExtatom(*scc))
            {
                mg = new GuessCheckModelGenerator(ctx);
            }
            else
            {
                mg = new FixpointModelGenerator(ctx);
            }

	    ///@todo another memory leak *sigh*
            Component* comp = new ProgramComponent(*scc, mg);

            //
            // component-object is finished, add it to the dependency graph
            //
            components.push_back(comp);

            //
            // add it also to the current subgraph
            //
            subgraph->addComponent(comp);

            //
            // mark these scc nodes as visited
            //
            for (std::vector<AtomNodePtr>::const_iterator ni = (*scc).begin();
                ni != (*scc).end();
                ++ni)
            {
	      ///@todo marking scc nodes as visited this is not so nice here
                visited.push_back(*ni);
            }
        }
    }

    //
{'fraction_non_alphanumeric': 0.10162061636556854, 'fraction_numerical': 0.009829968119022316, 'mean_word_length': 2.1098719537381245, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 26, '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': '902721', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2051, 'n_words': 700}