verifier/Verifier.cpp
// compute the projection of a state to a set of variables
compute the projection of a state to a set of variables
compute the projection of a state to a set of variables
void Verifier::project(State& state, int taskid, vector<int>& vars,
		State& res) {
	res.exprs.clear();
	res.eq_classes.clear();
	res.uneqs.clear();
	int num_expr = state.exprs.size();
	vector<bool> keep(num_expr, false);
	int num_eqc = 0;
	for (int i = 0; i < num_expr; i++)
		if (state.eq_classes[i] + 1 > num_eqc)
			num_eqc = state.eq_classes[i] + 1;
	vector<int> eq_cnt(num_eqc, 0);
	for (int i = 0; i < num_expr; i++) {
		int expr = state.exprs[i];
		if (is_const(expr))
			keep[i] = true;
		else {
			for (int x : vars) {
				if (task_var_expr_ids[taskid][x].count(expr)) {
					keep[i] = true;
					break;
				}
			}
		}
		if (keep[i]) {
			int eqc = state.eq_classes[i];
			eq_cnt[eqc]++;
		}
	}
	for (auto& pp : state.uneqs)
		if (eq_cnt[pp.first] > 0 && eq_cnt[pp.second] > 0) {
			eq_cnt[pp.first]++;
			eq_cnt[pp.second]++;
		}
	vector<int> new_eq_idx(num_eqc, -1);
	int num_new_eq = 0;
	for (int i = 0; i < num_expr; i++)
		if (keep[i] && eq_cnt[state.eq_classes[i]] > 1) {
			res.exprs.push_back(state.exprs[i]);
			if (new_eq_idx[state.eq_classes[i]] < 0)
				new_eq_idx[state.eq_classes[i]] = num_new_eq++;
			res.eq_classes.push_back(new_eq_idx[state.eq_classes[i]]);
		}
	for (auto pp : state.uneqs) {
		if (new_eq_idx[pp.first] >= 0 && new_eq_idx[pp.second] >= 0) {
			int e1 = new_eq_idx[pp.first];
			int e2 = new_eq_idx[pp.second];
			if (e1 > e2)
				swap(e1, e2);
			res.uneqs.push_back(pair<int, int>(e1, e2));
		}
	}
	sort(res.uneqs.begin(), res.uneqs.end());
	if (debug_cnt >= 0) {
		for (int var : vars)
			printf("X%d ", var);
		printf("\nBefore:\n");
		dump_state(state);
		printf("After:\n");
		dump_state(res);
		printf("\n");
		debug_cnt--;
	}
}
void Verifier :: project ( State & state , int taskid , vector < int > & vars , State & res ) { res . exprs . clear ( ) ; res . eq_classes . clear ( ) ; res . uneqs . clear ( ) ; int num_expr = state . exprs . size ( ) ; vector < bool > keep ( num_expr , false ) ; int num_eqc = 0 ; for ( int i = 0 ; i < num_expr ; i ++ ) if ( state . eq_classes [ i ] + 1 > num_eqc ) num_eqc = state . eq_classes [ i ] + 1 ; vector < int > eq_cnt ( num_eqc , 0 ) ; for ( int i = 0 ; i < num_expr ; i ++ ) { int expr = state . exprs [ i ] ; if ( is_const ( expr ) ) keep [ i ] = true ; else { for ( int x : vars ) { if ( task_var_expr_ids [ taskid ] [ x ] . count ( expr ) ) { keep [ i ] = true ; break ; } } } if ( keep [ i ] ) { int eqc = state . eq_classes [ i ] ; eq_cnt [ eqc ] ++ ; } } for ( auto & pp : state . uneqs ) if ( eq_cnt [ pp . first ] > 0 && eq_cnt [ pp . second ] > 0 ) { eq_cnt [ pp . first ] ++ ; eq_cnt [ pp . second ] ++ ; } vector < int > new_eq_idx ( num_eqc , -1 ) ; int num_new_eq = 0 ; for ( int i = 0 ; i < num_expr ; i ++ ) if ( keep [ i ] && eq_cnt [ state . eq_classes [ i ] ] > 1 ) { res . exprs . push_back ( state . exprs [ i ] ) ; if ( new_eq_idx [ state . eq_classes [ i ] ] < 0 ) new_eq_idx [ state . eq_classes [ i ] ] = num_new_eq ++ ; res . eq_classes . push_back ( new_eq_idx [ state . eq_classes [ i ] ] ) ; } for ( auto pp : state . uneqs ) { if ( new_eq_idx [ pp . first ] >= 0 && new_eq_idx [ pp . second ] >= 0 ) { int e1 = new_eq_idx [ pp . first ] ; int e2 = new_eq_idx [ pp . second ] ; if ( e1 > e2 ) swap ( e1 , e2 ) ; res . uneqs . push_back ( pair < int , int > ( e1 , e2 ) ) ; } } sort ( res . uneqs . begin ( ) , res . uneqs . end ( ) ) ; }
compute the projection of a state to a set of variables
compute the projection of a state to a set of variables
// printf("project\n"); // initialize // the number of equivalence classes // compute the set of expressions to be kept // set equivalence classes // //	if (debug_cnt >= 0) { //		for (int var : vars) //			printf("X%d ", var); //		printf("\nBefore:\n"); //		dump_state(state); //		printf("After:\n"); //		dump_state(res); //		printf("\n"); //		debug_cnt--; //	}