Beispiel #1
0
void taskGraphArray::requestData(CkArrayIndex from) {
  // If the problem isn't solved, kick this request onto the waiting queue
  if ( ! isSolved ) {
    Waiting.insertAtEnd(from);
    return;
  }

  // Otherwise, if the problem is solved send them the data we generated
  CProxy_taskGraphArray neighbor(thisArrayID);
  neighbor(from).depositData(Self);
}
Beispiel #2
0
void CityUpdater::getAdjacencyList() {
    adjacencyList.clear();
    Location location(0,0);
    Road* road;
    for (unsigned int i=0; i<roadMap.size(); i++) {
        vector<neighbor> tmpVector;
        if (roadMap[i]->isOpen(Road::NORTH) && ((roadMap[i]->getLocation().getRow())-1 >= 0)) {
            //
            location.setRow(roadMap[i]->getLocation().getRow()-1);
            location.setCol(roadMap[i]->getLocation().getCol());
            road = dynamic_cast<Road*>(cityMap->getCase(location));
            if (!(road->isBlocked())){
                int index = std::find(roadMap.begin(), roadMap.end(), road) - roadMap.begin();
                tmpVector.push_back(neighbor(index, 1));
            }
            //
        }
        if (roadMap[i]->isOpen(Road::WEST) && ((roadMap[i]->getLocation().getCol())-1 >= 0)) {
            //
            location.setRow(roadMap[i]->getLocation().getRow());
            location.setCol(roadMap[i]->getLocation().getCol()-1);
            road = dynamic_cast<Road*>(cityMap->getCase(location));
            if (!(road->isBlocked())){
                int index = std::find(roadMap.begin(), roadMap.end(), road) - roadMap.begin();
                tmpVector.push_back(neighbor(index, 1));
            }
            //
        }
        if (roadMap[i]->isOpen(Road::SOUTH) && ((roadMap[i]->getLocation().getRow())+1 < cityMap->getNumberOfRows())) {
            //
            location.setRow(roadMap[i]->getLocation().getRow()+1);
            location.setCol(roadMap[i]->getLocation().getCol());
            road = dynamic_cast<Road*>(cityMap->getCase(location));
            if (!(road->isBlocked())){
                int index = std::find(roadMap.begin(), roadMap.end(), road) - roadMap.begin();
                tmpVector.push_back(neighbor(index, 1));
            }
            //
        }
        if (roadMap[i]->isOpen(Road::EAST) && ((roadMap[i]->getLocation().getCol())+1 < cityMap->getNumberOfCols())) {
            //
            location.setRow(roadMap[i]->getLocation().getRow());
            location.setCol(roadMap[i]->getLocation().getCol()+1);
            road = dynamic_cast<Road*>(cityMap->getCase(location));
            if (!(road->isBlocked())){
                int index = std::find(roadMap.begin(), roadMap.end(), road) - roadMap.begin();
                tmpVector.push_back(neighbor(index, 1));
            }
            //
        }
        adjacencyList.push_back(tmpVector);
        tmpVector.clear();
    }
}
Anneal::Path Anneal::GenerateRandomNeighbor(const Path &path_before) const
{
    int size = path_before.size();
    // ((size - 1) * (size - 2) / 2) represents the total number of intervals
    // where only the first city will never be changed.
    // For example, when size = 3:
    //
    //  * * *
    //  * *
    //  *
    //
    //  There are 6 intervals in total
    int random_index = generator_() % ((size - 1) * (size - 2) / 2);
    int i;
    for (i = 1; i < size - 1; i++)
    {
        int j = size - 1 - i;
        if (random_index >= j)
            random_index -= j;
        else
            break;
    }

    Path neighbor(path_before);
    std::reverse(neighbor.begin() + i, neighbor.begin() + i + 2 + random_index);

    return neighbor;
}
Beispiel #4
0
 // Retrieve the neighboring partition
 partition_server(std::size_t partition_num, std::size_t num_elements)
     : data_(num_elements),
       left_(hpx::find_from_basename(partition_basename, neighbor(partition_num)))
 {
     // fill with some random data
     std::generate(data_.begin(), data_.end(), std::rand);
 }
