tests/testthat/test_ECP_ECOS.R

library(convexjlr)
context("Exponential Cone Programming with JuliaCall in ECOS solver")

## The original Julia version

# x = Variable(4)
# p = satisfy(norm(x) <= 100, exp(x[1]) <= 5, x[2] >= 7, geomean(x[3], x[4]) >= x[2])
# solve!(p, SCSSolver(verbose=0))
# println(p.status)
# x.value

test_that("Results for example of exponential cone programming in ECOS", {
    skip_on_cran()
    convex_setup(backend = "JuliaCall")

    ## The R version with convexjl.R

    x <- Variable(4)
    p <- satisfy(norm(x) <= 100, exp(x[1]) <= 5, x[2] >= 7, geomean(x[3], x[4]) >= x[2])
    cvx_optim(p, solver = "ECOS")

    ## The R version with XRJulia directly

    # ev <- XRJulia::RJulia()

    ## The R version with JuliaCall directly
    ev <- JuliaCall::julia_setup()
    ev$command("using Convex")
    ev$command("using ECOS")
    ev$command("x = Variable(4)")
    ev$command("p = satisfy(norm(x) <= 100, exp(x[1]) <= 5, x[2] >= 7, geomean(x[3], x[4]) >= x[2])")
    ev$command("solve!(p, ECOSSolver())")

    ## Compare the results

    expect_equal(value(x), ev$eval("x.value")) #, .get = TRUE))
})

Try the convexjlr package in your browser

Any scripts or data that you put into this service are public.

convexjlr documentation built on May 2, 2019, 5:28 a.m.