当前位置: 首页>>代码示例>>C++>>正文


C++ Relation::back方法代码示例

本文整理汇总了C++中Relation::back方法的典型用法代码示例。如果您正苦于以下问题:C++ Relation::back方法的具体用法?C++ Relation::back怎么用?C++ Relation::back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relation的用法示例。


在下文中一共展示了Relation::back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: special

bool special(Condition &condition, Relation &intermediate, Relation &filtered) {
  if (condition.type != ATOMIC) {
    return false;
  }
  switch (condition.get.atom.type) {
    case ATOM:
    case MEMBERSHIP:
    case SUBCLASS:
    case FRAME:
      return false;
    case EQUALITY: {
      Term *lhs = &(condition.get.atom.get.sides[0]);
      Term *rhs = &(condition.get.atom.get.sides[1]);
      if (lhs->type == VARIABLE && rhs->type == CONSTANT) {
        swap(lhs, rhs);
      }
      if (rhs->type == CONSTANT) {
        if (lhs->get.constant != rhs->get.constant) {
          Relation empty;
          filtered.swap(empty);
        } else {
          filtered = intermediate;
        }
      } else if (lhs->type == CONSTANT) {
        Relation result;
        Relation::iterator it = intermediate.begin();
        for (; it != intermediate.end(); ++it) {
          if (it->size() <= rhs->get.variable) {
            it->resize(rhs->get.variable + 1);
          }
          if (it->at(rhs->get.variable) == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[rhs->get.variable] = lhs->get.constant;
          } else if (it->at(rhs->get.variable) == lhs->get.constant) {
            result.push_back(*it);
          }
        }
        filtered.swap(result);
      } else {
        varint_t maxvar = max(lhs->get.variable, rhs->get.variable);
        Relation result;
        Relation::iterator it = intermediate.begin();
        for (; it != intermediate.end(); ++it) {
          if (it->size() <= maxvar) {
            it->resize(maxvar + 1);
          }
          constint_t c1 = it->at(lhs->get.variable);
          constint_t c2 = it->at(rhs->get.variable);
          if (c1 == 0 && c2 == 0) {
            cerr << "[ERROR] Please make sure equality statements occur to the right of atomic formulas that bind a variable." << endl;
            return true;
          }
          if (c1 == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[lhs->get.variable] = c2;
          } else if (c2 == 0) {
            result.push_back(*it);
            Tuple &t = result.back();
            t[rhs->get.variable] = c1;
          } else if (c1 == c2) {
            result.push_back(*it);
          }
        }
        filtered.swap(result);
      }
      return true;
    }
    case EXTERNAL: {
      break; // just handle outside the messy switch statement
    }
    default: {
      cerr << "[ERROR] Unhandled case " << (int)condition.get.atom.type << " at line " << __LINE__ << endl;
      return false;
    }
  }

  ///// HANDLE BUILTIN (EXTERNAL) /////
  Builtin &builtin = condition.get.atom.get.builtin;
  switch (builtin.predicate) {
    case BUILTIN_PRED_LIST_CONTAINS: {
      if (builtin.arguments.end - builtin.arguments.begin != 2) {
        cerr << "[ERROR] Invalid use of list contains builtin, which should have exactly two arguments, but instead found " << builtin << endl;
        return false;
      }
      Term *arg1 = builtin.arguments.begin;
      Term *arg2 = arg1 + 1;
      if (arg1->type != LIST) {
        cerr << "[ERROR] First argument of list contains builtin must be a list, but instead found " << *arg1 << endl;
        return false;
      }
      switch (arg2->type) {
        case FUNCTION:
          cerr << "[ERROR] Functions not supported." << endl;
          return false;
        case LIST:
          cerr << "[ERROR] Currently not supporting nested lists." << endl;
          return false;
        case CONSTANT: {
//.........这里部分代码省略.........
开发者ID:jrweave,项目名称:phd,代码行数:101,代码来源:infer-rules.cpp


注:本文中的Relation::back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。