diff --git a/src/networks/Coloring.jl b/src/networks/Coloring.jl index 09f180c6..24dd3850 100644 --- a/src/networks/Coloring.jl +++ b/src/networks/Coloring.jl @@ -31,7 +31,7 @@ function Coloring{K}(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedv rawcode = EinCode(([[i] for i in Graphs.vertices(g)]..., # labels for vertex tensors [[minmax(e.src,e.dst)...] for e in Graphs.edges(g)]...), collect(Int, openvertices)) # labels for edge tensors code = _optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier) - Coloring{K}(code, g, weights, fixedvertices) + Coloring{K}(code, g, weights, Dict{Int,Int}(fixedvertices)) end flavors(::Type{<:Coloring{K}}) where K = collect(0:K-1) @@ -69,4 +69,4 @@ function is_vertex_coloring(graph::SimpleGraph, config) config[e.src] == config[e.dst] && return false end return true -end \ No newline at end of file +end diff --git a/src/networks/DominatingSet.jl b/src/networks/DominatingSet.jl index f234e9f8..fd89ea6d 100644 --- a/src/networks/DominatingSet.jl +++ b/src/networks/DominatingSet.jl @@ -28,7 +28,7 @@ end function DominatingSet(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing) @assert weights isa NoWeight || length(weights) == nv(g) rawcode = EinCode(([[Graphs.neighbors(g, v)..., v] for v in Graphs.vertices(g)]...,), collect(Int, openvertices)) - DominatingSet(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices) + DominatingSet(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices)) end flavors(::Type{<:DominatingSet}) = [0, 1] diff --git a/src/networks/IndependentSet.jl b/src/networks/IndependentSet.jl index 5e6112c3..a8b6c251 100644 --- a/src/networks/IndependentSet.jl +++ b/src/networks/IndependentSet.jl @@ -42,7 +42,7 @@ function IndependentSet(g::SimpleGraph; weights=NoWeight(), openvertices=(), fix rawcode = EinCode([[[i] for i in Graphs.vertices(g)]..., # labels for vertex tensors [[minmax(e.src,e.dst)...] for e in Graphs.edges(g)]...], collect(Int, openvertices)) # labels for edge tensors code = _optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier) - IndependentSet(code, g, weights, fixedvertices) + IndependentSet(code, g, weights, Dict{Int,Int}(fixedvertices)) end flavors(::Type{<:IndependentSet}) = [0, 1] diff --git a/src/networks/Matching.jl b/src/networks/Matching.jl index 91e653a5..ab71a86b 100644 --- a/src/networks/Matching.jl +++ b/src/networks/Matching.jl @@ -22,16 +22,16 @@ struct Matching{CT<:AbstractEinsum, WT<:Union{NoWeight,Vector}} <: GraphProblem code::CT graph::SimpleGraph{Int} weights::WT - fixedvertices::Dict{Int,Int} + fixedvertices::Dict{Tuple{Int,Int},Int} end -function Matching(g::SimpleGraph; weights=NoWeight(), openvertices=(),fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing) +function Matching(g::SimpleGraph; weights=NoWeight(), openvertices=(),fixedvertices=Dict{Tuple{Int,Int},Int}(), optimizer=GreedyMethod(), simplifier=nothing) @assert weights isa NoWeight || length(weights) == ne(g) edges = [minmax(e.src,e.dst) for e in Graphs.edges(g)] rawcode = EinCode(vcat([[s] for s in edges], # labels for edge tensors [[minmax(i,j) for j in neighbors(g, i)] for i in Graphs.vertices(g)]), collect(Tuple{Int,Int}, openvertices)) - Matching(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices) + Matching(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Tuple{Int,Int},Int}(fixedvertices)) end flavors(::Type{<:Matching}) = [0, 1] diff --git a/src/networks/MaxCut.jl b/src/networks/MaxCut.jl index 8082d282..12be6e39 100644 --- a/src/networks/MaxCut.jl +++ b/src/networks/MaxCut.jl @@ -27,7 +27,7 @@ end function MaxCut(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing) @assert weights isa NoWeight || length(weights) == ne(g) rawcode = EinCode([[minmax(e.src,e.dst)...] for e in Graphs.edges(g)], collect(Int, openvertices)) # labels for edge tensors - MaxCut(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices) + MaxCut(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices)) end flavors(::Type{<:MaxCut}) = [0, 1] diff --git a/src/networks/MaximalIS.jl b/src/networks/MaximalIS.jl index 135532f8..773c7273 100644 --- a/src/networks/MaximalIS.jl +++ b/src/networks/MaximalIS.jl @@ -28,7 +28,7 @@ end function MaximalIS(g::SimpleGraph; weights=NoWeight(), openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{Int,Int}()) @assert weights isa NoWeight || length(weights) == nv(g) rawcode = EinCode(([[Graphs.neighbors(g, v)..., v] for v in Graphs.vertices(g)]...,), collect(Int, openvertices)) - MaximalIS(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices) + MaximalIS(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices)) end flavors(::Type{<:MaximalIS}) = [0, 1] diff --git a/src/networks/PaintShop.jl b/src/networks/PaintShop.jl index f4d58cc5..588176c7 100644 --- a/src/networks/PaintShop.jl +++ b/src/networks/PaintShop.jl @@ -44,7 +44,7 @@ struct PaintShop{CT<:AbstractEinsum,LT} <: GraphProblem fixedvertices::Dict{LT,Int} end -function paintshop_from_pairs(pairs::AbstractVector{Tuple{Int,Int}}; openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{LT,Int}()) +function paintshop_from_pairs(pairs::AbstractVector{Tuple{Int,Int}}; openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict()) n = length(pairs) @assert sort!(vcat(collect.(pairs)...)) == collect(1:2n) sequence = zeros(Int, 2*n) @@ -61,7 +61,7 @@ function PaintShop(sequence::AbstractVector{T}; openvertices=(), fixedvertices=D [[sequence[i], sequence[i+1]] for i=1:n-1], # labels for edge tensors ), collect(T, openvertices)) - PaintShop(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), sequence, isfirst, fixedvertices) + PaintShop(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), sequence, isfirst, Dict{T,Int}(fixedvertices)) end flavors(::Type{<:PaintShop}) = [0, 1] @@ -106,4 +106,4 @@ function paint_shop_coloring_from_config(p::PaintShop{CT,LT}, config) where {CT, return map(1:length(p.sequence)) do i p.isfirst[i] ? d[p.sequence[i]] : ~d[p.sequence[i]] end -end \ No newline at end of file +end diff --git a/src/networks/Satisfiability.jl b/src/networks/Satisfiability.jl index 2da7c914..8f93200f 100644 --- a/src/networks/Satisfiability.jl +++ b/src/networks/Satisfiability.jl @@ -161,7 +161,7 @@ end function Satisfiability(cnf::CNF{T}; weights=NoWeight(), openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{T,Int}()) where T rawcode = EinCode([[getfield.(c.vars, :name)...] for c in cnf.clauses], collect(T, openvertices)) - Satisfiability(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), cnf, weights, fixedvertices) + Satisfiability(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), cnf, weights, Dict{T,Int}(fixedvertices)) end flavors(::Type{<:Satisfiability}) = [0, 1] # false, true diff --git a/src/networks/SetCovering.jl b/src/networks/SetCovering.jl index 620456a0..4214edf4 100644 --- a/src/networks/SetCovering.jl +++ b/src/networks/SetCovering.jl @@ -44,7 +44,7 @@ function SetCovering(sets::AbstractVector{Vector{ET}}; weights=NoWeight(), openv code = EinCode([[[i] for i=1:nsets]..., [count[e] for e in elements]...], collect(Int,openvertices)) - SetCovering(_optimize_code(code, uniformsize_fix(code, 2, fixedvertices), optimizer, simplifier), sets, weights, fixedvertices) + SetCovering(_optimize_code(code, uniformsize_fix(code, 2, fixedvertices), optimizer, simplifier), sets, weights, Dict{ET,Int}(fixedvertices)) end function cover_count(sets) diff --git a/src/networks/SetPacking.jl b/src/networks/SetPacking.jl index aff3fa4f..bf484cf8 100644 --- a/src/networks/SetPacking.jl +++ b/src/networks/SetPacking.jl @@ -40,7 +40,7 @@ function SetPacking(sets::AbstractVector{Vector{ET}}; weights=NoWeight(), openve nsets = length(sets) @assert weights isa NoWeight || length(weights) == nsets code = EinCode(vcat([[i] for i=1:nsets], [[i,j] for i=1:nsets,j=1:nsets if j>i && !isempty(sets[i] ∩ sets[j])]), collect(Int,openvertices)) - SetPacking(_optimize_code(code, uniformsize_fix(code, 2, openvertices), optimizer, simplifier), sets, weights, fixedvertices) + SetPacking(_optimize_code(code, uniformsize_fix(code, 2, openvertices), optimizer, simplifier), sets, weights, Dict{ET,Int}(fixedvertices)) end flavors(::Type{<:SetPacking}) = [0, 1] diff --git a/test/networks/Coloring.jl b/test/networks/Coloring.jl index 4f066fc1..87ab2497 100644 --- a/test/networks/Coloring.jl +++ b/test/networks/Coloring.jl @@ -6,11 +6,11 @@ using Test, GenericTensorNetworks, Graphs add_edge!(g, i, j) end code = Coloring{3}(g; optimizer=GreedyMethod()) - res = best_solutions(code; all=true)[] + res = GenericTensorNetworks.best_solutions(code; all=true)[] @test length(res.c.data) == 12 g = smallgraph(:petersen) code = Coloring{3}(g; optimizer=GreedyMethod()) - res = best_solutions(code; all=true)[] + res = GenericTensorNetworks.best_solutions(code; all=true)[] @test length(res.c.data) == 120 c = solve(code, SingleConfigMax())[] diff --git a/test/networks/Matching.jl b/test/networks/Matching.jl index 48148960..a7bfc937 100644 --- a/test/networks/Matching.jl +++ b/test/networks/Matching.jl @@ -1,11 +1,17 @@ using Test, GenericTensorNetworks, Graphs +using GenericTensorNetworks: solutions @testset "enumerating - matching" begin g = smallgraph(:petersen) - code = Matching(g; optimizer=GreedyMethod()) + code = Matching(g; optimizer=GreedyMethod(), fixedvertices=Dict()) res = solutions(code, CountingTropicalF64; all=true)[] @test res.n == 5 @test length(res.c.data) == 6 + code = Matching(g; optimizer=GreedyMethod(), fixedvertices=Dict((1,2)=>1)) + res = solutions(code, CountingTropicalF64; all=true)[] + @test res.n == 5 + k = findfirst(x->x==(1,2), labels(code)) + @test length(res.c.data) == 2 && res.c.data[1][k] == 1 && res.c.data[2][k] == 1 end @testset "match polynomial" begin diff --git a/test/networks/MaxCut.jl b/test/networks/MaxCut.jl index 7c8c2a36..52d1be25 100644 --- a/test/networks/MaxCut.jl +++ b/test/networks/MaxCut.jl @@ -35,7 +35,7 @@ end add_edge!(g, i, j) end code = MaxCut(g; optimizer=GreedyMethod()) - res = best_solutions(code; all=true)[] + res = GenericTensorNetworks.best_solutions(code; all=true)[] @test length(res.c.data) == 2 @test cut_size(g, res.c.data[1]) == 5 end diff --git a/test/networks/MaximalIS.jl b/test/networks/MaximalIS.jl index fdd908cc..8b9d8387 100644 --- a/test/networks/MaximalIS.jl +++ b/test/networks/MaximalIS.jl @@ -1,4 +1,5 @@ using GenericTensorNetworks, Test, Graphs +using GenericTensorNetworks: graph_polynomial @testset "counting maximal IS" begin g = random_regular_graph(20, 3) diff --git a/test/networks/Satisfiability.jl b/test/networks/Satisfiability.jl index ee32d4be..d3135cbd 100644 --- a/test/networks/Satisfiability.jl +++ b/test/networks/Satisfiability.jl @@ -33,7 +33,7 @@ end gp = Satisfiability(cnf) @test solve(gp, SizeMax())[].n == 4.0 - res = best_solutions(gp; all=true)[].c.data + res = GenericTensorNetworks.best_solutions(gp; all=true)[].c.data for i=0:1<<6-1 v = StaticBitVector(Bool[i>>(k-1) & 1 for k=1:6]) if v ∈ res @@ -54,7 +54,7 @@ end gp = Satisfiability(cnf; weights=fill(2, length(cnf))) @test solve(gp, SizeMax())[].n == 8.0 - res = best_solutions(gp; all=true)[].c.data + res = GenericTensorNetworks.best_solutions(gp; all=true)[].c.data for i=0:1<<6-1 v = StaticBitVector(Bool[i>>(k-1) & 1 for k=1:6]) if v ∈ res diff --git a/test/networks/SetPacking.jl b/test/networks/SetPacking.jl index 65ed2e1b..c0573145 100644 --- a/test/networks/SetPacking.jl +++ b/test/networks/SetPacking.jl @@ -3,7 +3,7 @@ using GenericTensorNetworks, Test, Graphs @testset "set packing" begin sets = [[1, 2, 5], [1, 3], [2, 4], [3, 6], [2, 3, 6]] # each set is a vertex gp = SetPacking(sets; optimizer=GreedyMethod()) - res = best_solutions(gp; all=true)[] + res = GenericTensorNetworks.best_solutions(gp; all=true)[] @test res.n == 2 @test BitVector(Bool[0,0,1,1,0]) ∈ res.c.data @test BitVector(Bool[1,0,0,1,0]) ∈ res.c.data