changed Shape to Polycube
This commit is contained in:
10
julia/ImmutableOrientedPolyCube.jl
Normal file
10
julia/ImmutableOrientedPolyCube.jl
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using XXhash
|
||||||
|
|
||||||
|
struct ImmutableOrientedPolycube
|
||||||
|
cubes::Vector{Tuple{Int64, Int64, Int64}}
|
||||||
|
hash::UInt
|
||||||
|
end
|
||||||
|
|
||||||
|
function getImmutableOrientedPolycube(S::Polycube)
|
||||||
|
shape = ImmutableOrientedPolycube(S.orderedLists[1], hashList(S.orderedLists[1]))
|
||||||
|
end
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using XXhash
|
|
||||||
|
|
||||||
struct ImmutableOrientedShape
|
|
||||||
cubes::Vector{Tuple{Int64, Int64, Int64}}
|
|
||||||
hash::UInt
|
|
||||||
end
|
|
||||||
|
|
||||||
function getImmutableOrientedShape(S::Shape)
|
|
||||||
shape = ImmutableOrientedShape(S.orderedLists[1], hashList(S.orderedLists[1]))
|
|
||||||
end
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
include("Rotations.jl")
|
include("Rotations.jl")
|
||||||
|
|
||||||
struct Shape
|
struct Polycube
|
||||||
cubes::Set{Tuple{Int64, Int64, Int64}}
|
cubes::Set{Tuple{Int64, Int64, Int64}}
|
||||||
recentCubes::Set{Tuple{Int64, Int64, Int64}}
|
recentCubes::Set{Tuple{Int64, Int64, Int64}}
|
||||||
orderedLists::Vector{Vector{Tuple{Int64, Int64, Int64}}}
|
orderedLists::Vector{Vector{Tuple{Int64, Int64, Int64}}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.:push!(S::Shape, t::Tuple{Int64, Int64, Int64})
|
function Base.:push!(S::Polycube, t::Tuple{Int64, Int64, Int64})
|
||||||
push!(S.cubes, t)
|
push!(S.cubes, t)
|
||||||
for i ∈ 1:24
|
for i ∈ 1:24
|
||||||
t_rot = Rotations[i](t)
|
t_rot = Rotations[i](t)
|
||||||
@@ -15,7 +15,7 @@ function Base.:push!(S::Shape, t::Tuple{Int64, Int64, Int64})
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function getPossibleNeighbors(S::Shape)
|
function getPossibleNeighbors(S::Polycube)
|
||||||
possibleSpots = Set{Tuple{Int64, Int64, Int64}}()
|
possibleSpots = Set{Tuple{Int64, Int64, Int64}}()
|
||||||
for p ∈ S.cubes
|
for p ∈ S.cubes
|
||||||
push!(possibleSpots,
|
push!(possibleSpots,
|
||||||
@@ -32,7 +32,7 @@ function getPossibleNeighbors(S::Shape)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function getCube()
|
function getCube()
|
||||||
return Shape(
|
return Polycube(
|
||||||
Set([(0, 0, 0)]),
|
Set([(0, 0, 0)]),
|
||||||
Set([(0, 0, 0)]),
|
Set([(0, 0, 0)]),
|
||||||
[
|
[
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
include("Shape.jl")
|
include("Polycube.jl")
|
||||||
include("ImmutableOrientedShape.jl")
|
include("ImmutableOrientedPolycube.jl")
|
||||||
include("TupleMisc.jl")
|
include("TupleMisc.jl")
|
||||||
include("plot.jl")
|
include("plot.jl")
|
||||||
using XXhash
|
using XXhash
|
||||||
@@ -14,13 +14,13 @@ function main()
|
|||||||
help = "generator"
|
help = "generator"
|
||||||
arg_type = Int
|
arg_type = Int
|
||||||
"-c"
|
"-c"
|
||||||
help = "shape count"
|
help = "Polycube count"
|
||||||
action = :store_true
|
action = :store_true
|
||||||
"-l"
|
"-l"
|
||||||
help = "shape list"
|
help = "Polycube list"
|
||||||
action = :store_true
|
action = :store_true
|
||||||
"-p"
|
"-p"
|
||||||
help = "plot n_cubes i_shape"
|
help = "plot n_cubes i_Polycube"
|
||||||
nargs = '+'
|
nargs = '+'
|
||||||
arg_type = Int
|
arg_type = Int
|
||||||
end
|
end
|
||||||
@@ -29,34 +29,34 @@ function main()
|
|||||||
|
|
||||||
generate = get(parsed_args, "g", nothing)
|
generate = get(parsed_args, "g", nothing)
|
||||||
if generate !== nothing && generate > 0
|
if generate !== nothing && generate > 0
|
||||||
scanForShapes(generate)
|
scanForPolycubes(generate)
|
||||||
end
|
end
|
||||||
if get(parsed_args, "c", false)
|
if get(parsed_args, "c", false)
|
||||||
countShapes()
|
countPolycubes()
|
||||||
end
|
end
|
||||||
if get(parsed_args, "l", false)
|
if get(parsed_args, "l", false)
|
||||||
listShapes()
|
listPolycubes()
|
||||||
end
|
end
|
||||||
plot = get(parsed_args, "p", nothing)
|
plot = get(parsed_args, "p", nothing)
|
||||||
if length(plot) == 1
|
if length(plot) == 1
|
||||||
plotShapes(plot)
|
plotPolycubes(plot)
|
||||||
elseif length(plot) == 2
|
elseif length(plot) == 2
|
||||||
plotShape(plot)
|
plotPolycube(plot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function options()
|
function options()
|
||||||
println("scanForShapes(Int::n): scans for shapes of size <=n")
|
println("scanForPolycubes(Int::n): scans for Polycubes of size <=n")
|
||||||
println("countShapes(): opens shape storage and displays the amount of shapes for the generated sizes")
|
println("countPolycubes(): opens Polycube storage and displays the amount of Polycubes for the generated sizes")
|
||||||
println("listshapes(): lists all shapes from the shape storage")
|
println("listPolycubes(): lists all Polycubes from the Polycube storage")
|
||||||
println("plot(Vector{Int}::v): plots shapes of size v[1], or just v[2] from the list")
|
println("plot(Vector{Int}::v): plots Polycubes of size v[1], or just v[2] from the list")
|
||||||
end
|
end
|
||||||
|
|
||||||
function scanForShapes(MaxSize::Int64)
|
function scanForPolycubes(MaxSize::Int64)
|
||||||
D = Dict{UInt, ImmutableOrientedShape}()
|
D = Dict{UInt, ImmutableOrientedPolycube}()
|
||||||
S = Vector{Shape}();
|
S = Vector{Polycube}();
|
||||||
cube = getCube()
|
cube = getCube()
|
||||||
immutableCube = getImmutableOrientedShape(cube)
|
immutableCube = getImmutableOrientedPolycube(cube)
|
||||||
D[immutableCube.hash] = immutableCube
|
D[immutableCube.hash] = immutableCube
|
||||||
push!(S, cube)
|
push!(S, cube)
|
||||||
|
|
||||||
@@ -66,15 +66,15 @@ function scanForShapes(MaxSize::Int64)
|
|||||||
acceptable_growth = MaxSize - length(cube.cubes)
|
acceptable_growth = MaxSize - length(cube.cubes)
|
||||||
possibleGrowth = powerset(growableSpaces, 1, acceptable_growth)
|
possibleGrowth = powerset(growableSpaces, 1, acceptable_growth)
|
||||||
for cubesToAdd ∈ possibleGrowth
|
for cubesToAdd ∈ possibleGrowth
|
||||||
newShape = deepcopy(cube)
|
newPolycube = deepcopy(cube)
|
||||||
for c ∈ cubesToAdd
|
for c ∈ cubesToAdd
|
||||||
push!(newShape, c)
|
push!(newPolycube, c)
|
||||||
end
|
end
|
||||||
collision = checkForCollision(newShape, D)
|
collision = checkForCollision(newPolycube, D)
|
||||||
if !collision
|
if !collision
|
||||||
push!(S, newShape)
|
push!(S, newPolycube)
|
||||||
immutableNewShape = getImmutableOrientedShape(newShape)
|
immutableNewPolycube = getImmutableOrientedPolycube(newPolycube)
|
||||||
D[immutableNewShape.hash] = immutableNewShape
|
D[immutableNewPolycube.hash] = immutableNewPolycube
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,34 +82,34 @@ function scanForShapes(MaxSize::Int64)
|
|||||||
serialize("julia/results.bin", sanitizedData)
|
serialize("julia/results.bin", sanitizedData)
|
||||||
end
|
end
|
||||||
|
|
||||||
function scanForShapesRec(MaxSize::Int64)
|
function scanForPolycubesRec(MaxSize::Int64)
|
||||||
D = Dict{UInt, ImmutableOrientedShape}()
|
D = Dict{UInt, ImmutableOrientedPolycube}()
|
||||||
singletonCube = getCube()
|
singletonCube = getCube()
|
||||||
immutableCube = getImmutableOrientedShape(singletonCube)
|
immutableCube = getImmutableOrientedPolycube(singletonCube)
|
||||||
D[immutableCube.hash] = immutableCube
|
D[immutableCube.hash] = immutableCube
|
||||||
evaluateShape(singletonCube, D, MaxSize)
|
evaluatePolycube(singletonCube, D, MaxSize)
|
||||||
end
|
end
|
||||||
|
|
||||||
function evaluateShape(shape::Shape, D::Dict{UInt, ImmutableOrientedShape}, MaxSize::Int64)
|
function evaluatePolycube(polycube::Polycube, D::Dict{UInt, ImmutableOrientedPolycube}, MaxSize::Int64)
|
||||||
growableSpaces = collect(getPossibleNeighbors(shape))
|
growableSpaces = collect(getPossibleNeighbors(polycube))
|
||||||
acceptable_growth = MaxSize - length(shape.cubes)
|
acceptable_growth = MaxSize - length(polycube.cubes)
|
||||||
|
|
||||||
possibleGrowth = powerset(growableSpaces, 1, acceptable_growth)
|
possibleGrowth = powerset(growableSpaces, 1, acceptable_growth)
|
||||||
for cubesToAdd ∈ possibleGrowth
|
for cubesToAdd ∈ possibleGrowth
|
||||||
newShape = deepcopy(shape)
|
newPolycube = deepcopy(polycube)
|
||||||
for c ∈ cubesToAdd
|
for c ∈ cubesToAdd
|
||||||
push!(newShape, c)
|
push!(newPolycube, c)
|
||||||
end
|
end
|
||||||
collision = checkForCollision(newShape, D)
|
collision = checkForCollision(newPolycube, D)
|
||||||
if !collision
|
if !collision
|
||||||
immutableNewShape = getImmutableOrientedShape(newShape)
|
immutableNewPolycube = getImmutableOrientedPolycube(newPolycube)
|
||||||
D[immutableNewShape.hash] = immutableNewShape
|
D[immutableNewPolycube.hash] = immutableNewPolycube
|
||||||
evaluateShape(newShape, D, MaxSize)
|
evaluatePolycube(newPolycube, D, MaxSize)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function countShapes()
|
function countPolycubes()
|
||||||
T = deserialize("julia/results.bin")
|
T = deserialize("julia/results.bin")
|
||||||
n = T[1]
|
n = T[1]
|
||||||
for i ∈ 1:n
|
for i ∈ 1:n
|
||||||
@@ -120,7 +120,7 @@ function countShapes()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function listShapes()
|
function listPolycubes()
|
||||||
T = deserialize("julia/results.bin")
|
T = deserialize("julia/results.bin")
|
||||||
print("max size: ")
|
print("max size: ")
|
||||||
println(T[1])
|
println(T[1])
|
||||||
@@ -131,7 +131,7 @@ function listShapes()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function checkForCollision(S::Shape, D::Dict{UInt, ImmutableOrientedShape})
|
function checkForCollision(S::Polycube, D::Dict{UInt, ImmutableOrientedPolycube})
|
||||||
for i ∈ 1:24
|
for i ∈ 1:24
|
||||||
hash = hashList(S.orderedLists[i])
|
hash = hashList(S.orderedLists[i])
|
||||||
value = get(D, hash, nothing)
|
value = get(D, hash, nothing)
|
||||||
@@ -150,7 +150,7 @@ function hashList(L::Vector{Tuple{Int64, Int64, Int64}})
|
|||||||
return xxh3_64(diffList)
|
return xxh3_64(diffList)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sanitize(D::Dict{UInt, ImmutableOrientedShape}, size::Int64)
|
function sanitize(D::Dict{UInt, ImmutableOrientedPolycube}, size::Int64)
|
||||||
data = Vector{Vector{Vector{Tuple{Int64, Int64, Int64}}}}(undef, size)
|
data = Vector{Vector{Vector{Tuple{Int64, Int64, Int64}}}}(undef, size)
|
||||||
for i ∈ eachindex(data)
|
for i ∈ eachindex(data)
|
||||||
data[i] = Vector{Vector{Tuple{Int64, Int64, Int64}}}(undef, 0)
|
data[i] = Vector{Vector{Tuple{Int64, Int64, Int64}}}(undef, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user