예제 #1
0
struct t_rooms				*find_path(struct t_datas *datas, struct t_rooms *room)
{
	if (room->seen == 0 && find_neighbours(room, datas->tubes))
		return (find_path(datas, find_neighbours(room, datas->tubes)));
	else
		return (room);
}
예제 #2
0
static struct t_rooms		*find_neighbours(struct t_rooms *room, struct t_tubes *tubes)
{
	if (tubes != NULL)
	{
		if (!ft_strcmp(tubes->start, room->name))
			return (find_room(tubes->end, room));
		else if (!ft_strcmp(tubes->end, room->name))
			return (find_room(tubes->start, room));
		else
			return (find_neighbours(room, tubes->next));
	}
	return (NULL);
}
예제 #3
0
    bool frontier_detector::is_frontier(  const point_xy_t &p,     //{{{
                                    size_t height, size_t width,
                                    const gdal::raster& data ) {

        // NB: Remember that index = x + y * width
        
        // A point is a frontier iff it is in the open space 
        // (i.e. it is know and is not an obstacle )
        if ( data[ map.idx( p )]  < 0               // unknown
        ||   data[ map.idx( p )] == HUGE_VALF )     // obstacle
            return false ;
        // and at least one of is neighbour is unknown.
        for ( auto i : find_neighbours( p, height, width) )
            if ( data[ map.idx( i ) ] < 0 )          // unknown
                return true ;

        return false;
    }//}}}
