Skip to content

Commit

Permalink
fix: "evaluate' and Project.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
c-allergic committed Jul 15, 2024
1 parent e1a2474 commit b2afd00
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnitDiskMapping = "1b61a8d9-79ed-4491-8266-ef37f39e1727"

[compat]
Expand Down
6 changes: 3 additions & 3 deletions src/models/Coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ Compute the energy of the vertex coloring configuration `config`, the energy is
"""
function evaluate(c::Coloring, config)
@assert length(config) == nv(c.graph)
coloring_energy(terms(c), config)
coloring_energy(terms(c), c.weights,config)
end

coloring_energy(terms::AbstractVector, config) = sum([config[e[1]] == config[e[2]] for e in terms])

coloring_energy(terms::AbstractVector, weights::AbstractVector, config) = sum([(config[e[1]] == config[e[2]]) * w for (e, w) in zip(terms, weights)])
coloring_energy(terms::AbstractVector,::UnitWeight, config) = sum([(config[e[1]] == config[e[2]]) for e in terms])


"""
Expand Down
3 changes: 2 additions & 1 deletion test/models/Coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ using ProblemReductions: Coloring, SimpleGraph, add_edge!, UnitWeight, variables
@test set_parameters(c, [1, 2, 2, 1]) == Coloring{3}(g, [1, 2, 2, 1])

# evaluate,here I found the definition of Config is not clear, so I can't test the evaluate function
@test evaluate(c, [0, 1, 2, 0]) == 1
@test evaluate(c,[0, 1, 2, 0]) == 1
@test coloring_energy(terms(c),[1, 3, 2, 5],[0, 1, 2, 0]) == 3


end
Expand Down

0 comments on commit b2afd00

Please sign in to comment.