Skip to content

Rename transform! -> transform #498

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 1 commit into from
Aug 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/apimanual.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,19 @@ the right-hand side of a constraint in linear programming.
In some special cases, solvers may support efficiently changing the set of a
constraint (for example, from [`LessThan`](@ref MathOptInterface.LessThan) to
[`GreaterThan`](@ref MathOptInterface.GreaterThan)). For these cases,
MathOptInterface provides the [`transform!`](@ref MathOptInterface.transform!)
MathOptInterface provides the [`transform`](@ref MathOptInterface.transform)
method. For example, instead of the error we observed above, the following will
work:
```julia
c2 = transform!(m, c, GreaterThan(1.0))
c2 = transform(m, c, GreaterThan(1.0))
```
The [`transform!`](@ref MathOptInterface.transform!) function returns a new
The [`transform`](@ref MathOptInterface.transform) function returns a new
constraint index, and the old constraint index (i.e., `c`) is no longer valid:
```julia
is_valid(m, c) # false
is_valid(m, c2) # true
```
Also note that [`transform!`](@ref MathOptInterface.transform!) cannot be called
Also note that [`transform`](@ref MathOptInterface.transform) cannot be called
with a set of the same type; [`set`](@ref MathOptInterface.set) should be used
instead.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/apireference.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Functions for adding and modifying constraints.
is_valid(::ModelLike,::ConstraintIndex)
add_constraint
add_constraints
transform!
transform
supports_constraint
```

Expand Down
2 changes: 1 addition & 1 deletion src/Test/UnitTests/modifications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function solve_transform_singlevariable_lessthan(model::MOI.ModelLike, config::T
constraint_primal = [(c, 1.0)],
constraint_dual = [(c, -1.0)]
)
c2 = MOI.transform!(model, c, MOI.GreaterThan(2.0))
c2 = MOI.transform(model, c, MOI.GreaterThan(2.0))
@test !MOI.is_valid(model, c)
@test MOI.is_valid(model, c2)
MOI.set(model, MOI.ObjectiveSense(), MOI.MinSense)
Expand Down
2 changes: 1 addition & 1 deletion src/Test/contlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ function linear11test(model::MOI.ModelLike, config::TestConfig)
@test MOI.get(model, MOI.ObjectiveValue()) ≈ 2.0 atol=atol rtol=rtol
end

c3 = MOI.transform!(model, c2, MOI.LessThan(2.0))
c3 = MOI.transform(model, c2, MOI.LessThan(2.0))

@test isa(c3, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}})
@test MOI.is_valid(model, c2) == false
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ function MOI.delete!(m::CachingOptimizer, index::MOI.Index)
end


# TODO: add_constraints, transform!
# TODO: add_constraints, transform

## CachingOptimizer get and set attributes

Expand Down
2 changes: 1 addition & 1 deletion src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ function set_fallback_error(::ModelLike, ::ConstraintSet,
constraint_index::ConstraintIndex, set::AbstractSet)
throw(ArgumentError("""Cannot modify sets of different types. Constraint
type is $(set_type(constraint_index)) while the replacement set is of
type $(typeof(set)). Use `transform!` instead."""))
type $(typeof(set)). Use `transform` instead."""))
end

## Termination status
Expand Down
10 changes: 5 additions & 5 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ add_constraints(model::ModelLike, funcs, sets) = add_constraint.(model, funcs, s
"""
## Transform Constraint Set

transform!(model::ModelLike, c::ConstraintIndex{F,S1}, newset::S2)::ConstraintIndex{F,S2}
transform(model::ModelLike, c::ConstraintIndex{F,S1}, newset::S2)::ConstraintIndex{F,S2}

Replace the set in constraint `c` with `newset`. The constraint index `c`
will no longer be valid, and the function returns a new constraint index with
Expand All @@ -99,14 +99,14 @@ Typically, the user should delete the constraint and add a new one.
If `c` is a `ConstraintIndex{ScalarAffineFunction{Float64},LessThan{Float64}}`,

```julia
c2 = transform!(model, c, GreaterThan(0.0))
transform!(model, c, LessThan(0.0)) # errors
c2 = transform(model, c, GreaterThan(0.0))
transform(model, c, LessThan(0.0)) # errors
```
"""
function transform! end
function transform end

# default fallback
function transform!(model::ModelLike, c::ConstraintIndex, newset)
function transform(model::ModelLike, c::ConstraintIndex, newset)
f = get(model, ConstraintFunction(), c)
delete!(model, c)
add_constraint(model, f, newset)
Expand Down