コード例 #1
0
ファイル: HP2D.cpp プロジェクト: ana-GT/Homo2D
/**
 * @function GetAdjacent2
 */
std::vector<Vertex*> HP2D::GetAdjacent2( Vertex *_v ) {

	std::vector<int> a;
	Vertex *va;
	std::vector<Vertex*> Adj2;
	bool already = false;

	a = _v->GetAdjacent();

	for( unsigned int i = 0; i < a.size(); ++i ) {
		va = mV[a[i]];
		std::vector<int> a2;
		a2 = va->GetAdjacent();
		for( unsigned int j = 0; j < a2.size(); ++j ) {
			already = false;
			for( unsigned int k = 0; k < Adj2.size(); ++k ) {
				if( Adj2[k]->GetIndex() == mV[a2[j]]->GetIndex() ) {
					already = true; break;
				}
			}
			if( already == false ) {
				Adj2.push_back( mV[a2[j]] );
			}
		}
	}	
	return Adj2;
}
コード例 #2
0
ファイル: HP2D.cpp プロジェクト: ana-GT/Homo2D
/**
 * @function GetPath
 */
std::vector< std::vector<Pos> > HP2D::GetPath( Pos _p ) {
	std::vector<int> iv;
	Vertex* current;
	int minIndex;
	int minDist;
	std::vector< std::vector<Pos> > paths;

	iv = mG->GetVertices( _p );	

	for( unsigned int i = 0; i < iv.size(); ++i ) {

		current = mV[ iv[i] ];
		std::vector<Pos> path;
		
		while( current->GetIndex() != 0 ) {

			std::vector<int> a;
			a = current->GetAdjacent();
			if( a.size() == 0 ) {
				printf("--(!) Uh-oh, error here. No Adjacents! GetPath Function \n");
			}

			minDist = 1000;
			minIndex = -1;

			for( unsigned int j = 0; j < a.size(); ++ j ) {
				if( mV[ a[j] ]->GetDist() < minDist ) {
					minDist = mV[ a[j] ]->GetDist();
					minIndex = mV[ a[j] ]->GetIndex();
				}	
			}
			
			path.push_back( current->GetPos() ); 		
			current = mV[minIndex];
		}

		path.push_back( mV[0]->GetPos() );
		paths.push_back( path );
	}

	return paths;
}