Esempio n. 1
0
// construct an ebucore skeleton
ebucoreParser::ElementStruct ebucoreParser::constructSchema(xercesc::DOMElement * el) {
    // prepare the element information
    std::string str (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("name"))));
    std::string type (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("type"))));
    std::string ref (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("ref"))));
    std::string minimum (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
    std::string maximum (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
    // instantiate a new root
    ebucoreParser::ElementStruct root;
    // grab the name, the cardinalities, the type, attributes and children
    root.name = (str.size()>0)?str:ref;
    root.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
    root.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
    root.type = ((type.size()>0)?type:"undefined");
    // store the current element type inside the stack to avoid infinite loops
    ebucoreStack.push_back(root.type);
    // generate the attributes of the current element
    root.attribute = ebucoreParser::generateAttributes(removePrefix (type, ":"), el);
    // generate the children of the current element
    root.children = generateChildren(removePrefix (type, ":"), el,1);
    // pop the current element type outside of the stack
    ebucoreStack.pop_back();

    return root;
}
Esempio n. 2
0
const int BoardNode::generateChildren(const int depth)
{
  if(depth == 0 || b.won() != NULL)
  {
    children = NULL;
    return 0;
  }
  if(children != NULL)
    return generateChildren(depth - 1);
  
  children = new CHILD_LIST();
  
  vector<Piece> &pieces = b.getPieceList(b.whosTurn());
  for(auto i = pieces.begin(); i != pieces.end(); i++)
  {
    if(b.nextIn(b.whosTurn()))
    {
      if(b.nextIn(b.whosTurn()))
        continue;
    }
    auto validLocations = b.getValid(&*i);
    for(auto c = validLocations.begin(); c != validLocations.end(); c++)
    {
      ((*children)[Move(&*i, *c)] = new BoardNode(b, pov));
      auto temp = children->emplace(Move(&*i, *c, &b), new BoardNode(b, pov)).first;
      temp->first.changeBoard(temp->second->b);
      if(!temp->first.doMove())
	return -1;
    }
  }
  
  return 0;
}
Esempio n. 3
0
// include external elements (from groups)
void ebucoreParser::generateGroupChildren(std::list<ElementStruct> children, std::string father, xercesc::DOMElement * el) {
    // store the current position of xercesc pointer
    xercesc::DOMElement * tmpEl = el;
    // looking for the group who contains the other elements with the father name
    while (tmpEl != 0  && !((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) == removePrefix(father,":") )) {
        tmpEl = tmpEl->getNextElementSibling();
    }
    // enter inside the group
    tmpEl=tmpEl->getFirstElementChild();
    // looking for the sequence
    while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence") {
        tmpEl = tmpEl->getNextElementSibling();
    }
    // if pointer not null, grab the first child
    if (tmpEl != 0) {
        tmpEl=tmpEl->getFirstElementChild();
    }
    // while xerces pointer not null,
    while (tmpEl != 0) {
        // if it's an element
        if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
            // prepare the element informations
            std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
            std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
            std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
            std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
            std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
            // instantiate the list of children
            ebucoreParser::ElementStruct internalChildren;
            // identify the element name
            internalChildren.name = (name.size()>0)?name:ref;
            // identify the cardinality and type
            internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
            internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
            internalChildren.type = ( (type.size()>0) ? type : "" );
            // if it is not a standard type
            if (!isStandardType(type)) {
                // and if type is not null
                if (type.size()>0) {
                    // generate attributes
                    internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(removePrefix(internalChildren.type, ":"), tmpEl);
                    // and correct the type is required
                    internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
                } else {
                    // generate attributes and correct the type is required
                    internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
                    internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
                }
            }

            // if it is an ebucore element and the type of this element is not present in the element type stack
            if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
                // push the type
                ebucoreStack.push_back(internalChildren.type);
                // generate children
                internalChildren.children = generateChildren(removePrefix(internalChildren.type,":"), el, 1);
                // pop the type
                ebucoreStack.pop_back();
            }
            //push the internal child
            children.push_back(internalChildren);
        }
        // next
        tmpEl = tmpEl->getNextElementSibling();
    }
}
Esempio n. 4
0
// generate the children of an elements
std::list<ebucoreParser::ElementStruct> ebucoreParser::generateChildren(std::string father, xercesc::DOMElement * el, int level) {
    // instantiate the children list
    std::list<ebucoreParser::ElementStruct> children;
    // copy the current position of xercesc pointer
    xercesc::DOMElement * tmpEl = el;
    // while xercesc pointer not null, element different of complexType with the proper name
    while (tmpEl != 0  && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" || xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != father )) {
        tmpEl = tmpEl->getNextElementSibling();// next
    }
    // grab the first child of proper element
    tmpEl=tmpEl->getFirstElementChild();
    // looking for the sequence of elements
    while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence") {
        tmpEl = tmpEl->getNextElementSibling(); // next
    }
    // if pointer not null, grab the first child of the current element
    if (tmpEl != 0) {
        tmpEl=tmpEl->getFirstElementChild();
    }

    // while xerces point not null, loop
    while (tmpEl != 0) {
        // if current tag kind is element
        if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") {
            // prepare the element information
            std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))));
            std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type"))));
            std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))));
            std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs"))));
            std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs"))));
            // instantiate the children struct
            ebucoreParser::ElementStruct internalChildren;
            // grab the right name/references
            internalChildren.name = (name.size()>0)?name:ref;
            // identify the cardinality and the type of element
            internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1);
            internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1);
            internalChildren.type = ( (type.size()>0) ? type : "" );
            // if type is not standard
            if (!isStandardType(type)) {
                // if type is not null
                if (type.size()>0) {
                    //generate the attribute list of the current element
                    internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(removePrefix(internalChildren.type, ":"), tmpEl);
                    // and correct his type if required
                    internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type );
                } else {
                    // generate the attribute list of the current element and correct his type if required
                    internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl);
                    internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ;
                }
            }
            // if element type is ebucore and the type not present in the stack, then
            if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) {
                ebucoreStack.push_back(internalChildren.type); // push the type
                // generate the children
                internalChildren.children = generateChildren(removePrefix(internalChildren.type,":"), el, level+1);
                ebucoreStack.pop_back(); // pop the type
            }
            // push the children list
            children.push_back(internalChildren);
            // if the current tag king is group, then
        } else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group") {
            // generate the children of this group and then add it to current list of children
            generateGroupChildren(children, xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))), el);
        }
        tmpEl = tmpEl->getNextElementSibling(); // next
    }

    return children;

}
/*!
 This implements typical action traversal for an SoComplexShape node
*/
void
SoComplexShape::doAction(SoAction *action)
{
  // Make sure all the children exist
  if (children->getLength() == 0) { generateChildren(); }

  // SoAction has a method called "getPathCode()" that returns
  // a code indicating how this node is related to the path(s)
  // the action is being applied to. This code is one of the
  // following:
  //
  // NO_PATH    = Not traversing a path (action was applied
  //                to a node)
  // IN_PATH    = This node is in the path chain, but is not
  //                the tail node
  // BELOW_PATH = This node is the tail of the path chain or
  //                is below the tail
  // OFF_PATH   = This node is off to the left of some node in
  //                the path chain
  //
  // If getPathCode() returns IN_PATH, it returns (in its two
  // arguments) the indices of the next nodes in the paths.
  // (Remember that an action can be applied to a list of
  // paths.)

  // For the IN_PATH case, these will be set by getPathCode()
  // to contain the number of child nodes that are in paths and
  // the indices of those children, respectively. In the other
  // cases, they are not meaningful.
  int         numIndices;
  const int   *indices;

  // This will be set to the index of the last (rightmost)
  // child to traverse
  int         lastChildIndex;

  // If this node is in a path, see which of our children are
  // in paths, and traverse up to and including the rightmost
  // of these nodes (the last one in the "indices" array).
  if (action->getPathCode(numIndices, indices) ==
      SoAction::IN_PATH) {
    lastChildIndex = indices[numIndices - 1];
  }

  // Otherwise, consider all of the children
  else {
    lastChildIndex = children->getLength() - 1;
  }

  // Now we are ready to traverse the children, skipping every
  // other one. For the SoGetBoundingBoxAction, however, we
  // have to do some extra work in between each pair of
  // children - we have to make sure the center points get
  // averaged correctly.
  if (action->isOfType(
        SoGetBoundingBoxAction::getClassTypeId())) {
    SoGetBoundingBoxAction *bba =
      (SoGetBoundingBoxAction *) action;
    SbVec3f  totalCenter(0.0, 0.0, 0.0);
    int      numCenters = 0;

    for (int i = 0; i <= lastChildIndex; i++) {
      children->traverse(bba, i);

      // If the traversal set a center point in the action,
      // add it to the total and reset for the next child.
      if (bba->isCenterSet()) {
        totalCenter += bba->getCenter();
        numCenters++;
        bba->resetCenter();
      }
    }
    // Now, set the center to be the average. Since the
    // centers were already transformed, there's no need to
    // transform the average.
    if (numCenters != 0) {
      bba->setCenter(totalCenter / (float)numCenters, FALSE);
    }
  }

  // For all other actions, just traverse every child
  else
    for (int i = 0; i <= lastChildIndex; i++) {
      children->traverse(action, i);
    }
}
Esempio n. 6
0
int Principal::profundidade(vector<vector<int> > start, vector<vector<int> > goal){

    vector<pair < vector <vector<int> > , int > > open;
    vector<pair < vector <vector<int> > , int > > closed;
    pair < vector <vector<int> > , int >  X;
    vector<vector<vector <int> > > children;
    vector<vector<vector <int> > > temp;
    int id_pai = -1;
    int flag;
    int cont = 0;
    closed.clear();
    open.push_back(make_pair(start, id_pai));

    while(open.empty() == false){
        X = open.front();
        open.erase(open.begin());

        if(matriz_cmp(X.first, goal)){
            this->setLog(QString("Algoritmo: Busca em profundidade."));
            this->setLog(QString("Executando Movimentos..."));
            temp.push_back(X.first);
            while(X.second >= 0){
                X.first = closed.at(X.second).first;
                X.second = closed.at(X.second).second;
                temp.push_back(X.first);
                cont++;
            }
            for(int a = temp.size()-1; a >= 0; a--){
               printMatriz(temp.at(a));
            }
            this->setLog(QString("Numero de Estados: "+ QString("%1").arg(cont) ) );
            this->setLog(QString("Numero Total de Estados Visitados: "+QString("%1").arg( id_pai+1) ) );

            return 0;
        } else {
            children = generateChildren(X.first);
            closed.push_back(X);
            //printMatriz(X.first);
            id_pai++;
            flag = 0;

            int i = 0;
            int j = 0;
            for( i = children.size() - 1; i >= 0; i--){
                for(j=0;j<open.size(); j++){
                    if(matriz_cmp(children.at(i), open.at(j).first)){
                        flag = 1;
                    }
                }
                for(j = 0; j < closed.size(); j++){

                    if(matriz_cmp(children.at(i), closed.at(j).first)){
                        flag = 1;
                    }
                }
                if(flag == 0){

                    open.insert(open.begin(), make_pair(children.at(i), id_pai));
                }
                flag = 0;
            }
        }
    }
    this->setLog(QString("Fail"));
    return 1;
}