本文整理汇总了C++中Timer::EndTimer方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::EndTimer方法的具体用法?C++ Timer::EndTimer怎么用?C++ Timer::EndTimer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::EndTimer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: STPTest
void STPTest(unsigned long , tKeyboardModifier , char)
{
MNPuzzleState tmp(4, 4);
mnp->StoreGoal(tmp);
IDAStar<MNPuzzleState, slideDir> ida;
std::vector<slideDir> path1;
MNPuzzleState s(4, 4);
MNPuzzleState g(4, 4);
//ida.SetUseBDPathMax(true);
Timer t;
t.StartTimer();
uint64_t nodes = 0;
for (int x = 0; x < 100; x++)
{
s = GetKorfInstance(x);
g.Reset();
std::cout << "Searching from: " << std::endl << s << std::endl << g << std::endl;
Timer t;
t.StartTimer();
ida.GetPath(mnp, s, g, path1);
t.EndTimer();
std::cout << "Path found, length " << path1.size() << " time:" << t.GetElapsedTime() << std::endl;
nodes += ida.GetNodesExpanded();
}
printf("%1.2fs elapsed; %llu nodes expanded\n", t.EndTimer(), nodes);
// for (int x = 0; x < mnp->histogram.size(); x++)
// {
// printf("%2d %d\n", x, mnp->histogram[x]);
// }
//
// mnp->PrintHStats();
}
示例2: runProblemSet2
void runProblemSet2(char *problems, int multiplier)
{
Map *map = new Map(gDefaultMap);
map->Scale(512, 512);
msa = new MapSectorAbstraction(map, 8, multiplier);
Graph *g = msa->GetAbstractGraph(1);
GraphAbstractionHeuristic gah1(msa, 1);
GraphDistanceHeuristic localGDH(g);
localGDH.SetPlacement(kAvoidPlacement);
for (unsigned int x = 0; x < 10; x++)
localGDH.AddHeuristic();
GraphHeuristicContainer ghc(g);
GraphRefinementEnvironment env1(msa, 1, &localGDH);
GraphRefinementEnvironment env2(msa, 1, 0);
// ghc.AddHeuristic(&localGDH);
// ghc.AddHeuristic(&gah1);
env1.SetDirected(false);
FILE *f = fopen(problems, "r");
if (f == 0)
{
printf("Cannot open file: '%s'\n", problems);
exit(0);
}
Timer t;
printf("len\tnodes\ttoucht\tlen\ttime\tdiff_n\tdiff_t\tdiff_l\ttime\n");
while (!feof(f))
{
int from, to, cost;
if (fscanf(f, "%d\t%d\t%d\n", &from, &to, &cost) != 3)
break;
node *s1 = g->GetNode(from);
node *g1 = g->GetNode(to);
graphState gs, gg;
gs = s1->GetNum();
gg = g1->GetNum();
std::vector<graphState> thePath;
t.StartTimer();
astar.GetPath(&env2, gs, gg, thePath);
t.EndTimer();
printf("%d\t", cost);
printf("%llu\t%llu\t%1.2f\t%e\t",
astar.GetNodesExpanded(), astar.GetNodesTouched(),
env1.GetPathLength(thePath), t.GetElapsedTime());
t.StartTimer();
astar.GetPath(&env1, gs, gg, thePath);
t.EndTimer();
printf("%llu\t%llu\t%1.2f\t%e",
astar.GetNodesExpanded(), astar.GetNodesTouched(),
env1.GetPathLength(thePath), t.GetElapsedTime());
printf("\n");
}
fclose(f);
exit(0);
}
示例3: Test
void Test(TopSpin &tse, const char *prefix)
{
TopSpinState s(16, 4);
TopSpinState g(16, 4);
g.Reset();
tse.StoreGoal(g);
tse.SetPruneSuccessors(true);
IDAStar<TopSpinState, TopSpinAction> ida;
ida.SetUseBDPathMax(true);
std::vector<TopSpinAction> path1;
TopSpinState start;
Timer t1;
t1.StartTimer();
uint64_t nodes = 0;
double totaltime = 0;
for (int x = 0; x < 100; x++)
{
s = GetInstance(x, tse.GetWeighted());
g.Reset();
printf("Problem %d of %d\n", x+1, 100);
std::cout << "Searching from: " << std::endl << s << std::endl << g << std::endl;
Timer t;
t.StartTimer();
ida.GetPath(&tse, s, g, path1);
t.EndTimer();
totaltime += t.GetElapsedTime();
std::cout << "Path found, length " << path1.size() << " time:" << t.GetElapsedTime() << std::endl;
nodes += ida.GetNodesExpanded();
}
printf("%s: %1.2fs elapsed; %llu nodes expanded\n", prefix, t1.EndTimer(), nodes);
}
示例4: MyDisplayHandler
void MyDisplayHandler(unsigned long windowID, tKeyboardModifier mod, char key)
{
switch (key)
{
case 'r': recording = !recording; break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ts->ApplyAction(s, key-'0');
break;
case '\t':
if (mod != kShiftDown)
SetActivePort(windowID, (GetActivePort(windowID)+1)%GetNumPorts(windowID));
else
{
SetNumPorts(windowID, 1+(GetNumPorts(windowID)%MAXPORTS));
}
break;
case 'p':
break;
case 'o':
{
if (!ts) break;
if (mod == kShiftDown)
{
IDAStar<TopSpinState, TopSpinAction> ida;
std::vector<TopSpinAction> path1;
std::vector<TopSpinState> path2;
TopSpinState s(4, 4);
TopSpinState g(4, 4);
for (unsigned int x = 0; x < 500; x++)
{
std::vector<TopSpinAction> acts;
ts->GetActions(s, acts);
ts->ApplyAction(s, acts[random()%acts.size()]);
}
std::cout << "Searching from: " << std::endl << s << std::endl << g << std::endl;
Timer t;
t.StartTimer();
ida.GetPath(ts, s, g, path1);
t.EndTimer();
std::cout << "Path found, length " << path1.size() << " time:" << t.GetElapsedTime() << std::endl;
}
}
break;
default:
break;
}
}
示例5: DoBFS
void DoBFS()
{
// By default, starts at goal state
SlidingPuzzleState s;
LList<int> moves;
uint8_t *stateDepths = new uint8_t[s.GetMaxRank()];
// set all values to 255
memset(stateDepths, 255, s.GetMaxRank());
uint32_t seenStates = 1;
stateDepths[s.Rank()] = 0;
int currDepth = 0;
Timer fullTimer;
std::cout.setf( std::ios::fixed, std:: ios::floatfield ); // floatfield set to fixed
std::cout.precision(2);
while (seenStates != s.GetMaxRank())
{
Timer roundTimer;
for (int x = 0; x < s.GetMaxRank(); x++)
{
if (stateDepths[x] == currDepth)
{
s.Unrank(x);
s.GetMoves(moves);
while (moves.IsEmpty() == false)
{
s.ApplyMove(moves.PeekFront());
uint32_t rank = s.Rank();
s.UndoMove(moves.PeekFront());
moves.RemoveFront();
if (stateDepths[rank] == 255)
{
stateDepths[rank] = currDepth+1;
seenStates++;
}
}
}
}
std::cout << roundTimer.GetElapsedTime() << "s elapsed. ";
std::cout << "Depth " << currDepth;
std::cout << " complete. " << seenStates << " of " << s.GetMaxRank();
std::cout << " total states seen.\n";
currDepth++;
}
std::cout << fullTimer.EndTimer() << "s elapsed\n";
delete [] stateDepths;
}
示例6: runProblemSet3
void runProblemSet3(char *scenario)
{
printf("Loading scenario %s\n", scenario);
ScenarioLoader sl(scenario);
printf("Loading map %s\n", sl.GetNthExperiment(0).GetMapName());
Map *map = new Map(sl.GetNthExperiment(0).GetMapName());
map->Scale(sl.GetNthExperiment(0).GetXScale(),
sl.GetNthExperiment(0).GetYScale());
PEAStar<xyLoc, tDirection, MapEnvironment> pea;
TemplateAStar<xyLoc, tDirection, MapEnvironment> astar;
std::vector<xyLoc> thePath;
MapEnvironment ma(map);
ma.SetFourConnected();
for (int x = 0; x < sl.GetNumExperiments(); x++)
{
if (sl.GetNthExperiment(x).GetBucket() != 127)
continue;
xyLoc from, to;
printf("%d\t", sl.GetNthExperiment(x).GetBucket());
from.x = sl.GetNthExperiment(x).GetStartX();
from.y = sl.GetNthExperiment(x).GetStartY();
to.x = sl.GetNthExperiment(x).GetGoalX();
to.y = sl.GetNthExperiment(x).GetGoalY();
Timer t;
t.StartTimer();
pea.GetPath(&ma, from, to, thePath);
t.EndTimer();
printf("pea\t%ld\t%1.6f\t%llu\t%u", thePath.size(), t.GetElapsedTime(), pea.GetNodesExpanded(), pea.GetNumOpenItems());
t.StartTimer();
astar.GetPath(&ma, from, to, thePath);
t.EndTimer();
printf("\tastar\t%ld\t%1.6f\t%llu\t%u\n", thePath.size(), t.GetElapsedTime(), astar.GetNodesExpanded(), astar.GetNumOpenItems());
}
exit(0);
}
示例7: BFS
void BFS()
{
Timer t;
t.StartTimer();
ClearFiles();
RubiksCube c;
RubiksState s;
//uint64_t start1 = strtoll(argv[0], 0, 10);
GetInstanceFromStdin(s);
//GetSuperFlip(s);
hash128 start;
start.parent = 20;
start.edgeHash = c.GetEdgeHash(s);
start.cornerHash = c.GetCornerHash(s);
std::vector<hash128> states;
states.push_back(start);
WriteStatesToDisk(states, 0);
// write goal to disk
s.Reset();
start.parent = 20;
start.edgeHash = c.GetEdgeHash(s);
start.cornerHash = c.GetCornerHash(s);
states.clear();
states.push_back(start);
WriteStatesToDisk(states, 1);
int depth = 2;
bool done = false;
while (!done)
{
Timer t2, t3;
t2.StartTimer();
t3.StartTimer();
printf("***Starting layer: %d\n", depth); fflush(stdout);
ExpandLayer(depth-2);
printf("%1.2fs expanding\n", t2.EndTimer()); fflush(stdout);
t2.StartTimer();
done = DuplicateDetectLayer(depth);
printf("%1.2fs dd\n", t2.EndTimer());
printf("%1.2fs total elapsed at depth %d\n", t3.EndTimer(), depth); fflush(stdout);
depth++;
}
printf("%1.2fs elapsed; found solution at depth %d (cost %d)\n", t.EndTimer(), depth-1, depth-2); fflush(stdout);
}
示例8: RunExperiments1
// 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);
}
示例9: main
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 &&
//.........这里部分代码省略.........
示例10: runProblemSet
void runProblemSet(char *problems, int multiplier)
{
Map *map = new Map(gDefaultMap);
map->Scale(512, 512);
msa = new MapSectorAbstraction(map, 8, multiplier);
Graph *g = msa->GetAbstractGraph(1);
GraphAbstractionHeuristic gah2(msa, 2);
GraphAbstractionHeuristic gah1(msa, 1);
GraphRefinementEnvironment env2(msa, 2, &gah2);
GraphRefinementEnvironment env1(msa, 1, &gah1);
env1.SetDirected(false);
env2.SetDirected(false);
FILE *f = fopen(problems, "r");
if (f == 0)
{
printf("Cannot open file: '%s'\n", problems);
exit(0);
}
printf("len\tlvl2n\tlvl2nt\tlvl2len\tlvl2tim\tlvl1nf\tlvl1ntf\tlvl1tn\tlvl1tt\tlvl1len_f\ttot\ttott\ttot_len\n");
Timer t;
while (!feof(f))
{
int from, to, cost;
if (fscanf(f, "%d\t%d\t%d\n", &from, &to, &cost) != 3)
break;
node *s1 = g->GetNode(from);
node *g1 = g->GetNode(to);
node *s2 = msa->GetParent(s1);
node *g2 = msa->GetParent(g1);
uint64_t nodesExpanded = 0;
uint64_t nodesTouched = 0;
double totalTime = 0;
// printf("Searching from %d to %d in level 1; %d to %d in level 2\n",
// s1->GetNum(), g1->GetNum(), s2->GetNum(), g2->GetNum());
graphState gs1, gs2;
gs1 = s2->GetNum();
gs2 = g2->GetNum();
std::vector<graphState> thePath;
std::vector<graphState> abstractPath;
t.StartTimer();
astar.GetPath(&env2, gs1, gs2, abstractPath);
totalTime = t.EndTimer();
printf("%d\t", cost);
printf("%llu\t%llu\t%1.2f\t%f\t", astar.GetNodesExpanded(), astar.GetNodesTouched(), env2.GetPathLength(abstractPath), totalTime);
if (abstractPath.size() == 0)
{
printf("%llu\t%llu\t%llu\t%llu\t%1.2f\t%f\t", (uint64_t)0, (uint64_t)0, astar.GetNodesExpanded(), astar.GetNodesTouched(), 0.0, 0.0);
printf("%llu\t%llu\t%1.2f\t%f\t%d\t%d\n", astar.GetNodesExpanded(), astar.GetNodesTouched(), 0.0, 0.0, 0, 0);
// printf("\n");
continue;
}
nodesExpanded += astar.GetNodesExpanded();
nodesTouched += astar.GetNodesTouched();
env1.SetPlanningCorridor(abstractPath, 2);
gs1 = s1->GetNum();
gs2 = g1->GetNum();
t.StartTimer();
astar.GetPath(&env1, gs1, gs2, thePath);
t.EndTimer();
printf("%llu\t%llu\t%llu\t%llu\t%1.2f\t%f\t",
astar.GetNodesExpanded(), astar.GetNodesTouched(),
astar.GetNodesExpanded()+nodesExpanded, astar.GetNodesTouched()+nodesTouched,
env1.GetPathLength(thePath), totalTime+t.GetElapsedTime());
int abstractStart = 0;
gs1 = s1->GetNum();
double totalLength = 0;
int refineAmt = 2;
int refinedPathNodes = 0;
do { // not working yet -- fully check!
env1.SetPlanningCorridor(abstractPath, 2, abstractStart);
gs2 = g1->GetNum();
if (abstractPath.size()-abstractStart > refineAmt)
{
env1.SetUseAbstractGoal(true, 2);
gs2 = abstractPath[abstractStart+refineAmt];
}
else {
env1.SetUseAbstractGoal(false, 0);
}
t.StartTimer();
astar.GetPath(&env1, gs1, gs2, thePath);
t.EndTimer();
refinedPathNodes += thePath.size();
totalTime+=t.GetElapsedTime();
abstractStart += refineAmt;
gs1 = thePath.back();
nodesExpanded += astar.GetNodesExpanded();
nodesTouched += astar.GetNodesTouched();
totalLength += env1.GetPathLength(thePath);
if (thePath.back() == gs2)
break;
} while (thePath.back() != g1->GetNum());
//.........这里部分代码省略.........
示例11: TSTest
void TSTest(unsigned long , tKeyboardModifier , char)
{
int N = 16, k = 4;
std::vector<int> tiles;
TopSpin tse(N, k);
TopSpinState s(N, k);
TopSpinState g(N, k);
// if (ts->PDB.size() == 0)
// {
// tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_0-5.pdb", g, true);
// tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_12-15.pdb", g, true);
// tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_6-11.pdb", g, true);
// tse.lookups.push_back({kMaxNode, 3, 1, 0});
// tse.lookups.push_back({kLeafNode, 0, 0, 0});
// tse.lookups.push_back({kLeafNode, 0, 0, 1});
// tse.lookups.push_back({kLeafNode, 0, 0, 2});
// }
if (ts->PDB.size() == 0)
{
tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_0-3.pdb", g, true);
tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_0-5+.pdb", g, true);
tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_6-9.pdb", g, true);
tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_6-11+.pdb", g, true);
tse.Load_Regular_PDB("/Users/nathanst/Desktop/TS_12-15.pdb", g, true);
tse.lookups.push_back({kMaxNode, 3, 1, 0});
tse.lookups.push_back({kAddNode, 2, 4, 0});
tse.lookups.push_back({kAddNode, 2, 6, 0});
tse.lookups.push_back({kLeafNode, 0, 0, 4});
tse.lookups.push_back({kLeafNode, 0, 0, 0});
tse.lookups.push_back({kLeafNode, 0, 0, 1});
tse.lookups.push_back({kLeafNode, 0, 0, 2});
tse.lookups.push_back({kLeafNode, 0, 0, 3});
}
IDAStar<TopSpinState, TopSpinAction> ida;
std::vector<TopSpinAction> path1;
tse.SetPruneSuccessors(true);
for (int x = 0; x < 100; x++)
{
GetTSInstance(tse, s, x);
std::cout << "Problem " << x << std::endl;
std::cout << "Searching from: " << std::endl << s << std::endl << g << std::endl;
Timer t;
t.StartTimer();
ida.GetPath(&tse, s, g, path1);
t.EndTimer();
std::cout << "Path found, length " << path1.size() << " time:" << t.GetElapsedTime() << " ";
std::cout << ida.GetNodesExpanded() << " nodes expanded" << std::endl;
// for (int x = 0; x < ts->histogram.size(); x++)
// {
// printf("%2d %d\n", x, ts->histogram[x]);
// }
// tse.PrintHStats();
}
}
示例12: RunExperiments2
// 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);
}
示例13: MyPathfindingKeyHandler
void MyPathfindingKeyHandler(unsigned long windowID, tKeyboardModifier , char)
{
std::vector<graphState> thePath;
Directional2DEnvironment *env = unitSims[windowID]->GetEnvironment();
Map *m = env->GetMap();
Graph *g = GraphSearchConstants::GetGraph(m);
// GraphDistanceHeuristic diffHeuristic(g);
// diffHeuristic.SetPlacement(kAvoidPlacement);
// for (int x = 0; x < 20; x++)
// diffHeuristic.AddHeuristic();
GraphMapInconsistentHeuristic diffHeuristic(m, g);
diffHeuristic.SetPlacement(kAvoidPlacement);
for (int x = 0; x < 20; x++)
diffHeuristic.AddHeuristic();
GraphEnvironment gEnv(g, &diffHeuristic);
gEnv.SetDirected(true);
diffHeuristic.SetMode(kRandom);
diffHeuristic.SetNumUsedHeuristics(2);
TemplateAStar<graphState, graphMove, GraphEnvironment> taNew;
TemplateAStar<graphState, graphMove, GraphEnvironment> taOld;
Timer t;
for (int x = 0; x < 500; x++)
{
graphState s1, g1;
do {
s1 = g->GetRandomNode()->GetNum();
g1 = g->GetRandomNode()->GetNum();
} while (gEnv.HCost(s1, g1) < 100);
double firstLength;
taNew.SetUseBPMX(false);
t.StartTimer();
taNew.GetPath(&gEnv, s1, g1, thePath);
t.EndTimer();
printf("old: %lld nodes expanded. Path length %d / %f. Time: %f\nrate0: %lld %f\n",
taNew.GetNodesExpanded(), (int)thePath.size(), gEnv.GetPathLength(thePath), t.GetElapsedTime(),
taNew.GetNodesExpanded(), taNew.GetNodesExpanded()/t.GetElapsedTime());
firstLength = gEnv.GetPathLength(thePath);
for (int y = 1; y < 5; y++)
{
taNew.SetUseBPMX(y);
t.StartTimer();
taNew.GetPath(&gEnv, s1, g1, thePath);
t.EndTimer();
printf("new: %lld nodes expanded. Path length %d / %f. Time: %f\nrate%d: %lld %f\n",
taNew.GetNodesExpanded(), (int)thePath.size(), gEnv.GetPathLength(thePath), t.GetElapsedTime(),
y, taNew.GetNodesExpanded(), taNew.GetNodesExpanded()/t.GetElapsedTime());
if (gEnv.GetPathLength(thePath) != firstLength)
printf("\n\n\n!!!!!!!!!!!!!!!!!! IT FAILED!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n\n");
}
printf("--\n");
}
delete g;
}
示例14: DuplicateDetectLayer
bool DuplicateDetectLayer(int depth)
{
const int bufferSize = 128;
double m0Dups = 0;
double m2Dups = 0;
double m4Dups = 0;
double fDups = 0;
double writeTime = 0;
std::vector<uint64_t> values;
values.resize(bufferSize);
Timer t;
uint64_t count = 0;
bool dups = false;
std::unordered_map<uint64_t, uint8_t> map;
uint64_t removed0 = 0, removed2 = 0;
for (int x = 0; x < kNumBuckets; x++)
{
t.StartTimer();
FILE *f = fopen(GetFileName(depth, x), "r");
if (f == 0)
continue;
map.clear();
count = 0;
uint64_t numRead;
while ((numRead = fread(&values[0], sizeof(uint64_t), bufferSize, f)) > 0)
{
for (int x = 0; x < numRead; x++)
map[values[x]>>5] = values[x]&0x1F;
count++;
}
fclose(f);
m0Dups += t.EndTimer();
//printf("Read %llu states from depth %d bucket %d [%s]\n", count, depth, x, GetFileName(depth, x));
t.StartTimer();
f = fopen(GetFileName(depth-2, x), "r");
if (f != 0)
{
while ((numRead = fread(&values[0], sizeof(uint64_t), bufferSize, f)) > 0)
{
for (int x = 0; x < numRead; x++)
{
//printf("Looking for duplicate %d %llu\n", x, next);
auto loc = map.find(values[x]>>5);
if (loc != map.end())
{
//printf("Removing duplicate %d %llu\n", x, loc->first);
removed0++;
map.erase(loc);
}
}
}
fclose(f);
}
m2Dups += t.EndTimer();
t.StartTimer();
f = fopen(GetFileName(depth-4, x), "r");
if (f != 0)
{
while ((numRead = fread(&values[0], sizeof(uint64_t), bufferSize, f)) > 0)
{
for (int x = 0; x < numRead; x++)
{
auto loc = map.find(values[x]>>5);
if (loc != map.end())
{
removed2++;
map.erase(loc);
}
}
}
fclose(f);
}
m4Dups += t.EndTimer();
t.StartTimer();
f = fopen(GetFileName(depth-1, x), "r");
if (f != 0)
{
while ((numRead = fread(&values[0], sizeof(uint64_t), bufferSize, f)) > 0)
{
for (int x = 0; x < numRead; x++)
{
auto loc = map.find(values[x]>>5);
if (loc != map.end())
{
//printf("Found duplicate!\n");
dups = true;
}
}
}
fclose(f);
}
fDups += t.EndTimer();
t.StartTimer();
count = 0;
//.........这里部分代码省略.........
示例15: RunExperiments4
// 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);
}