Created
May 24, 2019 13:30
-
-
Save ianfiske/acbc4f39216b753bfea01f7b66a95f64 to your computer and use it in GitHub Desktop.
Test Module for Parametron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestParametron | |
# create a MathOptInterface optimizer instance | |
using OSQP | |
optimizer = OSQP.Optimizer() | |
# create a Parametron.Model, which holds problem information | |
using Parametron | |
using Random, LinearAlgebra | |
function model() | |
model = Model(optimizer) | |
# create decision variables and parameters | |
n = 8; m = 2 | |
x = [Variable(model) for _ = 1 : n] | |
A = Parameter(rand!, zeros(n, n), model) | |
b = Parameter(rand!, zeros(n), model) | |
C = Parameter(rand!, zeros(m, n), model) | |
d = Parameter(zeros(m), model) do d | |
# do syntax makes it easy to create custom Parameters | |
rand!(d) | |
d .*= 2 | |
end | |
# the @expression macro can be used to create 'lazy' expressions, | |
# which can be used in constraints or the objective function, and | |
# can be evaluated at a later time, automatically updating the | |
# Parameters in the process (if needed). | |
residual = @expression A * x - b | |
# set the objective function | |
@objective(model, Minimize, residual ⋅ residual) | |
# add the constraints. You could have multiple @constraint calls | |
# as well. ==, <=, and >= are supported. | |
@constraint(model, C * x == d) | |
model | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include("parametron_test_module.jl") | |
using BenchmarkTools | |
using Parametron | |
model = TestParametron.model() | |
Parametron.solve!(model) | |
@btime Parametron.solve!(model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment