Skip to content

Commit

Permalink
Smarter code generation in constraint macros (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
joehuchette authored Dec 12, 2016
1 parent 4dd662a commit 3dd548e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,14 @@ macro constraint(args...)
end
return assert_validmodel(m, quote
$(getloopedcode(variable, code, condition, idxvars, idxsets, idxpairs, :ConstraintRef))
!$anonvar && registercon($m, $quotvarname, $variable)
$(anonvar ? variable : :($escvarname = $variable))
$(if anonvar
variable
else
quote
registercon($m, $quotvarname, $variable)
$escvarname = $variable
end
end)
end)
end

Expand Down Expand Up @@ -1143,8 +1149,14 @@ macro NLconstraint(m, x, extra...)
initNLP($m)
$m.internalModelLoaded = false
$looped
!$anonvar && registercon($m, $quotvarname, $variable)
$(anonvar ? variable : :($escvarname = $variable))
$(if anonvar
variable
else
quote
registercon($m, $quotvarname, $variable)
$escvarname = $variable
end
end)
end)
end

Expand Down

0 comments on commit 3dd548e

Please sign in to comment.