Skip to content

Instantly share code, notes, and snippets.

View IainNZ's full-sized avatar

Iain Dunning IainNZ

View GitHub Profile
function iain_magic(n::Int)
if n % 2 == 1
# Odd-order magic square
# http://en.wikipedia.org/wiki/Magic_square#Method_for_constructing_a_magic_square_of_odd_order
M = zeros(Int, n, n)
for I = 1:n, J = 1:n # row, column
@inbounds M[I,J] = n*((I+J-1+div(n,2))%n) + ((I+2J-2)%n) + 1
end
return M
elseif n % 4 == 0
function genspmat2(N)
iseven(N) && error("even N not allowed")
# Determine memory usage
k = N^2
for i in 1:N^2
if i > N
k += 2
elseif i > 1
Julia
getObjectiveValue(m) => 118.11250034248698
norm((getValue(x))[:]) => 100.0
callbacks => 1041
minimum(times) => 2.275295964
median(times) => 2.3760397215
mean(times) => 2.3844805166
dummy => 3.0e8
@IainNZ
IainNZ / gist:aa75b3298d0ad6a70d86
Created October 20, 2014 03:45
N20, R50, MIPGap=0.01, Threads=1
PYTHON
2651
-75.3212163
49.8698305592
min 7.85425305367
mean 7.98054280281
75656742.8543
cb_work_time/ITERS 1.93139100075e-06
@IainNZ
IainNZ / sma.jl
Last active August 29, 2015 14:10
function sma_original(avect, numPer)
numEle = length(avect)
tout = Array(Float32, numEle)
for ndx = 1:numEle
tsum = 0.0
begndx = max(1, ndx - numPer)
for slicendx = begndx:ndx
tsum += avect[slicendx]
end
tout[ndx] = tsum / float32(numPer)
@IainNZ
IainNZ / goddard.jl
Created February 13, 2015 18:40
Goddard rocket
#############################################################################
# JuMP
# An algebraic modelling langauge for Julia
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################
# goddard.jl
#
# Goddard Rocket control problem from:
# Benchmarking Optimization Software with COPS 3.0
# http://www.mcs.anl.gov/~more/cops/cops3.pdf
@IainNZ
IainNZ / robot.dat
Created February 13, 2015 22:45
Robot Arm
param max_u_rho := 1;
param max_u_the := 1;
param max_u_phi := 1;
param L := 5;
let tf := 1.0;
let {k in 0..nh} rho[k] := 4.5;
let {k in 0..nh} the[k] := (2*pi/3)*(k/nh)^2;
@IainNZ
IainNZ / lsp.ipynb
Created February 13, 2015 23:10
LargestSmallestPolygon
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@IainNZ
IainNZ / nightlynames.txt
Created February 28, 2015 23:02
Exported names
AffineTransforms.tformscale
AffineTransforms.tformtranslate
AffineTransforms.tformfwd3rd
AffineTransforms.tformrigid
AffineTransforms.rotationmatrix
AffineTransforms.tformrotate
AffineTransforms.tforminv!
AffineTransforms.rotation3
AffineTransforms.rotationparameters
AffineTransforms.AffineTransforms
@IainNZ
IainNZ / jumprepl.jl
Created April 21, 2015 01:21
JuMP REPL
using JuMP
_model = Model()
import Base: LineEdit, REPL
function handle_line(line)
if line[1:3] == "Var"
Base.parse_input_line("@defVar(_model,$(line[5:end]))")
elseif line[1:3] == "Max" || line[1:3] == "Min"