const QImage& ImageTransformer::
KNNMFtransform(int size, int K)
{
    std::vector<int> redList;
    std::vector<int> greenList;
    std::vector<int> blueList;

    QImage NewImage(_DataHandled.size(),_DataHandled.format());
    int step = size/2;

    int width = NewImage.width();
    int height = NewImage.height();
    int depth = NewImage.depth();

    if(depth == 32 && size>1 && K<=(step*2+1)*(step*2+1)&&K>0)
    {
        for(int i=0;i<width;++i)
        {
            for(int j=0;j<height;++j)
            {
                redList.clear();
                greenList.clear();
                blueList.clear();

                for(int p=((i-step)>0)?(i-step):0;p<=i+step&&p<width;++p)
                {
                    for(int q=((j-step)>0)?(j-step):0;q<=j+step&&q<height;++q)
                    {
                       QColor neighbor(_DataHandled.pixel(p,q));
                       redList.push_back(neighbor.red());
                       greenList.push_back(neighbor.green());
                       blueList.push_back(neighbor.blue());
                    }
                }
                std::sort(redList.begin(),redList.end()-1);
                std::sort(greenList.begin(),greenList.end()-1);
                std::sort(blueList.begin(),blueList.end()-1);

                if(redList.size()<=K)
                {
                    NewImage.setPixel(i,j,QColor(redList.at(redList.size()/2),
                                                 greenList.at(greenList.size()/2),
                                                 blueList.at(blueList.size()/2)).rgb());
                }
                else
                {
                    QColor baseColor(_DataHandled.pixel(i,j));

                    NewImage.setPixel(i,j,QColor(KNNMFmiddle(redList,baseColor.red(),K),
                                                 KNNMFmiddle(greenList,baseColor.green(),K),
                                                 KNNMFmiddle(blueList,baseColor.blue(),K)).rgb());

                }
            }
        }
        _DataHandled = NewImage;
    }
    return _DataHandled;
}
Beispiel #6
0
void
AStarSearch::processOpenedList(
		const ILandscape& _landscape
	,	const GameObject& _forObject
	,	Tools::Core::Object::Ptr _locateComponent
	,	const IPathFinder::PointsCollection& _targets )
{
	if ( m_openedList.empty() )
		return;

	int dx[ 8 ] = {  0, 0, -1, 1,  1, 1, -1, -1 };
	int dy[ 8 ] = { -1, 1,  0, 0, -1, 1,  1, -1 };

	int currentPointIndex = findWithMinDistanceInList( m_openedList );
	AStarSearch::PointData pointData = m_openedList[ currentPointIndex ];

	if ( pointData.m_h == 0 )
	{
		m_closedList.push_back( pointData );
		m_openedList.clear();
		return;
	}

	for ( int i = 0; i < 8; ++i )
	{
		QPoint neighbor( pointData.m_point.x() + dx[ i ], pointData.m_point.y() + dy[ i ] );

		if (	!_landscape.isLocationInLandscape( neighbor )
			||	!_landscape.canObjectBePlaced( neighbor, _forObject.getMember< QString >( ObjectNameKey ) )
			||	findInList( neighbor, m_closedList ) != -1 )
		{
			continue;
		}

		PointData neighborData;

		neighborData.m_point = neighbor;
		neighborData.m_parentPoint = pointData.m_point;
		neighborData.m_g = pointData.m_g + Geometry::getDistance( pointData.m_point, neighbor );
		neighborData.m_h = Geometry::getDistance( neighbor, _targets.front() );
		neighborData.m_f = neighborData.m_h + neighborData.m_g;

		int foundNeighborDataIndex = findInList( neighbor, m_openedList );

		if ( foundNeighborDataIndex == -1 )
		{
			m_openedList.push_back( neighborData );
		}
		else if ( m_openedList[ foundNeighborDataIndex ].m_g > neighborData.m_g )
		{
			m_openedList[ foundNeighborDataIndex ] = neighborData;
		}
	}

	m_closedList.push_back( pointData );
	m_openedList.erase( m_openedList.begin() + currentPointIndex );

} // AStarSearch::processOpenedList
void
MotionPlannerGraph::add_edge(size_t from, size_t to, double weight)
{
    // extend adjacency list until this start node
    if (this->adjacency_list.size() < from+1)
        this->adjacency_list.resize(from+1);
    
    this->adjacency_list[from].push_back(neighbor(to, weight));
}
Beispiel #8
0
bool Place::has_neighbor(std::string dir) const
{
    try {
        neighbor(dir);
        return true;
    } catch (std::logic_error &) {
        return false;
    }
}
Beispiel #9
0
std::array<Coord2D, 8> Coord2D::allNeighbors() const
{
    std::array<Coord2D, 8> ret =
    {
        neighbor(Direction::leftup),   neighbor(Direction::up),   neighbor(Direction::rightup),
        neighbor(Direction::left),                                neighbor(Direction::right),
        neighbor(Direction::leftdown), neighbor(Direction::down), neighbor(Direction::rightdown),
    };

    return ret;
}
int Welder::getIndex(const Vector3& vertex) {

    int closestIndex = -1;
    double distanceSquared = inf();

    int ix, iy, iz;
    toGridCoords(vertex, ix, iy, iz);

    // Check against all vertices within radius of this grid cube
    const List& list = grid[ix][iy][iz];

    for (int i = 0; i < list.size(); ++i) {
        double d = (newVertexArray[list[i]] - vertex).squaredMagnitude();

        if (d < distanceSquared) {
            distanceSquared = d;
            closestIndex = list[i];
        }
    }

    if (distanceSquared <= radius * radius) {

        return closestIndex;

    } else {

        // This is a new vertex
        int newIndex = newVertexArray.size();
        newVertexArray.append(vertex);

        // Create a new vertex and store its index in the
        // neighboring grid cells (usually, only 1 neighbor)

        Set<List*> neighbors;

        for (float dx = -1; dx <= +1; ++dx) {
            for (float dy = -1; dy <= +1; ++dy) {
                for (float dz = -1; dz <= +1; ++dz) {
                    int ix, iy, iz;
                    toGridCoords(vertex + Vector3(dx, dy, dz) * radius, ix, iy, iz);
                    neighbors.insert(&(grid[ix][iy][iz]));
                }
            }
        }

        Set<List*>::Iterator neighbor(neighbors.begin());
        Set<List*>::Iterator none(neighbors.end());

        while (neighbor != none) {
            (*neighbor)->append(newIndex);
            ++neighbor;
        }

        return newIndex;
    }
}
 vector<vector<neighbor> > generateGraph(vector<string> &strVec) {
     
     auto n = strVec.size();
     // the graph is saved by an adjacency list
     vector<vector<neighbor> > adjList(n, vector<neighbor>());
     if(strVec.size() == 0)
         return adjList;
     
     for(int i=0; i<n-1; i++) {
         for(int j=i+1; j<n; j++) {
             if(strDist(strVec[i], strVec[j]) == 1) {
                 adjList[i].push_back(neighbor(j, 1));
                 adjList[j].push_back(neighbor(i, 1));
             }
         }
     }
     
     return adjList;
 }
