cloud9_root/src/third_party/stp/src/simplifier/SubstitutionMap.cpp
// If n0 is replaced by n1 in the substitution map. Will it cause a loop?
// i.e. will the dependency graph be an acyclic graph still.
// For example, if we have x = F(y,z,w), it would make the substitutionMap loop
// if there's already z = F(x).
If n0 is replaced by n1 in the substitution map. Will it cause a loop.
If n0 is replaced by n1 in the substitution map . Will it cause a loop .
bool SubstitutionMap::loops(const ASTNode& n0, const ASTNode& n1)
	{
	if (n0.GetKind() != SYMBOL)
		return false; 
	if (n1.isConstant())
		return false; 
	if (rhs.find(n0) == rhs.end())
	{
		return vars.VarSeenInTerm(n0,n1);
	}
	if (n1.GetKind() == SYMBOL && dependsOn.find(n1) == dependsOn.end() )
		return false; 
	if (debug_substn)
		cout << loopCount++  << endl;
	bool destruct = true;
	ASTNodeSet* dependN = vars.SetofVarsSeenInTerm(n1,destruct);
	if (debug_substn)
	{
		cout << n0 << " " <<  n1.GetNodeNum(); 
		cout << "Variables in expression: "<< dependN->size() << endl;
	}
	set<ASTNode> depend(dependN->begin(), dependN->end());
	if (destruct)
		delete dependN;
	set<ASTNode> visited;
	loops_helper(depend,visited);
	bool loops = visited.find(n0) != visited.end();
	if (debug_substn)
		cout << "Visited:" << visited.size() << "Loops:" << loops << endl;
	return (loops);
	}
bool SubstitutionMap :: loops ( const ASTNode & n0 , const ASTNode & n1 ) { if ( n0 . GetKind ( ) != SYMBOL ) return false ; if ( n1 . isConstant ( ) ) return false ; if ( rhs . find ( n0 ) == rhs . end ( ) ) { return vars . VarSeenInTerm ( n0 , n1 ) ; } if ( n1 . GetKind ( ) == SYMBOL && dependsOn . find ( n1 ) == dependsOn . end ( ) ) return false ; if ( debug_substn ) cout << loopCount ++ << endl ; bool destruct = true ; ASTNodeSet * dependN = vars . SetofVarsSeenInTerm ( n1 , destruct ) ; if ( debug_substn ) { cout << n0 << " " << n1 . GetNodeNum ( ) ; cout << " " << dependN -> size ( ) << endl ; } set < ASTNode > depend ( dependN -> begin ( ) , dependN -> end ( ) ) ; if ( destruct ) delete dependN ; set < ASTNode > visited ; loops_helper ( depend , visited ) ; bool loops = visited . find ( n0 ) != visited . end ( ) ; if ( debug_substn ) cout << " " << visited . size ( ) << " " << loops << endl ; return ( loops ) ; }
If n0 is replaced by n1 in the substitution map.
If n0 is replaced by n1 in the substitution map .
// sometimes this function is called with constants on the lhs. // constants contain no variables. Can't loop. // We are adding an edge FROM n0, so unless there is already an edge TO n0, // there is no change it can loop. Unless adding this would add a TO and FROM edge. // The rhs is a symbol and doesn't appear. //<< " Expression size:" << bm->NodeSize(n1,true);