diff --git a/src/jump_interop.jl b/src/jump_interop.jl index 2f812ce..1882f9c 100644 --- a/src/jump_interop.jl +++ b/src/jump_interop.jl @@ -255,7 +255,6 @@ function JuMP.GenericQuadExpr{C,NodeVariableRef}( graph::OptiGraph, f::MOI.ScalarQuadraticFunction, ) where {C} - # affine terms quad = JuMP.GenericQuadExpr{C,NodeVariableRef}( JuMP.GenericAffExpr{C,NodeVariableRef}( diff --git a/src/moi_backend.jl b/src/moi_backend.jl index 7352a62..ae0f3d1 100644 --- a/src/moi_backend.jl +++ b/src/moi_backend.jl @@ -265,11 +265,17 @@ function _create_graph_moi_func( coeff = term[1] var1 = term[2] var2 = term[3] + + # TODO: debug why i have to do this; the coeff is 1, but it prints as 2 + if var1 == var2 + coeff *= 2 + end + var_idx_1 = backend.element_to_graph_map[var1] var_idx_2 = backend.element_to_graph_map[var2] moi_func_graph.quadratic_terms[i] = MOI.ScalarQuadraticTerm{Float64}( - coeff, + coeff, var_idx_1, var_idx_2 ) @@ -280,7 +286,10 @@ function _create_graph_moi_func( coeff = term[1] var = term[2] backend_var_idx = backend.element_to_graph_map[var] - moi_func_graph.affine_terms[i] = MOI.ScalarAffineTerm{Float64}(coeff, backend_var_idx) + moi_func_graph.affine_terms[i] = MOI.ScalarAffineTerm{Float64}( + coeff, + backend_var_idx + ) end return moi_func_graph end @@ -307,26 +316,6 @@ function _create_graph_moi_func( return moi_func_graph end -# function _update_nonlinear_func!( -# backend::GraphMOIBackend, -# moi_func::MOI.ScalarNonlinearFunction, -# jump_func::JuMP.GenericNonlinearExpr -# ) -# for i = 1:length(jump_func.args) -# jump_arg = jump_func.args[i] -# moi_arg = moi_func.args[i] -# if jump_arg isa Number -# continue -# elseif typeof(jump_arg) == NodeVariableRef -# moi_func.args[i] = backend.element_to_graph_map[jump_arg] -# else -# new_func = _create_graph_moi_func(backend, moi_arg, jump_arg) -# moi_func.args[i] = new_func -# end -# end -# return -# end - # add variables to a backend for linking across subgraphs function _add_backend_variables( backend::GraphMOIBackend, diff --git a/src/optigraph.jl b/src/optigraph.jl index 53d99af..f8e16f4 100644 --- a/src/optigraph.jl +++ b/src/optigraph.jl @@ -338,13 +338,11 @@ function _moi_set_objective_function( expr::JuMP.GenericQuadExpr{C,NodeVariableRef} ) where C <: Real moi_func = JuMP.moi_function(expr) - # add variables to backend if using subgraphs _add_backend_variables(graph_backend(graph), expr) # update the moi function variable indices graph_moi_func = _create_graph_moi_func(graph_backend(graph), moi_func, expr) - MOI.set( graph_backend(graph), MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{C}}(),