-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/alldifferent #115
Feature/alldifferent #115
Conversation
has an inconsistant behavior been introduced recently in the tsptw.jl test? Because it ran smoothly until I merged the last version of |
This reverts commit 7562f93.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great code!
I would like to discuss the variable and function names, but otherwise it seems good!
- `start::Int`: the free value node to start the search from. | ||
- `free::Vector{Int}`: the list of all the free variables indexes. | ||
""" | ||
function augmentmatching!(digraph::DiGraph{Int}, start::Int, free::Set{Int})::Union{Nothing, Pair{Int, Int}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thing the function names and the variable names should be in camel case.
Example : augmentMatching
""" | ||
function augmentmatching!(digraph::DiGraph{Int}, start::Int, free::Set{Int})::Union{Nothing, Pair{Int, Int}} | ||
parents = bfs_parents(digraph, start; dir=:out) | ||
reached = intersect(free, findall(v -> v > 0, parents)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodes_reached ?
|
||
Compute a random matching in a bipartite graph, between 1:lastfirst and (lastfirst + 1):nv(graph). | ||
""" | ||
function randommatching(graph::Graph{Int}, lastfirst::Int)::Matching{Int} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
randomMatching?
Compute a random matching in a bipartite graph, between 1:lastfirst and (lastfirst + 1):nv(graph). | ||
""" | ||
function randommatching(graph::Graph{Int}, lastfirst::Int)::Matching{Int} | ||
seen = Set{Int}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodesSeen?
(lastfirst + 1):nv(digraph). A variable is assigned to a value if the directed | ||
edge (Var => Val) exists. | ||
""" | ||
function matchingfromdigraph(digraph::DiGraph{Int}, lastfirst::Int)::Matching{Int} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matchingFromDigraph?
the first group. | ||
""" | ||
function maximizematching!(digraph::DiGraph{Int}, lastfirst::Int)::Matching{Int} | ||
currentmatching = matchingfromdigraph(digraph, lastfirst) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentMatching
maximizeMatching
function maximizematching!(digraph::DiGraph{Int}, lastfirst::Int)::Matching{Int} | ||
currentmatching = matchingfromdigraph(digraph, lastfirst) | ||
stop = currentmatching.size == lastfirst | ||
freevar = Set(filter(v -> outdegree(digraph, v) == 0, 1:lastfirst)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use complet name
freeVariables
freeValues
It is longer to write, but clearer to read.
src/CP/constraints/alldifferent.jl
Outdated
|
||
Return the node index of a value. | ||
""" | ||
function val2node(con::AllDifferent, val::Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about the names. i Would use To instead of 2.
src/CP/constraints/alldifferent.jl
Outdated
Return all the edges in a strongly connected component vars ∪ vars. | ||
""" | ||
function getalledges(digraph::DiGraph{Int}, vars::Vector{Int}, vals::Vector{Int})::Set{Edge{Int}} | ||
res = Set{Edge{Int}}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res ?
src/CP/constraints/alldifferent.jl
Outdated
end | ||
end | ||
|
||
allvar = 1:constraint.numberOfVars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
complete name?
This is my proposition for the AllDifferent constraint, relating to the issue #49. It contains:
My implementation uses only
LightGraphs.jl
and no third-party solver.The downside is that I manually implemented the matching algorithm and thus introduced many potential inefficiency sources. I tried to use
LightGraphsMatching.jl
but the BlossomV modules breaks the cross-platform portability as it requires some C++ files.Moreover the matching algorithm code is placed in the same file as the AllDifferent constraint as no dedicated folder exists for backend algorithms currently. But it could be wiser and cleaner to move it to a dedicated part of the architecture if more complex constraints are to be added in the future.
Thus potential improvements are:
One hesitation I had is in the last 2 test: I created a n-queens model to grant a full test of the constraint. But these tests thus rely on many other parts of the code. Is this anti-pattern? Because otherwise it is hard to guarantee the correct behavior of the constraint (for instance, I missed a few solutions in the n-queens at some point, but solving the problem integrally was the only way to detect this bug).