@@ -135,7 +135,6 @@ function MOI.is_empty(model::Optimizer)
135135 model. affine_objective_cache === nothing &&
136136 model. quadratic_objective_cache === nothing &&
137137 MOI. is_empty (model. original_objective_cache) &&
138- isempty (model. quadratic_objective_cache_product) &&
139138 #
140139 isempty (model. vector_affine_constraint_cache) &&
141140 #
@@ -172,7 +171,6 @@ function MOI.empty!(model::Optimizer{T}) where {T}
172171 model. affine_objective_cache = nothing
173172 model. quadratic_objective_cache = nothing
174173 MOI. empty! (model. original_objective_cache)
175- empty! (model. quadratic_objective_cache_product)
176174 #
177175 empty! (model. vector_affine_constraint_cache)
178176 #
@@ -1232,8 +1230,7 @@ function MOI.modify(
12321230 chg:: Union{MOI.ScalarConstantChange{T},MOI.ScalarCoefficientChange{T}} ,
12331231) where {F<: MathOptInterface.AbstractScalarFunction ,T}
12341232 if model. quadratic_objective_cache != = nothing ||
1235- model. affine_objective_cache != = nothing ||
1236- ! isempty (model. quadratic_objective_cache_product)
1233+ model. affine_objective_cache != = nothing
12371234 error (
12381235 " A parametric objective cannot be modified as it would conflict with the parameter update mechanism. Please set a new objective or use parameters to perform such updates." ,
12391236 )
@@ -1946,128 +1943,6 @@ function MOI.set(
19461943 return model. constraints_interpretation = value
19471944end
19481945
1949- struct QuadraticObjectiveCoef <: MOI.AbstractModelAttribute end
1950-
1951- function _set_quadratic_product_in_obj! (model:: Optimizer{T} ) where {T}
1952- n = length (model. quadratic_objective_cache_product)
1953-
1954- f = if model. affine_objective_cache != = nothing
1955- _current_function (model. affine_objective_cache)
1956- elseif model. quadratic_objective_cache != = nothing
1957- _current_function (model. quadratic_objective_cache)
1958- else
1959- F = MOI. get (model. original_objective_cache, MOI. ObjectiveFunctionType ())
1960- MOI. get (model. original_objective_cache, MOI. ObjectiveFunction {F} ())
1961- end
1962- F = typeof (f)
1963-
1964- quadratic_prods_vector = MOI. ScalarQuadraticTerm{T}[]
1965- sizehint! (quadratic_prods_vector, n)
1966-
1967- for ((x, y), fparam) in model. quadratic_objective_cache_product
1968- # x, y = prod_var
1969- evaluated_fparam = _evaluate_parametric_expression (model, fparam)
1970- push! (
1971- quadratic_prods_vector,
1972- MOI. ScalarQuadraticTerm (evaluated_fparam, x, y),
1973- )
1974- end
1975-
1976- f_new = if F <: MOI.VariableIndex
1977- MOI. ScalarQuadraticFunction (
1978- quadratic_prods_vector,
1979- MOI. ScalarAffineTerm{T}[MOI. ScalarAffineTerm {T} (1.0 , f)],
1980- 0.0 ,
1981- )
1982- elseif F <: MOI.ScalarAffineFunction{T}
1983- MOI. ScalarQuadraticFunction (quadratic_prods_vector, f. terms, f. constant)
1984- elseif F <: MOI.ScalarQuadraticFunction{T}
1985- quadratic_terms = vcat (f. quadratic_terms, quadratic_prods_vector)
1986- MOI. ScalarQuadraticFunction (quadratic_terms, f. affine_terms, f. constant)
1987- end
1988-
1989- MOI. set (
1990- model. optimizer,
1991- MOI. ObjectiveFunction {MOI.ScalarQuadraticFunction{T}} (),
1992- f_new,
1993- )
1994-
1995- return
1996- end
1997-
1998- function _evaluate_parametric_expression (model:: Optimizer , p:: MOI.VariableIndex )
1999- return model. parameters[p_idx (p)]
2000- end
2001-
2002- function _evaluate_parametric_expression (
2003- model:: Optimizer ,
2004- fparam:: MOI.ScalarAffineFunction{T} ,
2005- ) where {T}
2006- constant = fparam. constant
2007- terms = fparam. terms
2008- evaluated_parameter_expression = zero (T)
2009- for term in terms
2010- coef = term. coefficient
2011- p = term. variable
2012- evaluated_parameter_expression += coef * model. parameters[p_idx (p)]
2013- evaluated_parameter_expression += constant
2014- end
2015- return evaluated_parameter_expression
2016- end
2017-
2018- function MOI. set (
2019- model:: Optimizer ,
2020- :: QuadraticObjectiveCoef ,
2021- (x1, x2):: Tuple{MOI.VariableIndex,MOI.VariableIndex} ,
2022- :: Nothing ,
2023- )
2024- if x1. value > x2. value
2025- aux = x1
2026- x1 = x2
2027- x2 = aux
2028- end
2029- delete! (model. quadratic_objective_cache_product, (x1, x2))
2030- model. quadratic_objective_cache_product_changed = true
2031- return
2032- end
2033-
2034- function MOI. set (
2035- model:: Optimizer ,
2036- :: QuadraticObjectiveCoef ,
2037- (x1, x2):: Tuple{MOI.VariableIndex,MOI.VariableIndex} ,
2038- f_param:: Union{MOI.VariableIndex,MOI.ScalarAffineFunction{T}} ,
2039- ) where {T}
2040- if x1. value > x2. value
2041- aux = x1
2042- x1 = x2
2043- x2 = aux
2044- end
2045- model. quadratic_objective_cache_product[(x1, x2)] = f_param
2046- model. quadratic_objective_cache_product_changed = true
2047- return
2048- end
2049-
2050- function MOI. get (
2051- model:: Optimizer ,
2052- :: QuadraticObjectiveCoef ,
2053- (x1, x2):: Tuple{MOI.VariableIndex,MOI.VariableIndex} ,
2054- )
2055- if x1. value > x2. value
2056- aux = x1
2057- x1 = x2
2058- x2 = aux
2059- end
2060- if haskey (model. quadratic_objective_cache_product, (x1, x2))
2061- return model. quadratic_objective_cache_product[(x1, x2)]
2062- else
2063- throw (
2064- ErrorException (
2065- " Parameter not set in product of variables ($x1 ,$x2 )" ,
2066- ),
2067- )
2068- end
2069- end
2070-
20711946#
20721947# Optimize
20731948#
@@ -2076,13 +1951,6 @@ function MOI.optimize!(model::Optimizer)
20761951 if ! isempty (model. updated_parameters)
20771952 update_parameters! (model)
20781953 end
2079- if (
2080- ! isempty (model. quadratic_objective_cache_product) ||
2081- model. quadratic_objective_cache_product_changed
2082- )
2083- model. quadratic_objective_cache_product_changed = false
2084- _set_quadratic_product_in_obj! (model)
2085- end
20861954 MOI. optimize! (model. optimizer)
20871955 if MOI. get (model, MOI. DualStatus ()) != MOI. NO_SOLUTION &&
20881956 model. evaluate_duals
0 commit comments