Beispiel #12
0
std::array<Coord2D, 9> Coord2D::meAndAllNeighbors() const
{
    std::array<Coord2D, 9> ret =
    {
        *this,
        neighbor(Direction::leftup),   neighbor(Direction::up),   neighbor(Direction::rightup),
        neighbor(Direction::left),                                neighbor(Direction::right),
        neighbor(Direction::leftdown), neighbor(Direction::down), neighbor(Direction::rightdown),
    };

    return ret;
}
Beispiel #13
0
void doGoats(struct RastPort *r)
{
	LONG	ptr = numGoats-1;
	LONG	i,n,newX,newY,startDir,tmpDir;
	LONG	flag = 0;

	while (ptr >= 0) {
		if (goatQ[ptr] ) {
			flag = 1;
			x = goats[ptr].x;
			y = goats[ptr].y;
			SetAPen(r, backgroundClr);
			WritePixel(r, x, y);
			startDir = tmpDir  = (LONG)RangeRand(8);
			while (1) {
				n = neighbor(r, tmpDir);
				if (n != grassClr || n == -1) {
					tmpDir = (tmpDir+1) % 8;
					if (tmpDir == startDir) {
						goatQ[ptr] = 0;
						break;
					}
				}
				else {
					goats[ptr].x = newX = tx;
					goats[ptr].y = newY = ty;
					++grassEaten[ptr];
					if (grassEaten[ptr] >= reproduction) {
						grassEaten[ptr] = 0;
						i = 0;
						while(goatQ[i] != 0 && i < numGoats)
							++i;
						if (i != numGoats) {
							goats[i].x = newX;
							goats[i].y = newY;
							goatQ[i] = 1;
							grassEaten[i] = 0;
						}
					}
					SetAPen(r,goatClr);
					WritePixel(r,newX,newY);
					break;
				}
			}
		}
		--ptr;
	}
	if (!flag) {
		goatQ[0] = 1;
		goats[0].x = (LONG)RangeRand(Width-1);
		goats[0].y = (LONG)RangeRand(Height-1);
		grassEaten[0] = 0;
	}
}
Beispiel #14
0
void taskGraphArray::tryToSolve() {
  if ( DepsCount == DepsReceived ) {
    if ( DepsCount != 0 ) {
      Self->solve(DepsCount, DepsData);
    } else {
      Self->setup();
    }
    isSolved = true;

    // Return that to whoever spawned me
    callbackMsg *res = new callbackMsg( Self, thisIndexMax );
    ReturnResults.send( res );
  
    // And tell everyone who's waiting on me that I solved myself
    for ( int i = 0 ; i < Waiting.size() ; i++ ) {
      CProxy_taskGraphArray neighbor(thisArrayID);
      neighbor(Waiting[i]).depositData(Self);
    }
  }
}
 int dfs(vector<vector<bool>>& grid, int r, int c, int d, int m, int n)
 {
   int cnt = d >= m;
   if (d >= n) return cnt;
   grid[r][c] = true;
   for (int i = 0; i < 3; ++i)
     for (int j = 0; j < 3; ++j)
       if (!grid[i][j] && neighbor(grid, r, c, i, j))
         cnt += dfs(grid, i, j, d + 1, m, n);
   grid[r][c] = false;
   return cnt;
 }
