Skip to content

Commit ec61a4b

Browse files
authored
update (#45)
* update * update * fix tests
1 parent e6d11f3 commit ec61a4b

File tree

16 files changed

+29
-22
lines changed

16 files changed

+29
-22
lines changed

src/networks/Coloring.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Coloring{K}(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedv
3131
rawcode = EinCode(([[i] for i in Graphs.vertices(g)]..., # labels for vertex tensors
3232
[[minmax(e.src,e.dst)...] for e in Graphs.edges(g)]...), collect(Int, openvertices)) # labels for edge tensors
3333
code = _optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier)
34-
Coloring{K}(code, g, weights, fixedvertices)
34+
Coloring{K}(code, g, weights, Dict{Int,Int}(fixedvertices))
3535
end
3636

3737
flavors(::Type{<:Coloring{K}}) where K = collect(0:K-1)
@@ -69,4 +69,4 @@ function is_vertex_coloring(graph::SimpleGraph, config)
6969
config[e.src] == config[e.dst] && return false
7070
end
7171
return true
72-
end
72+
end

src/networks/DominatingSet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
function DominatingSet(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing)
2929
@assert weights isa NoWeight || length(weights) == nv(g)
3030
rawcode = EinCode(([[Graphs.neighbors(g, v)..., v] for v in Graphs.vertices(g)]...,), collect(Int, openvertices))
31-
DominatingSet(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices)
31+
DominatingSet(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices))
3232
end
3333

3434
flavors(::Type{<:DominatingSet}) = [0, 1]

src/networks/IndependentSet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function IndependentSet(g::SimpleGraph; weights=NoWeight(), openvertices=(), fix
4242
rawcode = EinCode([[[i] for i in Graphs.vertices(g)]..., # labels for vertex tensors
4343
[[minmax(e.src,e.dst)...] for e in Graphs.edges(g)]...], collect(Int, openvertices)) # labels for edge tensors
4444
code = _optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier)
45-
IndependentSet(code, g, weights, fixedvertices)
45+
IndependentSet(code, g, weights, Dict{Int,Int}(fixedvertices))
4646
end
4747

4848
flavors(::Type{<:IndependentSet}) = [0, 1]

src/networks/Matching.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ struct Matching{CT<:AbstractEinsum, WT<:Union{NoWeight,Vector}} <: GraphProblem
2222
code::CT
2323
graph::SimpleGraph{Int}
2424
weights::WT
25-
fixedvertices::Dict{Int,Int}
25+
fixedvertices::Dict{Tuple{Int,Int},Int}
2626
end
2727

28-
function Matching(g::SimpleGraph; weights=NoWeight(), openvertices=(),fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing)
28+
function Matching(g::SimpleGraph; weights=NoWeight(), openvertices=(),fixedvertices=Dict{Tuple{Int,Int},Int}(), optimizer=GreedyMethod(), simplifier=nothing)
2929
@assert weights isa NoWeight || length(weights) == ne(g)
3030
edges = [minmax(e.src,e.dst) for e in Graphs.edges(g)]
3131
rawcode = EinCode(vcat([[s] for s in edges], # labels for edge tensors
3232
[[minmax(i,j) for j in neighbors(g, i)] for i in Graphs.vertices(g)]),
3333
collect(Tuple{Int,Int}, openvertices))
34-
Matching(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices)
34+
Matching(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Tuple{Int,Int},Int}(fixedvertices))
3535
end
3636

3737
flavors(::Type{<:Matching}) = [0, 1]

src/networks/MaxCut.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
function MaxCut(g::SimpleGraph; weights=NoWeight(), openvertices=(), fixedvertices=Dict{Int,Int}(), optimizer=GreedyMethod(), simplifier=nothing)
2828
@assert weights isa NoWeight || length(weights) == ne(g)
2929
rawcode = EinCode([[minmax(e.src,e.dst)...] for e in Graphs.edges(g)], collect(Int, openvertices)) # labels for edge tensors
30-
MaxCut(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices)
30+
MaxCut(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices))
3131
end
3232

3333
flavors(::Type{<:MaxCut}) = [0, 1]

