File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 4
4
# Use of this source code is governed by an MIT-style license that can be found
5
5
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6
6
7
+ function MOI.empty!(model::Model)
8
+ model.objective = nothing
9
+ empty!(model.expressions)
10
+ empty!(model.constraints)
11
+ empty!(model.parameters)
12
+ model.operators = OperatorRegistry()
13
+ model.last_constraint_index = 0
14
+ return
15
+ end
16
+
17
+ function MOI.is_empty(model::Model)
18
+ return model.objective === nothing &&
19
+ isempty(model.expressions) &&
20
+ isempty(model.constraints) &&
21
+ isempty(model.parameters) &&
22
+ isempty(model.operators.registered_univariate_operators) &&
23
+ isempty(model.operators.registered_multivariate_operators) &&
24
+ model.last_constraint_index === Int64(0)
25
+ end
26
+
7
27
function Base.copy(::Model)
8
28
return error("Copying nonlinear problems not yet implemented")
9
29
end
Original file line number Diff line number Diff line change @@ -1103,6 +1103,34 @@ function test_parse_unsupported_operator()
1103
1103
return
1104
1104
end
1105
1105
1106
+ function test_is_empty()
1107
+ model = MOI.Nonlinear.Model()
1108
+ @test MOI.is_empty(model)
1109
+ x = MOI.VariableIndex(1)
1110
+ Nonlinear.set_objective(model, :(log($x)))
1111
+ @test !MOI.is_empty(model)
1112
+ MOI.empty!(model)
1113
+ @test MOI.is_empty(model)
1114
+ Nonlinear.add_constraint(model, :(log($x)), MOI.GreaterThan(1.0))
1115
+ @test !MOI.is_empty(model)
1116
+ MOI.empty!(model)
1117
+ @test MOI.is_empty(model)
1118
+ Nonlinear.add_expression(model, :(sin($x)^2))
1119
+ @test !MOI.is_empty(model)
1120
+ MOI.empty!(model)
1121
+ @test MOI.is_empty(model)
1122
+ Nonlinear.add_parameter(model, 1.2)
1123
+ @test !MOI.is_empty(model)
1124
+ MOI.empty!(model)
1125
+ @test MOI.is_empty(model)
1126
+ f(x) = log(x + 1)
1127
+ Nonlinear.register_operator(model, :f, 1, f)
1128
+ @test !MOI.is_empty(model)
1129
+ MOI.empty!(model)
1130
+ @test MOI.is_empty(model)
1131
+ return
1132
+ end
1133
+
1106
1134
end
1107
1135
1108
1136
TestNonlinear.runtests()
You can’t perform that action at this time.
0 commit comments