Skip to content

Commit

Permalink
fix issues with nonlinear mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jalving committed Feb 4, 2024
1 parent 01d8b1c commit ccf1c89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
48 changes: 25 additions & 23 deletions src/moi_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,40 +291,42 @@ function _create_graph_moi_func(
jump_func::JuMP.GenericNonlinearExpr
)
moi_func_graph = deepcopy(moi_func)
_update_nonlinear_func!(backend, moi_func_graph, jump_func)
return moi_func_graph
end

function _update_nonlinear_func!(
backend::GraphMOIBackend,
moi_func::MOI.ScalarNonlinearFunction,
jump_func::JuMP.GenericNonlinearExpr
)
println("args: ", jump_func.args)
for i = 1:length(jump_func.args)
jump_arg = jump_func.args[i]
moi_arg = moi_func.args[i]
println("jump_arg: ", jump_arg)
println("typeof(jump_arg): ", typeof(jump_arg))
println("moi_arg: ", moi_arg)

if jump_arg isa Number
continue
elseif typeof(jump_arg) == NodeVariableRef
moi_func.args[i] = backend.element_to_graph_map[jump_arg]
moi_func_graph.args[i] = backend.element_to_graph_map[jump_arg]
else
_update_nonlinear_func!(backend, moi_arg, jump_arg)
new_func = _create_graph_moi_func(backend, moi_arg, jump_arg)
moi_func_graph.args[i] = new_func
end
# if jump_arg isa JuMP.GenericNonlinearExpr
# println("updating nonlinear arg")
# _update_nonlinear_func!(backend, moi_arg, jump_arg)
# elseif typeof(jump_arg) == NodeVariableRef
# moi_func.args[i] = backend.element_to_graph_map[jump_arg]
# end
end
return
#_update_nonlinear_func!(backend, moi_func_graph, jump_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,
Expand Down
3 changes: 0 additions & 3 deletions src/optiedge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,13 @@ function _moi_add_edge_constraint(
cref = ConstraintRef(edge, constraint_index, JuMP.shape(con))

# update graph backends
println("con to add: ", con)
for graph in containing_optigraphs(edge)
# add backend variables if linking across optigraphs
_add_backend_variables(graph_backend(graph), jump_func)

# update the moi function variable indices
moi_func_graph = _create_graph_moi_func(graph_backend(graph), moi_func, jump_func)

#println("moi_func_graph: ", moi_func_graph)

# add the constraint to the backend
_add_element_constraint_to_backend(
graph_backend(graph),
Expand Down
1 change: 0 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ function _extract_variables(func::JuMP.GenericNonlinearExpr)
append!(vars, _extract_variables(func_arg))
end
end
println("extracted vars ", vars)
return vars
end

0 comments on commit ccf1c89

Please sign in to comment.