1
1
"""
2
2
JuMP.build_variable(::Function, info::JuMP.VariableInfo, set::T) where T <: MOI.AbstractScalarSet
3
3
4
- DOCSTRING
4
+ Create a variable constrained by a scalar set.
5
5
6
- # Arguments:
7
- - ``: DESCRIPTION
8
- - `info`: DESCRIPTION
9
- - `set`: DESCRIPTION
6
+ # Arguments
7
+ - `info::JuMP.VariableInfo`: Information about the variable to be created.
8
+ - `set::T where T <: MOI.AbstractScalarSet`: The set defining the constraints on the variable.
9
+
10
+ # Returns
11
+ - `JuMP.VariableConstrainedOnCreation`: A variable constrained by the specified set.
10
12
"""
11
13
function JuMP. build_variable (
12
14
:: Function ,
19
21
"""
20
22
Optimizer <: MOI.AbstractOptimizer
21
23
22
- DOCSTRING
24
+ Defines an optimizer for CBLS.
23
25
24
- # Arguments:
25
- - `solver::Solver `: DESCRIPTION
26
- - `status::MOI.TerminationStatusCode `: DESCRIPTION
27
- - `options::Options `: DESCRIPTION
26
+ # Fields
27
+ - `solver::LS.MainSolver `: The main solver used for local search.
28
+ - `int_vars::Set{Int} `: Set of integer variables.
29
+ - `compare_vars::Set{Int} `: Set of variables to compare.
28
30
"""
29
31
mutable struct Optimizer <: MOI.AbstractOptimizer
30
32
solver:: LS.MainSolver
35
37
"""
36
38
Optimizer(model = Model(); options = Options())
37
39
38
- DOCSTRING
40
+ Create an instance of the Optimizer.
41
+
42
+ # Arguments
43
+ - `model`: The model to be optimized.
44
+ - `options::Options`: Options for configuring the solver.
45
+
46
+ # Returns
47
+ - `Optimizer`: An instance of the optimizer.
39
48
"""
40
49
function Optimizer (model = model (); options = Options ())
41
50
return Optimizer (
51
60
@forward Optimizer. solver LS. _best_bound, LS. best_value, LS. is_sat, LS. get_value
52
61
@forward Optimizer. solver LS. domain_size, LS. best_values, LS. _max_cons, LS. update_domain!
53
62
@forward Optimizer. solver LS. get_variable, LS. has_solution, LS. sense, LS. sense!
54
- @forward Optimizer. solver LS. time_info, LS. status
63
+ @forward Optimizer. solver LS. time_info, LS. status, LS . length_vars
55
64
56
65
# forward functions from Solver (from Options)
57
66
@forward Optimizer. solver LS. _verbose, LS. set_option!, LS. get_option
58
67
59
68
"""
60
- MOI.get(::Optimizer, ::MOI.SolverName) = begin
69
+ MOI.get(::Optimizer, ::MOI.SolverName)
70
+
71
+ Get the name of the solver.
61
72
62
- DOCSTRING
73
+ # Arguments
74
+ - `::Optimizer`: The optimizer instance.
75
+
76
+ # Returns
77
+ - `String`: The name of the solver.
63
78
"""
64
- MOI. get (:: Optimizer , :: MOI.SolverName ) = " LocalSearchSolvers "
79
+ MOI. get (:: Optimizer , :: MOI.SolverName ) = " CBLS "
65
80
66
81
"""
67
- MOI.set(::Optimizer, ::MOI.Silent, bool = true) = begin
82
+ MOI.set(::Optimizer, ::MOI.Silent, bool = true)
83
+
84
+ Set the verbosity of the solver.
68
85
69
- DOCSTRING
86
+ # Arguments
87
+ - `::Optimizer`: The optimizer instance.
88
+ - `::MOI.Silent`: The silent option for the solver.
89
+ - `bool::Bool`: Whether to set the solver to silent mode.
70
90
71
- # Arguments:
72
- - ``: DESCRIPTION
73
- - ``: DESCRIPTION
74
- - `bool`: DESCRIPTION
91
+ # Returns
92
+ - `Nothing`
75
93
"""
76
94
MOI. set (:: Optimizer , :: MOI.Silent , bool = true ) = @debug " TODO: Silent"
77
95
78
96
"""
79
- MOI.is_empty(model::Optimizer) = begin
97
+ MOI.is_empty(model::Optimizer)
98
+
99
+ Check if the model is empty.
80
100
81
- DOCSTRING
101
+ # Arguments
102
+ - `model::Optimizer`: The optimizer instance.
103
+
104
+ # Returns
105
+ - `Bool`: True if the model is empty, false otherwise.
82
106
"""
83
107
MOI. is_empty (model:: Optimizer ) = LS. _is_empty (model. solver)
84
108
85
109
"""
86
- Copy constructor for the optimizer
110
+ MOI.supports_incremental_interface(::Optimizer)
111
+
112
+ Check if the optimizer supports incremental interface.
113
+
114
+ # Arguments
115
+ - `::Optimizer`: The optimizer instance.
116
+
117
+ # Returns
118
+ - `Bool`: True if the optimizer supports incremental interface, false otherwise.
87
119
"""
88
120
MOI. supports_incremental_interface (:: Optimizer ) = true
121
+
122
+ """
123
+ MOI.copy_to(model::Optimizer, src::MOI.ModelLike)
124
+
125
+ Copy the source model to the optimizer.
126
+
127
+ # Arguments
128
+ - `model::Optimizer`: The optimizer instance.
129
+ - `src::MOI.ModelLike`: The source model to be copied.
130
+
131
+ # Returns
132
+ - `Nothing`
133
+ """
89
134
function MOI. copy_to (model:: Optimizer , src:: MOI.ModelLike )
90
135
return MOIU. default_copy_to (model, src)
91
136
end
92
137
93
138
"""
94
139
MOI.optimize!(model::Optimizer)
140
+
141
+ Optimize the model using the optimizer.
142
+
143
+ # Arguments
144
+ - `model::Optimizer`: The optimizer instance.
145
+
146
+ # Returns
147
+ - `Nothing`
95
148
"""
96
149
MOI. optimize! (optimizer:: Optimizer ) = solve! (optimizer. solver)
97
150
98
151
"""
99
152
DiscreteSet(values)
153
+
154
+ Create a discrete set of values.
155
+
156
+ # Arguments
157
+ - `values::Vector{T}`: A vector of values to include in the set.
158
+
159
+ # Returns
160
+ - `DiscreteSet{T}`: A discrete set containing the specified values.
100
161
"""
101
162
struct DiscreteSet{T <: Number } <: MOI.AbstractScalarSet
102
163
values:: Vector{T}
@@ -105,22 +166,82 @@ DiscreteSet(values) = DiscreteSet(collect(values))
105
166
DiscreteSet (values:: T... ) where {T <: Number } = DiscreteSet (collect (values))
106
167
107
168
"""
108
- Base.copy(set::DiscreteSet) = begin
169
+ Base.copy(set::DiscreteSet)
170
+
171
+ Copy a discrete set.
172
+
173
+ # Arguments
174
+ - `set::DiscreteSet`: The discrete set to be copied.
109
175
110
- DOCSTRING
176
+ # Returns
177
+ - `DiscreteSet`: A copy of the discrete set.
111
178
"""
112
179
Base. copy (set:: DiscreteSet ) = DiscreteSet (copy (set. values))
113
180
114
181
"""
115
- MOI.empty!(opt) = begin
182
+ MOI.empty!(opt)
116
183
117
- DOCSTRING
184
+ Empty the optimizer.
185
+
186
+ # Arguments
187
+ - `opt::Optimizer`: The optimizer instance.
188
+
189
+ # Returns
190
+ - `Nothing`
118
191
"""
119
192
MOI. empty! (opt) = empty! (opt)
120
193
194
+ """
195
+ MOI.is_valid(optimizer::Optimizer, index::CI{VI, MOI.Integer})
196
+
197
+ Check if an index is valid for the optimizer.
198
+
199
+ # Arguments
200
+ - `optimizer::Optimizer`: The optimizer instance.
201
+ - `index::CI{VI, MOI.Integer}`: The index to be checked.
202
+
203
+ # Returns
204
+ - `Bool`: True if the index is valid, false otherwise.
205
+ """
121
206
function MOI. is_valid (optimizer:: Optimizer , index:: CI{VI, MOI.Integer} )
122
207
return index. value ∈ optimizer. int_vars
123
208
end
124
209
210
+ """
211
+ Base.copy(op::F) where {F <: Function}
212
+
213
+ Copy a function.
214
+
215
+ # Arguments
216
+ - `op::F`: The function to be copied.
217
+
218
+ # Returns
219
+ - `F`: The copied function.
220
+ """
125
221
Base. copy (op:: F ) where {F <: Function } = op
222
+
223
+ """
224
+ Base.copy(::Nothing)
225
+
226
+ Copy a `Nothing` value.
227
+
228
+ # Arguments
229
+ - `::Nothing`: The `Nothing` value to be copied.
230
+
231
+ # Returns
232
+ - `Nothing`: The copied `Nothing` value.
233
+ """
126
234
Base. copy (:: Nothing ) = nothing
235
+
236
+ """
237
+ Moi.get(::Optimizer, ::MOI.SolverVersion)
238
+
239
+ Get the version of the solver, here `LocalSearchSolvers.jl`.
240
+ """
241
+ function MOI. get (:: Optimizer , :: MOI.SolverVersion )
242
+ deps = Pkg. dependencies ()
243
+ local_search_solver_uuid = Base. UUID (" 2b10edaa-728d-4283-ac71-07e312d6ccf3" )
244
+ return " v" * string (deps[local_search_solver_uuid]. version)
245
+ end
246
+
247
+ MOI. get (opt:: Optimizer , :: MOI.NumberOfVariables ) = LS. length_vars (opt)
0 commit comments