src/networks/MaximalIS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
function MaximalIS(g::SimpleGraph; weights=NoWeight(), openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{Int,Int}())
2929
@assert weights isa NoWeight || length(weights) == nv(g)
3030
rawcode = EinCode(([[Graphs.neighbors(g, v)..., v] for v in Graphs.vertices(g)]...,), collect(Int, openvertices))
31-
MaximalIS(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, fixedvertices)
31+
MaximalIS(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), g, weights, Dict{Int,Int}(fixedvertices))
3232
end
3333

3434
flavors(::Type{<:MaximalIS}) = [0, 1]

src/networks/PaintShop.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct PaintShop{CT<:AbstractEinsum,LT} <: GraphProblem
4444
fixedvertices::Dict{LT,Int}
4545
end
4646

47-
function paintshop_from_pairs(pairs::AbstractVector{Tuple{Int,Int}}; openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{LT,Int}())
47+
function paintshop_from_pairs(pairs::AbstractVector{Tuple{Int,Int}}; openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict())
4848
n = length(pairs)
4949
@assert sort!(vcat(collect.(pairs)...)) == collect(1:2n)
5050
sequence = zeros(Int, 2*n)
@@ -61,7 +61,7 @@ function PaintShop(sequence::AbstractVector{T}; openvertices=(), fixedvertices=D
6161
[[sequence[i], sequence[i+1]] for i=1:n-1], # labels for edge tensors
6262
),
6363
collect(T, openvertices))
64-
PaintShop(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), sequence, isfirst, fixedvertices)
64+
PaintShop(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), sequence, isfirst, Dict{T,Int}(fixedvertices))
6565
end
6666

6767
flavors(::Type{<:PaintShop}) = [0, 1]
@@ -106,4 +106,4 @@ function paint_shop_coloring_from_config(p::PaintShop{CT,LT}, config) where {CT,
106106
return map(1:length(p.sequence)) do i
107107
p.isfirst[i] ? d[p.sequence[i]] : ~d[p.sequence[i]]
108108
end
109-
end
109+
end

src/networks/Satisfiability.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ end
161161

162162
function Satisfiability(cnf::CNF{T}; weights=NoWeight(), openvertices=(), optimizer=GreedyMethod(), simplifier=nothing, fixedvertices=Dict{T,Int}()) where T
163163
rawcode = EinCode([[getfield.(c.vars, :name)...] for c in cnf.clauses], collect(T, openvertices))
164-
Satisfiability(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), cnf, weights, fixedvertices)
164+
Satisfiability(_optimize_code(rawcode, uniformsize_fix(rawcode, 2, fixedvertices), optimizer, simplifier), cnf, weights, Dict{T,Int}(fixedvertices))
165165
end
166166

167167
flavors(::Type{<:Satisfiability}) = [0, 1] # false, true

src/networks/SetCovering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function SetCovering(sets::AbstractVector{Vector{ET}}; weights=NoWeight(), openv
4444

4545
code = EinCode([[[i] for i=1:nsets]...,
4646
[count[e] for e in elements]...], collect(Int,openvertices))
47-
SetCovering(_optimize_code(code, uniformsize_fix(code, 2, fixedvertices), optimizer, simplifier), sets, weights, fixedvertices)
47+
SetCovering(_optimize_code(code, uniformsize_fix(code, 2, fixedvertices), optimizer, simplifier), sets, weights, Dict{ET,Int}(fixedvertices))
4848
end
4949

5050
function cover_count(sets)

src/networks/SetPacking.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function SetPacking(sets::AbstractVector{Vector{ET}}; weights=NoWeight(), openve
4040
nsets = length(sets)
4141
@assert weights isa NoWeight || length(weights) == nsets
4242
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))
43-
SetPacking(_optimize_code(code, uniformsize_fix(code, 2, openvertices), optimizer, simplifier), sets, weights, fixedvertices)
43+
SetPacking(_optimize_code(code, uniformsize_fix(code, 2, openvertices), optimizer, simplifier), sets, weights, Dict{ET,Int}(fixedvertices))
4444
end
4545

4646
flavors(::Type{<:SetPacking}) = [0, 1]

0 commit comments

Comments
 (0)