コード例 #1
0
ファイル: List.cpp プロジェクト: MelinkJL/HW04_Sonodabe
List::List(Entry* entries, int len, bool x){
    sentinel = new Node;
    isX = x;
    sentinel->next = sentinel;
    sentinel->prev = sentinel;
    length = 0;
    
    insertAll(entries, len);
}
コード例 #2
0
// VALUE SEMATICS
// Copy Constructor
set::set(const set &s)
// Postcondition: initializes the
// active set with a shallow copy of s.
{
	// self initialization?
	if(this == &s)
		return;

	entry_count=0; child_count=0; cardinal=0;

	// Insert all the items from the
	// source node to the active node.
	insertAll(s);
}
コード例 #3
0
// += operator (UNION)
set& set::operator+=(const set &s)
// Postcondition: assigns a shallow
// copy of s into the current set.
{
	// self assignment
	if(this == &s)
		return *this;

	// Insert all the items from the
	// source node to the active node.
	insertAll(s);

	return *this;
}
コード例 #4
0
void set::insertAll(const set *s)
// Postcondition: inserts all the items from the subset 's' into
// the current (active) set. This form of the function is recursive.
{
	int i;

	// Insert all the data in the current subset's root node.
	for(i = 0; i<s->entry_count; i++)
		insert(s->data[i]);

	// Insert all the data in the current subset's subset nodes.
	for(i = 0; i<s->child_count; i++)
		insertAll(s->subset[i]);
}
コード例 #5
0
// Assignment operator
void set::operator=(const set &s)
// Postcondition: assigns a shallow
// copy of s into the current set
{
	// self assignment
	if(this == &s)
		return;

	// clear all items in the current set
	clearAll();

	// Insert all the items from the
	// source node to the active node.
	insertAll(s);
}
コード例 #6
0
void set::insertAll(const set &s)
// Postcondition: inserts all the items from the set 's' into
// the current (active) set. This form of the function is not
// recursive. However, the recursive subset 'insertAll' form is
// utiltized to recusrivly insert all the items in the subsets.
{
	int i;

	// Insert all the data in the root node.
	for(i = 0; i<s.entry_count; i++)
		insert(s.data[i]);

	// Insert all the data in the subset nodes.
	for(i = 0; i<s.child_count; i++)
		insertAll(s.subset[i]);
}
コード例 #7
0
void main()
{
    int i;
    int value;
    int position;
    setHashMatrixNull();
    generateRandomNumbers();
    insertAll();
    printHashMatrix();
    printf("Enter the desired value or -1 to exit\n");

    while( value!= -1 )
    {
        scanf("%d", &value);
        if(value != -1)
        {
            position = findValue(value);
            if(position > -1)
            {
                printf("value stored on position %d \n", position);
            }
        }
    }
}
コード例 #8
0
Module::ReturnType OutputUpwardEdgeInserter::insertAll(UpwardPlanRep &UPR,
														List<edge> &toInsert,		
														EdgeArray<int>  &costOrig)
{
	if (toInsert.empty())
		return Module::retFeasible;

	List<edge> l;
	int size_new = toInsert.size();
	int size_old = 0;
	while (size_old != size_new) {
		size_old = size_new;
		while (!toInsert.empty()) {
			edge e_orig = toInsert.popFrontRet();
			SList<adjEntry> path;
			
			/*
			//debug
			cout << endl;
			cout << "  insertion path for e_orig :" << e_orig << ";  e_UPR: (" << UPR.copy(e_orig->source()) << "," 
				 << UPR.copy(e_orig->target()) << ")" << endl;
			*/

			minFIP(UPR, toInsert, costOrig, e_orig, path);						

			
			/*
			//--------------------------------------debug					
			forall_slistiterators(adjEntry, it, path) {
				cout << (*it)->theEdge() << ";  node: " << (*it)->theNode() << endl;
			}
			//--------------------------------------end debug
			*/
			
			List<edge> lEdges = toInsert, lTmp = l;
			lEdges.conc(lTmp);
			bool ok = isConstraintFeasible(UPR, lEdges, e_orig, path);						
			if (ok) {
				UPR.insertEdgePathEmbedded(e_orig, path, costOrig);				
				
				OGDF_ASSERT(isUpwardPlanar(UPR));			
				OGDF_ASSERT(isSimple(UPR));
				OGDF_ASSERT(isConnected(UPR));
				OGDF_ASSERT(hasSingleSource(UPR));

			}
			else 
				l.pushBack(e_orig);
			
			/*
			if (false) {
			//---------------------------------------------------debug		
			//UPR.outputFaces(UPR.getEmbedding());
			//UPR.writeGML("c:/temp/bug5.gml");

			LayerBasedUPRLayout uprLayout;
			Graph GTmp( (const Graph &) UPR);
			CombinatorialEmbedding embTmp(GTmp);
			node tTmp = 0;
			//GTmp.writeGML("c:/temp/bug4.gml");
			hasSingleSink(GTmp, tTmp);
			OGDF_ASSERT(tTmp != 0);
			embTmp.setExternalFace(embTmp.rightFace(tTmp->firstAdj()));
			//adjEntry adjTmp = GCTmp.copy(UPR.extFaceHandle->theEdge())->adjTarget();
			UpwardPlanRep upr_bug(embTmp);
			adjEntry adj_bug = upr_bug.getAdjEntry(upr_bug.getEmbedding(), upr_bug.getSuperSource(), upr_bug.getEmbedding().externalFace());
			node s_upr_bug = upr_bug.newNode();
			upr_bug.getEmbedding().splitFace(s_upr_bug, adj_bug);
			upr_bug.m_isSourceArc.init(upr_bug, false);
			upr_bug.m_isSourceArc[s_upr_bug->firstAdj()->theEdge()] = true;
			upr_bug.s_hat = s_upr_bug;
			upr_bug.augment();
		
			GraphAttributes GA_UPR_tmp(GTmp, GraphAttributes::nodeGraphics|
					GraphAttributes::edgeGraphics|
					GraphAttributes::nodeColor|
					GraphAttributes::edgeColor|
					GraphAttributes::nodeLabel|
					GraphAttributes::edgeLabel
					);
			GA_UPR_tmp.setAllHeight(30.0);
			GA_UPR_tmp.setAllWidth(30.0);	

			uprLayout.call(upr_bug, GA_UPR_tmp);				
			
			// label the nodes with their index
			node z;
			forall_nodes(z, GA_UPR_tmp.constGraph()) {			
				char str[255];
				sprintf_s(str, 255, "%d", z->index()); 	// convert to string	
				GA_UPR_tmp.labelNode(z) = str;		
				GA_UPR_tmp.y(z)=-GA_UPR_tmp.y(z);
				GA_UPR_tmp.x(z)=-GA_UPR_tmp.x(z);				
			}
			edge eee;
			forall_edges(eee, GA_UPR_tmp.constGraph()) {
				DPolyline &line = GA_UPR_tmp.bends(eee);
				ListIterator<DPoint> it;
				for(it = line.begin(); it.valid(); it++) {		
					(*it).m_y = -(*it).m_y;	
					(*it).m_x = -(*it).m_x;
				}
			}
			GA_UPR_tmp.writeGML("c:/temp/UPR_int.gml");	
			//cout << "face of UPR_int :" << endl;
			//upr_bug.outputFaces(upr_bug.getEmbedding());
			//end -----------------------------------------------debug
			}
			*/

		}
		size_new = l.size();
		toInsert = l;
		l.clear();
	}
	
	/*
	 * some edges cannot be inserted, so use heuristic insertion methods
	 */
	if (!toInsert.empty()) {

		//cout << endl << "\a\a\a\a\aheuristical call!! " << endl;

		edge e_orig = toInsert.popFrontRet();

		/*
		cout << endl;
		cout << "heuristical insertion path for e_orig :" << e_orig << ";  e_UPR: (" << UPR.copy(e_orig->source()) << "," 
			<< UPR.copy(e_orig->target()) << ")" <<  endl;
		*/

		
			/*
			if (false) {
			//---------------------------------------------------debug		
			//UPR.outputFaces(UPR.getEmbedding());
			//UPR.writeGML("c:/temp/bug5.gml");

			LayerBasedUPRLayout uprLayout;
			Graph GTmp( (const Graph &) UPR);
			CombinatorialEmbedding embTmp(GTmp);
			node tTmp = 0;
			//GTmp.writeGML("c:/temp/bug4.gml");
			hasSingleSink(GTmp, tTmp);
			OGDF_ASSERT(tTmp != 0);
			embTmp.setExternalFace(embTmp.rightFace(tTmp->firstAdj()));
			//adjEntry adjTmp = GCTmp.copy(UPR.extFaceHandle->theEdge())->adjTarget();
			UpwardPlanRep upr_bug(embTmp);
			adjEntry adj_bug = upr_bug.getAdjEntry(upr_bug.getEmbedding(), upr_bug.getSuperSource(), upr_bug.getEmbedding().externalFace());
			node s_upr_bug = upr_bug.newNode();
			upr_bug.getEmbedding().splitFace(s_upr_bug, adj_bug);
			upr_bug.m_isSourceArc.init(upr_bug, false);
			upr_bug.m_isSourceArc[s_upr_bug->firstAdj()->theEdge()] = true;
			upr_bug.s_hat = s_upr_bug;
			upr_bug.augment();
		
			GraphAttributes GA_UPR_tmp(GTmp, GraphAttributes::nodeGraphics|
					GraphAttributes::edgeGraphics|
					GraphAttributes::nodeColor|
					GraphAttributes::edgeColor|
					GraphAttributes::nodeLabel|
					GraphAttributes::edgeLabel
					);
			GA_UPR_tmp.setAllHeight(30.0);
			GA_UPR_tmp.setAllWidth(30.0);	

			uprLayout.call(upr_bug, GA_UPR_tmp);				
			
			// label the nodes with their index
			node z;
			forall_nodes(z, GA_UPR_tmp.constGraph()) {			
				char str[255];
				sprintf_s(str, 255, "%d", z->index()); 	// convert to string	
				GA_UPR_tmp.labelNode(z) = str;		
				GA_UPR_tmp.y(z)=-GA_UPR_tmp.y(z);
				GA_UPR_tmp.x(z)=-GA_UPR_tmp.x(z);				
			}
			edge eee;
			forall_edges(eee, GA_UPR_tmp.constGraph()) {
				DPolyline &line = GA_UPR_tmp.bends(eee);
				ListIterator<DPoint> it;
				for(it = line.begin(); it.valid(); it++) {		
					(*it).m_y = -(*it).m_y;	
					(*it).m_x = -(*it).m_x;
				}
			}
			GA_UPR_tmp.writeGML("c:/temp/UPR_int.gml");	
			//cout << "face of UPR_int :" << endl;
			//upr_bug.outputFaces(upr_bug.getEmbedding());
			//end -----------------------------------------------debug
			}
			*/		

		SList<adjEntry> path;
		constraintFIP(UPR, toInsert, costOrig, e_orig, path);	

		/*
		//--------------------------------------debug
		
		forall_slistiterators(adjEntry, it, path) {
			cout << (*it)->theEdge() << ";  node: " << (*it)->theNode() << endl;; 
		}
		//--------------------------------------end debug
		*/

		UPR.insertEdgePathEmbedded(e_orig, path, costOrig);		
		
		OGDF_ASSERT(isUpwardPlanar(UPR));

		return insertAll(UPR, toInsert, costOrig);
	}	
	return Module::retFeasible;
}