bool AbstractNode::isDisjunctionOfComplexConjunctions()
{
    if(AbstractNode::TYPE_OPERATION_OR != getType())
        return false; //not a disjunction

    int numOperations = 0;
    ChainIterator<AbstractNode*> *iterator = children->getIterator();
    while(true == iterator->hasNext()) {
        AbstractNode *child = iterator->next(); //Get an element which might be conjunction

        //Disjunction contains elements which are not parts of conjunction
        if(!((AbstractNode::TYPE_VARIABLE == child->getType()) ||
               (AbstractNode::TYPE_OPERATION_AND == child->getType()) ||
               (AbstractNode::TYPE_OPERATION_NOT == child->getType()))) {
            return false;
        }

        if(AbstractNode::TYPE_OPERATION_AND == child->getType()) {
            if(child->getChildren()->getSize() > 1)
                numOperations++;
        }

        if(AbstractNode::TYPE_OPERATION_NOT == child->getType()) {
            AbstractNode *grandChild = child->getChildren()->getFirstElement();
            if(AbstractNode::TYPE_VARIABLE != grandChild->getType()) {
                return false; //Contains complex NOT operation
            }
        }

    }
    return (numOperations > 0);
}
bool AbstractNode::consistsFromSimpleElements()
{
    ChainIterator<AbstractNode*> *iterator = children->getIterator();
    while(true == iterator->hasNext()) {
        AbstractNode *child = iterator->next();
        if(AbstractNode::TYPE_VARIABLE == child->getType())
            continue;
        if(AbstractNode::TYPE_OPERATION_NOT == child->getType()) {
            AbstractNode *notChild = child->getChildren()->getFirstElement();
            if(AbstractNode::TYPE_VARIABLE == notChild->getType())
                continue;
        }
        return false;
    }
    return true;
}
void AStarSearcher::computeBestPath(std::vector<AbstractNode*>& out_path)
{
	std::priority_queue<AbstractNode*, std::vector<AbstractNode*>, AStarPriorityQueueComparer> edgeList;

	AbstractNode* currentNode = m_rootNode;

	while(!currentNode->isEnd())
	{
		currentNode->spawnChildren();
		addExpandedNode();
		const std::vector<AbstractNode*>& children = currentNode->getChildren();

		for(int i = 0; i < children.size(); i++)
		{
			edgeList.push(children[i]);
		}

		if (edgeList.size() == 0)
			break;

		AbstractNode* nextBest = edgeList.top();
		edgeList.pop();

		//if we did not select a child node then we have to go back down and up through the tree
		if(nextBest->getParent() != currentNode)
			goToChild(currentNode, nextBest->getParent());

		currentNode = nextBest;
		currentNode->onEnter();
	}

	if (currentNode->isGoal()) {
		// Award 100 points
		setFinalScore(-currentNode->getTotalCost());
	} else {
		setFinalScore(-currentNode->getTotalCost());
	}

	while(currentNode)
	{
		out_path.insert(out_path.begin(), currentNode);
		currentNode = currentNode->getParent();
	}
}