예제 #4
0
void
qxl_free (struct qxl_mem *mem, void *d)
{
    struct block *b = d - sizeof (unsigned long);
    struct block *before, *after;

    mem->total_freed += b->n_bytes;
    mem->n_freed_blocks++;
    
#if 0
    printf ("freeing %p (%d bytes)\n", b, b->n_bytes);
    
    qxl_mem_dump_stats (mem, "before free");
#endif
    
    find_neighbours (mem, (void *)b, &before, &after);

    if (before)
    {
#if 0
	printf ("  free: merge before: %p\n", before->u.used.data);
#endif
	    
	if ((void *)before + before->n_bytes == b)
	{
#if 0
 	    printf ("  free: merge with before (adding %d bytes)\n", b->n_bytes);
#endif
	    
	    /* Merge before and b */
	    before->n_bytes += b->n_bytes;
	    b = before;
	}
	else
	{
#if 0
	    printf ("  free: no merge with before\n");
#endif

	    if (b == (void *)0xffffffffffffffff)
		abort();
	    
	    before->u.unused.next = b;
	}
    }
    else
    {
#if 0
	printf ("  free: no before\n");
#endif
	mem->unused = b;
    }
    
    if (after)
    {
	if (after == (void *)0xffffffffffffffff)
	    abort();

#if 0
	printf ("  free: after: %p\n", after->u.used.data);
#endif
	if ((void *)b + b->n_bytes == after)
	{
#if 0
	    printf ("  merge with after\n");
#endif
	    b->n_bytes += after->n_bytes;
	    b->u.unused.next = after->u.unused.next;
	}
	else
	{
#if 0
	    printf ("  no merge with after\n");
#endif
	    b->u.unused.next = after;
 	}
    }
    else
    {
#if 0
	printf ("  free: no after\n");
#endif
	b->u.unused.next = NULL;
    }

#if 0
    qxl_mem_dump_stats (mem, "after free");
#endif
    sanity_check (mem);
}
long cell_energy(long n)			// Sum the interaction energy attributable to cell n
{
	find_neighbours(n);
	return -1 *(lattice[n] - 1) * sum_neighbours();
}
예제 #6
0
    /* computing functions */
    void frontier_detector::compute_frontiers_WFD(const point_xy_t &seed) {//{{{
        // Get size of the map
        size_t width, height;
        width   = map.get_width();
        height  = map.get_height();

        // Get the raster band
        const gdal::raster& data = map.get_weight_band() ;

        // check conditions on seed :
        // - inside the map
        assert( seed[0] > 0 && seed[0] < (width-1) && seed[1] > 0 && seed[1] < (height-1) );
        // - within the known area and not an obstacle
        assert( data[ map.idx( seed ) ]  > 0 && data[ map.idx( seed ) ] != HUGE_VALF );

        /* {{{ compute frontiers with the WFD algorithm
         *
         * Use the description given by :
         * "Robot Exploration with Fast Frontier Detection : Theory and
         * Experiments", M. Keidar afd G. A. Kaminka (AAMAS 2012)
         *
         */
        // Requested containers
        // queues
        std::deque< point_xy_t > mQueue ;       // std::queue are restricted std::deque
        std::deque< point_xy_t > fQueue ;       // std::queue are restricted std::deque

        // markers lists
        std::vector< bool > mapOpenList       (height*width, false) ;
        std::vector< bool > mapCloseList      (height*width, false) ;
        std::vector< bool > frontierOpenList  (height*width, false) ;
        std::vector< bool > frontierCloseList (height*width, false) ;

        // points
        point_xy_t p,q ;

        //init
        frontiers.empty();    // clear the previous frontiers
        mQueue.push_back( seed );
        mapOpenList[ map.idx( seed )] = true ;

        int c1 = 0;
        // Main while over queued map points
        while ( !mQueue.empty() ) {

            p = mQueue.front();
            mQueue.pop_front();

            // if p has already been visited, then continue
            if ( mapCloseList[ map.idx( p )] ) {
                continue ;
            }

            // else, if p is a frontier point,
            // compute the whole related frontier
            if ( is_frontier( p, height, width, data ) ) {
                int c2 = 0 ;

                fQueue.clear();
                // create a new frontier
                frontiers.push_back( points_t() );

                fQueue.push_back( p );
                frontierOpenList[ map.idx( p )] = true ;

                // while over potential frontier points
                while ( !fQueue.empty() ) {

                    q = fQueue.front();
                    fQueue.pop_front();

                    // if q has already been visited, then continue
                    if  ( mapCloseList[ map.idx( q ) ]
                    || frontierCloseList[ map.idx( q ) ]) {
                        continue;
                    }

                    // if p is a frontier point,
                    // deal with it and its neighbours
                    if ( is_frontier( q, height, width, data ) ) {
                        frontiers.back().push_back( q );
                        //for all neighbours of q
                        for ( auto i : find_neighbours( q, height, width) ) {
                            // if NOT marked yet
                            if  ( !( mapCloseList[ map.idx( i ) ]
                            || frontierCloseList[ map.idx( i ) ]
                            || frontierOpenList[ map.idx( i ) ])) {
                            // then proceed
                                fQueue.push_back( i );
                                frontierOpenList[ map.idx( i )] = true ;
                            }
                        }
                    }
                    // mark q
                    frontierCloseList[ map.idx( q )] = true ;
                }

                // Note : no need to save the new frontier explicitly

                // mark all points of the new frontier in the closed list
                for ( auto i : frontiers.back() ) {
                    mapCloseList[ map.idx( i )] = true ;
                }

            }

            //for all neighbours of p
            for ( auto i : find_neighbours( p, height, width) ) {
                // if NOT marked yet
                if  ( !( mapCloseList[ map.idx( i ) ]
                || mapOpenList[ map.idx( i ) ])
                // and has at least one neighbour in "Open Space", ie a
                // neighbour in the known area ard which is not an obstacle.
                && ( ! (data[ map.idx( i )]  < 0                // unknown
                    || data[ map.idx( i )] == HUGE_VALF ))) {   // obstacle
                    // then proceed
                    mQueue.push_back( i );
                    mapOpenList[ map.idx( i )] = true ;
                }
            }

            //mark p
            mapCloseList[ map.idx( p )] = true ;
        }
        //}}}
    }//}}}