コード例 #1
0
void Dijkstra::calcPath(Workload& request, Graph& network, Stats& stats) {

	bool pathFound=false;
	bool exitLoop=false;
	Element current; // current Element
	Visited visited; // Visited list
	Priority items; // priority queue
	double previousCost=-1;

	// 1. Get initial Start node
	current.id=request.origin;
	current.cost=0;
	current.parent=request.origin; // TODO - possible problem...
	items.push(current);

	// 2. Loop until we have found a valid path
	//while (!exitLoop && !items.empty()){
	while (!items.empty()){
		// Pop from the priority queue
		current=items.top();
		//std::cout<<"Current: "<<current.id<<" | Parent: "<<current.parent<< " | Goal:"<<request.destination<<std::endl;
		items.pop(); // remove the element from the list
		if (pathFound){
			if(current.cost>previousCost){
				exitLoop=true; // we want to exit the main loop
				break;
			}
		}
		previousCost=current.cost;

		if (visited.find(current.id)==visited.end()) { //visited.find(current.id)==visited.end()
			// Check if desired node
			if (current.id==request.destination){ // Found the node!
				pathFound=true;
				//std::cout<<std::endl<<request.origin<<request.destination<<std::endl;
				exitLoop=true; // TODO - remove me in future but currently bug when this is not here ????? map appears to be losing the parent of N for some weird reason..
			}
			else { // push the valid children which have bandwidth and are not allready visited onto the priority queue
				network.begin(current.id,request.time);
				while (!network.end()) {
					pushChild(network.nextChild(),current,visited,items,network,request.time);
				}
			}
			// Append the current node to the visited list
			visited.insert(std::pair<char,Element>(current.id,current)); // be careful that the node is not allready in the visited list..possibly
		}
	}

	// 3. Choose one valid path at random and backtrack -> calculate and append statistics...
	if (pathFound){ // we have a valid path... -> backtrack to allocate resources
		backTrack(request.origin,request.destination,request.time ,request.timeDuration ,visited,network,stats);
	}
	else {
		//Path was impossible -> add blocked circuit
		stats.addCircuit(false);
	}
}
コード例 #2
0
ファイル: xmlSetter.cpp プロジェクト: Aldrog/corecvs
void XmlSetter::saveValue(const char *fieldName, QString value)
{
    QDomElement element = getChildByTag(fieldName);

    qDebug() << "We arrived at DOM path of length " << mNodePath.size() << " adding " << fieldName << " with value:" << value;

    if (element.isNull())
    {
        pushChild(fieldName);

        QDomElement mainElement = mNodePath.back().toElement();
        mainElement.setAttribute("value", value);
        popChild();
    }
    else {
        element.setAttribute("value", value);
    }
}
コード例 #3
0
void FlameGraphModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
    if (!m_acceptedTypes.contains(type.rangeType))
        return;

    if (m_stackBottom.children.isEmpty())
        beginResetModel();

    const QmlEvent *potentialParent = &(m_callStack.top());
    if (event.rangeStage() == RangeEnd) {
        m_stackTop->duration += event.timestamp() - potentialParent->timestamp();
        m_callStack.pop();
        m_stackTop = m_stackTop->parent;
        potentialParent = &(m_callStack.top());
    } else {
        QTC_ASSERT(event.rangeStage() == RangeStart, return);
        m_callStack.push(event);
        m_stackTop = pushChild(m_stackTop, event);
    }
}
コード例 #4
0
void FlameGraphModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
    Q_UNUSED(type);

    if (m_stackBottom.children.isEmpty())
        beginResetModel();

    const bool isCompiling = (type.rangeType() == Compiling);
    QStack<QmlEvent> &stack =  isCompiling ? m_compileStack : m_callStack;
    FlameGraphData *&stackTop = isCompiling ? m_compileStackTop : m_callStackTop;

    const QmlEvent *potentialParent = &(stack.top());
    if (type.message() == MemoryAllocation) {
        if (type.detailType() == HeapPage)
            return; // We're only interested in actual allocations, not heap pages being mmap'd

        qint64 amount = event.number<qint64>(0);
        if (amount < 0)
            return; // We're not interested in GC runs here

        for (FlameGraphData *data = stackTop; data; data = data->parent) {
            ++data->allocations;
            data->memory += amount;
        }

    } else if (event.rangeStage() == RangeEnd) {
        stackTop->duration += event.timestamp() - potentialParent->timestamp();
        stack.pop();
        stackTop = stackTop->parent;
        potentialParent = &(stack.top());
    } else {
        QTC_ASSERT(event.rangeStage() == RangeStart, return);
        stack.push(event);
        stackTop = pushChild(stackTop, event);
    }
}
コード例 #5
0
ファイル: flamegraphmodel.cpp プロジェクト: openmv/qt-creator
void FlameGraphModel::loadData(qint64 rangeStart, qint64 rangeEnd)
{
    const bool checkRanges = (rangeStart != -1) && (rangeEnd != -1);
    if (m_modelManager->state() == QmlProfilerModelManager::ClearingData) {
        beginResetModel();
        clear();
        endResetModel();
        return;
    } else if (m_modelManager->state() != QmlProfilerModelManager::ProcessingData &&
               m_modelManager->state() != QmlProfilerModelManager::Done) {
        return;
    }

    beginResetModel();
    clear();

    const QVector<QmlProfilerDataModel::QmlEventData> &eventList
            = m_modelManager->qmlModel()->getEvents();
    const QVector<QmlProfilerDataModel::QmlEventTypeData> &typesList
            = m_modelManager->qmlModel()->getEventTypes();

    // used by binding loop detection
    QStack<const QmlProfilerDataModel::QmlEventData *> callStack;
    callStack.append(0);
    FlameGraphData *stackTop = &m_stackBottom;

    for (int i = 0; i < eventList.size(); ++i) {
        const QmlProfilerDataModel::QmlEventData *event = &eventList[i];
        int typeIndex = event->typeIndex();
        const QmlProfilerDataModel::QmlEventTypeData *type = &typesList[typeIndex];

        if (!m_acceptedTypes.contains(type->rangeType))
            continue;

        if (checkRanges) {
            if ((event->startTime() + event->duration() < rangeStart)
                    || (event->startTime() > rangeEnd))
                continue;
        }

        const QmlProfilerDataModel::QmlEventData *potentialParent = callStack.top();
        while (potentialParent &&
               potentialParent->startTime() + potentialParent->duration() <= event->startTime()) {
            callStack.pop();
            stackTop = stackTop->parent;
            potentialParent = callStack.top();
        }

        callStack.push(event);
        stackTop = pushChild(stackTop, event);

        m_modelManager->modelProxyCountUpdated(m_modelId, i, eventList.count());
    }

    foreach (FlameGraphData *child, m_stackBottom.children)
        m_stackBottom.duration += child->duration;

    loadNotes(-1, false);

    m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1);
    endResetModel();
}