Example #1
0
void Node::AddChild(Node& child)
{
	child.DetachNode();
	m_members.push_back(&child);
	child.SetParent(this);
	child.SetRoot(GetRoot());
}
Example #2
0
Node* Semester::CreateSplit(Node *parent){
  Node *retnode = new Node(NODE_SPLIT);
  parent->SetChild(retnode);
  retnode->SetParent(parent);
  total_width += 250;
  return retnode;
}//createSplit
Example #3
0
void Node::DetachChild( Node &child )
{
	auto it = std::find(mChilds.begin(), mChilds.end(), &child);
	GCLAssert(it != mChilds.end());
	mChilds.erase(it);
	child.SetParent(nullptr);
}
Example #4
0
void Trie::addWord(string word)
{
	Node* CurrentNode = root;
	
	// Check if the string is empty if so return.
	if(word.length() == 0)
		return;
	
	// Loop through the word
	for(unsigned int i = 0; i < word.length(); i++)
	{
		// Grab the child node associated with the character from the current node.
		Node* Child = CurrentNode->GetChild(word[i]);
		
		// If not null the child node is the current node.
		if(Child != NULL)
		{
			CurrentNode = Child;
		}
		else // If the child node is empty we add a new child node to the current.
		{
			Node* NewNode = new Node();
			// Set the new nodes value.
			NewNode->SetValue(word[i]);
			NewNode->SetParent(CurrentNode);
			CurrentNode->addChildNode(NewNode);
			CurrentNode = NewNode;
		}
		
		// If we are at the end of the word set the word mark to true.
		if(word.length() - 1 == i)
			CurrentNode->SetMarkEnd();	
	}
}
Example #5
0
bool RBT::LeftRotate(Node* toLR)
{
    if (!toLR)
        return false;

    Node* right = toLR->GetRight();

    toLR->SetRight(right->GetLeft());

    if (right->GetLeft() != NIL)
        right->GetLeft()->SetParent(toLR);

    right->SetParent(toLR->GetParent());

    if (toLR->GetParent() == NIL)
        _root = right;
    else if (toLR == toLR->GetParent()->GetLeft())
        toLR->GetParent()->SetLeft(right);
    else
        toLR->GetParent()->SetRight(right);

    right->SetLeft(toLR);
    toLR->SetParent(right);

    return true;
}
Example #6
0
bool RBT::RightRotate(Node* toRR)
{
    if (!toRR)
        return false;

    Node* left = toRR->GetLeft();

    toRR->SetLeft(left->GetRight());

    if (left->GetRight() != NIL)
        left->GetRight()->SetParent(toRR);

    left->SetParent(toRR->GetParent());

    if (toRR->GetParent() == NIL)
        _root = left;
    else if (toRR == toRR->GetParent()->GetRight())
        toRR->GetParent()->SetRight(left);
    else
        toRR->GetParent()->SetLeft(left);

    left->SetRight(toRR);
    toRR->SetParent(left);

    return true;
}
Example #7
0
Node* Semester::CreateChoice(Node *parent, std::vector<Course*> options){
  Node *retnode = new Node(NODE_CHOICE);
  std::vector<Node*> choices;
  for(unsigned int i = 0; i < options.size(); i++)
    choices.push_back(new Node(options[i]));
  retnode->SetChoices(choices);
  retnode->SetParent(parent);
  return retnode;
}//CreateChoice
Example #8
0
// the constructor
CCDIKSolver::CCDIKSolver(Actor* actor, Node* startNode, Node* endNode, bool cloneNodes) : Controller( actor )
{
	mStartNode	= startNode;
	mEndNode	= endNode;

	// if we want to clone the IK chain
	if (cloneNodes) 
	{
		mEndNode_Clone = endNode->Clone(actor);
		Node *tempNode = mEndNode_Clone;

		Node *i = endNode->GetParent();
		while (i != startNode)
		{
			tempNode->SetParent(i->Clone(actor));
			tempNode->GetParent()->AddChild(tempNode);
			tempNode = tempNode->GetParent();
			i = i->GetParent();
		}

		mStartNode_Clone = mStartNode->Clone(actor);
		tempNode->SetParent(mStartNode_Clone);
		mStartNode_Clone->AddChild(tempNode);
		mStartNode_Clone->SetParent(startNode->GetParent());

		// when cloning nodes, one iteration is enough to find the new solution
		mMaxIterations  = 1;
	}
	else
	{
		mEndNode_Clone	 = mEndNode;
		mStartNode_Clone = mStartNode;
		
		// The solver usually doesn't take more than 10 iterations to find the solution if its in reach.
		// Its usually below 5. If this is set higher, then the solver will meerly take longer to realise
		// that it cant reach the goal.
		mMaxIterations  = 10;
	}
	
	mHasSolution	= false;
	mDistThreshold	= 0.1f;
	mDoJointLimits  = true;
	mGoal.Set(0, 0, 0);
}
void Map::AddToWListM(Node n, Node p)
{
	if (CheckDuplicates(n.GetX(), n.GetY())) {
		n.SetParent(p);
		nodes[n.GetX()][n.GetY()].SetParent(p);
		nodes[n.GetX()][n.GetY()].SetGDistance(p.GetGDistance() + 10);	
		nodes[n.GetX()][n.GetY()].SetHDistanceManhatten(eNode.GetX(), eNode.GetY());
		workinglist.push(nodes[n.GetX()][n.GetY()]);
		duplicates[n.GetX()][n.GetY()] = true;
	}
}
Example #10
0
/// Make an exact, deep copy of a map node
Node* Node::Copy()
{
	Node* copy = new Node(_pos, _mov, _tt, _nt);
	copy->SetParent(_parent);
	copy->SetChild(_child);
	copy->setG(_g);
	copy->setH(_h);
	copy->setF(_f);

	return copy;
}
Example #11
0
Node* Node::InsertChild(int pos)
{
    vector<Node*>::iterator it = children.begin();
    Node* n = this->CreateNode(treeInfo);
    children.insert(it + pos, n);
    n->SetParent(this);


    if (treeInfo)
        treeInfo->OnNodeInserted(n, pos);

    return n;
}
Example #12
0
GCL::Node::~Node()
{
	if (mParentNode)
	{
		mParentNode->DetachChild(*this);
	}
	for (auto it = mChilds.begin(); it != mChilds.end(); ++it)
	{
		Node *tempNode = *it;
		tempNode->SetParent(nullptr);
		delete tempNode;
	}
	mChilds.clear();
}
Example #13
0
// Reference code (it's in document)
void AStar::FindPath(Node *start, Node *end)
{
    start->SetF(0);
    start->SetG(0);
    start->SetH(0);
    this->PushNode(start);

    while (open.count() > 0)
    {
        // Find node by lowest F value
        Node *node = this->PopNode();
        this->IncreaseNodeCount();

        if (node == end)
        {
            this->ReconstructPath(end);
            return;
        }

        closed.append(node);

        for (int i = 0; i < node->GetConnectors().count(); i++)
        {
            Connector *connector = node->GetConnectors().at(i);
            Node *neighbour = connector->GetChild();

            if (this->closed.contains(neighbour))
                continue;

            double g = node->GetG() + GetCost(node,connector);

            if (!open.contains(neighbour) || g < neighbour->GetG())
            {
                neighbour->SetParent(node);
                neighbour->SetG(g);
                neighbour->SetH(GetHeuristic(neighbour,end));
                neighbour->SetF(neighbour->GetG() + neighbour->GetH());
                //this->IncreaseNodeCount();

                if (!this->open.contains(neighbour))
                    this->PushNode(neighbour);
            }
        }
    }

    this->ReconstructPath(end);
}
Example #14
0
void Tools::UpdateNodeScoreInVector(Node *currentNode,Node updatedNode,std::vector<Node>& nodeVector, int gAdd, std::map<Node,Node>& parents)
{

    for(std::vector<Node>::iterator it = nodeVector.begin(); it != nodeVector.end(); ++it) {
        Node itNode = *it;
        if ( updatedNode.GetX() == itNode.GetX() && updatedNode.GetY() == itNode.GetY()) {

            int tempScore = currentNode->GetG() + gAdd + itNode.GetH();
            //std::cout << "UPDAAAAATTTEEEEEE: " << itNode.GetScore()<< " into :" << tempScore << "\n";
            if(tempScore < itNode.GetScore()) {
                itNode.SetG(currentNode->GetG() + gAdd);
                parents[itNode] = *currentNode;
                itNode.SetParent(currentNode);
            }
        }
    }
}
Example #15
0
void Map::AddToWListD(Node n, Node p)
{
	if (CheckDuplicates(n.GetX(), n.GetY())) {
		n.SetParent(p);
		nodes[n.GetX()][n.GetY()].SetParent(p);

		if (n.GetX() != p.GetX() && n.GetY() != p.GetY()) {
			nodes[n.GetX()][n.GetY()].SetGDistance(p.GetGDistance() + 14);
		} else {
			nodes[n.GetX()][n.GetY()].SetGDistance(p.GetGDistance() + 10);
		}

		nodes[n.GetX()][n.GetY()].SetHDistanceDiagonal(eNode.GetX(), eNode.GetY());
		workinglist.push(nodes[n.GetX()][n.GetY()]);
		duplicates[n.GetX()][n.GetY()] = true;
	}
}
Example #16
0
bool RBT::Delete(Node* toDelete)
{
    if (!toDelete)
        return false;

    COLOR deletedColor = toDelete->GetColor();
    Node* toFix;

    if (toDelete->GetLeft() == NIL)
    {
        toFix = toDelete->GetRight();
        Transplant(toDelete, toDelete->GetRight());
    }
    else if (toDelete->GetRight() == NIL)
    {
        toFix = toDelete->GetLeft();
        Transplant(toDelete, toDelete->GetLeft());
    }
    else
    {
        Node* successor = GetSuccessorOf(toDelete);
        deletedColor = successor->GetColor();
        toFix = successor->GetRight();

        if (successor->GetParent() == NIL)
            toFix->SetParent(successor);
        else
        {
            Transplant(successor, successor->GetRight());
            successor->SetRight(toDelete->GetRight());
            successor->GetRight()->SetParent(successor);
        }

        Transplant(toDelete, successor);
        successor->SetLeft(toDelete->GetLeft());
        successor->GetLeft()->SetParent(successor);
        successor->SetColor(toDelete->GetColor());
    }

    if (deletedColor == BLACK)
        FixDeletion(toFix);

    return true;
}
Example #17
0
bool Tools::Astar(Node start, Node destination, bool **pathingMap, std::vector<Node>& path)
{
    //initialisation des structure necessaire
    bool solution = false;
    std::vector<Node> openNodes;
    std::vector<Node> closedNodes;
    std::map<Node,Node> parents;
    //initialisation du cout du premier node a 0
    start.SetG(0);
    start.SetH(0);
    //ajout au vecteur ouvert
    openNodes.push_back(start);
    Node current;
    int currentIndex;

    while (solution == false) {

        //Si le vecteur ouvert est vide il n'y a pas de solution
        if(openNodes.empty()) {
            return false;
        }
        //index pour faciliter le retrer de current au vecteur ouvert
        int index = 0;

        //choisi le meilleur noeud dans le vecteur ouvert
        current = BestNodeInVector(openNodes, index);

        //ajout dans le vecteur fermer
        closedNodes.push_back(current);
        currentIndex = closedNodes.size() - 1;
        //on suprime le node choisi du vecteur ouvert
        openNodes.erase(openNodes.begin()+index);

        //verification si on est a destination alors on quitte la boucle
        if (current.GetX() == destination.GetX() && current.GetY() == destination.GetY()) {
            solution = true;
            break;
        }

        //Verification de la case en bas a gauche
        if(CheckInBound(current.GetBottomLeftNode()) && Passable(current.GetBottomLeftNode(),pathingMap) && !VectorContainsNode(current.GetBottomLeftNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetBottomLeftNode(),openNodes)) {
                Node nodeToAdd = current.GetBottomLeftNode();
                nodeToAdd.SetG(current.GetG()+14);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetBottomLeftNode(),openNodes, 14,parents);
            }
        }

        //Verification de la case en bas
        if(CheckInBound(current.GetBottomNode()) && Passable(current.GetBottomNode(),pathingMap) && !VectorContainsNode(current.GetBottomNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetBottomNode(),openNodes)) {
                Node nodeToAdd = current.GetBottomNode();
                nodeToAdd.SetG(current.GetG()+10);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetBottomNode(),openNodes, 10,parents);
            }
        }
        //Verification de la case a gauche
        if(CheckInBound(current.GetLeftNode()) && Passable(current.GetLeftNode(),pathingMap) && !VectorContainsNode(current.GetLeftNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetLeftNode(),openNodes)) {
                Node nodeToAdd = current.GetLeftNode();
                nodeToAdd.SetG(current.GetG()+10);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetLeftNode(),openNodes, 10,parents);
            }
        }
        // Verification de la case en haut a gauche
        if(CheckInBound(current.GetTopLeftNode()) && Passable(current.GetTopLeftNode(),pathingMap) && !VectorContainsNode(current.GetTopLeftNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetTopLeftNode(),openNodes)) {
                Node nodeToAdd = current.GetTopLeftNode();
                nodeToAdd.SetG(current.GetG()+14);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetTopLeftNode(),openNodes, 14,parents);
            }
        }
        //Verification de la case en haut
        if(CheckInBound(current.GetTopNode()) && Passable(current.GetTopNode(),pathingMap) && !VectorContainsNode(current.GetTopNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetTopNode(),openNodes)) {
                Node nodeToAdd = current.GetTopNode();
                nodeToAdd.SetG(current.GetG()+10);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetTopNode(),openNodes, 10,parents);
            }
        }
        // Verification de la case en haut a droite
        if(CheckInBound(current.GetTopRightNode()) && Passable(current.GetTopRightNode(),pathingMap) && !VectorContainsNode(current.GetTopRightNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetTopRightNode(),openNodes)) {
                Node nodeToAdd = current.GetTopRightNode();
                nodeToAdd.SetG(current.GetG()+14);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetTopRightNode(),openNodes, 14,parents);
            }
        }
        //Verification de la case a droite
        if(CheckInBound(current.GetRightNode()) && Passable(current.GetRightNode(),pathingMap) && !VectorContainsNode(current.GetRightNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetRightNode(),openNodes)) {
                Node nodeToAdd = current.GetRightNode();
                nodeToAdd.SetG(current.GetG()+10);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetRightNode(),openNodes, 10,parents);
            }
        }
        // Verification de la case en bas a droite
        if(CheckInBound(current.GetBottomRightNode()) && Passable(current.GetBottomRightNode(),pathingMap) && !VectorContainsNode(current.GetBottomRightNode(),closedNodes))
        {
            if(!VectorContainsNode(current.GetBottomRightNode(),openNodes)) {
                Node nodeToAdd = current.GetBottomRightNode();
                nodeToAdd.SetG(current.GetG()+14);
                nodeToAdd.SetH(DistanceManhattan(nodeToAdd,destination)*10);
                nodeToAdd.SetParent(&closedNodes[currentIndex]);
                parents[nodeToAdd] = closedNodes[currentIndex];
                openNodes.push_back(nodeToAdd);
            }
            else
            {
                UpdateNodeScoreInVector(&closedNodes[currentIndex],current.GetBottomRightNode(),openNodes, 14,parents);
            }
        }
    }

    //Si on trouve une solution alors on Backtrack jusqu'au noeux d'origine
    if(solution == true) {

//      Implementation avec les pointeur parent directement dans les Node
//        Node *currentBactrack = &closedNodes[currentIndex];
//        path.push_back(*currentBactrack);
//        while (currentBactrack->HasParent()){
//            std::cout << "solution x : " << currentBactrack->GetX()<<" solution y : " << currentBactrack->GetY() << "\n";
//            std::cout << "trackback : "<< path.size() << "\n";
//            currentBactrack = currentBactrack->GetParent();
//            std::cout << "test";
//            path.push_back(*currentBactrack);
//            std::cout << " solution x : " << currentBactrack->GetX()<<" solution y : " << currentBactrack->GetY() << "\n";
//
//        }

        //Implementation en utilisant une map entre les Nodes et leur parents
        Node currentBactrack = closedNodes[currentIndex];
        path.push_back(currentBactrack);
        std::map<Node,Node>::iterator it = parents.find(currentBactrack);
        while(it != parents.end()) {
            currentBactrack = it->second;
            //std::cout << "solution x : " << currentBactrack.GetX()<<" solution y : " << currentBactrack.GetY() << "\n";
            //std::cout << "trackback : "<< path.size() << "\n";
            path.push_back(currentBactrack);
            it = parents.find(currentBactrack);

        }
    }
    return true;
}
Example #18
0
Node* Semester::AddChild(Node *parent, Course *child){
  Node *retnode = new Node(child);
  parent->SetChild(retnode);
  retnode->SetParent(parent);
  return retnode;
}//AddChild
Example #19
0
Node* Semester::AddChild(Node *parent, Course *child, unsigned int index){
  Node *retnode = new Node(child);
  parent->SetChild(retnode, index);
  retnode->SetParent(parent);
  return retnode;
}//AddChild