Esempio n. 1
0
void verifyModels(
    const ModelGraphT& mg,
    const typename ModelGraphT::ModelList& models,
    const std::set< std::set<std::string> >& refints)
{
    std::set< std::set<std::string> > ints;
    for(typename ModelGraphT::ModelList::const_iterator itm = models.begin();
            itm != models.end(); ++itm)
    {
        BOOST_REQUIRE(mg.propsOf(*itm).interpretation != NULL);
        TestInterpretation& ti = *(mg.propsOf(*itm).interpretation);
        ints.insert(ti.getAtoms());
    }
    LOG(INFO,"checking equality of set of models:");
    BOOST_FOREACH(const std::set<std::string>& pset, refints)
    {
        LOG(INFO,"reference " << printset(pset));
    }
Esempio n. 2
0
void writeEgMgGraphViz(
		std::ostream& o, bool verbose,
		const FinalEvalGraph& eg, const ModelGraphT& mg,
    boost::optional<std::set<typename ModelGraphT::Model> > onlyForModels = boost::none)
{
	typedef typename ModelGraphT::ModelList ModelList;
	typedef typename ModelGraphT::Model Model;
	typedef typename ModelGraphT::PredecessorIterator ModelPredecessorIterator;
	typedef typename ModelGraphT::ModelIterator ModelIterator;
  typedef std::set<typename ModelGraphT::Model> ModelSet;

  ModelSet printModels;
  if( !!onlyForModels )
  {
    // we need a hash map, as component graph is no graph with vecS-storage
    typedef boost::unordered_map<Model, boost::default_color_type> ColorHashMap;
    typedef boost::associative_property_map<ColorHashMap> ColorMap;
    ColorHashMap whiteHashMap;

    // fill white hash map
    ModelIterator mit, mit_end;
    for(boost::tie(mit, mit_end) = mg.getModels();
        mit != mit_end; ++mit)
    {
      whiteHashMap[*mit] = boost::white_color;
    }

    // one hash map for all!
    ColorHashMap myHashMap(whiteHashMap);
    ColorMap myColorMap(myHashMap);
    for(typename ModelSet::const_iterator it = onlyForModels.get().begin();
        it != onlyForModels.get().end(); ++it)
    {
      //LOG(INFO,"doing dfs visit for " << *it);
      boost::depth_first_visit(
          mg.getInternalGraph(),
          *it, 
          boost::default_dfs_visitor(),
          myColorMap);
    }
    for(boost::tie(mit, mit_end) = mg.getModels();
        mit != mit_end; ++mit)
    {
      if( myHashMap[*mit] == boost::white_color )
      {
        //LOG(INFO,"model " << *mit << " still white");
      }
      else
      {
        //LOG(INFO,"model " << *mit << " not white -> printing");
        printModels.insert(*mit);
      }
    }
  }
  else
  {
    // include all
    ModelIterator mit, mit_end;
    for(boost::tie(mit, mit_end) = mg.getModels();
        mit != mit_end; ++mit)
    {
      printModels.insert(*mit);
    }
  }

  // boost::graph::graphviz is horribly broken!
  // therefore we print it ourselves

  o << "digraph G {" << std::endl <<
    "rankdir=BT;" << std::endl << // print root nodes at bottom, leaves at top!
    "concentrate=true;" << std::endl <<
    //"center=false;" << std::endl <<
    "pagedir=BL;" << std::endl <<
    //"ranksep=\"0.5\";" << std::endl <<
    //"nodesep=\"0.5\";" << std::endl <<
    //"page=\"44,35\";" << std::endl <<
    "compound=true;" << std::endl; // print clusters = eval units, inside nodes = models

	// stream deps into this stream
	std::stringstream odeps;

  FinalEvalGraph::EvalUnitIterator uit, ubegin, uend;
  boost::tie(ubegin, uend) = eg.getEvalUnits();
  for(uit = ubegin; uit != uend; ++uit)
  {
    EvalUnit u = *uit;
    o << "subgraph clusteru" << u << "{" << std::endl;
    o << "node [shape=box];" << std::endl;
    o << "label=\"";
    {
      std::stringstream s;
			if( eg.propsOf(u).mgf != 0 )
			{
				s << *eg.propsOf(u).mgf;
			}
			else
			{
				s << "NULL";
			}
      // escape " into \"
      breakLinesAndGraphViz(s.str(), o);
    }
		o << "\";" << std::endl;

    // models in this subgraph
		{
			for(ModelType t = MT_IN; t <= MT_OUTPROJ; t = static_cast<ModelType>(static_cast<unsigned>(t)+1))
			{
				const ModelList& modelsAt = mg.modelsAt(u, t);
				typename ModelList::const_iterator mit;
				for(mit = modelsAt.begin(); mit != modelsAt.end(); ++mit)
				{
          if( printModels.find(*mit) == printModels.end() )
            continue;

					Model m = *mit;
					o << "m" << m << "[label=\"";
					{
						std::stringstream s;
						s << toString(mg.propsOf(m).type) << " " << m << " @" << mg.propsOf(m).location << "\\n";
            if( mg.propsOf(m).interpretation != 0 )
              s << *mg.propsOf(m).interpretation;
            breakLinesAndGraphViz(s.str(), o);
					}
					o << "\"];" << std::endl;

					// model dependencies (preds)
					ModelPredecessorIterator pit, pbegin, pend;
					boost::tie(pbegin, pend) = mg.getPredecessors(m);
					for(pit = pbegin; pit != pend; ++pit)
					{
						odeps <<
							"m" << m << " -> m" << mg.targetOf(*pit) <<
							"[label=\"" << mg.propsOf(*pit).joinOrder << "\"];" << std::endl;
					}
				} // through all models
			}
		}
		o << "}" << std::endl;

		/*
    // unit dependencies
    typename EvalGraphT::PredecessorIterator pit, pbegin, pend;
    boost::tie(pbegin, pend) = eg.getPredecessors(u);
    for(pit = pbegin; pit != pend; ++pit)
    {
      LOG(INFO,"-> depends on unit " << eg.targetOf(*pit) << "/join order " << eg.propsOf(*pit).joinOrder);
    }
		*/

  }

	// deps between models
	o << odeps.str() << std::endl;
	o << "}" << std::endl;
}