Exemple #1
0
// Construct the set of clauses for TRUE truth value of a fact at a level
bool StripsEncoding::supporting_constraints(int ft, int level, ClauseSet& clauses) const {

//#define DEBUG_SUPPORTING_CONSTRAINTS
#ifdef DEBUG_SUPPORTING_CONSTRAINTS
	int t=2;
	TAB(t);
	cout<<"In supporting constraints: ft = "<<ft<<", level = "<<level<<endl;
#endif

	if (clauses.size())
		clauses.clear();

	if (level < 0 || level > this->actions.size())
		return false;

	if (!is_in_state(ft, this->states[level]))	// There's no way to satisfy this fact
		return false;

	int confirmed_level = get_confirmed_level(ft, level);

#ifdef DEBUG_SUPPORTING_CONSTRAINTS
	TAB(t+1);
	cout<<"Confirmed level: "<<confirmed_level<<endl;
#endif

	// If "ft" is false at the confirmed level, we first need "establishment constraints"
	if (!is_in_state(ft, this->states[confirmed_level])) {
		Clause c;
		int k;
		for (k = confirmed_level; k < level; k++)
			if (is_poss_add(ft, this->actions[k])) {
				int bvar = get_bool_var(ft, this->actions[k], POSS_ADD);
				c.add_literal(bvar);
			}
		clauses.add_clause(c);
	}

	// Protection constraints
	for (int k = confirmed_level; k < level; k++)
		if (is_poss_del(ft, this->actions[k])) {
			Clause c;
			int bvar = get_bool_var(ft, this->actions[k], POSS_DEL);
			c.add_literal(-bvar);

			for (int j=k+1;j<level;j++) {
				if (is_poss_add(ft, this->actions[j])) {
					bvar = get_bool_var(ft, this->actions[j], POSS_ADD);
					c.add_literal(bvar);
				}
			}
			clauses.add_clause(c);
		}

	return true;

}
Exemple #2
0
Node::Node(Node::Serialized& s)
{
    int i;

    // Someday I'll find out why copy doesn't work here
    this->unassigned_atoms.clear();
    for (i = 0; i < s.unassigned_atoms_count; ++i)
        this->unassigned_atoms.insert(s.unassigned_atoms[i]);

    this->assignments.clear();
    for (i = 0; i < s.assignments_count; ++i)
    {
        int atom = abs(s.assignments[i]);
        this->assignments[atom] = (s.assignments[i] > 0);
    }

    // The following takes care of both clauses and literals list
    this->clauses.clear();
    this->literals.clear();
    i = 0;
    while (i < s.clauses_count)
    {
        Clause c;
        while (s.clauses[i] != 0)
        {
            Literal l(s.clauses[i]);
            c.add_literal(l);
            this->literals[l]++;
            ++i;
        }
        this->add_clause(c);
        ++i;
    }
}
Exemple #3
0
void StripsEncoding::append(int action) {

//#define DEBUG_APPEND
#ifdef DEBUG_APPEND
	int t = 1;
	TAB(t);
	cout<<"In appending action "<<action<<"..."<<endl;
#endif

	assert(action >= 0 && action < gnum_op_conn);

	State *current_state = this->get_last_state();

	State *resulting_state = (State*) calloc(1, sizeof(State));
	make_state(resulting_state, gnum_ft_conn);
	resulting_state->max_F = gnum_ft_conn;
	result_to_dest(resulting_state, current_state, action);

	this->states.push_back(resulting_state);
	this->actions.push_back(action);

	// Clauses associated with the new action
	ActionClauses new_action_clauses;

	// Update the clause set
	int level = this->actions.size()-1;

	assert(gop_conn[action].num_E == 1);
	int n_ef = gop_conn[action].E[0];

	// First, for known preconditions
	for (int i=0;i<gef_conn[n_ef].num_PC;i++) {

		int ft = gef_conn[n_ef].PC[i];

#ifdef DEBUG_APPEND
		TAB(t+1);
		cout<<"Known pre ";
		print_ft_name(ft);
		cout<<endl;
#endif

		ClauseSet cs;
		bool success = supporting_constraints(ft, level, cs);
		assert(success);

		// Update clauses for this precondition
		if (cs.size()) {
			new_action_clauses.pre_clauses[ft] = cs;

		}
	}

	// Second, for possible preconditions
	for (int i = 0; i < gef_conn[n_ef].num_poss_PC;i++) {
		int ft = gef_conn[n_ef].poss_PC[i];
		int bvar = get_bool_var(ft, action, POSS_PRE);
		assert(bvar > 0);

		if (is_in_state(ft, this->states[level])) {
			ClauseSet cs;
			bool success = supporting_constraints(ft, level, cs);
			assert(success);

			// Since "ft" is possible precondition, the above constraints need only when it is realized
			// as a precondition of the action.
			ClauseSet temp_cs;
			for (ClauseSet::const_iterator itr = cs.cbegin(); itr != cs.cend(); itr++) {
				Clause c = *itr;
				c.add_literal(-bvar);
				temp_cs.add_clause(c);
			}

			// Update clauses for this possible precondition
			if (temp_cs.size()) {
				new_action_clauses.poss_pre_clauses[ft] = temp_cs;

				//
//				cout<<temp_cs<<endl;
			}
		}
		else {	// If "ft" is false at the level, we don't need to find supporting clauses (i.e., they are empty)
				// This action is applicable only when this possible precondition is not realized
			Clause c;
			c.add_literal(-bvar);

			// Update clauses for this possible precondition
			ClauseSet cs;
			cs.add_clause(c);
			new_action_clauses.poss_pre_clauses[ft] = cs;

			//
//			cout<<cs<<endl;
		}
	}

	this->action_clauses.push_back(new_action_clauses);

	//


	//
//	cout<<"DONE APPEND."<<endl;
}