Beispiel #16
0
/// Virtual function to return diffusion X-section area for each neighbor
vector< double > CubeMesh::getDiffusionArea( unsigned int fid ) const
{
	assert( fid < m2s_.size() );

	vector< double > ret;
	unsigned int spaceIndex = m2s_[fid];

	unsigned int nIndex = neighbor( spaceIndex, 0, 0, 1 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dx_ * dy_ );

	nIndex = neighbor( spaceIndex, 0, 0, -1 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dx_ * dy_ );

	nIndex = neighbor( spaceIndex, 0, 1, 0 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dz_ * dx_ );

	nIndex = neighbor( spaceIndex, 0, -1, 0 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dz_ * dx_ );

	nIndex = neighbor( spaceIndex, 1, 0, 0 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dy_ * dz_ );

	nIndex = neighbor( spaceIndex, -1, 0, 0 );
	if ( nIndex != EMPTY ) 
		ret.push_back( dy_ * dz_ );

	return ret;
}
Beispiel #17
0
void SeededRegionGrowing::executeOnHost(T* input, Image::pointer output) {
    ImageAccess::pointer outputAccess = output->getImageAccess(ACCESS_READ_WRITE);
    uchar* outputData = (uchar*)outputAccess->get();
    // initialize output to all zero
    memset(outputData, 0, output->getWidth()*output->getHeight()*output->getDepth());
    std::stack<Vector3ui> queue;

    // Add seeds to queue
    for(int i = 0; i < mSeedPoints.size(); i++) {
        Vector3ui pos = mSeedPoints[i];

        // Check if seed point is in bounds
        if(pos.x() < 0 || pos.y() < 0 || pos.z() < 0 ||
            pos.x() >= output->getWidth() || pos.y() >= output->getHeight() || pos.z() >= output->getDepth())
            throw Exception("One of the seed points given to SeededRegionGrowing was out of bounds.");

        queue.push(pos);
    }

    // Process queue
    while(!queue.empty()) {
        Vector3ui pos = queue.top();
        queue.pop();

        // Add neighbors to queue
        for(int a = -1; a < 2; a++) {
        for(int b = -1; b < 2; b++) {
        for(int c = -1; c < 2; c++) {
            if(abs(a)+abs(b)+abs(c) != 1) // connectivity
                continue;
            Vector3ui neighbor(pos.x()+a,pos.y()+b,pos.z()+c);
            // Check for out of bounds
            if(neighbor.x() < 0 || neighbor.y() < 0 || neighbor.z() < 0 ||
                neighbor.x() >= output->getWidth() || neighbor.y() >= output->getHeight() || neighbor.z() >= output->getDepth())
                continue;

            // Check that voxel is not already segmented
            if(outputData[neighbor.x()+neighbor.y()*output->getWidth()+neighbor.z()*output->getWidth()*output->getHeight()] == 1)
                continue;

            // Check condition
            T value = input[neighbor.x()+neighbor.y()*output->getWidth()+neighbor.z()*output->getWidth()*output->getHeight()];
            if(value >= mMinimumIntensity && value <= mMaximumIntensity) {
                // add it to segmentation
                outputData[neighbor.x()+neighbor.y()*output->getWidth()+neighbor.z()*output->getWidth()*output->getHeight()] = 1;

                // Add to queue
                queue.push(neighbor);
            }
        }}}
    }
}
Beispiel #18
0
TEST(JumpPointSearch, StraightJP){
    cv::Mat map5x5 = (cv::Mat_<char>(5,5) << 255, 255,   0, 255, 255,
                                             255, 255,   0, 255, 255,
                                             255, 255,   0, 255, 255,
                                             255, 255,   0, 255, 255,
                                             255, 255, 255, 255, 255);
    jpsastar::JPSAStar jpsastar(map5x5);
    cv::Vec2i current(1,0);
    cv::Vec2i neighbor(1,1);
    cv::Vec2i *jp = jpsastar.jumpPoint( current, neighbor, cv::Vec2i(0,0) );

    ASSERT_EQ( *jp, cv::Vec2i(1,3) );
    }
