Skip to content

Instantly share code, notes, and snippets.

@mlubin
mlubin / high-level design.md
Last active December 14, 2015 21:59
Prototype design for linear(/mixed-integer/quadradic/+) programming interface in Julia

There are four different levels at which users may interact with LP solvers (top to bottom):

  • Algebraic modeling languages such as MathProg.jl
  • Matlab-style linprog functions, provide problem as input and retrieve solution in one function call. Maybe put this in Optim.jl.
  • Standard low-level interface. This is a state-based interface with a solver object where the user may dynamically add and remove variables and constraints, repeatedly resolve the problem with hotstarts (important for decomposition algorithms), etc. Inspired by COIN-OR's OSI project, but hopefully we can improve on some of their mistakes.
  • Solver-specific low-level interface. Typically a lightweight wrapper around the solver's C interface. Names should follow the solver's convention.

Implementers of solver interfaces (or solvers written in Julia) are responsible for providing the standard low-level interface (not linprog). The linprog interface will be built on top of the standard low-level interface.

function genF(Q)
f(x) = (1/2)*dot(x,Q*x)
fgrad(x) = Q*x
return f, fgrad
end
function gradDescent(f, fgrad, startX)
const stepsize = 1.0
const sigma = 0.1
@mlubin
mlubin / main.jl
Last active August 29, 2015 14:01
import Optim
function clogit_ll{R}(coeff::Vector{R}, x1, x2, x3, x4, x5, x6,
y1, y2, y3, y4, y5, y6,
T, nObs, nVar)
llit = zero(R)
for i=1:nObs
for t=1:T
@mlubin
mlubin / newton.jl
Last active May 24, 2017 04:40
julia/C microbenchmark
function squareroot(x)
it = x
while abs(it*it - x) > 1e-13
it = it - (it*it-x)/(2it)
end
return it
end
function time_sqrt(x)
const num_iter = 100000
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
using Convex
using ECOS
using SCS
using ConicNonlinearBridge
using Ipopt
x1 = Variable(1)
x2 = Variable(1)
x3 = Variable(1)
x4 = Variable(1)
x5 = Variable(1)
using Mosek, MathProgBase
I = [1,1,2,2,3,3,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,32,33,33,34,34,35,36,37,38,39,40]
J = [14,10,15,11,16,12,13,18,1,21,2,24,3,19,2,22,4,25,5,20,3,23,5,26,6,17,13,17,13,14,15,16,17,18,19,20,21,22,23,24,25,26,7,10,8,11,9,12,1,2,3,4,5,6]
V = [1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,1.0,1.0,-1.0,1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0]
b = [-0.6088331477422722,-0.02852197818671054,-0.9016074145524158,0.4999165215049682,-0.025485683857737418,-0.07276320066249353,0.056565030662414396,-0.07276320066249353,-0.3319954143963322,0.3286736785015988,0.056565030662414396,0.3286736785015988,-0.43682537007384287,1.0516057442061533,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,18.999999999999996,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
var_cones = Any[(:SDP,1:6),(:NonNeg,[13,17
using JuMP, Mosek, FactCheck
sdp_solvers = [MosekSolver(LOG=0)]
include(Pkg.dir("JuMP","test","data","robust_uncertainty.jl"))
facts("[sdp] Robust uncertainty example") do
for solver in sdp_solvers
context("With solver $(typeof(solver))") do
R = 1
d = 3
pcost dcost gap pres dres
0: 3.8500e+03 3.9338e+03 2e+03 1e+00 1e+00
1: 2.0645e+03 2.1700e+03 2e+03 1e+00 1e+00
2: 4.0064e+02 5.8278e+02 2e+03 1e+00 1e+00
3: 2.5441e+02 6.9543e+02 2e+03 9e-01 9e-01
4: 4.3080e+02 1.2381e+03 1e+03 8e-01 8e-01
5: 6.7652e+02 2.0939e+03 1e+03 7e-01 7e-01
6: 8.9445e+02 2.8259e+03 1e+03 6e-01 6e-01
7: 1.2857e+03 4.1114e+03 1e+03 6e-01 6e-01
8: 1.6758e+03 5.4303e+03 1e+03 5e-01 5e-01