Skip to content

Commit

Permalink
managed_scip: fix storage of power exponent
Browse files Browse the repository at this point in the history
 - don't use separate EXPR_CONST
 - this would lead to memory leak
 - see discussion at scipopt/CSIP#28
  • Loading branch information
rschwarz committed Feb 22, 2019
1 parent eda856e commit f17720e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/managed_scip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ function add_nonlinear_constraint(mscip::ManagedSCIP, operators::Vector{SCIP_Exp
elseif op == SCIP_EXPR_REALPOWER
nchildren == 2 || error("Need two children for op. $(op)!")
base = exprs[children[offsets[i]]]
exponent_expr = children[offsets[i] + 1] # is SCIP_EXPR_CONST,
exponent = values[children[offsets[exponent_expr]]] # directly get value
exponent = values[children[offsets[i] + 1]]
@SC SCIPexprCreate(SCIPblkmem(mscip), expr__, op, base, exponent)
elseif op == SCIP_EXPR_DIV
nchildren == 2 || error("Need two children for op. $(op)!")
Expand Down
8 changes: 4 additions & 4 deletions test/managed_scip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ end
# abspower: y == sign(x) * |x|^2 ( == x * |x| )
a = SCIP.add_abspower_constraint(mscip, x, 0.0, 2.0, y, -1.0, 0.0, 0.0)
# nonlinear: x^0.2 == 1
_operators = [SCIP.SCIP_EXPR_VARIDX, SCIP.SCIP_EXPR_CONST, SCIP.SCIP_EXPR_REALPOWER]
_offsets = [1, 2, 3, 5]
_children = [x.val, 1, 1, 2] # extract integer from VarRef!
_values = [ 0.2]
_operators = [SCIP.SCIP_EXPR_VARIDX, SCIP.SCIP_EXPR_REALPOWER]
_offsets = [1, 2, 4]
_children = [x.val, 1, 1] # extract integer from VarRef!
_values = [0.2]
n = SCIP.add_nonlinear_constraint(mscip, _operators, _offsets,
_children, _values, 1.0, 1.0)

Expand Down

0 comments on commit f17720e

Please sign in to comment.