-
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
Maximum Independent Set Generator #234
Conversation
@@ -35,7 +35,7 @@ edge (Var => Val) exists. | |||
function matchingFromDigraph(digraph::DiGraph{Int}, lastfirst::Int)::Matching{Int} | |||
matches = Vector{Pair{Int, Int}}() | |||
for i = 1:lastfirst | |||
nodesPossible = outneighbors(digraph, i) | |||
nodesPossible = LightGraphs.outneighbors(digraph, i) |
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.
Quick question, digraph
is an object of type DiGraph{Int}
which belongs to Graph.jl ? Therefore, isn't there a problem of using LightGraphs functions such as outneighbors
on Graph.jl object ?
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.
Edit : this may be an oversight.
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.
The structure must be identical in both libraries, but in fact it is better to add a LightGraphs.
before DiGraph
.
|
||
# edge constraints | ||
for e in Graphs.edges(graph) | ||
SeaPearl.addConstraint!(cpmodel, SeaPearl.SumLessThan([vars[e.src], vars[e.dst]], 1, cpmodel.trailer)) |
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.
e.src
and e.dst
are the index for the associated source node and destination node ?
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.
Yes that's right, it's the index of the nodes in the graph. Since the variables have been defined in the same order as in the node array of the graph, this also corresponds to the node index in vars
.
|
||
# edge constraints | ||
for e in Graphs.edges(graph) | ||
SeaPearl.addConstraint!(cpmodel, SeaPearl.SumLessThan([vars[e.src], vars[e.dst]], 1, cpmodel.trailer)) |
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.
As long as all constraints SumLessThan have the same fixed upper bound 1
( that can't be currently encoded into our graph representation), the model should have less difficulty to infer a meaningful representation of the constraint, which was one of the main limits that we faced while solving more complex problems.
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.
Indeed, if we ever used SumLessThan
with different bounds, our representation would be unable to represent it. But this is not the case here and therefore it should not be a problem.
function fill_with_generator!(cpmodel::CPModel, gen::MaximumIndependentSetGenerator; rng::AbstractRNG = MersenneTwister()) | ||
graph = Graphs.SimpleGraphs.barabasi_albert(gen.n, gen.k, seed=rand(rng, typemin(Int64):typemax(Int64))) | ||
|
||
# create variables | ||
vars = SeaPearl.IntVar[] | ||
for v in Graphs.vertices(graph) | ||
push!(vars, SeaPearl.IntVar(0, 1, "node_" * string(v), cpmodel.trailer)) | ||
addVariable!(cpmodel, last(vars)) | ||
end | ||
|
||
# edge constraints | ||
for e in Graphs.edges(graph) | ||
SeaPearl.addConstraint!(cpmodel, SeaPearl.SumLessThan([vars[e.src], vars[e.dst]], 1, cpmodel.trailer)) | ||
end | ||
|
||
### Objective ### minimize: -sum(x[i]) | ||
objective = SeaPearl.IntVar(-Graphs.nv(graph), 0, "objective", cpmodel.trailer) | ||
SeaPearl.addVariable!(cpmodel, objective;branchable=false) | ||
push!(vars, objective) | ||
|
||
# sum(x[i]) + objective = 0 <=> objective = -sum(x[i]) | ||
SeaPearl.addConstraint!(cpmodel, SeaPearl.SumToZero(vars, cpmodel.trailer)) | ||
SeaPearl.addObjective!(cpmodel,objective) | ||
|
||
nothing |
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.
Looks good for me.
Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com>
Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com>
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.
This branch is ready to be merged into master
in my opinion!
* Create heterogeneous file * Add check_dimensions for hetereogeneous graph * First version of HeterogeneousGraphConv * Add heterogeneous batched featured graph * Add HeterogeneousTrajectoryState * Created HeterogeneousStateRepresentation * Consistent order of types of nodes + naming adjustments * Vertex ordering consistency * Adapted the conversion of DefaultTrajectoryState * Add HeterogeneousGraphConvInit + Fix HeterogeneousGraphConv * Fixed syntax errors * include heterogeneous file * Fix HeterogeneousStateRepresentation * Fix adjacency_matrices * fix HeterogeneousTrajectoryState from HeterogeneousStateRepresentation * Fix compilation warning and multiple include of same file * New management of VarViews in tripartite graph * Add HeterogeneousCPNN * New management of VarViews for heterogeneous graphs * Fix compilation error * Fixed error for registering VarView constraints * Fixed indexing error * Move totalLength * Fixed ViewConstraint * Adapted tests to new management of VarViews * Add update_with_cp_models for heterogeneous + fix featurize for heterogeneous * Redefine constraint_activity for ViewConstraint + fix in featurize * Fixed constraint type onehot encoding * Adapted tests to new management of VarViews * Fixing some issues in HeterogeneousCPNN * Fixed HeterogeneousCPNN-related bugs * Fixed bugs in HeterogeneousFeaturedGraph * Fixed bug in HeterogeneousStateRepresentation * First test about heterogeneousSR * Add ! to initChosenFeatures * Add test for HeterogeneousSR with chosen_features * test HeterogeneousTrajectoryState constructor + heterogeneous on square graph * test contovar and val to var in square graph * Create heterogeneous file * Add check_dimensions for hetereogeneous graph * First version of HeterogeneousGraphConv * Created HeterogeneousStateRepresentation * Add heterogeneous batched featured graph * Add HeterogeneousTrajectoryState * Consistent order of types of nodes + naming adjustments * Vertex ordering consistency * Add HeterogeneousGraphConvInit + Fix HeterogeneousGraphConv * Adapted the conversion of DefaultTrajectoryState * Fixed syntax errors * include heterogeneous file * Fix HeterogeneousStateRepresentation * Fix adjacency_matrices * fix HeterogeneousTrajectoryState from HeterogeneousStateRepresentation * New management of VarViews in tripartite graph * Fix compilation warning and multiple include of same file * New management of VarViews for heterogeneous graphs * Add HeterogeneousCPNN * Fixed error for registering VarView constraints * Fix compilation error * Fixed indexing error * Fixed ViewConstraint * Move totalLength * Add update_with_cp_models for heterogeneous + fix featurize for heterogeneous * Adapted tests to new management of VarViews * Redefine constraint_activity for ViewConstraint + fix in featurize * Fixed constraint type onehot encoding * Adapted tests to new management of VarViews * Fixing some issues in HeterogeneousCPNN * Fixed HeterogeneousCPNN-related bugs * Fixed bugs in HeterogeneousFeaturedGraph * Fixed bug in HeterogeneousStateRepresentation * First test about heterogeneousSR * Add ! to initChosenFeatures * Add test for HeterogeneousSR with chosen_features * test HeterogeneousTrajectoryState constructor + heterogeneous on square graph * test contovar and val to var in square graph * include test for heterogeneousSR * Fixed error in DefaultStateRepresentation * added possibleValuesIdx features * added HeterogeneousVariableOutputCPNN * added possibleValuesIdx field for DefaultTrajectoryState * fixed associated testsets * Add chosen_features field to SupervisedLearnedHeuristic * Fixes for using VariableOutputCPNN with HeterogeneousStateRepresentation * WIP HeterogeneousFFCPNN * Fixed mistakes in BatchedHeterogeneousTrajectoryState * fixed bug for defaulstaterepresentation * action_to_value testset * Implementing HeterogeneousFullFeaturedCPNN * added doc * fixed from_order_to_id for DefaultTrajectoryState * added advanced test for default trajectory state * Simplifying HeterogeneousCPNN * added accessors bor batchedheterogeneousfeaturedgraph * fixed edge cases and bugs * added basic testsets for heterogeneousfeaturedgraph * Fix rb generator * fix bug on varying featured graph stored in the trajectory * added testset for trajectoryState copy * test for HeterogeneousFFCPNN * added test dependency * fixed testsets * Fix kep generator * Fixed bug causing error when running KEP * Cleaned model.jl * Fixed bug causing duplicate constraints in graphcoloring * Added new features is_branchable and is_objective * fix typo * more testset for heterogeneousFFcpnn * added heterogeneoustrajectorystate testsets * Added unit tests for new features * temporary fix of the function state |> "device" * fix chosen_feature's attribute : variable_is_branchable * fix graph coloring datagen * added type specific fc layer for HFFCPNN * fix coloring.jl for v1.7 * Fixed mistakes for new features * Fixed error for is_branchable feature on non-branchable variables * Add from_id_to_order function in utils * Fix the action retrieval from helpSolution in supervisedLearnedHeuristic * Add documentation * Minor bug fix and remove prints * Added testset for new variable featured * added testsets * implemented mean pooling * fix testsets * fix on mean pooling * fix * removed zygote.ignore * remove zygote.ignore * Clean heterogeneouscpnn * Fixed bug on GeneralReward * Graph conv change default sigma to leakyrelu * Added new features number of neighbors and variable assigned value * Fixed SyntaxError * Fixed errors on new features * Fixed error on new features * Fix (?) graph conv and make meanPooling work * Set sumPooling by default * Added testsets for new features * Rewrite from_id_to_order function * Enable batch processing on variableOutputCPNN * Add documentation on fullfeaturedcpnn * Fixed coloring generation testset * Add test for variableoutputcpnn * fixed a little bug on LegacyGraphColoringGenerator * Enable batch processing for HeterogeneousVariableOutputCPNN * Fixed major bug in the pipeline and associated testsets * Fixed graphcoloring generator testset after symmetry removal * Fix graphcoloring generator testset after symmetry removal * Rework heterogeneousGraphConv for meanPooling * Fix non batched meanPooling * Rework GraphConv for meanPooling * Fix graphcoloring generator testset after symmetry removal Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Fixed SyntaxError * Fix graphcoloring generator testset after symmetry removal * Add test for heterogeneousVariableOutputCPNN * Clean variableOutputCPNN and heterogeneousVariableOutputCPNN * added small iterator for verbose * Maximum Independent Set Generator (#234) * Add MaximumIndependentSet Generator * Change NotEqual to SumLessThan * Fix test by introducing LigthGraphs. everywhere * Introduce test for maximum independent set * Fix testset for maximumindependentset * Update src/CP/constraints/algorithms/matching.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Update src/CP/constraints/alldifferent.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Add missing LightGraphs. prefix Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> Co-authored-by: louis-gautier <louisgautier99@gmail.com> * fixed empty! function : add model.adhocInfo * fix isempty! * Update src/CP/valueselection/learning/utils.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Management of ViewConstraints in nb_involved_constraint_propagation Co-authored-by: louis-gautier <louisgautier99@gmail.com> Co-authored-by: 3rdCore <tom.marty@polytechnique.edu> Co-authored-by: Ziad <ziadelassal@gmail.com> Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> Co-authored-by: 3rdCore <tom.marty@polytec>
* Create heterogeneous file * Add check_dimensions for hetereogeneous graph * First version of HeterogeneousGraphConv * Add heterogeneous batched featured graph * Add HeterogeneousTrajectoryState * Created HeterogeneousStateRepresentation * Consistent order of types of nodes + naming adjustments * Vertex ordering consistency * Adapted the conversion of DefaultTrajectoryState * Add HeterogeneousGraphConvInit + Fix HeterogeneousGraphConv * Fixed syntax errors * include heterogeneous file * Fix HeterogeneousStateRepresentation * Fix adjacency_matrices * fix HeterogeneousTrajectoryState from HeterogeneousStateRepresentation * Fix compilation warning and multiple include of same file * New management of VarViews in tripartite graph * Add HeterogeneousCPNN * New management of VarViews for heterogeneous graphs * Fix compilation error * Fixed error for registering VarView constraints * Fixed indexing error * Move totalLength * Fixed ViewConstraint * Adapted tests to new management of VarViews * Add update_with_cp_models for heterogeneous + fix featurize for heterogeneous * Redefine constraint_activity for ViewConstraint + fix in featurize * Fixed constraint type onehot encoding * Adapted tests to new management of VarViews * Fixing some issues in HeterogeneousCPNN * Fixed HeterogeneousCPNN-related bugs * Fixed bugs in HeterogeneousFeaturedGraph * Fixed bug in HeterogeneousStateRepresentation * First test about heterogeneousSR * Add ! to initChosenFeatures * Add test for HeterogeneousSR with chosen_features * test HeterogeneousTrajectoryState constructor + heterogeneous on square graph * test contovar and val to var in square graph * Create heterogeneous file * Add check_dimensions for hetereogeneous graph * First version of HeterogeneousGraphConv * Created HeterogeneousStateRepresentation * Add heterogeneous batched featured graph * Add HeterogeneousTrajectoryState * Consistent order of types of nodes + naming adjustments * Vertex ordering consistency * Add HeterogeneousGraphConvInit + Fix HeterogeneousGraphConv * Adapted the conversion of DefaultTrajectoryState * Fixed syntax errors * include heterogeneous file * Fix HeterogeneousStateRepresentation * Fix adjacency_matrices * fix HeterogeneousTrajectoryState from HeterogeneousStateRepresentation * New management of VarViews in tripartite graph * Fix compilation warning and multiple include of same file * New management of VarViews for heterogeneous graphs * Add HeterogeneousCPNN * Fixed error for registering VarView constraints * Fix compilation error * Fixed indexing error * Fixed ViewConstraint * Move totalLength * Add update_with_cp_models for heterogeneous + fix featurize for heterogeneous * Adapted tests to new management of VarViews * Redefine constraint_activity for ViewConstraint + fix in featurize * Fixed constraint type onehot encoding * Adapted tests to new management of VarViews * Fixing some issues in HeterogeneousCPNN * Fixed HeterogeneousCPNN-related bugs * Fixed bugs in HeterogeneousFeaturedGraph * Fixed bug in HeterogeneousStateRepresentation * First test about heterogeneousSR * Add ! to initChosenFeatures * Add test for HeterogeneousSR with chosen_features * test HeterogeneousTrajectoryState constructor + heterogeneous on square graph * test contovar and val to var in square graph * include test for heterogeneousSR * Fixed error in DefaultStateRepresentation * added possibleValuesIdx features * added HeterogeneousVariableOutputCPNN * added possibleValuesIdx field for DefaultTrajectoryState * fixed associated testsets * Add chosen_features field to SupervisedLearnedHeuristic * Fixes for using VariableOutputCPNN with HeterogeneousStateRepresentation * WIP HeterogeneousFFCPNN * Fixed mistakes in BatchedHeterogeneousTrajectoryState * fixed bug for defaulstaterepresentation * action_to_value testset * Implementing HeterogeneousFullFeaturedCPNN * added doc * fixed from_order_to_id for DefaultTrajectoryState * added advanced test for default trajectory state * Simplifying HeterogeneousCPNN * added accessors bor batchedheterogeneousfeaturedgraph * fixed edge cases and bugs * added basic testsets for heterogeneousfeaturedgraph * Fix rb generator * fix bug on varying featured graph stored in the trajectory * added testset for trajectoryState copy * test for HeterogeneousFFCPNN * added test dependency * fixed testsets * Fix kep generator * Fixed bug causing error when running KEP * Cleaned model.jl * Fixed bug causing duplicate constraints in graphcoloring * Added new features is_branchable and is_objective * fix typo * more testset for heterogeneousFFcpnn * added heterogeneoustrajectorystate testsets * Added unit tests for new features * temporary fix of the function state |> "device" * fix chosen_feature's attribute : variable_is_branchable * fix graph coloring datagen * added type specific fc layer for HFFCPNN * fix coloring.jl for v1.7 * Fixed mistakes for new features * Fixed error for is_branchable feature on non-branchable variables * Add from_id_to_order function in utils * Fix the action retrieval from helpSolution in supervisedLearnedHeuristic * Add documentation * Minor bug fix and remove prints * Added testset for new variable featured * added testsets * implemented mean pooling * fix testsets * fix on mean pooling * fix * removed zygote.ignore * remove zygote.ignore * Clean heterogeneouscpnn * Fixed bug on GeneralReward * Graph conv change default sigma to leakyrelu * Added new features number of neighbors and variable assigned value * Fixed SyntaxError * Fixed errors on new features * Fixed error on new features * Fix (?) graph conv and make meanPooling work * Set sumPooling by default * Added testsets for new features * Rewrite from_id_to_order function * Enable batch processing on variableOutputCPNN * Add documentation on fullfeaturedcpnn * Fixed coloring generation testset * Basic structure of HGT * Definition draft for HGT * WIP on HGT * WIP on HGT * WIP on HGT * Add test for variableoutputcpnn * First draft version of HGT * include heterogeneousgraphtransformer * Debugging HGT * Fix dimension in hgt * Add zygote.ignore on replace * First version of batched HGT * fixed a little bug on LegacyGraphColoringGenerator * global * Enable batch processing for HeterogeneousVariableOutputCPNN * Using NNLib softmax again * Fixing a major bug in the pipeline * Fixed major bug in the pipeline and associated testsets * Fixed graphcoloring generator testset after symmetry removal * Fix graphcoloring generator testset after symmetry removal * Rework heterogeneousGraphConv for meanPooling * Fix non batched meanPooling * Rework GraphConv for meanPooling * Fix graphcoloring generator testset after symmetry removal Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Fixed SyntaxError * Fix graphcoloring generator testset after symmetry removal * Add test for heterogeneousVariableOutputCPNN * Clean variableOutputCPNN and heterogeneousVariableOutputCPNN * added small iterator for verbose * Maximum Independent Set Generator (#234) * Add MaximumIndependentSet Generator * Change NotEqual to SumLessThan * Fix test by introducing LigthGraphs. everywhere * Introduce test for maximum independent set * Fix testset for maximumindependentset * Update src/CP/constraints/algorithms/matching.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Update src/CP/constraints/alldifferent.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Add missing LightGraphs. prefix Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> Co-authored-by: louis-gautier <louisgautier99@gmail.com> * fixed empty! function : add model.adhocInfo * fix isempty! * Update src/CP/valueselection/learning/utils.jl Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> * Management of ViewConstraints in nb_involved_constraint_propagation * Implement FFCPNNv2 * Small comment corrections * Implement FFCPNNv3 * Cleaned GraphConv * Add max and mean pooling in ffcpnnv3 * Fixed statistics updates in ILDS and RBS * added maxPooling for GraphConv * work on MaxPooling * fixed latin test * maxPooling for HFG * added doc for graphconv * added doc for HGC maxPooling * Merge branch 'maxPooling' into hgt * fix maxPool operation * fixed adjacency matrix type for FG and HFG * fix contovar valtovar def * take_objective error correction * Allow for restarts without pruning the objective variable domain * Merge branch 'hgt' of https://github.com/corail-research/SeaPearl.jl into hgt * Update testsets * Removed new CPNNs from hgt branch Co-authored-by: Tristan François <tpv.francois@gmail.com> Co-authored-by: 3rdCore <tom.marty@polytechnique.edu> Co-authored-by: Ziad <ziadelassal@gmail.com> Co-authored-by: Tom Marty <59280588+3rdCore@users.noreply.github.com> Co-authored-by: 3rdCore <tom.marty@polytec> Co-authored-by: Tristan François <33726628+gostreap@users.noreply.github.com> Co-authored-by: Ziad El Assal <89725221+ziadelassal@users.noreply.github.com>
Introduces a Maximum Independent Set problem generator.
The graph generation algorithm on which the generator is based is Barabasi-Albert. We use here the version implemented by
Graphs.jl
.The generation of the CP problem is very simple.
We start by creating a boolean variable for each node (more precisely we create an integer variable with domain
[0, 1]
in order to sum them up) .Then, for each edge in the graph, we create a constraint ensuring that the sum of the nodes at each end of the edge is less than 1 (
SumLessThan([src, dst], 1)
). Thus, two neighboring nodes cannot have the value 1, but they can both have the value 0.Finally, we create a variable for the objective, and we make sure that the sum of all the node variables is equal to the objective.
The introduction of
Graphs.jl
introduced conflicts with the deprecatedLightGraphs.jl
currently used inSeaPearl
. Therefore, it was necessary to prefix all LightGraphs (e.g.nv => LightGraphs.nv
). Although this may introduce bugs, as it is likely that some prefixes have been forgotten, they will be easy to fix as it will trigger an error at compile time. I think that the transition to theGraphs.jl
library is essential in the long term and that's why I wanted to initiate it.