Beispiel #19
0
TEST(JumpPointSearch, StraightWall){
    cv::Mat map5x5 = (cv::Mat_<char>(5,5) << 0, 255, 255, 255, 255,
                                             0, 255, 255, 255, 255,
                                             0, 255, 255, 255, 255,
                                             0, 255, 255, 255, 255,
                                             0, 255, 255, 255, 255);
    jpsastar::JPSAStar jpsastar(map5x5);
    cv::Vec2i current(4,2);
    cv::Vec2i neighbor(3,2);
    cv::Vec2i *jp = jpsastar.jumpPoint( current, neighbor, cv::Vec2i(0,0) );

    ASSERT_THAT(jp, testing::IsNull());
    }
void
NewThreadFactory::createNeighborThreads(NewConcurrentMessageDispatcherPtr md,
					NewNeighborVecPtr neighbors)
{
  for (NewNeighborVec::const_iterator it = neighbors->begin();
       it != neighbors->end(); ++it)
    {
      DBGLOG(DBG, "NewThreadFactory::createNeighborThreads: neighbor = " << **it);
      NewNeighborThreadPtr neighbor(new NewNeighborThread(*it));
      NewNeighborThreadWrapper neighbor_wrapper;
      boost::thread* neighbor_thread = new boost::thread(neighbor_wrapper, neighbor, md);
      neighbor_thread_vec.push_back(neighbor_thread);
    }
}
Beispiel #21
0
SquareLattice::SquareLattice(int L):L_(L), N_(L*L)
{
  neighbors_.reserve(N_);
  for(int y=0; y<L_; ++y){
    for(int x=0; x<L_; ++x){
      std::vector<int> neighbor(4);
      neighbor[0] = index(x, y-1);
      neighbor[1] = index(x-1, y);
      neighbor[2] = index(x+1, y);
      neighbor[3] = index(x, y+1);
      neighbors_.push_back(neighbor);
    }
  }
}
Beispiel #22
0
void calculate_channels_at(point p) {
    int dir;
    point p2;

    if (!map_has_water(p)) {
        add_channel(p, &grid(aroma1, p));
        for (dir = 1; dir < STAY; dir *= 2) {
            p2 = neighbor(p, dir);
            // if (!map_has_water(p2)) {
                add_channel(p, &grid(aroma1, p2));
            // }
        }
    }
}
Beispiel #23
0
TEST(JumpPointSearch, DiagonalWall){
    cv::Mat map5x5 = (cv::Mat_<char>(5,5) << 255, 255, 255, 255, 255,
                                             255, 255, 255, 255, 255,
                                             255, 255, 255, 255, 255,
                                             255, 255, 255, 255,   0,
                                             255, 255, 255, 255,   0);
    jpsastar::JPSAStar jpsastar(map5x5);
    cv::Vec2i current(0,0);
    cv::Vec2i neighbor(1,1);
    cv::Vec2i *jp = jpsastar.jumpPoint( current, neighbor, cv::Vec2i(0,0) );

    ASSERT_THAT(jp, testing::IsNull())
        << "Expected: NULL\n"
        << "  Actual: " << to_string(*jp);
    }
