-
Notifications
You must be signed in to change notification settings - Fork 269
Adds bipartite graph function #874
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d17b5d5
Add strong branching wrappers
Opt-Mucca a8d126a
merge master into branch. Update documentation
Opt-Mucca 89fbc86
Update CHANGELOG
Opt-Mucca 2b9a2d0
Add new wrappers and unfinished tests
Opt-Mucca c0e4dbb
Update strong branching test
Opt-Mucca e489a4e
Fix typo
Opt-Mucca 1c4d233
Update CHANGELOG
Opt-Mucca 05a2f69
Add test for other features in branching rule
Opt-Mucca 376372d
Fix spelling errors
Opt-Mucca 9ac5e3f
Remove commented out line
Opt-Mucca 544fb44
Add bipartite graph generation function
Opt-Mucca 5bb433d
Update CHANGELOG
Opt-Mucca 9ee118c
Merge branch 'master' into mt/addstrongbranchingcalls
Opt-Mucca a8e8629
Merge branch 'mt/addstrongbranchingcalls' of github.com:scipopt/PySCI…
Opt-Mucca 24bdafb
Merge branch 'master' into mt/add_bipartite_graph
Opt-Mucca 1cf60fc
Add changes from joao
Opt-Mucca b64dd53
Add assert to ensure safe branching
Opt-Mucca 935e042
Add changes from Joao
Opt-Mucca cbe99a0
Merge branch 'master' into mt/add_bipartite_graph
Joao-Dionisio 0e5f9c2
Change names to copy those of SCIp interface
Opt-Mucca 62e85c3
Merge branch 'mt/addstrongbranchingcalls' into mt/add_bipartite_graph
Opt-Mucca e676481
Merge master into branch
Opt-Mucca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
from pyscipopt import Model, Branchrule, SCIP_RESULT, quicksum, SCIP_PARAMSETTING | ||
|
||
""" | ||
This is a test for the bipartite graph generation functionality. | ||
To make the test more practical, we embed the function in a dummy branching rule. Such functionality would allow | ||
users to then extract the feature set before any branching decision. This can be used to gather data for training etc | ||
and to to deploy actual branching rules trained on data from the graph representation. | ||
""" | ||
|
||
|
||
class DummyFeatureExtractingBranchRule(Branchrule): | ||
|
||
def __init__(self, scip, static=False, use_prev_states=True): | ||
self.scip = scip | ||
self.static = static | ||
self.use_prev_states = use_prev_states | ||
self.prev_col_features = None | ||
self.prev_row_features = None | ||
self.prev_edge_features = None | ||
|
||
def branchexeclp(self, allowaddcons): | ||
|
||
# Get the bipartite graph data | ||
if self.use_prev_states: | ||
prev_col_features = self.prev_col_features | ||
prev_edge_features = self.prev_edge_features | ||
prev_row_features = self.prev_row_features | ||
else: | ||
prev_col_features = None | ||
prev_edge_features = None | ||
prev_row_features = None | ||
col_features, edge_features, row_features, feature_maps = self.scip.getBipartiteGraphRepresentation( | ||
prev_col_features=prev_col_features, prev_edge_features=prev_edge_features, | ||
prev_row_features=prev_row_features, static_only=self.static | ||
) | ||
|
||
# Here is now where a decision could be based off the features. If no decision is made just return DIDNOTRUN | ||
|
||
return {"result": SCIP_RESULT.DIDNOTRUN} | ||
|
||
|
||
|
||
|
||
|
||
def create_model(): | ||
scip = Model() | ||
scip.setHeuristics(SCIP_PARAMSETTING.OFF) | ||
scip.setSeparating(SCIP_PARAMSETTING.OFF) | ||
scip.setLongintParam("limits/nodes", 250) | ||
scip.setParam("presolving/maxrestarts", 0) | ||
|
||
x0 = scip.addVar(lb=-2, ub=4) | ||
r1 = scip.addVar() | ||
r2 = scip.addVar() | ||
y0 = scip.addVar(lb=3) | ||
t = scip.addVar(lb=None) | ||
l = scip.addVar(vtype="I", lb=-9, ub=18) | ||
u = scip.addVar(vtype="I", lb=-3, ub=99) | ||
|
||
more_vars = [] | ||
for i in range(100): | ||
more_vars.append(scip.addVar(vtype="I", lb=-12, ub=40)) | ||
scip.addCons(quicksum(v for v in more_vars) <= (40 - i) * quicksum(v for v in more_vars[::2])) | ||
|
||
for i in range(100): | ||
more_vars.append(scip.addVar(vtype="I", lb=-52, ub=10)) | ||
scip.addCons(quicksum(v for v in more_vars[50::2]) <= (40 - i) * quicksum(v for v in more_vars[200::2])) | ||
|
||
scip.addCons(r1 >= x0) | ||
scip.addCons(r2 >= -x0) | ||
scip.addCons(y0 == r1 + r2) | ||
scip.addCons(t + l + 7 * u <= 300) | ||
scip.addCons(t >= quicksum(v for v in more_vars[::3]) - 10 * more_vars[5] + 5 * more_vars[9]) | ||
scip.addCons(more_vars[3] >= l + 2) | ||
scip.addCons(7 <= quicksum(v for v in more_vars[::4]) - x0) | ||
scip.addCons(quicksum(v for v in more_vars[::2]) + l <= quicksum(v for v in more_vars[::4])) | ||
|
||
scip.setObjective(t - quicksum(j * v for j, v in enumerate(more_vars[20:-40]))) | ||
Joao-Dionisio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return scip | ||
|
||
|
||
def test_bipartite_graph(): | ||
scip = create_model() | ||
|
||
dummy_branch_rule = DummyFeatureExtractingBranchRule(scip) | ||
scip.includeBranchrule(dummy_branch_rule, "dummy branch rule", "custom feature extraction branching rule", | ||
priority=10000000, maxdepth=-1, maxbounddist=1) | ||
|
||
scip.optimize() | ||
|
||
|
||
def test_bipartite_graph_static(): | ||
scip = create_model() | ||
|
||
dummy_branch_rule = DummyFeatureExtractingBranchRule(scip, static=True) | ||
scip.includeBranchrule(dummy_branch_rule, "dummy branch rule", "custom feature extraction branching rule", | ||
priority=10000000, maxdepth=-1, maxbounddist=1) | ||
|
||
scip.optimize() | ||
|
||
def test_bipartite_graph_use_prev(): | ||
scip = create_model() | ||
|
||
dummy_branch_rule = DummyFeatureExtractingBranchRule(scip, use_prev_states=True) | ||
scip.includeBranchrule(dummy_branch_rule, "dummy branch rule", "custom feature extraction branching rule", | ||
priority=10000000, maxdepth=-1, maxbounddist=1) | ||
|
||
scip.optimize() | ||
|
||
def test_bipartite_graph_static_use_prev(): | ||
scip = create_model() | ||
|
||
dummy_branch_rule = DummyFeatureExtractingBranchRule(scip, static=True, use_prev_states=True) | ||
scip.includeBranchrule(dummy_branch_rule, "dummy branch rule", "custom feature extraction branching rule", | ||
priority=10000000, maxdepth=-1, maxbounddist=1) | ||
|
||
scip.optimize() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.