-
Notifications
You must be signed in to change notification settings - Fork 5
Add Extension Friendly Variable Creation Methods #123
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 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
81e17fa
Initial commit for VariableProperties and _variable_from_properties.
dnguyen227 18f5eef
80 Character Edit
dnguyen227 3684429
Change to use JuMP.VariableInfo
dnguyen227 8e73558
modified test
dnguyen227 ec4477e
docstring update
dnguyen227 7034a5b
80 character line limit
dnguyen227 da093af
80 character line limit
dnguyen227 7103343
Modified tests, hull.jl when disaggregating variables, comments per P…
dnguyen227 8e38dd6
modified test comments
dnguyen227 b739aa3
removed make_disaggregated_variable test (now create_variable workflo…
dnguyen227 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
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,134 @@ | ||
| function test_VariableProperties_constructor() | ||
| model = Model() | ||
|
|
||
| @variable(model, x, lower_bound = 2.5) | ||
| x_props = DP.VariableProperties(x) | ||
| @test x_props.info.has_lb == true | ||
| @test x_props.info.lower_bound == 2.5 | ||
| @test x_props.info.has_ub == false | ||
| @test x_props.info.upper_bound == 0.0 | ||
| @test x_props.info.has_fix == false | ||
| @test x_props.info.fixed_value == 0.0 | ||
| @test x_props.info.has_start == false | ||
| @test x_props.name == "x" | ||
| @test x_props.set === nothing | ||
| @test x_props.variable_type === nothing | ||
|
|
||
| @variable(model, y, start = 3.14) | ||
| y_props = DP.VariableProperties(y) | ||
| @test y_props.info.has_start == true | ||
| @test y_props.info.start == 3.14 | ||
| @test y_props.info.has_lb == false | ||
| @test y_props.info.lower_bound == 0.0 | ||
|
|
||
| @variable(model, z == 7.5) | ||
| z_props = DP.VariableProperties(z) | ||
| @test z_props.info.has_fix == true | ||
| @test z_props.info.fixed_value == 7.5 | ||
| @test z_props.info.has_lb == false | ||
| @test z_props.info.lower_bound == 0.0 | ||
| end | ||
|
|
||
| function test_make_variable_object() | ||
| model = Model() | ||
|
|
||
| @variable(model, x, lower_bound = 1.0, upper_bound = 5.0) | ||
| props = DP.VariableProperties(x) | ||
|
|
||
| modified_info = JuMP.VariableInfo( | ||
| props.info.has_lb, | ||
| props.info.lower_bound, | ||
| props.info.has_ub, | ||
| 10.0, # Modified upper bound | ||
| props.info.has_fix, | ||
| props.info.fixed_value, | ||
| props.info.has_start, | ||
| props.info.start, | ||
| props.info.binary, | ||
| props.info.integer | ||
| ) | ||
|
|
||
| props.info = modified_info | ||
|
|
||
| var_obj = DP._make_variable_object(props) | ||
| @test var_obj.info.upper_bound == 10.0 | ||
| end | ||
|
|
||
| function test_create_variable() | ||
| model1 = Model() | ||
| model2 = Model() | ||
|
|
||
| @variable(model1, x, lower_bound = 1.0, upper_bound = 5.0, start = 2.0) | ||
| props_no_set = DP.VariableProperties(x) | ||
|
|
||
| @test props_no_set.set === nothing | ||
|
|
||
| var_no_set = DP.create_variable(model2, props_no_set) | ||
|
|
||
| @test var_no_set !== nothing | ||
| @test JuMP.name(var_no_set) == "x" | ||
| @test JuMP.has_lower_bound(var_no_set) == true | ||
| @test JuMP.lower_bound(var_no_set) == 1.0 | ||
| @test JuMP.has_upper_bound(var_no_set) == true | ||
| @test JuMP.upper_bound(var_no_set) == 5.0 | ||
| @test JuMP.has_start_value(var_no_set) == true | ||
| @test JuMP.start_value(var_no_set) == 2.0 | ||
|
|
||
| @test var_no_set in JuMP.all_variables(model2) | ||
| @test !(var_no_set in JuMP.all_variables(model1)) | ||
| end | ||
|
|
||
| function test_complete_workflow() | ||
| model1 = Model() | ||
| model2 = Model() | ||
|
|
||
| @variable(model1, original, lower_bound = 1, upper_bound = 5, start = 3.0) | ||
|
|
||
| props = DP.VariableProperties(original) | ||
|
|
||
| recreated = DP.create_variable(model2, props) | ||
|
|
||
| @test JuMP.has_lower_bound(recreated) == JuMP.has_lower_bound(original) | ||
| @test JuMP.lower_bound(recreated) == JuMP.lower_bound(original) | ||
| @test JuMP.has_upper_bound(recreated) == JuMP.has_upper_bound(original) | ||
| @test JuMP.upper_bound(recreated) == JuMP.upper_bound(original) | ||
| @test JuMP.has_start_value(recreated) == JuMP.has_start_value(original) | ||
| @test JuMP.start_value(recreated) == JuMP.start_value(original) | ||
| @test JuMP.name(recreated) == JuMP.name(original) | ||
|
|
||
| @test original in JuMP.all_variables(model1) | ||
| @test recreated in JuMP.all_variables(model2) | ||
| @test !(original in JuMP.all_variables(model2)) | ||
| @test !(recreated in JuMP.all_variables(model1)) | ||
| end | ||
|
|
||
| function test_variable_copy() | ||
| model1 = Model() | ||
| model2 = Model() | ||
|
|
||
| @variable(model1, original, lower_bound = 1, upper_bound = 5, start = 3.0) | ||
|
|
||
| props = DP.VariableProperties(original) | ||
|
|
||
| recreated = DP.create_variable(model2, props) | ||
|
|
||
| @test JuMP.has_lower_bound(recreated) == JuMP.has_lower_bound(original) | ||
| @test JuMP.lower_bound(recreated) == JuMP.lower_bound(original) | ||
| @test JuMP.has_upper_bound(recreated) == JuMP.has_upper_bound(original) | ||
| @test JuMP.upper_bound(recreated) == JuMP.upper_bound(original) | ||
| @test JuMP.has_start_value(recreated) == JuMP.has_start_value(original) | ||
| @test JuMP.start_value(recreated) == JuMP.start_value(original) | ||
| @test JuMP.name(recreated) == JuMP.name(original) | ||
| println("##################################") | ||
| @test original in JuMP.all_variables(model1) | ||
| @test recreated in JuMP.all_variables(model2) | ||
| @test !(original in JuMP.all_variables(model2)) | ||
| @test !(recreated in JuMP.all_variables(model1)) | ||
| end | ||
|
|
||
| @testset "Variable Creation" begin | ||
| test_VariableProperties_constructor() | ||
| test_make_variable_object() | ||
| test_create_variable() | ||
| test_complete_workflow() | ||
| end |
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.