2 Copyright 2018 Wesley Werner <wesley.werner@gmail.com>
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 local luastar = require("lua-star")
14 local numberOfTests = 1000
15 local mapDensity = 0.65
17 local seed = os.time()
19 print (string.format("Running with seed %d", seed))
21 print (string.format("Building a map of %dx%d...", mapsize, mapsize))
25 map[x][y] = math.random()
29 -- precalculate a bunch of start and goal positions
30 -- doubled up for each start/goal pair
32 print (string.format("Precalculating %d random start/goal positions...", mapsize * 2))
33 local testPoints = { }
34 for i = 1, mapsize * 2 do
35 table.insert (testPoints, { x = math.random(1, mapsize), y = math.random(1, mapsize)})
38 print (string.format("Finding %d paths...", numberOfTests))
39 function positionIsOpenFunc(x, y)
40 return map[x][y] > mapDensity
42 local testStart = os.clock()
43 for testNumber = 1, numberOfTests do
45 mapsize, mapsize, -- map size
46 table.remove (testPoints), -- start
47 table.remove (testPoints), -- goal
50 local testEnd = os.clock()
51 local totalSec = testEnd - testStart
52 local pathSec = totalSec / numberOfTests
54 print (string.format([[
56 That is %.4f seconds, or %d milliseconds, per path.
57 The map has %.1f million locations, with about %d%% open space.]],
58 totalSec, -- total seconds
59 pathSec, -- seconds per path
60 pathSec*1000, -- milliseconds per path
61 (mapsize*mapsize)/1000000, -- number of locations
62 mapDensity*100 -- % open space on the map