Exemplo n.º 1
0
static void run(const char *name, void (*scen)(void))
{
	uint8_t page_buf[1 << sim_nand.log2_page_size];
	struct dhara_journal journal;

	printf("========================================"
	       "================================\n"
	       "%s\n"
	       "========================================"
	       "================================\n\n", name);

	sim_reset();
	dhara_journal_init(&journal, &sim_nand, page_buf);

	/* All tests are tuned for this value */
	assert(journal.log2_ppc == 2);

	scen();

	jt_enqueue_sequence(&journal, 0, 30);
	jt_dequeue_sequence(&journal, 0, 30);

	sim_dump();
	printf("\n");
}
int main(int argc, char **argv)
{
	char filename[255];
	std::vector<xyLoc> thePath;
	std::vector<bool> mapData;
	int width, height;
	bool pre = false;
	bool run = false;

/*
	if (argc != 4)
	{
		printf("Invalid Arguments\nUsage %s <flag> <map> <scenario>\n", argv[0]);
		printf("Flags:\n");
		printf("\t-full : Preprocess map and run scenario\n");
		printf("\t-pre : Preprocess map\n");
		printf("\t-run : Run scenario without preprocessing\n");
		exit(0);
	}
	if (strcmp(argv[1], "-full") == 0)
	{
		pre = run = true;
	}
	else if (strcmp(argv[1], "-pre") == 0)
	{
		pre = true;
	}
	else if (strcmp(argv[1], "-run") == 0)
	{
		run = true;
	}
	else {
        printf("Invalid Arguments\nUsage %s <flag> <map> <scenario>\n", argv[0]);
		printf("Flags:\n");
        printf("\t-full : Preprocess map and run scenario\n");
        printf("\t-pre : Preprocess map\n");
        printf("\t-run : Run scenario without preprocessing\n");
        exit(0);
	}

	LoadMap(argv[2], mapData, width, height);
	sprintf(filename, "%s-%s.txt", GetName(), argv[2]);
*/
	// Testing area
	LoadMap("ca_cave.map", mapData, width, height);
	sprintf(filename, "%s-%s.txt", GetName(), "TEST");

	pre = run = true;
	if (pre)
	{
		PreprocessMap(mapData, width, height, filename);
	}

	if (!run)
	{
		return 0;
	}

	void *reference = PrepareForSearch(mapData, width, height, filename);

	//ScenarioLoader scen(argv[3]);
	ScenarioLoader scen("ca_cave.map.scen");


	Timer t;
	std::vector<stats> experimentStats;
	for (int x = 0; x < scen.GetNumExperiments(); x++)
    {
		printf("%d of %d\n", x+1, scen.GetNumExperiments());
		thePath.resize(0);
		experimentStats.resize(x+1);
		bool done;
		xyLoc s, g;
		s.x = scen.GetNthExperiment(x).GetStartX();
		s.y = scen.GetNthExperiment(x).GetStartY();
		g.x = scen.GetNthExperiment(x).GetGoalX();
		g.y = scen.GetNthExperiment(x).GetGoalY();
		SetFirstSearch(true);
		InitializeSearch();
		do {
			t.StartTimer();
			done = GetPath(reference, s, g, thePath);
			t.EndTimer();

			experimentStats[x].times.push_back(t.GetElapsedTime());
			experimentStats[x].lengths.push_back(thePath.size());
			for (unsigned int t = experimentStats[x].path.size(); t < thePath.size(); t++)
				experimentStats[x].path.push_back(thePath[t]);
		} while (done == false);
    }

	for (unsigned int x = 0; x < experimentStats.size(); x++)
	{
		printf("%s\ttotal-time\t%f\tmax-time-step\t%f\ttime-20-moves\t%f\ttotal-len\t%f\tsubopt\t%f\t", argv[3],
			   experimentStats[x].GetTotalTime(), experimentStats[x].GetMaxTimestep(), experimentStats[x].Get20MoveTime(),
			   experimentStats[x].GetPathLength(), experimentStats[x].GetPathLength()/scen.GetNthExperiment(x).GetDistance());
		if (experimentStats[x].path.size() == 0 ||
			(experimentStats[x].ValidatePath(width, height, mapData) &&
			 scen.GetNthExperiment(x).GetStartX() == experimentStats[x].path[0].x &&
			 scen.GetNthExperiment(x).GetStartY() == experimentStats[x].path[0].y &&
			 scen.GetNthExperiment(x).GetGoalX() == experimentStats[x].path.back().x &&
			 scen.GetNthExperiment(x).GetGoalY() == experimentStats[x].path.back().y))
		{
			printf("valid\n");
		}
		else {
			printf("invalid\n");
		}
	}
/*
	// Testing section...
//131	233	163	50
	xyLoc s, g;
	s.x = 95;
	s.y = 146;
	g.x = 92;
	g.y = 189;
	InitializeSearch();
	Timer t;
	t.StartTimer();
	bool done = false;
	while (!done)
	{
		done = GetPath(reference, s, g, thePath);
	}
	t.EndTimer();
	printf("(%d,%d)->(%d,%d)\n",s.x,s.y,g.x,g.y);
	printf("time: %fs\n",t.GetElapsedTime());
	write_map(mapData, width, height, s, g, thePath);
	stats st;
	st.path = thePath;
	bool k = (st.ValidatePath(width, height, mapData)
			&& s.x == thePath[0].x
			&& s.y == thePath[0].y
			&& g.x == thePath.back().x
			&& g.y == thePath.back().y
			);
	if (k)
		printf("valid\n");
	else
		printf("invalid\n");

	return 0;*/
}