Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from JuliaOpt/jd/parsing
Browse files Browse the repository at this point in the history
Handle changes to comparison parsing in Julia 0.5. Fixes #16
  • Loading branch information
tkelman authored Aug 1, 2016
2 parents 5265a6d + fc98d0a commit 007e5d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
21 changes: 17 additions & 4 deletions src/CoinOptServices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,16 @@ function MathProgBase.loadproblem!(outer::OsilNonlinearModel,
end
while nextrowlinear
constrexpr = MathProgBase.constr_expr(d, row)
@assertequal(constrexpr.head, :comparison)

if VERSION < v"0.5.0-dev+3231"
@assertequal(constrexpr.head, :comparison)
constrlinpart = constrexpr.args[end - 2]
else
@assertequal(constrexpr.head, :call)
constrlinpart = constrexpr.args[2]
end

#(lhs, rhs) = constr2bounds(constrexpr.args...)
constrlinpart = constrexpr.args[end - 2]
@assertequal(constrlinpart.head, :call)
constrlinargs = constrlinpart.args
@assertequal(constrlinargs[1], :+)
Expand Down Expand Up @@ -341,9 +348,15 @@ function MathProgBase.loadproblem!(outer::OsilNonlinearModel,
nl = new_child(nonlinearExpressions, "nl")
set_attribute(nl, "idx", row - 1) # OSiL is 0-based
constrexpr = MathProgBase.constr_expr(d, row)
@assertequal(constrexpr.head, :comparison)
#(lhs, rhs) = constr2bounds(constrexpr.args...)
expr2osnl!(nl, constrexpr.args[end - 2])
if VERSION >= v"0.5.0-dev+3231" && constrexpr.head == :call
@assert(constrexpr.args[1] in [:<=, :(==), :>=])
constrpart = constrexpr.args[2]
else
@assertequal(constrexpr.head, :comparison)
constrpart = constrexpr.args[end - 2]
end
expr2osnl!(nl, constrpart)
end
end

Expand Down
38 changes: 25 additions & 13 deletions src/translations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ jl2osnl_binary = Dict(
:rem => "rem",
:^ => "power",
:.^ => "power",
:log => "log")
:log => "log",
:< => "lt",
:<= => "leq",
: => "leq",
:> => "gt",
:>= => "geq",
: => "geq",
:(==) => "eq",
:!= => "neq",
: => "neq")
# and, or, xor, not?

jl2osnl_unary = Dict(
:- => "negate",
Expand Down Expand Up @@ -48,17 +58,19 @@ for op in [:abs, :sqrt, :floor, :factorial, :exp, :sign, :erf,
jl2osnl_unary[op] = string(op)
end

jl2osnl_comparison = Dict(
:< => "lt",
:<= => "leq",
: => "leq",
:> => "gt",
:>= => "geq",
: => "geq",
:(==) => "eq",
:!= => "neq",
: => "neq")
# and, or, xor, not?
if VERSION < v"0.5.0-dev+3231"
jl2osnl_comparison = Dict(
:< => "lt",
:<= => "leq",
: => "leq",
:> => "gt",
:>= => "geq",
: => "geq",
:(==) => "eq",
:!= => "neq",
: => "neq")
# and, or, xor, not?
end

jl2osil_vartypes = Dict(:Cont => "C", :Int => "I", :Bin => "B",
:SemiCont => "D", :SemiInt => "J", :Fixed => "C")
Expand Down Expand Up @@ -155,7 +167,7 @@ function expr2osnl!(parent, ex::Expr)
elseif head == :ref
child = var2osnl!(parent, args)
elseif head == :comparison
if numargs == 3
if VERSION < v"0.5.0-dev+3231" && numargs == 3
if haskey(jl2osnl_comparison, args[2])
child = new_child(parent, jl2osnl_comparison[args[2]])
expr2osnl!(child, args[1])
Expand Down

0 comments on commit 007e5d9

Please sign in to comment.