3636mutable struct ConstraintInfo
3737 # Only necessary information to access an existing constraint, delete it when needed.
3838 index:: MOI.ConstraintIndex
39- constraint:: Union{Constraint , Nothing}
39+ constraint:: Union{JavaObject , Nothing}
4040 f:: Union{MOI.AbstractScalarFunction, MOI.AbstractVectorFunction}
4141 set:: MOI.AbstractSet
4242 name:: String
4343end
4444
4545function ConstraintInfo (
4646 index:: MOI.ConstraintIndex ,
47- constraint:: Union{Constraint , Nothing} ,
47+ constraint:: Union{JavaObject , Nothing} ,
4848 f:: Union{MOI.AbstractScalarFunction, MOI.AbstractVectorFunction} ,
4949 set:: MOI.AbstractSet ,
5050)
@@ -73,8 +73,9 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
7373 # objective_function_cp::Union{Nothing, NumExpr}
7474 # objective_cp::Union{Nothing, IloObjective}
7575
76- # # Cache parts of a solution.
77- # cached_solution_state::Union{Nothing, Bool}
76+ # Cached solution state.
77+ termination_status:: MOI.TerminationStatusCode
78+ primal_status:: MOI.ResultStatusCode
7879
7980 # # Mappings from variable and constraint names to their indices. These are
8081 # # lazily built on-demand, so most of the time, they are `nothing`.
@@ -97,12 +98,14 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
9798 CleverDicts. CleverDict {MOI.VariableIndex, VariableInfo} ()
9899 model. constraint_info = Dict {MOI.ConstraintIndex, ConstraintInfo} ()
99100
101+ model. termination_status = MOI. OPTIMIZE_NOT_CALLED
102+ model. primal_status = MOI. NO_SOLUTION
103+
100104 # model.objective_sense = MOI.FEASIBILITY_SENSE
101105 # model.objective_function = nothing
102106 # model.objective_function_cp = nothing
103107 # model.objective_cp = nothing
104108
105- # model.cached_solution_state = nothing
106109 # model.callback_state = CB_NONE
107110
108111 MOI. empty! (model)
@@ -117,29 +120,16 @@ function MOI.empty!(model::Optimizer)
117120 model. name = " "
118121 empty! (model. variable_info)
119122 empty! (model. constraint_info)
120-
121- # model.objective_sense = MOI.FEASIBILITY_SENSE
122- # model.objective_function = nothing
123- # model.objective_function_cp = nothing
124- # model.objective_cp = nothing
125-
126- # model.cached_solution_state = nothing
127- # model.name_to_variable = nothing
128- # model.name_to_constraint = nothing
123+ model. termination_status = MOI. OPTIMIZE_NOT_CALLED
124+ model. primal_status = MOI. NO_SOLUTION
129125 return
130126end
131127
132128function MOI. is_empty (model:: Optimizer )
133129 ! isempty (model. name) && return false
134130 ! isempty (model. variable_info) && return false
135131 ! isempty (model. constraint_info) && return false
136- # model.objective_sense != MOI.FEASIBILITY_SENSE && return false
137- # model.objective_function !== nothing && return false
138- # model.objective_function_cp !== nothing && return false
139- # model.objective_cp !== nothing && return false
140- # model.name_to_variable !== nothing && return false
141- # model.name_to_constraint !== nothing && return false
142- # model.cached_solution_state !== nothing && return false
132+ model. termination_status != MOI. OPTIMIZE_NOT_CALLED && return false
143133 return true
144134end
145135
226216function MOI. get (:: Optimizer , :: MOI.ListOfConstraintAttributesSet )
227217 return MOI. AbstractConstraintAttribute[MOI. ConstraintName ()]
228218end
219+
220+ function MOI. optimize! (model:: Optimizer )
221+ int_vars = IntVar[
222+ info. variable for info in values (model. variable_info)
223+ if info. variable isa IntVar
224+ ]
225+ if isempty (int_vars)
226+ model. termination_status = MOI. OPTIMAL
227+ model. primal_status = MOI. FEASIBLE_POINT
228+ return
229+ end
230+ search = DepthFirstSearch (())
231+ indomain = IndomainMin (())
232+ select = InputOrderSelect (
233+ (Store, Vector{Var}, Indomain),
234+ model. inner, int_vars, indomain,
235+ )
236+ result = jcall (
237+ search, " labeling" , jboolean, (Store, SelectChoicePoint),
238+ model. inner, select,
239+ )
240+ if result != 0
241+ model. termination_status = MOI. OPTIMAL
242+ model. primal_status = MOI. FEASIBLE_POINT
243+ else
244+ model. termination_status = MOI. INFEASIBLE
245+ model. primal_status = MOI. NO_SOLUTION
246+ end
247+ return
248+ end
249+
250+ function MOI. get (model:: Optimizer , :: MOI.TerminationStatus )
251+ return model. termination_status
252+ end
253+
254+ function MOI. get (model:: Optimizer , :: MOI.PrimalStatus )
255+ return model. primal_status
256+ end
257+
258+ function MOI. get (model:: Optimizer , :: MOI.ResultCount )
259+ return model. primal_status == MOI. FEASIBLE_POINT ? 1 : 0
260+ end
261+
262+ function MOI. get (model:: Optimizer , :: MOI.VariablePrimal , vi:: MOI.VariableIndex )
263+ v = _info (model, vi). variable
264+ return Int (jcall (v, " value" , jint, ()))
265+ end
0 commit comments