Beispiel #24
0
/*
 * Now define the taskGraphArray that actually handles doing all that work.
 */
taskGraphArray::taskGraphArray(
	CkVec<CkArrayIndex> deps,
	taskGraphSolver *data,
	CkCallback returnResults
) : Waiting() {
  // Set some state variables
  ReturnResults = returnResults;
  Self = data;
  isSolved = false;

  // Save everything I need to know about
  DepsCount = deps.length();
  DepsData = new taskGraphSolver*[DepsCount];
  DepsReceived = 0;

  // Ask everyone I depend on for their data
  CProxy_taskGraphArray neighbor(thisArrayID);
  for ( int i = 0 ; i < DepsCount ; i++ ) {
    neighbor(deps[i]).requestData(thisIndexMax);
  }

  // If we're waiting on nothing we're solved
  tryToSolve();
}
Beispiel #25
0
void doHerders(struct RastPort *r)
{
	LONG	ptr = numHerders-1;
	LONG	i,n,newX,newY,startDir,tmpDir;
	LONG	flag = 0;
	
	while( ptr >= 0 ) {
		if( herderQ[ptr] ) {
			flag = 1;
			x = herders[ptr].x;
			y = herders[ptr].y;
			SetAPen(r, grassClr);
			WritePixel(r, x, y);
			startDir = tmpDir  = (LONG)RangeRand(8);
			while (1) {
				n = neighbor(r, tmpDir);
				if (n == grassClr || n == -1) {
					tmpDir = (tmpDir+1) % 8;
					if (tmpDir == startDir) {
						herderQ[ptr] = 0;
						break;
					}
				}
				else {
					herders[ptr].x = newX = tx;
					herders[ptr].y = newY = ty;
					i = 0;
					while(herderQ[i] && i < numHerders)
						++i;
					if (i != numHerders) {
						herders[i].x = newX;
						herders[i].y = newY;
						herderQ[i] = 1;
					}
					SetAPen(r,herderClr);
					WritePixel(r,newX,newY);
					break;
				}
			}
		}
		--ptr;
	}
	if (!flag) {
		herderQ[0] = 1;
		herders[0].x = (LONG)RangeRand(Width-1);
		herders[0].y = (LONG)RangeRand(Height-1);
	}
}
Beispiel #26
0
Coord::Neighborhood Coord::neighborhood() const {
    return Neighborhood {
        neighbor(N),
        neighbor(E),
        neighbor(SE),
        neighbor(S),
        neighbor(W),
        neighbor(NW),
    };
}
Beispiel #27
0
//迷宫寻径算法:在格单元s至t之间规划一条通路(如果的确存在)
bool labyrinth(Cell Laby[LABY_MAX][LABY_MAX], Cell* s, Cell* t){
	if ((AVAILABLE != s->status) || (AVAILABLE != t->status)) return false;//退化情况
	Stack <Cell*> path;//用栈记录通路(Theseus的线绳)
	s->incoming = UNKNOWN; s->status = ROUTE; path.push(s);//起点
	do{//从起点出发不断试探、回溯,直到抵达终点,或者穷尽所有可能
		Cell* c = path.top();//检查当前位置(栈顶)
		if (c == t) return true;//若已抵达终点,则找到了一条通路;否则,沿尚未试探的方向继续试探
		while (NO_WAY > (c->outgoing = nextESWN(c->outgoing)))//逐一检查所有方向
			if (AVAILABLE == neighbor(c)->status)break;//试图找到尚未试探的方向
		if (NO_WAY <= c->outgoing)//若所有方向都已尝试过
		{c->status = BACKTRACKED; c = path.pop();} //则向后回溯一步
		else//否则,向前试探一步
		{path.push(c = advance(c)); c->outgoing = UNKNOWN; c->status = ROUTE;}
	} while (!path.empty());
	return false;
}
Beispiel #28
0
TEST(JumpPointSearch, DiagonalJPNeighbor){
    cv::Mat map5x5 = (cv::Mat_<char>(5,5) << 255, 255, 255, 255, 255,
                                             255, 255, 255,   0, 255,
                                             255, 255, 255,   0, 255,
                                             255, 255, 255, 255, 255,
                                             255, 255, 255, 255, 255);
    cv::Vec2i expected(1,3);

    jpsastar::JPSAStar jpsastar(map5x5);
    cv::Vec2i current(0,4);
    cv::Vec2i neighbor(1,3);
    cv::Vec2i *jp = jpsastar.jumpPoint( current, neighbor, cv::Vec2i(0,0) );

    ASSERT_EQ(*jp, expected)
        << "Expected: " << to_string(expected) << "\n"
        << "  Actual: " << to_string(*jp);
    }
