Skip to content

Instantly share code, notes, and snippets.

View odow's full-sized avatar

Oscar Dowson odow

View GitHub Profile
@odow
odow / defNLExpr
Created May 27, 2015 16:57
Unexpected behaviour of @defNLExpr in Julia/JuMP.jl
m1 = Model(solver=IpoptSolver(print_level=0))
@defVar(m1, x1)
@defNLExpr(myexpr1[i=1:2], i * sin(x1))
@addNLConstraint(m1, myexpr1[1] == 0.5)
solve(m1)
println("x1 = $(getValue(x1))")
println("Analytic: x = $(asin(0.5))")
# x1 = 0.5235987687270579
# Analytic: x = 0.5235987755982989
@odow
odow / bonmin.sol
Last active August 29, 2015 14:23
Ipopt returns infeasible solution but says it has found optimal
bonmin: Optimal
Options
3
1
1
0
418
0
This file has been truncated, but you can view the full file.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WinMerge File Compare Report</title>
<style type="text/css">
<!--
td,th {font-size: 12pt;}
.ln {text-align: right; background-color: lightgrey;}
using AmplNLWriter
using JuMP
function foo(want_to_work)
a, b= 1, 0.8
m = Model(solver=IpoptNLSolver(Dict{ASCIIString, Any}("print_level"=>1)))
@defVar(m, 0 <= x <= 1)
@defVar(m, 0 <= y <= 1)
@odow
odow / CPU timeout
Last active September 23, 2015 03:19
Acceptable Level Termination
Ipopt 3.12.2: Maximum CPU Time Exceeded.
Options
3
1
1
0
2503
2503
@odow
odow / model.jl
Created September 23, 2015 23:18
.nl min function
# uncomment lines 9, 79 in nl_params.jl
using JuMP, AmplNLWriter
m = Model(solver=IpoptNLSolver())
@defVar(m, -1 <= x <= 1)
@setNLObjective(m, Max, min( x, -x, 0.5x-0.25 ))
solve(m)
@odow
odow / 0_julia.lp
Last active September 19, 2016 05:13
Gurobi Bug
Maximize
C4
Subject To
R0: C2 = 0.5
R1: - 4.1 C0 + C1 = 0
R2: 5.1 C0 - C2 + C3 >= -0.1
R3: - 5.1 C0 + C2 + C3 >= 0.1
R4: - 0.230438 C0 + C2 + C4 <= 3.9695627
Bounds
-infinity <= C0 <= 1
@odow
odow / main.py
Last active September 25, 2016 00:02
Gurobi Bug v6.5.2
from gurobipy import *
# This function mimics the JuMP functionality whereby it always
# sets the objective coefficients to the JuMP representation of
# what the coefficients should be...
def JuMPsolve(m, objective_coefficients):
# Set the objective coefficients
m.setAttr("Obj", m.getVars(), objective_coefficients)
# Update the model just to be safe
m.update()
@odow
odow / correct_model.lp
Last active September 29, 2016 22:38
Bug in Gurobi v6.5.2 and earlier
Minimize
- C2
Subject To
R0: C0 + C1 >= 0
R1: 2 C0 - C1 >= 0
R2: C2 >= -2
R3: C0 - C2 >= 0
R4: - 1.000001 C0 + C1 - C2 >= 0
Bounds
C0 <= 1
using JuMP
abstract VariableDomain
immutable Continuous <: VariableDomain
lower::Float64
upper::Float64
end
Continuous() = Continuous(-Inf, Inf)
Continuous(;lowerbound=-Inf, upperbound=Inf) = Continuous(lowerbound, upperbound)
function setdomain!(m::JuMP.Model, x, c::Continuous)
m.colLower[x.col] = max(m.colLower[x.col], c.lower)