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 = 1
15 local mapDensity = 0.1
17 local seed = os.time()
19 print (string.format("Running with seed %d", seed))
21 print (string.format("Building a map of %dx%dx%d...", mapsize, mapsize, mapsize))
27 map[x][y][z] = math.random()
32 -- precalculate a bunch of start and goal positions
33 -- doubled up for each start/goal pair
35 print (string.format("Precalculating %d random start/goal positions...", numberOfTests * 2))
36 local testPoints = { }
37 for i = 1, numberOfTests * 2 do
38 table.insert (testPoints, { x = math.random(1, mapsize), y = math.random(1, mapsize), z = math.random(1, mapsize)})
41 print (string.format("Finding %d paths...", numberOfTests))
42 function positionIsOpenFunc(x, y, z)
43 return map[x][y][z] > mapDensity
45 local testStart = os.clock()
46 for testNumber = 1, numberOfTests do
48 mapsize, mapsize, mapsize, -- map size
49 table.remove (testPoints), -- start
50 table.remove (testPoints), -- goal
53 local testEnd = os.clock()
54 local totalSec = testEnd - testStart
55 local pathSec = totalSec / numberOfTests
57 print (string.format([[
59 That is %.4f seconds, or %d milliseconds, per path.
60 The map has %.1f million locations, with about %d%% open space.]],
61 totalSec, -- total seconds
62 pathSec, -- seconds per path
63 pathSec*1000, -- milliseconds per path
64 (mapsize*mapsize*mapsize)/1000000, -- number of locations
65 mapDensity*100 -- % open space on the map