Exemple #1
0
// experiments with 0, 10, ..., 100 differential heuristics
void RunExperiments1(ScenarioLoader *sl)
{
	std::vector<graphState> aPath;

	Map *m = new Map(sl->GetNthExperiment(0).GetMapName());
	m->Scale(sl->GetNthExperiment(0).GetXScale(), 
			 sl->GetNthExperiment(0).GetYScale());
	Graph *g = GraphSearchConstants::GetGraph(m);
	
	GraphDistanceHeuristic diffHeuristic(g);
	diffHeuristic.SetPlacement(kAvoidPlacement);
	
	GraphEnvironment gEnv(g, &diffHeuristic);
	gEnv.SetDirected(true);
	
	TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;

	
	for (int z = 0; z <= 10; z++)
	{
		for (int x = 0; x < sl->GetNumExperiments(); x++)
		{
			Experiment e = sl->GetNthExperiment(x);

			graphState start, goal;
			start = m->GetNodeNum(e.GetStartX(), e.GetStartY());
			goal = m->GetNodeNum(e.GetGoalX(), e.GetGoalY());

			Timer t;
			t.StartTimer();
			taNew.GetPath(&gEnv, start, goal, aPath);
			t.EndTimer();

			printf("%d\t%d\t%lld\t%f\n", e.GetBucket(), diffHeuristic.GetNumHeuristics(), taNew.GetNodesExpanded(), t.GetElapsedTime());
		}
		for (int x = 0; x < 10; x++)
			diffHeuristic.AddHeuristic();
	}
	exit(0);
}
Exemple #2
0
bool MySearchUnit::makeMove(MapProvider *mp, reservationProvider *rp, AbsMapSimulationInfo *simInfo, tDirection &res)
{
    if (getCachedMove(res))
        return true;

    Map *map = mp->GetMap();
    MapAbstraction *aMap = mp->GetMapAbstraction();
    PublicUnitInfo<xyLoc,tDirection,AbsMapEnvironment> pui;

    // if we have a cache to be used, use it!
    if (spread_cache)
    {
        addPathToCache(spread_cache);
        node *next_start = spread_cache->tail()->n;
        int targx, targy;
        simInfo->GetPublicUnitInfo( targetUnit, pui );
        xyLoc l = pui.currentState;
        targx = l.x;
        targy = l.y;

        // Get a path by path-planning
        node *to = aMap->GetAbstractGraph(0)->GetNode(map->GetNodeNum(targx, targy));

        s_algorithm->setTargets(mp->GetMapAbstraction(), next_start, to, rp);
        delete spread_cache;
        spread_cache = 0;
        res = moves.back();
        moves.pop_back();
        return true;
    }

    // Check if we have a target defined
    if (targetUnit < 0)
    {
        if (verbose)
            printf("SU %s: No target, doing nothing\n", this->GetName());
        return false;
    }

    // Get the position of the target
    int targx, targy;
    simInfo->GetPublicUnitInfo( targetUnit, pui );
    xyLoc l = pui.currentState;
    targx = l.x;
    targy = l.y;

    // Get a path by path-planning
    Graph *g0 = aMap->GetAbstractGraph(0);
    // Get the start and goal nodes
    node *from = g0->GetNode(map->GetNodeNum(loc.x, loc.y));
    node *to = g0->GetNode(map->GetNodeNum(targx, targy));

    if (from == to)
    {
        if (!onTarget)
        {
            if (verbose)
            {
                printf("STAY ON TARGET!\n");
                printf("%p target time %1.4f\n", (void*)this, targetTime);
            }
            if (simInfo)
                targetTime = simInfo->GetSimulationTime();
        }
        onTarget = true;
//		return kStay;
    }
    else
        onTarget = false;
//	if (verbose)
//		printf("SU %p: Getting new path\n", this);
    path *p;
    p = algorithm->GetPath(aMap, from, to, rp);
    nodesExpanded+=algorithm->GetNodesExpanded();
    nodesTouched+=algorithm->GetNodesTouched();

    // returning an empty path means there is no path between the start and goal
    if (p == NULL)
    {
        if (verbose)
            printf("SU %s: Path returned NIL\n", this->GetName());
        return false;
    }

    if (!(p->n && p->next && p->next->n && (loc.x == p->n->GetLabelL(kFirstData))
            && (loc.y == p->n->GetLabelL(kFirstData+1))))
    {
        if (p->n)
            std::cout << *p->n << std::endl;
        if ((p->next) && (p->next->n))
            std::cout << *p->next->n << std::endl;
        std::cout << loc.x << ", " << loc.y << std::endl;
    }

    // a valid path must have at least 2 nodes and start where the unit is located
    assert(p->n && p->next && p->next->n && (loc.x == p->n->GetLabelL(kFirstData))
           && (loc.y == p->n->GetLabelL(kFirstData+1)));

    addPathToCache(p);
    if (s_algorithm)
    {
        node *next_start = p->tail()->n;
        s_algorithm->setTargets(mp->GetMapAbstraction(), next_start, to, rp);
    }
    delete p;

    assert(moves.size() > 0);

    res = moves.back();
    moves.pop_back();
//	if (verbose)
//		printf("SU %p: returning move 0x%X\n", this, (int)dir);
    return true;
}
Exemple #3
0
// Compare:
// * 1 random lookup of 10 with BPMX
// * 1 random lookup of 10 without BPMX
// * octile
// * max of 10 heuristics
// * 1 lookup in compressed heuristic
void RunExperiments4(ScenarioLoader *sl)
{
	std::vector<graphState> aPath;
	
	Map *m = new Map(sl->GetNthExperiment(0).GetMapName());
	m->Scale(sl->GetNthExperiment(0).GetXScale(), 
			 sl->GetNthExperiment(0).GetYScale());
	Graph *g = GraphSearchConstants::GetGraph(m);
	
	GraphMapInconsistentHeuristic diffHeuristic(m, g);
	diffHeuristic.SetPlacement(kAvoidPlacement);
	diffHeuristic.SetMode(kRandom);
	
	GraphEnvironment gEnv(g, &diffHeuristic);
	gEnv.SetDirected(true);
	
	TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;

	Timer t;
	
	for (int x = 0; x < 10; x++)
		diffHeuristic.AddHeuristic();
	//diffHeuristic.SetNumUsedHeuristics(diffHeuristic.GetNumHeuristics()/10);

	for (int x = 0; x < sl->GetNumExperiments(); x++)
	{
		Experiment e = sl->GetNthExperiment(x);
		
		graphState start, goal;
		start = m->GetNodeNum(e.GetStartX(), e.GetStartY());
		goal = m->GetNodeNum(e.GetGoalX(), e.GetGoalY());
	
		
		printf("%d\t", e.GetBucket());
		
		// N memory -- 1 heuristic
		diffHeuristic.SetNumUsedHeuristics(1);
		diffHeuristic.SetMode(kMax);
		taNew.SetUseBPMX(0);

		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%df\t%lld\t%f\t%f\t", diffHeuristic.GetNumHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
		// N memory -- 10 compressed heuristics no BPMX
		diffHeuristic.SetNumUsedHeuristics(10);
		diffHeuristic.SetMode(kCompressed);
		taNew.SetUseBPMX(0);

		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%dc\t%lld\t%f\t%f\t", diffHeuristic.GetNumHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
		// N memory -- 10 compressed heuristics BPMX 1
		diffHeuristic.SetNumUsedHeuristics(10);
		diffHeuristic.SetMode(kCompressed);
		taNew.SetUseBPMX(1);

		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%dcb1\t%lld\t%f\t%f\t", diffHeuristic.GetNumHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
		// N memory -- 10 compressed heuristics BPMX(°)
		diffHeuristic.SetNumUsedHeuristics(10);
		diffHeuristic.SetMode(kCompressed);
		taNew.SetUseBPMX(1000);
				
		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%dcbi\t%lld\t%f\t%f\n", diffHeuristic.GetNumHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
	}
	exit(0);
}
Exemple #4
0
// Compare:
// * 10 N memory
// * 1...10 regular lookups
// * 1...9 random lookups with and without BPMX
// Only compare on longest problems
void RunExperiments5(ScenarioLoader *sl)
{
	std::vector<graphState> aPath;
	
	Map *m = new Map(sl->GetNthExperiment(0).GetMapName());
	m->Scale(sl->GetNthExperiment(0).GetXScale(), 
			 sl->GetNthExperiment(0).GetYScale());
	Graph *g = GraphSearchConstants::GetGraph(m);
	
	GraphMapInconsistentHeuristic diffHeuristic(m, g);
	diffHeuristic.SetPlacement(kAvoidPlacement);
	diffHeuristic.SetMode(kRandom);
	
	GraphEnvironment gEnv(g, &diffHeuristic);
	gEnv.SetDirected(true);
	
	TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;
	
	Timer t;
	
	for (int x = 0; x < 10; x++)
		diffHeuristic.AddHeuristic();
	//diffHeuristic.SetNumUsedHeuristics(diffHeuristic.GetNumHeuristics()/10);
	
	for (int x = 0; x < sl->GetNumExperiments(); x++)
	{
		Experiment e = sl->GetNthExperiment(x);
		
		if (e.GetBucket() != 127)
			continue;
		
		graphState start, goal;
		start = m->GetNodeNum(e.GetStartX(), e.GetStartY());
		goal = m->GetNodeNum(e.GetGoalX(), e.GetGoalY());
		
		
		printf("%d\t", e.GetBucket());
		
		
		for (int y = 1; y <= 10; y++)
		{
			// N memory -- 1 heuristic
			diffHeuristic.SetNumUsedHeuristics(y);
			diffHeuristic.SetMode(kMax);
			taNew.SetUseBPMX(0);
			
			t.StartTimer();
			taNew.GetPath(&gEnv, start, goal, aPath);
			t.EndTimer();		
			printf("%dmx\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
				   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		}
		
		for (int y = 1; y <= 9; y++)
		{
			for (int z = 0; z <= 1; z++)
			{
				// N memory -- 1 heuristic
				diffHeuristic.SetNumUsedHeuristics(y);
				diffHeuristic.SetMode(kRandom);
				taNew.SetUseBPMX(z);
				
				t.StartTimer();
				taNew.GetPath(&gEnv, start, goal, aPath);
				t.EndTimer();	
				if (z==0)
					printf("%drnd\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
						   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
				else
					printf("%drdb\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
						   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
			}
		}
		printf("\n");
		
	}
	exit(0);
}
Exemple #5
0
// Compare:
// * 10 N memory
// * 100 compressed heuristics
void RunExperiments(ScenarioLoader *sl, int memory)
{
	std::vector<graphState> aPath;
	
	Map *m = new Map(sl->GetNthExperiment(0).GetMapName());
	m->Scale(sl->GetNthExperiment(0).GetXScale(), 
			 sl->GetNthExperiment(0).GetYScale());
	Graph *g = GraphSearchConstants::GetGraph(m);
	
	GraphMapInconsistentHeuristic diffHeuristic(m, g);
	GraphMapInconsistentHeuristic diff1(m, g);
	diffHeuristic.SetPlacement(kAvoidPlacement);
	diffHeuristic.SetMode(kRandom);
	diff1.SetPlacement(kAvoidPlacement);
	diff1.SetMode(kMax);
	
	GraphEnvironment gEnv(g, &diffHeuristic);
	gEnv.SetDirected(true);
	GraphEnvironment gEnv2(g, &diff1);
	gEnv2.SetDirected(true);
	
	TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;
	
	Timer t;
	
	for (int x = 0; x < memory; x++)
		diffHeuristic.AddHeuristic();
	diffHeuristic.SetNumUsedHeuristics(memory);
	diffHeuristic.Compress();
	diff1.AddHeuristic();
	diff1.SetNumUsedHeuristics(1);
	
	for (int x = 0; x < sl->GetNumExperiments(); x++)
	{
		Experiment e = sl->GetNthExperiment(x);
		
//		if (e.GetBucket() < 100)
//			continue;
		
		graphState start, goal;
		start = m->GetNodeNum(e.GetStartX(), e.GetStartY());
		goal = m->GetNodeNum(e.GetGoalX(), e.GetGoalY());
		
		
		printf("%d\t", e.GetBucket());
		
		
		// 10N memory -- 10 heuristics
//		diffHeuristic.SetNumUsedHeuristics(1);
//		diffHeuristic.SetMode(kMax);
//		taNew.SetUseBPMX(0);
//			
//		t.StartTimer();
//		taNew.GetPath(&gEnv, start, goal, aPath);
//		t.EndTimer();		
//		printf("%dmx\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
//			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
//		diffHeuristic.SetNumUsedHeuristics(memory);
//		diffHeuristic.SetMode(kCompressed);
//		taNew.SetUseBPMX(0);
		
//		t.StartTimer();
//		taNew.GetPath(&gEnv, start, goal, aPath);
//		t.EndTimer();		
//		printf("%dcmp\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
//			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
//		diffHeuristic.SetNumUsedHeuristics(memory);
//		diffHeuristic.SetMode(kCompressed);
		taNew.SetUseBPMX(0);
		
		t.StartTimer();
		taNew.GetPath(&gEnv2, start, goal, aPath);
		t.EndTimer();		
		printf("%dbx1\t%lld\t%f\t%f\t", diff1.GetNumUsedHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
		taNew.SetUseBPMX(0);
		
		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%dbx1\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));

		taNew.SetUseBPMX(1);
		
		t.StartTimer();
		taNew.GetPath(&gEnv, start, goal, aPath);
		t.EndTimer();		
		printf("%dbx1\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
//		diffHeuristic.SetNumUsedHeuristics(memory);
//		diffHeuristic.SetMode(kCompressed);
//		taNew.SetUseBPMX(1000);
//		
//		t.StartTimer();
//		taNew.GetPath(&gEnv, start, goal, aPath);
//		t.EndTimer();		
//		printf("%dbxi\t%lld\t%f\t%f\t", diffHeuristic.GetNumUsedHeuristics(),
//			   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
		
		printf("\n");
		fflush(stdout);
	}
	exit(0);
}
Exemple #6
0
// experiments with 0, 10, ..., 100 differential heuristics
// 10% of them are used at each step with and without BPMX
void RunExperiments2(ScenarioLoader *sl)
{
	std::vector<graphState> aPath;
	
	Map *m = new Map(sl->GetNthExperiment(0).GetMapName());
	m->Scale(sl->GetNthExperiment(0).GetXScale(), 
			 sl->GetNthExperiment(0).GetYScale());
	Graph *g = GraphSearchConstants::GetGraph(m);
	
	GraphMapInconsistentHeuristic diffHeuristic(m, g);
	diffHeuristic.SetPlacement(kAvoidPlacement);
	diffHeuristic.SetMode(kRandom);
	
	GraphEnvironment gEnv(g, &diffHeuristic);
	gEnv.SetDirected(true);
	
	TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;
	
	Timer t;
	
	for (int z = 0; z < 1; z++)
	{
		for (int x = 0; x < 10; x++)
			diffHeuristic.AddHeuristic();
		diffHeuristic.SetNumUsedHeuristics(diffHeuristic.GetNumHeuristics()/10);
		
		for (int x = 0; x < sl->GetNumExperiments(); x++)
		{
			Experiment e = sl->GetNthExperiment(x);
			//			if (e.GetBucket() != 127)
			//			{ continue; }
			
			graphState start, goal;
			start = m->GetNodeNum(e.GetStartX(), e.GetStartY());
			goal = m->GetNodeNum(e.GetGoalX(), e.GetGoalY());
			
			//			taNew.SetUseBPMX(false);
			//			Timer t;
			//			t.StartTimer();
			//			taNew.GetPath(&gEnv, start, goal, aPath);
			//			t.EndTimer();
			//			
			//			printf("%d\t%d.%d\t%d\t%f\t\t%f\n", e.GetBucket(), diffHeuristic.GetNumHeuristics(), diffHeuristic.GetNumHeuristics()/10,
			//				   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
			
			for (int y = 1; y < 6; y++)
			{
				if (y == 5)
					taNew.SetUseBPMX(1000);
				else
					taNew.SetUseBPMX(y);
				t.StartTimer();
				taNew.GetPath(&gEnv, start, goal, aPath);
				t.EndTimer();
				
				printf("%d\t%d.%d\t%lld\t%f\tBPMX\t%f\n", e.GetBucket(), diffHeuristic.GetNumHeuristics(), y,
					   taNew.GetNodesExpanded(), t.GetElapsedTime(), gEnv.GetPathLength(aPath));
			}
		}
	}
	exit(0);
}