本文整理汇总了C++中FunctionTerm::get_args方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionTerm::get_args方法的具体用法?C++ FunctionTerm::get_args怎么用?C++ FunctionTerm::get_args使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionTerm
的用法示例。
在下文中一共展示了FunctionTerm::get_args方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: instantiate_term
Term* UniversalInstantiator::instantiate_term(Term* t,
map<int, Term*> &sub_map)
{
if(t->get_term_type() == CONSTANT_TERM)
return t;
if(t->get_term_type() == VARIABLE_TERM){
VariableTerm *vt = (VariableTerm*)t;
if(sub_map.count(vt->get_var_id()) == 0)
return vt;
return sub_map[vt->get_var_id()];
}
if(t->get_term_type() == ARITHMETIC_TERM) {
ArithmeticTerm* at = (ArithmeticTerm*)t;
bool changed = false;
map<Term*, long int> new_elems;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for(; it!= at->get_elems().end(); it++) {
Term* new_t = instantiate_term(it->first, sub_map);
if(new_t != t) changed = true;
new_elems[new_t] = it->second;
}
if(!changed) return at;
return ArithmeticTerm::make(new_elems, at->get_constant());
}
FunctionTerm *ft = (FunctionTerm*)t;
vector<Term*> new_args;
for(unsigned int i=0; i < ft->get_args().size(); i++)
{
Term* cur = instantiate_term(ft->get_args()[i], sub_map);
new_args.push_back(cur);
}
return FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());
}
示例2: get_vars
void Term::get_vars(set<Term*>& vars)
{
term_type tt = get_term_type();
if (tt == CONSTANT_TERM)
return;
if (tt == VARIABLE_TERM) {
VariableTerm* vt = (VariableTerm*) this;
vars.insert(vt);
return;
}
if (tt == FUNCTION_TERM) {
FunctionTerm* ft = (FunctionTerm*) this;
for (unsigned int i = 0; i < ft->get_args().size(); i++) {
ft->get_args()[i]->get_vars(vars);
}
} else {
assert(tt == ARITHMETIC_TERM);
ArithmeticTerm* at = (ArithmeticTerm*) this;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for (; it != at->get_elems().end(); it++) {
it->first->get_vars(vars);
}
}
}
示例3: get_all_fun_ids
void Term::get_all_fun_ids(set<int> & ids)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
case VARIABLE_TERM:
return;
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*)this;
ids.insert(ft->get_id());
for(unsigned int i=0; i < ft->get_args().size(); i++)
{
ft->get_args()[i]->get_all_fun_ids(ids);
}
return;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!=elems.end(); it++)
{
it->first->get_all_fun_ids(ids);
}
return;
}
default:
assert(false);
}
}
示例4: evalute_term
Term* Term::evalute_term(map<Term*, SatValue>& assignments)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
return this;
case VARIABLE_TERM:
{
if(assignments.count(this) > 0){
return ConstantTerm::make(assignments[this].value.to_int());
}
return this;
}
case FUNCTION_TERM:
{
if(assignments.count(this) > 0){
return ConstantTerm::make(assignments[this].value.to_int());
}
vector<Term*> new_args;
FunctionTerm* ft = (FunctionTerm*) this;
for(unsigned int i = 0; i < ft->get_args().size(); i++)
{
Term* arg = ft->get_args()[i];
arg = arg->evalute_term(assignments);
new_args.push_back(arg);
}
Term* new_t =
FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());
if(assignments.count(new_t) > 0)
return ConstantTerm::make(assignments[new_t].value.to_int());
return new_t;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
Term* res = ConstantTerm::make(at->get_constant());
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!=elems.end(); it++)
{
Term* t = it->first;
Term* val = t->evalute_term(assignments);
res = res->add(val->multiply(it->second));
}
if(assignments.count(res) > 0)
return ConstantTerm::make(assignments[res].value.to_int());
return res;
}
default:
assert(false);
}
}
示例5: build_index_set_term
/*
* Cdr's down terms to build the index set.
* This can only be called if the term is not in index guard.
*/
bool UniversalInstantiator::build_index_set_term(Term* t, set<int> &qvars,
int fun_id, int arg_num)
{
if(t->get_term_type() == FUNCTION_TERM)
{
FunctionTerm* ft = (FunctionTerm*)t;
bool contains_uvar = false;
for(unsigned int i=0; i < ft->get_args().size(); i++) {
bool res =
build_index_set_term(ft->get_args()[i], qvars, ft->get_id(), i);
if(res) contains_uvar = true;
}
if(contains_uvar) return true;
}
if(t->get_term_type() == ARITHMETIC_TERM)
{
bool contains_uvar = false;
ArithmeticTerm* at = (ArithmeticTerm*) t;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for(; it!=at->get_elems().end(); it++){
bool res = build_index_set_term(it->first, qvars, -1, -1);
if(res) contains_uvar = true;
}
if(contains_uvar) return true;
}
pair<int, int> key(fun_id, arg_num);
if(reverse_fun_arg_universal.count(key) ==0) return false;
if(t->get_term_type() == VARIABLE_TERM){
VariableTerm* vt = (VariableTerm*) t;
if(qvars.count(vt->get_var_id()) != 0){
return true;
}
}
Term* se = t;
set<qvar>* val = reverse_fun_arg_universal[key];
if(val->size() == 0) {
return false;
}
bool added = false;
set<qvar>::iterator it = val->begin();
for(; it!= val->end(); it++){
set<Term*>* s = index_set[*it];
if(s == NULL){
s= new set<Term*>();
index_set[*it] =s;
}
unsigned int old_size = s->size();
s->insert(se);
if(s->size() > old_size) added = true;
}
return false;
}
示例6: contains_term
bool Term::contains_term(Term* t)
{
if(this == t) return true;
switch(this->get_term_type())
{
case CONSTANT_TERM:
return false;
case VARIABLE_TERM:
{
return false;
}
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
for(unsigned int i=0; i< args.size(); i++) {
if(args[i]->contains_term(t)) return true;
}
return false;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!= elems.end(); it++) {
if(it->first->contains_term(t)) return true;
}
return false;
}
default:
assert(false);
}
}
示例7: clear_representatives
void Term::clear_representatives()
{
this->representative = NULL;
switch(this->get_term_type())
{
case CONSTANT_TERM:
case VARIABLE_TERM:
return;
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
for(unsigned int i=0; i< args.size(); i++) {
Term* t = args[i];
t->clear_representatives();
}
return;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!= elems.end(); it++)
{
Term* t = it->first;
t->clear_representatives();
}
return;
}
default:
assert(false);
}
}
示例8: contains_var
bool Term::contains_var(int var_id)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
return false;
case VARIABLE_TERM:
{
VariableTerm* vt = (VariableTerm*) this;
return(vt->get_var_id() == var_id);
}
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
for(unsigned int i=0; i<args.size(); i++) {
Term* cur_arg = args[i];
if(cur_arg->contains_var(var_id)) return true;
}
return false;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!= elems.end(); it++) {
if(it->first->contains_var(var_id)) return true;
}
return false;
}
default:
assert(false);
}
}
示例9: substitute
Term* Term::substitute(Term* (*sub_func)(Term* t, void* data), void* my_data)
{
Term* new_t = (*sub_func)(this, my_data);
if(new_t != this) {
return new_t;
}
Term* res = NULL;
switch (get_term_type()) {
case CONSTANT_TERM:
case VARIABLE_TERM: {
res= this;
break;
}
case FUNCTION_TERM: {
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
vector<Term*> new_args;
bool changed = false;
for (unsigned int i = 0; i < args.size(); i++) {
Term* new_arg = args[i]->substitute(sub_func, my_data);
if (new_arg != args[i])
changed = true;
new_args.push_back(new_arg);
}
if (!changed) {
res = this;
break;
}
res= FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());
break;
}
case ARITHMETIC_TERM: {
ArithmeticTerm* at = (ArithmeticTerm*) this;
bool changed = false;
map<Term*, long int> new_elems;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for (; it != at->get_elems().end(); it++) {
Term* new_t = it->first->substitute(sub_func, my_data);
if (new_t != it->first)
changed = true;
new_elems[new_t]+= it->second;
}
if (!changed) {
res = at;
break;
}
res = ArithmeticTerm::make(new_elems, at->get_constant());
break;
}
default:
assert(false);
}
return res;
}
示例10: replace_argument
Term* Term::replace_argument(int fun_id, int arg_num, Term* replacement)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
case VARIABLE_TERM:
return this;
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*)this;
const vector<Term*>& args = ft->get_args();
bool changed = false;
vector<Term*> new_args;
for(unsigned int i=0; i < args.size(); i++)
{
Term* cur = args[i];
Term* new_cur = cur->replace_argument(fun_id, arg_num, replacement);
if(cur != new_cur) {
changed = true;
}
new_args.push_back(new_cur);
}
if(ft->get_id() == fun_id )
{
changed = true;
new_args[arg_num] = replacement;
}
if(!changed) return this;
return FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
bool changed = false;
map<Term*, long int> new_elems;
for(; it!=elems.end(); it++)
{
Term* t = it->first;
long int c = it->second;
Term* new_t = t->replace_argument(fun_id, arg_num, replacement);
new_elems[new_t] = c;
if(t!= new_t) changed = true;
}
if(!changed) return this;
return ArithmeticTerm::make(new_elems, at->get_constant());
}
default:
assert(false);
}
}
示例11: rename_variables
Term* Term::rename_variables(map<int, int>& replacements)
{
switch (get_term_type()) {
case CONSTANT_TERM:
return this;
case VARIABLE_TERM: {
VariableTerm* vt = (VariableTerm*) this;
int var_id = vt->get_var_id();
if (replacements.count(var_id)==0)
return this;
Term* res= VariableTerm::make(replacements[var_id]);
return res;
}
case FUNCTION_TERM: {
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
vector<Term*> new_args;
bool changed = false;
for (unsigned int i = 0; i < args.size(); i++) {
Term* new_arg = args[i]->rename_variables(replacements);
if (new_arg != args[i])
changed = true;
new_args.push_back(new_arg);
}
if (!changed)
return this;
Term* res= FunctionTerm::make(ft->get_id(), new_args,
ft->is_invertible());
return res;
}
case ARITHMETIC_TERM: {
ArithmeticTerm* at = (ArithmeticTerm*) this;
bool changed = false;
map<Term*, long int> new_elems;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for (; it != at->get_elems().end(); it++) {
Term* new_t = it->first->rename_variables(replacements);
if (new_t != it->first)
changed = true;
new_elems[new_t] += it->second;
}
if (!changed)
return at;
Term* res= ArithmeticTerm::make(new_elems, at->get_constant());
return res;
}
default:
assert(false);
}
}
示例12: rename_variable
Term* Term::rename_variable(int old_var_id, int new_var_id)
{
switch (get_term_type()) {
case CONSTANT_TERM:
return this;
case VARIABLE_TERM: {
VariableTerm* vt = (VariableTerm*) this;
if (old_var_id != vt->get_var_id())
return this;
Term* res = VariableTerm::make(new_var_id);
return res;
}
case FUNCTION_TERM: {
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*>& args = ft->get_args();
map<Term*, Term*> old_to_new;
bool changed = false;
for (unsigned int i = 0; i < args.size(); i++) {
Term* old_arg = args[i];
Term* new_arg = args[i]->rename_variable(old_var_id, new_var_id);
if (new_arg != args[i])
changed = true;
old_to_new[old_arg] = new_arg;
}
if (!changed)
return this;
Term* res = ft->substitute(old_to_new);
return res;
}
case ARITHMETIC_TERM: {
ArithmeticTerm* at = (ArithmeticTerm*) this;
bool changed = false;
map<Term*, long int> new_elems;
map<Term*, long int>::const_iterator it = at->get_elems().begin();
for (; it != at->get_elems().end(); it++) {
Term* new_t = it->first->rename_variable(old_var_id, new_var_id);
if (new_t != it->first)
changed = true;
new_elems[new_t] += it->second;
}
if (!changed)
return at;
Term* res = ArithmeticTerm::make(new_elems, at->get_constant());
return res;
}
default:
assert(false);
}
}
示例13: get_all_arguments
void Term::get_all_arguments(int fun_id, int arg_num, set<Term*> & args)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
case VARIABLE_TERM:
return;
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*)this;
if(ft->get_id() == fun_id){
assert((int) ft->get_args().size() > arg_num);
args.insert(ft->get_args()[arg_num]);
}
for(unsigned int i=0; i < ft->get_args().size(); i++)
{
ft->get_args()[i]->get_all_arguments(fun_id, arg_num, args);
}
return;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!=elems.end(); it++)
{
it->first->get_all_arguments(fun_id, arg_num, args);
}
return;
}
default:
assert(false);
}
}
示例14: get_all_first_arguments
void Term::get_all_first_arguments(set<int>& fn_ids, map<int, set<Term*> >&
fn_id_to_first_arg)
{
switch(this->get_term_type())
{
case CONSTANT_TERM:
case VARIABLE_TERM:
return;
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*)this;
const vector<Term*>& args = ft->get_args();
int my_id = ft->get_id();
if(fn_ids.count(my_id) > 0) {
Term* arg = args[0];
fn_id_to_first_arg[my_id].insert(arg);
}
for(unsigned int i=0; i < args.size(); i++)
{
Term* cur = args[i];
cur->get_all_first_arguments(fn_ids, fn_id_to_first_arg);
}
return;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int>& elems = at->get_elems();
map<Term*, long int>::const_iterator it = elems.begin();
for(; it!=elems.end(); it++)
{
Term* t = it->first;
t->get_all_first_arguments(fn_ids, fn_id_to_first_arg);
}
return;
}
default:
assert(false);
}
}
示例15: get_attributes
void Term::get_attributes(set<CNode*> & attributes)
{
CNode* attrib_c = NULL;
if(attribute == TERM_ATTRIB_GEQZ) {
attrib_c = ILPLeaf::make(this, ConstantTerm::make(0), ILP_GEQ);
}
else if(attribute == TERM_ATTRIB_GTZ) {
attrib_c = ILPLeaf::make(this, ConstantTerm::make(0), ILP_GT);
}
if(attrib_c != NULL) attributes.insert(attrib_c);
switch(get_term_type())
{
case FUNCTION_TERM:
{
FunctionTerm* ft = (FunctionTerm*) this;
const vector<Term*> & args = ft->get_args();
for(unsigned int i=0; i<args.size(); i++)
{
Term* t = args[i];
t->get_attributes(attributes);
}
break;
}
case ARITHMETIC_TERM:
{
ArithmeticTerm* at = (ArithmeticTerm*) this;
const map<Term*, long int> & elems = at->get_elems();
map<Term*, long int>::const_iterator it= elems.begin();
for(; it!= elems.end(); it++)
{
Term* t = it->first;
t->get_attributes(attributes);
}
break;
}
default:
break;
}
}