Beispiel #29
0
int fmll_som_so_kohonen(fmll_som * som, const double ** vec, const unsigned vec_num, const double beta_0, double (* next_beta)(const double),
		const double gamma_mult, const double gamma_add, double (* neighbor)(const fmll_som *, const double, const double, const unsigned, const unsigned))
{
	int ret = 0;
	const unsigned num = som->num, dim = som->dim;
	unsigned u, v, q, index_winner;
	double beta_gamma, beta = beta_0, ** w = som->w;

	fmll_try;

		fmll_throw_if(beta_0 < 0 || beta_0 > 1);
		fmll_throw_if(neighbor == & fmll_som_neighbor_radial && (gamma_mult < 0 || gamma_mult > 1));
		fmll_throw_if(neighbor == & fmll_som_neighbor_radial && (gamma_add < 0));

		while(beta < 1.0000001)
		{
			fmll_print("Self - organization: beta == %.7lf\n", beta);

			for(u = 0; u < vec_num; u++)
			{
				index_winner = fmll_som_run(som, vec[u]);

				if(neighbor == & fmll_som_neighbor_wta)
					for(q = 0; q < dim; q++)
						w[index_winner][q] += beta * (vec[u][q] - w[index_winner][q]);
				else
					for(v = 0; v < num; v++)
					{
						beta_gamma = beta * neighbor(som, gamma_mult, gamma_add, index_winner, v);

						for(q = 0; q < dim; q++)
							w[v][q] += beta_gamma * (vec[u][q] - w[v][q]);
					}
			}

			beta = (* next_beta)(beta);
		}

	fmll_catch;

		ret = -1;

	fmll_finally;

	return ret;
}
void test_neighbor(FILE* out, struct Map* map)
{
  int i;
  int j;
  int is_adjacent;
  
  fprintf(out, "Testing neighbor function...\n");
  for(i = 0; i < map->rooms; i++)
  {
    for(j = 0; j < map->rooms; j++)
    {
      is_adjacent = neighbor(i, j, map);
      fprintf(out, "  Can %d reach %d? result = %d\n",
              i, j, is_adjacent);
    }
  }
}