Beispiel #1
0
vector<Range<T> > RoutingTree<T>::splitRange(Range<T> range, Node<T> *parentNode){
	vector<Node<T> *> childNodes = parentNode->getChildNodes();
	vector<Range<T> > result;
	int i = 0;
	try{
		for (; i < childNodes.size(); i++){
			Range<T> curRange = childNodes[i]->getRange();
			if (range.atLeft(curRange)){
				result.push_back(range);
				break;
			}
			else if (range.leftOverlap(curRange)){
				Range<T> tempResult(range.first, curRange.first); // overlap at the margin
				result.push_back(tempResult);
				break;  
			}
			else if (range.isContainedBy(curRange)){
				break;
			}
			else if (range.contains(curRange)){
				if (range.first != curRange.first){
					Range<T> tempResult(range.first, curRange.first); // overlap at the margin
					result.push_back(tempResult);
				}

				if (range.second != curRange.second){
					range.first = curRange.second;
				}
				else{
					break;
				}
			}
			else{ // right overlap or at right
				if (range.first < curRange.second){
					range.first = curRange.second;
				}
			}
		}
	}

	catch (string e){
		cerr<<e<<endl;
	}

	if (i == childNodes.size()){
		result.push_back(range);
	}

	return result;
}
Beispiel #2
0
vector<Node<T> *> RoutingTree<T>::insert(vector<Range<T> > subRanges, Node<T> *parentNode){
	Range<T> parentNodeRange = parentNode->getRange();
	vector<Node<T> *> childrenNodes = parentNode->getChildNodes();
	vector<Node<T> *> result;
	int childrenNodesIndex = 0, subRangeIndex = 0;
	cout << "parentNode before insertion: ... \n";
	//DisplayCoveredRanges(parentNode);
	parentNode->printChildNodes();
	try{
		/* Error Handling Section */
		if (subRanges.size() == 0)
		{
			cerr << "ERROR: no subranges need to be inserted!\n";
		}
		for (int i = 0; i < subRanges.size(); i++)
		{
			Range<T> currentSubRange = subRanges.at(i);
			if (!parentNodeRange.contains(currentSubRange))
			{
				cerr << "ERROR: One or more splitted subrange exceeded the parent range! \n";
			}
			for (int j = i + 1; j < subRanges.size(); j++)
			{
				Range<T> rangeToBeChecked = subRanges.at(j);
				if (currentSubRange.overlap(rangeToBeChecked))
				{
					cerr << "ERROR: overlap in subranges! \n";
				}
			}	
		}
		/* Insertion */
		for (; childrenNodesIndex < childrenNodes.size(); childrenNodesIndex++)
		{
			Range<T> currentChildRange = (childrenNodes.at(childrenNodesIndex))->getRange();
			Range<T> currentSubRange = subRanges.at(subRangeIndex);
			if (currentChildRange.atLeft(currentSubRange))
			{
				//result.push_back(childrenNodes.at(childrenNodesIndex));
			}
			else if (currentSubRange.atLeft(currentChildRange))
			{
				Node<T> *newNode = new Node<T>(currentSubRange);
				parentNode->insertChildNode(newNode);
				result.push_back(newNode);
				//result.push_back(childrenNodes.at(childrenNodesIndex));
				if (++subRangeIndex < subRanges.size())
				{
					if ((subRanges.at(subRangeIndex)).equals(currentChildRange))
					{
						subRangeIndex++;
					}
				}
				else
				{
					break;
				}
			}
			else if (currentSubRange.equals(currentChildRange))
			{
				//result.push_back(childrenNodes.at(childrenNodesIndex));
				subRangeIndex++;
			}
			else
			{
				cerr << "Error:possible overlapping! \n";
			}
		}
		if (subRangeIndex < subRanges.size())
		{
			Node<T> *newNode = new Node<T>(subRanges.at(subRangeIndex));
			parentNode->insertChildNode(newNode);
			result.push_back(newNode);
		}
	}

	catch (string e){
		cerr<<e<<endl;
	}
	cout << "After Insertion: ... \n";
	//DisplayCoveredRanges(parentNode);
	//parentNode -> printChildNodes();
	return result;
}