Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ZDD/jl_zdd/node_auxillaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function readable(arr::Vector{UInt8})::Array{Int64, 1}
Array{Int, 1}([Int64(x) for x in arr])
end

function readable(arr::Vector{UInt32})::Array{Int64, 1}
Array{Int, 1}([Int64(x) for x in arr])
end

function readable(cc::UInt8)::Int64
Int64(cc)
end
Expand Down
93 changes: 93 additions & 0 deletions ZDD/jl_zdd/old_two_way_zdd.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
include("zdd.jl")

function all_vertices_connected_to(v, node)
representative_vertex = node.comp_assign[v]
return Set(findall(==(representative_vertex), node.comp_assign))
end

function setup(fnode, bnode, frontier)
fcomp, bcomp, intcomp = Dict(), Dict(), Dict() # add type annotations
ffrontier, bfrontier, frontier_span = Dict(), Dict(), Dict() # add type annotations
isolated_frontier_vtxs = Set()

for v ∈ frontier
fcomp[v] = all_vertices_connected_to(v, fnode)
bcomp[v] = all_vertices_connected_to(v, bnode)
intcomp[v] = intersect(fcomp[v],bcomp[v])

ffrontier[v] = intersect(fcomp[v], frontier)
bfrontier[v] = intersect(bcomp[v], frontier)
frontier_span[v] = union(ffrontier[v], bfrontier[v])

push!(isolated_frontier_vtxs, maximum(frontier_span[v]))
end
return fcomp, bcomp, intcomp, isolated_frontier_vtxs
end

function check_weights(fcomp, bcomp, intcomp, frontier, acceptable, w)
for v ∈ frontier
if !(w(fcomp[v]) + w(bcomp[v]) - w(intcomp[v]) ∈ acceptable)
return false
end
end
return true
end

function check_fps(fnode, bnode, fcomp, bcomp, intcomp, frontier)
for v ∈ frontier
for x ∈ fcomp[v]
for y ∈ bcomp[v]
if (x,y) ∈ union(fnode.fps, bnode.fps)
return false
end
end
end
end
return true
end

function check_cc(fnode, bnode, k, isolated_frontier_vtxs)
if fnode.cc + bnode.cc + length(isolated_frontier_vtxs) == k
return true
end
return false
end

function is_compatible(fnode, bnode, frontier, acceptable, w, k, checking)
fcomp, bcomp, intcomp, isolated_frontier_vtxs = setup(fnode, bnode, frontier)
weights = check_weights(fcomp, bcomp, intcomp, frontier, acceptable, w)
fps = check_fps(fnode, bnode, fcomp, bcomp, intcomp, frontier)
cc = check_cc(fnode, bnode, k, isolated_frontier_vtxs)

checklist = []
if "weights" ∈ checking
push!(checklist, weights)
end
if "fps" ∈ checking
push!(checklist, fps)
end
if "cc" ∈ checking
push!(checklist, cc)
end
if all(checklist)
return true
end
return false
end

function w(v)
return 1
end

function number_compatible(fnodes, bnodes, frontier, acceptable, w, k, checking)
println("Total # of node pairs: $(length(fnodes)) * $(length(bnodes)) = $(length(fnodes) * length(bnodes))")
num_partitions = 0
for fnode ∈ fnodes
for bnode ∈ bnodes
if is_compatible(fnode, bnode, frontier, acceptable, w, k, checking)
num_partitions += 1
end
end
end
return num_partitions
end
55 changes: 55 additions & 0 deletions ZDD/jl_zdd/two_way_algo_notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
1-2-3

4-5 6
|
7 8 9

1 2 3
|
4 5 6

7-8-9

f: {3}, {5,7}
b: {3}, {5}, {7}
--> {3}, {5,7}

----
{3,5,7}


f: {1,2} {3} {4,5,6}
b: {1,4} {2,3}, {5,6}

d = {1:2, 2:2, 3:3, 4:6, 5:6, 6:6} # start with the forwards dictionary
weights = {}
for each bset in b:
find: find the 1 group, find the 4 group.
union those groups into U
add weights of 1group to 4group + weight of bset - intersection (which is the sum of weights of vertices in bset)
and find the max: max(d[u] for u in U)
relabel: d[u] = max for u in U
d = {1:6, 2:6, 3:3, 4:6, 5:6, 6:6} # after one iteration
d = {1:6, 2:6, 3:6, 4:6, 5:6, 6:6} # after second iteration

{{1,2,3,4,5,6}}

Union-Find:
{1,2} {1,4} -> 4
{3} -> 3
{2,3} -> 4 which changes 3
{4,5,6} -> 6 which changes 1-4
{5,6} = 6



--- (answer is {1,2,3,4,5,6})
{1,2,4,3}
{3,2}
{4,5,6,1}
--> {1,2,3,4,5,6}





Loading