Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Merge 3eda667 into 8b4d362
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 25, 2019
2 parents 8b4d362 + 3eda667 commit e92ae9c
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: julia
coveralls: true
os:
- linux
julia:
- 0.5
- nightly
- 1.0
- 1.1
- 1.2
- 1.3
notifications:
email: false
sudo: false
addons:
apt_packages:
- libgmp-dev
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.init(); Pkg.add("JuMP"); Pkg.clone(pwd()); Pkg.build("JuMPChance"); Pkg.test("JuMPChance"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("JuMPChance")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
23 changes: 23 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "JuMPChance"
uuid = "bbd82366-0c69-5eef-bed9-5a0dd17fc720"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MathProgBase = "fdba3010-5040-5b88-9595-932c9decdf73"

[compat]
Distributions = "0.21"
ECOS = "0.10"
JuMP = "0.18"
MathProgBase = "0.7.7"
julia = "1"

[extras]
GLPKMathProgInterface = "3c7084bd-78ad-589a-b5bb-dbd673274bea"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["GLPKMathProgInterface", "Random", "Test"]
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

37 changes: 23 additions & 14 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 1.0
- julia_version: 1.1
- julia_version: 1.2
- julia_version: 1.3

platform:
- x86 # 32-bit
- x64 # 64-bit

# This is left as an example for the next big version switch.
#matrix:
# allow_failures:
# - julia_version: latest

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
Expand All @@ -12,17 +26,12 @@ notifications:
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.clone(pwd(), \"JuMPChance\"); Pkg.build(\"JuMPChance\");"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"JuMPChance\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
14 changes: 4 additions & 10 deletions src/JuMPChance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export ChanceModel,
@indepnormal

# stores extension data inside JuMP Model
type CCData
mutable struct CCData
# pure chance constraints
chanceconstr
# robust chance constraints
Expand Down Expand Up @@ -45,7 +45,7 @@ end


# pointer back to JuMP model and r.v. index
type IndepNormal <: JuMP.AbstractJuMPScalar
mutable struct IndepNormal <: JuMP.AbstractJuMPScalar
m::Model
idx::Int
end
Expand All @@ -71,19 +71,13 @@ function getmean(v::IndepNormal)
return ccdata.RVmeans[v.idx]
end

@Base.deprecate getMean getmean

function getvariance(v::IndepNormal)
ccdata = getCCData(v.m)
return ccdata.RVvars[v.idx]
end

@Base.deprecate getVariance getvariance

getstdev(v::IndepNormal) = sqrt(getvariance(v))

@Base.deprecate getStdev getstdev

const CCAffExpr = JuMP.GenericAffExpr{AffExpr,IndepNormal}

CCAffExpr() = CCAffExpr(IndepNormal[],AffExpr[],AffExpr())
Expand Down Expand Up @@ -132,7 +126,7 @@ function Base.show(io::IO,a::RandomAffExpr)
print(io, string(join(strs," + "), " + ", string(a.constant)))
end

type ChanceConstr <: JuMP.AbstractConstraint
mutable struct ChanceConstr <: JuMP.AbstractConstraint
ccexpr::CCAffExpr
sense::Symbol # :(<=) or :(>=), right-hand side assumed to be zero
with_probability::Float64 # with this probability *or greater*
Expand Down Expand Up @@ -194,7 +188,7 @@ function JuMP.show(io::IO,c::ChanceConstr)
end
end

type TwoSideChanceConstr <: JuMP.AbstractConstraint
mutable struct TwoSideChanceConstr <: JuMP.AbstractConstraint
ccexpr::CCAffExpr
lb::AffExpr
ub::AffExpr
Expand Down
11 changes: 2 additions & 9 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ using Base.Meta

macro indepnormal(m, x, mean, var)
m = esc(m)
kwsymbol = VERSION < v"0.6.0-dev.1934" ? :kw : :(=) # changed by julia PR #19868
@assert isexpr(mean,kwsymbol) && mean.args[1] == :mean
@assert isexpr(var,kwsymbol) && var.args[1] == :var
@assert isexpr(mean, :(=)) && mean.args[1] == :mean
@assert isexpr(var, :(=)) && var.args[1] == :var
mean = esc(mean.args[2])
var = esc(var.args[2])

Expand Down Expand Up @@ -41,12 +40,6 @@ macro indepnormal(m, x, mean, var)
end
end

macro defIndepNormal(m, x, mean, var)
Base.warn_once("@defIndepNormal is deprecated. Use @indepnormal instead")
return :(@indepnormal($(esc(m)),$(esc(x)),$(esc(mean)),$(esc(var))))
end
export @defIndepNormal

# Extensions to make JuMP macros work with chance constraints

function JuMP.constructconstraint!(faff::CCAffExpr, sense::Symbol)
Expand Down
42 changes: 21 additions & 21 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function solvehook(m::Model; suppress_warnings=false, method=:Refomulate,lineari
end
continue
end

# add auxiliary variables for variance of each term
varterm = @variable(m, [1:nterms])
defvar = @constraint(m, [i=1:nterms], varterm[i] == getstdev(ccexpr.vars[i])*ccexpr.coeffs[i])
Expand Down Expand Up @@ -198,7 +198,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
twosidechancevarterm = Dict()
linearizechanceconstr = Int[]
linearizetwosidechanceconstr = Int[]

# one sided chance constraints case
for i in 1:nchanceconstr
cc = ccdata.chanceconstr[i]
Expand Down Expand Up @@ -229,7 +229,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
defvar = @constraint(m, [k=1:nterms], chancevarterm[i][k] == getstdev(ccexpr.vars[k])*ccexpr.coeffs[k])
end
end

# Two sided chance constraints with :Cuts option
lbvar = @variable(m, [1:ntwosidechanceconstr])
ubvar = @variable(m, [1:ntwosidechanceconstr])
Expand Down Expand Up @@ -293,7 +293,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::

nviol = 0
nviol_obj = 0

# check violated chance constraints
for i in linearizechanceconstr
cc::ChanceConstr = ccdata.chanceconstr[i]
Expand Down Expand Up @@ -338,7 +338,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
end
end
end

# check violated two sided chance constraint
for i in linearizetwosidechanceconstr
cc::TwoSideChanceConstr = ccdata.twosidechanceconstr[i]
Expand Down Expand Up @@ -401,7 +401,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
end
return nviol, nviol_obj
end

do_lazy = has_integers && lazy_constraints
(debug && !do_lazy) && println("Solving deterministic model")

Expand All @@ -415,7 +415,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
#toc()
return status
end

if status != :Optimal
return status
end
Expand All @@ -425,7 +425,7 @@ function solvecc_cuts(m::Model, suppress_warnings::Bool, probability_tolerance::
while niter < iteration_limit

nviol, nviol_obj = addcuts(nothing)

if nviol == 0 && nviol_obj == 0
silent || println("Done after $niter iterations")
#toc()
Expand Down Expand Up @@ -511,11 +511,11 @@ function solverobustcc_cuts(m::Model, suppress_warnings::Bool, probability_toler
debug && println("Variance deviations: ", vars_deviation)

# TODO: special handling for quadratic objectives

debug && println("Solving deterministic model")

status = solve(m, suppress_warnings=suppress_warnings, ignore_solve_hook=true)

if status != :Optimal
return status
end
Expand Down Expand Up @@ -656,14 +656,14 @@ function solverobustcc_cuts(m::Model, suppress_warnings::Bool, probability_toler
end

# We can remove the code for IndexedVector once JuMP issue #340 is resolved.
type IndexedVector{T}
mutable struct IndexedVector{T}
elts::Vector{T}
nzidx::Vector{Int}
nnz::Int
empty::BitArray{1}
end

IndexedVector{T}(::Type{T},n::Integer) = IndexedVector(zeros(T,n),zeros(Int,n),0,trues(n))
IndexedVector(::Type{T},n::Integer) where {T} = IndexedVector(zeros(T,n),zeros(Int,n),0,trues(n))

function addelt!(v::IndexedVector{AffExpr},i::Integer,val::AffExpr)
if v.empty[i] # new index
Expand All @@ -676,7 +676,7 @@ function addelt!(v::IndexedVector{AffExpr},i::Integer,val::AffExpr)
return nothing
end

function addelt!{T}(v::IndexedVector{T},i::Integer,val::T)
function addelt!(v::IndexedVector{T},i::Integer,val::T) where {T}
if v.empty[i] # new index
v.elts[i] = val
v.nzidx[v.nnz += 1] = i
Expand All @@ -687,7 +687,7 @@ function addelt!{T}(v::IndexedVector{T},i::Integer,val::T)
return nothing
end

function Base.empty!{T}(v::IndexedVector{T})
function Base.empty!(v::IndexedVector{T}) where {T}
elts = v.elts
nzidx = v.nzidx
empty = v.empty
Expand All @@ -713,7 +713,7 @@ end
# Adapted from JuMP:
# returns a GenericAffExpr with terms merged
# assume that v is zero'd
function merge_duplicates{CoefType <: JuMP.GenericAffExpr}(aff::JuMP.GenericAffExpr{CoefType,IndepNormal}, v::IndexedVector{CoefType}, counts::IndexedVector{Int}, m::Model)
function merge_duplicates(aff::JuMP.GenericAffExpr{CoefType,IndepNormal}, v::IndexedVector{CoefType}, counts::IndexedVector{Int}, m::Model) where {CoefType <: JuMP.GenericAffExpr}
ccdata = getCCData(m)

resize!(v, ccdata.numRVs)
Expand All @@ -734,8 +734,8 @@ function merge_duplicates{CoefType <: JuMP.GenericAffExpr}(aff::JuMP.GenericAffE
for ind in 1:length(aff.coeffs)
addelt!(v, aff.vars[ind].idx, aff.coeffs[ind])
end
vars = Array{IndepNormal}(v.nnz)
coeffs = Array{CoefType}(v.nnz)
vars = Array{IndepNormal}(undef, v.nnz)
coeffs = Array{CoefType}(undef, v.nnz)
for i in 1:v.nnz
idx = v.nzidx[i]
vars[i] = IndepNormal(m,idx)
Expand All @@ -748,17 +748,17 @@ function merge_duplicates{CoefType <: JuMP.GenericAffExpr}(aff::JuMP.GenericAffE

end

function merge_duplicates{CoefType <: Number}(aff::JuMP.GenericAffExpr{CoefType,IndepNormal}, v::IndexedVector{CoefType}, m::Model)
function merge_duplicates(aff::JuMP.GenericAffExpr{CoefType,IndepNormal}, v::IndexedVector{CoefType}, m::Model) where {CoefType <: Number}
ccdata = getCCData(m)

resize!(v, ccdata.numRVs)
for ind in 1:length(aff.coeffs)
var = aff.vars[ind]
is(var.m, m) || error("Variable does not belong to this model")
var.m === m || error("Variable does not belong to this model")
addelt!(v, aff.vars[ind].idx, aff.coeffs[ind])
end
vars = Array{IndepNormal}(v.nnz)
coeffs = Array{CoefType}(v.nnz)
vars = Array{IndepNormal}(undef, v.nnz)
coeffs = Array{CoefType}(undef, v.nnz)
for i in 1:v.nnz
idx = v.nzidx[i]
vars[i] = IndepNormal(m,idx)
Expand Down
2 changes: 0 additions & 2 deletions test/REQUIRE

This file was deleted.

0 comments on commit e92ae9c

Please sign in to comment.