Example #1
0
void test2()
{
	struct key
	{
		int i;
		int j;
		int k;
	};

	struct k_less
	{
		bool operator() ( key _l, key _r )
		{
			if( _l.i < _r.i )
			{
				return true;
			}

			if( _l.j < _r.j )
			{
				return true;
			}

			if( _l.k < _r.k )
			{
				return true;
			}

			return false;
		}
	};

	typedef std::map<key, int, k_less> M; 
	M m;

	key k0;
	k0.i = 1;
	k0.j = 2;
	k0.k = 3;

	m[k0] = 1;

	key k1;
	k1.i = -1;
	k1.j = -2;
	k1.k = -3;

	m[k1] = 2;

	m[k0] = 3;

	m[k1] = 4;

	key k2;
	k2.i = 1;
	k2.j = 2;
	k2.k = 2;

	m[k2] = 5;

	if( true & false )
	{
		printf("11");
	}

	fastpathfinder::graph g;

	node gn0(0);
	node gn1(1);
	node gn2(2);
	node gn3(3);
	node gn4(4);
	node gn5(5);
	node gn6(6);
	node gn7(7);
	node gn8(8);
	node gn9(9);


	g.addNode( &gn0 );
	g.addNode( &gn1 );
	g.addNode( &gn2 );
	g.addNode( &gn3 );
	g.addNode( &gn4 );
	g.addNode( &gn5 );
	g.addNode( &gn6 );
	g.addNode( &gn7 );
	g.addNode( &gn8 );
	g.addNode( &gn9 );

	g.addEdge2( &gn0, &gn6, 2 );
	g.addEdge2( &gn0, &gn7, 2 );
	g.addEdge2( &gn6, &gn3, 1 );
	g.addEdge2( &gn3, &gn2, 1 );
	g.addEdge2( &gn0, &gn1, 2 );
	g.addEdge2( &gn7, &gn1, 1 );
	g.addEdge2( &gn1, &gn2, 1 );
	g.addEdge2( &gn1, &gn9, 3 );
	g.addEdge2( &gn9, &gn5, 3 );
	g.addEdge2( &gn5, &gn8, 2 );
	g.addEdge2( &gn4, &gn8, 2 );
	g.addEdge2( &gn4, &gn5, 2 );
	g.addEdge2( &gn2, &gn4, 2 );

	g.blockNode( &gn2, true );

	fastpathfinder::vector_graph_node path;
	g.getPath( &gn8, &gn7, path );

	for( fastpathfinder::vector_graph_node::iterator
		it = path.begin(),
		it_end= path.end();
	it != it_end;
	++it )
	{
		node * n = (node *)*it;

		printf("%d\n"
			, n->index 
			);
	}
}
Example #2
0
int main(void){

	TriangleCache::TriangleCache TC(50,2);

	sm::Point p11(10,10);
	sm::Point p12(20,20);
	sm::Point p13(30,30);
	sm::Point p21(40,40);
	sm::Point p22(50,50);
	sm::Point p23(60,60);

	Triangle t1(&p11, &p12, &p13);
	Triangle t2(&p21, &p22, &p23);
	GNode gn1(&t1);
	GNode gn2(&t2);

	GNode gn3(&t2);
	GNode gn4(&t2);
	GNode gn5(&t1);
	GNode gn6(&t1);

	const GNode ** path1 = (const GNode **)calloc(3, sizeof(GNode *));
	path1[0] = &gn3;
	path1[1] = &gn4;
	path1[2] = 0;
	const GNode ** path = (const GNode **)calloc(3, sizeof(GNode *));
	path[0] = &gn1;
	path[1] = &gn2;
	path[2] = 0;
	const GNode ** path2 = (const GNode **)calloc(4, sizeof(GNode *));
	path2[0] = &gn5;
	path2[1] = &gn3;
	path2[2] = &gn6;
	path2[3] = 0;
	bool f = false;

	debugGREEN("TEST FIND WHEN THERE IS NOTHING\n");
	const GNode **r = TC.getPath( &gn1, &gn2, f);
	ASSERT(!r);
	debugRED("OK... \n");

	debugGREEN("TEST ADD AND SEARCH ONE ELEMENT\n");
	TC.addPath( &gn1, &gn2, path);
	const GNode **ret = TC.getPath( &gn1, &gn2, f);
	ASSERT(ret);
	ASSERT(f);
	ASSERT(&gn1 == ret[0]);
	ASSERT(&gn2 == ret[1]);
	debugRED("OK... \n");

	debugGREEN("TEST SEARCH THE SAME ELEMENT BUT IN REVERSE ORDER\n");
	ASSERT(TC.getPath( &gn2, &gn1, f));
	ASSERT(!f);
	debugRED("OK... \n");

	debugGREEN("TEST ADD 500000 MORE ELEMENTS gn2-gn1 and look for gn1-gn2 and gn2-gn1\n");
	for (int i = 0; i < 50000; i++){
		TC.addPath( &gn2, &gn1, path);
	}
	ASSERT(TC.getPath( &gn1, &gn2, f));
	ASSERT(TC.getPath( &gn2, &gn1, f));
	debugRED("OK... \n");

	debugGREEN("TEST ADD path, then path1, then path2, and then find path 1\n");
	TC.addPath( &gn1, &gn2, path);
	TC.addPath( &gn3, &gn4, path1);
	TC.addPath( &gn5, &gn6, path2);
	ASSERT(!TC.getPath( &gn1, &gn2, f));
	ASSERT(!TC.getPath( &gn2, &gn1, f));
	ASSERT(TC.getPath( &gn4, &gn3, f));
	ASSERT(TC.getPath( &gn3, &gn4, f));
	ASSERT(TC.getPath( &gn5, &gn6, f));
	ASSERT(TC.getPath( &gn6, &gn5, f));
	debugRED("OK... \n");

	debugGREEN("TEST CLEAR CACHE\n");
	TC.clear();
	ASSERT(!TC.getPath( &gn1, &gn2, f));
	ASSERT(!TC.getPath( &gn2, &gn1, f));
	ASSERT(!TC.getPath( &gn4, &gn3, f));
	ASSERT(!TC.getPath( &gn3, &gn4, f));
	ASSERT(!TC.getPath( &gn5, &gn6, f));
	ASSERT(!TC.getPath( &gn6, &gn5, f));
	debugRED("OK... \n");

	debugGREEN("TEST REFRESHING\n");
	TC.addPath( &gn2, &gn1, path);
	TC.addPath( &gn3, &gn4, path1);
	TC.addPath( &gn2, &gn1, path);
	TC.addPath( &gn5, &gn6, path2);
	ASSERT(!TC.getPath( &gn4, &gn3, f));
	ASSERT(TC.getPath( &gn1, &gn2, f));
	ASSERT(TC.getPath( &gn5, &gn6, f));
	debugRED("OK... \n");

	debugBLUE("END TESTS (ALL OK)\n");

	free(path);
	free(path1);
	free(path2);

	return 0;
}