Skip to content

Instantly share code, notes, and snippets.

View odow's full-sized avatar

Oscar Dowson odow

View GitHub Profile
@odow
odow / Manifest.toml
Created March 21, 2022 04:23
Symbolics.jl and JuMP
# This file is machine-generated - editing it directly is not advised
[[AbstractTrees]]
git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.3.4"
[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "af92965fb30777147966f58acb05da51c5616b5f"
@odow
odow / simple_jump.jl
Last active September 30, 2019 08:47
using JuMP, Ipopt
function minimize(
f::Function,
A::Matrix,
b::Vector,
optimizer::JuMP.OptimizerFactory
)
M, N = size(A)
@assert length(b) == M
Academic license - for non-commercial use only
Gurobi Optimizer version 7.5.2 build v7.5.2rc1 (mac64)
Copyright (c) 2017, Gurobi Optimization, Inc.
Read MPS format model from file server_file.mps
Reading time = 0.00 seconds
mdpDEFthreshold: 507 rows, 165 columns, 3561 nonzeros
Optimize a model with 507 rows, 165 columns and 3561 nonzeros
Variable types: 121 continuous, 44 integer (44 binary)
@odow
odow / nlp_parser.jl
Last active January 17, 2019 20:16
Create a NLPEvaluator from expressions
using Calculus, MathOptInterface
const MOI = MathOptInterface
# ==============================================================================
#
# First we construct a simple subtype of MOI.AbstractNLPEvaluator. We use it
# to provide thin overloads for all the MOI NLP functions.
#
# ==============================================================================
@odow
odow / gurobi_deletion.jl
Created September 2, 2018 21:28
Gurobi: delete variable in quadratic expression
using Gurobi
model = Gurobi.Model(Gurobi.Env(), "model")
Gurobi.add_cvar!(model, 0.0, 0.0, 100.0)
Gurobi.add_cvar!(model, 0.0, 0.0, 100.0)
Gurobi.update_model!(model)
Gurobi.add_constr!(model, [1, 2], [1.0, 2.0], '=', 2.0)
Gurobi.update_model!(model)
@everywhere begin
using SDDP, JuMP, SDDiP, Gurobi
srand(myid() * 111111)
const NUMBER_OF_DAYS = 3 # Number of days
const NUMBER_OF_ROOMS = 2 # Number of rooms (room 1 cost 1 dollar, room 2 cost 2 dollar etc.)
const NUMBER_OF_REQUESTS = 5 # Number of requests (i.e. stages)
# revenue
using BenchmarkTools
struct VarRef
x::UInt64
end
function f(A, B)
s = 0
for y in Y
s += X[y]
end
C:\Users\odow003>julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32
using JuMP, Clp
n = 4
m = 3
# Investment cost
ic = [16, 5, 32, 2]
# Fuel cost
C = [25, 80, 6.5, 160]
# Duration
T = [8760, 7000, 1500] / 8760
# First comment out lines https://github.com/JuliaOpt/Gurobi.jl/blob/master/src/GurobiSolverInterface.jl#L246-L254
using Gurobi,JuMP
# Create the JuMP Model:
# min 0
# s.t.
# x >= 1
# x <= 3
m=Model(solver=GurobiSolver())
@variable(m, x)