From 4396a6a62d1eb84b98d754e9d9184f59e83ad3a7 Mon Sep 17 00:00:00 2001 From: "Doake, Raja" Date: Fri, 14 Dec 2018 14:20:05 -0600 Subject: [PATCH 01/12] Julia 1.0 compatibility updates. --- .travis.yml | 6 +- Manifest.toml | 290 +++++++++++++++++++++++ Project.toml | 14 ++ README.md | 6 +- REQUIRE | 2 +- appveyor.yml | 8 +- examples/block_with_wall.jl | 2 +- examples/complementarity.jl | 15 +- examples/friction.jl | 6 +- examples/multicontact_complementarity.jl | 7 +- examples/polyhedra.jl | 12 +- src/ConditionalJuMP.jl | 31 ++- src/macros.jl | 15 +- test/REQUIRE | 2 + test/runtests.jl | 27 ++- 15 files changed, 378 insertions(+), 65 deletions(-) create mode 100644 Manifest.toml create mode 100644 Project.toml diff --git a/.travis.yml b/.travis.yml index 9be64a0..6656c04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: julia os: - linux julia: - - 0.6 + - 1.0 - nightly notifications: email: false @@ -15,7 +15,7 @@ matrix: allow_failures: - julia: nightly branches: - only: + only: - master ## uncomment and modify the following lines to manually install system packages @@ -31,4 +31,4 @@ branches: # - julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' after_success: # push coverage results to Codecov - - julia -e 'cd(Pkg.dir("ConditionalJuMP")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' + - julia -e 'using Pkg; cd(Pkg.dir("ConditionalJuMP")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000..de67ed1 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,290 @@ +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[BufferedStreams]] +deps = ["Compat", "Test"] +git-tree-sha1 = "5d55b9486590fdda5905c275bb21ce1f0754020f" +uuid = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d" +version = "1.0.0" + +[[CRlibm]] +deps = ["Libdl", "Test"] +git-tree-sha1 = "805164abcd31facf3a7e5b7d803a0d16b23329bc" +uuid = "96374032-68de-5a5b-8d9e-752f78720389" +version = "0.7.1" + +[[Calculus]] +deps = ["Compat"] +git-tree-sha1 = "f60954495a7afcee4136f78d1d60350abd37a409" +uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" +version = "0.4.1" + +[[Cbc]] +deps = ["BinDeps", "Compat", "Homebrew", "Libdl", "MathOptInterface", "MathProgBase", "WinRPM"] +path = "/Users/rdoake/.julia/dev/Cbc" +uuid = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" +version = "0.4.3+" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "ec61a16eed883ad0cfa002d7489b3ce6d039bb9a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.4.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "8fc6e166e24fda04b2b648d4260cdad241788c54" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.14.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "c49ec69428ffea0c1d1bbdc63d1a70f5df5860ad" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.7" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[ErrorfreeArithmetic]] +deps = ["Test"] +git-tree-sha1 = "071677938ef6e8f2a51ec0fedf5c312af88e26dc" +uuid = "90fa49ef-747e-5e6f-a989-263ba693cf1a" +version = "0.2.1" + +[[FastRounding]] +deps = ["ErrorfreeArithmetic", "Test"] +git-tree-sha1 = "224175e213fd4fe112db3eea05d66b308dc2bf6b" +uuid = "fa42c844-2597-5d31-933b-ebd51ab2693f" +version = "0.2.0" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "8425a7d4e060bc2ded32d090bce910a187d6cce7" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.9.0" + +[[HTTPClient]] +deps = ["Compat", "LibCURL"] +git-tree-sha1 = "161d5776ae8e585ac0b8c20fb81f17ab755b3671" +uuid = "0862f596-cf2d-50af-8ef4-f2be67dfa83f" +version = "0.2.1" + +[[Homebrew]] +deps = ["BinDeps", "InteractiveUtils", "JSON", "Libdl", "Test", "Unicode"] +git-tree-sha1 = "5582ec74f735cf8d12e562a2e65c47f34063bd51" +uuid = "d9be37ee-ecc9-5288-90f1-b9ca67657a75" +version = "0.7.0" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[IntervalArithmetic]] +deps = ["CRlibm", "FastRounding", "LinearAlgebra", "Markdown", "RecipesBase", "SetRounding", "StaticArrays", "Test"] +git-tree-sha1 = "9ce05b28f218d833aedbed0a53ca35948275f336" +uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" +version = "0.15.0" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[JuMP]] +deps = ["Calculus", "Compat", "ForwardDiff", "Libdl", "MathProgBase", "Pkg", "ReverseDiffSparse", "Serialization"] +git-tree-sha1 = "3bd8e52f7aeb2736a8e1b0d8ae8d01c2c85fea24" +uuid = "4076af6c-e467-56ae-b986-b466b2749572" +version = "0.18.5" + +[[LibCURL]] +deps = ["BinaryProvider", "Compat", "Libdl", "Printf"] +git-tree-sha1 = "6339c87cb76923a3cf947fcd213cbc364355c9c9" +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.4.1" + +[[LibExpat]] +deps = ["Compat"] +git-tree-sha1 = "fde352ec13479e2f90e57939da2440fb78c5e388" +uuid = "522f3ed2-3f36-55e3-b6df-e94fee9b0c07" +version = "0.5.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[Libz]] +deps = ["BufferedStreams", "Random", "Test"] +git-tree-sha1 = "d405194ffc0293c3519d4f7251ce51baac9cc871" +uuid = "2ec943e9-cfe8-584d-b93d-64dcb6d567b7" +version = "1.0.0" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[MathOptInterface]] +deps = ["Compat", "Unicode"] +git-tree-sha1 = "bc8dffc05c4697addeb3c536b303be3f8b16b1ed" +uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +version = "0.6.4" + +[[MathProgBase]] +deps = ["Compat"] +git-tree-sha1 = "3bf2e534e635df810e5f4b4f1a8b6de9004a0d53" +uuid = "fdba3010-5040-5b88-9595-932c9decdf73" +version = "0.7.7" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[Nullables]] +deps = ["Compat"] +git-tree-sha1 = "ae1a63457e14554df2159b0b028f48536125092d" +uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" +version = "0.0.8" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RecipesBase]] +deps = ["Random", "Test"] +git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "0.6.0" + +[[ReverseDiffSparse]] +deps = ["Calculus", "Compat", "DataStructures", "ForwardDiff", "MathProgBase", "NaNMath"] +git-tree-sha1 = "2c445d3c0a519376c950023ac67079bb71418f9b" +uuid = "89212889-6d3f-5f97-b412-7825138f6c9c" +version = "0.8.4" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SetRounding]] +deps = ["Test"] +git-tree-sha1 = "faca28c7937138d560ede5bfef2076d0cdf3584b" +uuid = "3cc68bcd-71a2-5612-b932-767ffbe40ab0" +version = "0.2.0" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "97c4bf0f647488dd7ac01ea12be5885f88762938" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.0" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[WinRPM]] +deps = ["BinDeps", "Compat", "HTTPClient", "LibExpat", "Libdl", "Libz", "URIParser"] +git-tree-sha1 = "2a889d320f3b77d17c037f295859fe570133cfbf" +uuid = "c17dfb99-b4f7-5aad-8812-456da1ad7187" +version = "0.4.2" diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..f0ccf8f --- /dev/null +++ b/Project.toml @@ -0,0 +1,14 @@ +name = "ConditionalJuMP" +uuid = "ea3fa366-ffb9-11e8-1115-f36c47a855cd" +authors = ["Deits, Robin "] +version = "0.1.0" + +[deps] +Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" +IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/README.md b/README.md index 20064a8..2a29bea 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ solve(m) ## Disjunctions -This package also provides the `@ifelse` macro to create simple `if` statements which work both on numbers and on optimization variables. For example, let's write a simple update function: +This package also provides the `@ifelse_conditional` macro to create simple `if` statements which work both on numbers and on optimization variables. For example, let's write a simple update function: ```julia function update(x) @@ -129,11 +129,11 @@ Stacktrace: [1] update(::JuMP.Variable) at ./REPL[3]:2 ``` -But if we replace the `if` statement with `@ifelse`, then the function will magically just work in both cases: +But if we replace the `if` statement with `@ifelse_conditional`, then the function will magically just work in both cases: ```julia function update(x) - @ifelse(x <= 0, + @ifelse_conditional(x <= 0, 1, -1 ) diff --git a/REQUIRE b/REQUIRE index 127447e..438d8b5 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ -julia 0.6 +julia 1.0 JuMP 0.16 0.19 IntervalArithmetic 0.9 diff --git a/appveyor.yml b/appveyor.yml index 213a968..5f99b28 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" @@ -41,7 +41,7 @@ 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(), \"ConditionalJuMP\"); Pkg.build(\"ConditionalJuMP\")" + using Pkg; Pkg.clone(pwd(), \"ConditionalJuMP\"); Pkg.build(\"ConditionalJuMP\")" test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"ConditionalJuMP\")" + - C:\projects\julia\bin\julia -e "using Pkg; Pkg.test(\"ConditionalJuMP\")" diff --git a/examples/block_with_wall.jl b/examples/block_with_wall.jl index 7fa8d36..83594f0 100644 --- a/examples/block_with_wall.jl +++ b/examples/block_with_wall.jl @@ -14,7 +14,7 @@ const Δt = 0.1 const u_max = 10 function update(x::State, u) - contact_force = ifelse(@?(x.q <= 0), + contact_force = ifelse_conditional(@?(x.q <= 0), -k * x.q, zero(x.q)) acceleration = u + contact_force diff --git a/examples/complementarity.jl b/examples/complementarity.jl index cb09307..3c37f96 100644 --- a/examples/complementarity.jl +++ b/examples/complementarity.jl @@ -1,16 +1,17 @@ module Complementarity using JuMP, ConditionalJuMP, Cbc -using Base.Test +using Test +using Pkg # A simple complementarity-based time-stepping rigid body simulation. All # notation is taken from Stewart & Trinkle "An Implicit Time-Stepping Scheme for # Rigid Body Dynamics with Coulomb Friction". This particular example solves # for all N timesteps simultaneously. That's not actually necessary, but it makes -# the code a bit simpler to read. +# the code a bit simpler to read. # # The model consists of a point mass (visualized as a brick) moving in two dimensions -# with gravity and a single planar surface at y = 0. +# with gravity and a single planar surface at y = 0. const h = 0.05 const μ = 0.5 @@ -63,7 +64,7 @@ end """ Simulate the system using the LCP update. This creates and solves a small -model for every time step 1:N. +model for every time step 1:N. """ function simulate(q0, v0, N) q, v = q0, v0 @@ -97,7 +98,7 @@ function optimize(q0, v0, N)::Vector{LCPUpdate{Float64}} end solve(m) getvalue.(results) -end +end q0 = [-1, 0.5] v0 = [2, 0.5] @@ -115,8 +116,8 @@ v = [r.v for r in results1] @test q[end] ≈ [-0.16892500000000002, 0] @test v[end] ≈ [0, 0] -if Pkg.installed("DrakeVisualizer") !== nothing - @eval using DrakeVisualizer; +if haskey(Pkg.installed(), "DrakeVisualizer") + @eval using DrakeVisualizer; @eval using CoordinateTransformations @eval using GeometryTypes DrakeVisualizer.any_open_windows() || DrakeVisualizer.new_window() diff --git a/examples/friction.jl b/examples/friction.jl index aad8bc4..4389329 100644 --- a/examples/friction.jl +++ b/examples/friction.jl @@ -1,5 +1,5 @@ using JuMP, ConditionalJuMP, Cbc -using Base.Test +using Test const viscosity = 100 const stiffness = 100 @@ -8,9 +8,9 @@ const normal_force = stiffness * penetration const μ = 0.5 const Δt = 0.05 -# A very simple stick-slip dynamics. Frictional force is equal to +# A very simple stick-slip dynamics. Frictional force is equal to # -(viscosity * velocity), clipped to lie within the friction cone -# at ±(μ * normal_force). +# at ±(μ * normal_force). function dynamics(x) q = x[1] v = x[2] diff --git a/examples/multicontact_complementarity.jl b/examples/multicontact_complementarity.jl index 68c4003..ce57b93 100644 --- a/examples/multicontact_complementarity.jl +++ b/examples/multicontact_complementarity.jl @@ -3,7 +3,8 @@ module Complementarity using Polyhedra using StaticArrays using JuMP, ConditionalJuMP, Cbc -using Base.Test +using Test +using Pkg rot2(θ) = SMatrix{2, 2}(cos(θ), -sin(θ), sin(θ), cos(θ)) @@ -191,7 +192,7 @@ results2 = optimize(q0, v0, env, N) results_seeded = optimize(q0, v0, env, results1) @test all([r1.q ≈ r2.q for (r1, r2) in zip(results1, results_seeded)]) -if Pkg.installed("DrakeVisualizer") !== nothing +if haskey(Pkg.installed(), "DrakeVisualizer") @eval using DrakeVisualizer; @eval using CoordinateTransformations DrakeVisualizer.any_open_windows() || DrakeVisualizer.new_window() @@ -206,4 +207,4 @@ if Pkg.installed("DrakeVisualizer") !== nothing end end -end \ No newline at end of file +end diff --git a/examples/polyhedra.jl b/examples/polyhedra.jl index c14bc4e..1190386 100644 --- a/examples/polyhedra.jl +++ b/examples/polyhedra.jl @@ -1,8 +1,9 @@ -using Base.Test +using Test using JuMP using Cbc using ConditionalJuMP using Polyhedra +using LinearAlgebra # In this example, we search for the point closest to the origin in the union # of a list of convex polyhedra @@ -14,7 +15,7 @@ function ConditionalJuMP.Conditional(op::typeof(in), x::AbstractVector, P::HRepr (&)([@?(h.a' * x <= h.β) for h in allhalfspaces(P)]...) end -# A simple L1-norm objective we can minimize (since the Cbc +# A simple L1-norm objective we can minimize (since the Cbc function l1norm_objective(x::AbstractVector{Variable}) model = first(x).m y = @variable(model, [1:length(x)], basename="y", lowerbound=0) @@ -26,10 +27,10 @@ function l1norm_objective(x::AbstractVector{Variable}) end # P1 is a box from [-1.5, -1] to [-0.5, 1] -P1 = hrep(vcat(eye(2), -eye(2)), [-0.5, 1, 1.5, 1]) +P1 = hrep(vcat(Matrix(I, 2, 2), -Matrix(I, 2, 2)), [-0.5, 1, 1.5, 1]) # P2 is a box from [1, -1] to [2, 1] -P2 = hrep(vcat(eye(2), -eye(2)), [2., 1, -1, 1]) +P2 = hrep(vcat(Matrix(I, 2, 2), -Matrix(I, 2, 2)), [2., 1, -1, 1]) m = Model(solver=CbcSolver(logLevel=0)) @variable(m, -5 <= x[1:2] <= 5) @@ -40,6 +41,3 @@ m = Model(solver=CbcSolver(logLevel=0)) solve(m) x = getvalue(x) @test x ≈ [-0.5, 0] - - - diff --git a/src/ConditionalJuMP.jl b/src/ConditionalJuMP.jl index 1166c90..eb1e19c 100644 --- a/src/ConditionalJuMP.jl +++ b/src/ConditionalJuMP.jl @@ -6,12 +6,14 @@ using JuMP using JuMP: GenericAffExpr, GenericRangeConstraint, Variable, AbstractJuMPScalar using IntervalArithmetic: Interval import Base: <=, ==, >=, !, &, hash, show +using Printf +using Nullables export @disjunction, @implies, @?, @switch, - @ifelse, + @ifelse_conditional, warmstart!, interval, upperbound, @@ -32,7 +34,7 @@ end """ Naive O(N^2) simplification. Slower for very large expressions, but allocates -no memory and is solidly faster for expressions with < 100 variables. +no memory and is solidly faster for expressions with < 100 variables. """ function simplify_inplace!(e::JuMP.GenericAffExpr{T, Variable}) where T i1 = 1 @@ -62,7 +64,7 @@ end """ O(N) simplification, but with a substantially larger constant cost due to the -need to construct a Dict. +need to construct a Dict. """ function simplify_dict!(e::JuMP.GenericAffExpr{T, Variable}) where T vars = Variable[] @@ -258,8 +260,8 @@ struct IndicatorMap z_idx::Base.RefValue{Int} end -IndicatorMap(m::Model) = IndicatorMap(m, - Dict{Conditional, AffExpr}(), +IndicatorMap(m::Model) = IndicatorMap(m, + Dict{Conditional, AffExpr}(), Vector{Vector{Implication}}(), Ref(1), Ref(1)) @@ -404,17 +406,20 @@ function disjunction!(indmap::IndicatorMap, imps::Union{Tuple, AbstractArray}) push!(indmap.disjunctions, collect(imps)) end -function disjunction!(indmap::IndicatorMap, +function disjunction!(indmap::IndicatorMap, conditions::Union{Tuple{Vararg{Conditional}}, <:AbstractArray{Conditional}}) disjunction!(indmap, (c -> (c => Conditional())).(conditions)) end +Broadcast.broadcastable(i::IndicatorMap) = Ref(i) +Broadcast.broadcastable(m::Model) = Ref(m) + implies!(m::Model, imps::Implication...) = disjunction!(m, imps) implies!(m::Model, imps::Pair...) = implies!(m, convert.(Implication, imps)...) -Base.convert(::Type{Conditional}, ::Void) = Conditional() +Base.convert(::Type{Conditional}, ::Nothing) = Conditional() function implies!(m::Model, imp::Implication) c1, c2 = imp @@ -522,7 +527,7 @@ function switch!(m::Model, args::Pair{<:Conditional, <:AbstractArray}...) end -function Base.ifelse(c::Conditional, v1, v2) +function ifelse_conditional(c::Conditional, v1, v2) @assert size(v1) == size(v2) m = getmodel(c) y = newcontinuousvar(m) @@ -532,7 +537,7 @@ function Base.ifelse(c::Conditional, v1, v2) y end -function Base.ifelse(c::Conditional, v1::AbstractArray, v2::AbstractArray) +function ifelse_conditional(c::Conditional, v1::AbstractArray, v2::AbstractArray) @assert size(v1) == size(v2) m = getmodel(c) y = newcontinuousvar(m, size(v1)) @@ -578,7 +583,7 @@ function warmstart!(m::Model, fix=false) for implications in indmap.disjunctions violations = Nullable{Float64}[_getvalue(first(i)) for i in implications] if !any(isnull, violations) - best_match = indmin(get.(violations)) + best_match = argmin(get.(violations)) for i in eachindex(violations) imp = implications[i] lhs, rhs = imp @@ -624,8 +629,8 @@ end """ Gurobi doesn't understand constant terms in the objective, which can affect the way the relative MIP gap is interpreted. To work around this, -we'll replace the constant term k with an affine term 1*x for a new -variable x fixed to equal k. +we'll replace the constant term k with an affine term 1*x for a new +variable x fixed to equal k. """ function handle_constant_objective!(m::Model) x = @variable(m, basename="x_{objective_constant}") @@ -637,4 +642,4 @@ function handle_constant_objective!(m::Model) end -end \ No newline at end of file +end diff --git a/src/macros.jl b/src/macros.jl index 5f74488..599e72f 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -1,8 +1,9 @@ _conditionalize(ex) = esc(ex) -is_function_broadcast(ex::Expr) = ex.head == :(.) && ex.args[2].head == :tuple +is_function_broadcast(ex::Expr) = ex.head == :(.) && !isa(ex.args[2], QuoteNode) && x.args[2].head == :tuple is_operator_broadcast(ex::Expr) = ex.head == :(call) && isa(ex.args[1], Symbol) && string(ex.args[1])[1] === '.' + function _conditionalize_function_broadcast(ex::Expr) Expr(:call, :_all_conditional, Expr(:call, GlobalRef(Base, :broadcast), :_conditional, esc(ex.args[1]), esc.(ex.args[2].args)...)) end @@ -11,12 +12,13 @@ function _conditionalize_operator_broadcast(ex::Expr) Expr(:call, :_all_conditional, Expr(:call, GlobalRef(Base, :broadcast), :_conditional, esc(Symbol(string(ex.args[1])[2:end])), esc.(ex.args[2:end])...)) end + function _conditionalize(ex::Expr) if is_function_broadcast(ex) _conditionalize_function_broadcast(ex) elseif is_operator_broadcast(ex) _conditionalize_operator_broadcast(ex) - elseif ex.head == :call + elseif ex.head == :call if ex.args[1] == :(=>) Expr(:call, :(=>), _conditionalize.(ex.args[2:end])...) else @@ -27,10 +29,7 @@ function _conditionalize(ex::Expr) end end -macro ?(ex) - _conditionalize(ex) -end - +eval(:(macro $(Symbol("?"))(ex) _conditionalize(ex) end)) macro implies(m, args...) Expr(:call, :implies!, esc(m), _conditionalize.(args)...) @@ -44,6 +43,6 @@ macro switch(args...) Expr(:call, :switch, _conditionalize.(args)...) end -macro ifelse(c, v1, v2) - Expr(:call, :ifelse, _conditionalize(c), v1, v2) +macro ifelse_conditional(c, v1, v2) + Expr(:call, :ifelse_conditional, _conditionalize(c), v1, v2) end diff --git a/test/REQUIRE b/test/REQUIRE index 46bfa7d..c94f125 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,2 +1,4 @@ Cbc +LinearAlgebra Polyhedra 0.3 +Nullables diff --git a/test/runtests.jl b/test/runtests.jl index 3d96e5b..e8b5c02 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,12 +3,15 @@ using ConditionalJuMP: switch!, _getvalue, UnhandledComplementException, hascom using IntervalArithmetic: Interval using JuMP using Cbc -using Base.Test +using Test +using Random +using Pkg +using Nullables # Macro hygiene module MacroHygieneTest using ConditionalJuMP: @? - using Base.Test + using Test function f(x) x + 1 @@ -29,11 +32,11 @@ end ] for (test_name, num_vars_total, num_vars_in_expr, num_trials) in test_cases @testset "$(test_name)" begin - srand(42) m = Model() + seed = Random.seed!(42) @variable m q[1:num_vars_total] for i in 1:num_trials - N = rand(1:num_vars_in_expr) + N = rand(seed, 1:num_vars_in_expr) x = randn(N)' * rand(q, N) s1 = copy(x) s2 = copy(x) @@ -91,7 +94,7 @@ end c2 = @?(x >= 0) c3 = @?(x + 5 <= 5) c4 = @?(x + 1 == 10) - + print(IOBuffer(), c1) print(IOBuffer(), c2) print(IOBuffer(), c1 & c2) @@ -246,7 +249,7 @@ end @testset "dynamics" begin function update(x) - @ifelse(x <= 0, 1, -1) + @ifelse_conditional(x <= 0, 1, -1) end @testset "mixed integer" begin @@ -300,7 +303,7 @@ end @testset "vector" begin function update2(x) - @ifelse(x[1] <= 0, + @ifelse_conditional(x[1] <= 0, [1, 2], [3, 4]) end @@ -318,7 +321,7 @@ end io = IOBuffer() show(io, MIME"text/latex"(), m) seekstart(io) - readstring(io) + read(io, String) end @testset "fixing and unfixing" begin @@ -365,7 +368,7 @@ end c1 = @?(x <= -0.5) c3 = @?(x >= 0.5) c2 = !c1 & !c3 - @implies(m, + @implies(m, c1 => nothing, c2 => y == -0.5, c3 => nothing) @@ -498,7 +501,7 @@ end ((x >= -0.5) & (x <= 0.5)) => [0.2, 2.2], (x >= 0.5) => [0.3, 3.3] ) - end + end @test @inferred(g(-1)) == [0.1, 1.1] @test @inferred(g(0)) == [0.2, 2.2] @@ -619,7 +622,7 @@ end end @testset "block with wall" begin - if Pkg.installed("Gurobi") !== nothing + if haskey(Pkg.installed(), "Gurobi") include("../examples/block_with_wall.jl") run_mpc(State(1.0, -1.0), 10) end @@ -637,7 +640,7 @@ end @testset "constant objective" begin m = Model(solver=CbcSolver()) @variable m x >= 0 - @objective m Min x - 1 + @objective m Min x - 1 ConditionalJuMP.handle_constant_objective!(m) @test getobjective(m).aff.constant == 0 @test sum(m.colCat .== :Cont) == 1 From 4ae1039c0f80546af183d18a81ba9ebe0a1540c2 Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Wed, 19 Dec 2018 10:56:53 -0500 Subject: [PATCH 02/12] Try to fix travis build --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6656c04..c1c80ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,9 @@ branches: # - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi ## uncomment the following lines to override the default test script -#script: -# - julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' +script: + - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' + #- julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' after_success: # push coverage results to Codecov - julia -e 'using Pkg; cd(Pkg.dir("ConditionalJuMP")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' From 024a7b294546d6779ef2bba2827d57c57f768d1b Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Wed, 19 Dec 2018 11:00:39 -0500 Subject: [PATCH 03/12] Try to fix travis build --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c1c80ac..29bc7d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,11 @@ branches: #before_script: # homebrew for mac # - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi -## uncomment the following lines to override the default test script +before_script: + - export PATH=$HOME/.local/bin:$PATH + script: + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' #- julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' after_success: From 47c2405a7a73a45bc2bbc941bd659c69553b1857 Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Wed, 19 Dec 2018 11:03:09 -0500 Subject: [PATCH 04/12] We don't need Manifest.toml and Project.toml and they might be breaking travis --- Manifest.toml | 290 -------------------------------------------------- Project.toml | 14 --- 2 files changed, 304 deletions(-) delete mode 100644 Manifest.toml delete mode 100644 Project.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index de67ed1..0000000 --- a/Manifest.toml +++ /dev/null @@ -1,290 +0,0 @@ -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[BinDeps]] -deps = ["Compat", "Libdl", "SHA", "URIParser"] -git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" -uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" -version = "0.8.10" - -[[BinaryProvider]] -deps = ["Libdl", "Pkg", "SHA", "Test"] -git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.3" - -[[BufferedStreams]] -deps = ["Compat", "Test"] -git-tree-sha1 = "5d55b9486590fdda5905c275bb21ce1f0754020f" -uuid = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d" -version = "1.0.0" - -[[CRlibm]] -deps = ["Libdl", "Test"] -git-tree-sha1 = "805164abcd31facf3a7e5b7d803a0d16b23329bc" -uuid = "96374032-68de-5a5b-8d9e-752f78720389" -version = "0.7.1" - -[[Calculus]] -deps = ["Compat"] -git-tree-sha1 = "f60954495a7afcee4136f78d1d60350abd37a409" -uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" -version = "0.4.1" - -[[Cbc]] -deps = ["BinDeps", "Compat", "Homebrew", "Libdl", "MathOptInterface", "MathProgBase", "WinRPM"] -path = "/Users/rdoake/.julia/dev/Cbc" -uuid = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" -version = "0.4.3+" - -[[CommonSubexpressions]] -deps = ["Test"] -git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" -uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" -version = "0.2.0" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "ec61a16eed883ad0cfa002d7489b3ce6d039bb9a" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "1.4.0" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] -git-tree-sha1 = "8fc6e166e24fda04b2b648d4260cdad241788c54" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.14.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[DiffResults]] -deps = ["Compat", "StaticArrays"] -git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" -uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" -version = "0.0.3" - -[[DiffRules]] -deps = ["Random", "Test"] -git-tree-sha1 = "c49ec69428ffea0c1d1bbdc63d1a70f5df5860ad" -uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "0.0.7" - -[[Distributed]] -deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[ErrorfreeArithmetic]] -deps = ["Test"] -git-tree-sha1 = "071677938ef6e8f2a51ec0fedf5c312af88e26dc" -uuid = "90fa49ef-747e-5e6f-a989-263ba693cf1a" -version = "0.2.1" - -[[FastRounding]] -deps = ["ErrorfreeArithmetic", "Test"] -git-tree-sha1 = "224175e213fd4fe112db3eea05d66b308dc2bf6b" -uuid = "fa42c844-2597-5d31-933b-ebd51ab2693f" -version = "0.2.0" - -[[ForwardDiff]] -deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] -git-tree-sha1 = "8425a7d4e060bc2ded32d090bce910a187d6cce7" -uuid = "f6369f11-7733-5829-9624-2563aa707210" -version = "0.9.0" - -[[HTTPClient]] -deps = ["Compat", "LibCURL"] -git-tree-sha1 = "161d5776ae8e585ac0b8c20fb81f17ab755b3671" -uuid = "0862f596-cf2d-50af-8ef4-f2be67dfa83f" -version = "0.2.1" - -[[Homebrew]] -deps = ["BinDeps", "InteractiveUtils", "JSON", "Libdl", "Test", "Unicode"] -git-tree-sha1 = "5582ec74f735cf8d12e562a2e65c47f34063bd51" -uuid = "d9be37ee-ecc9-5288-90f1-b9ca67657a75" -version = "0.7.0" - -[[InteractiveUtils]] -deps = ["LinearAlgebra", "Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[IntervalArithmetic]] -deps = ["CRlibm", "FastRounding", "LinearAlgebra", "Markdown", "RecipesBase", "SetRounding", "StaticArrays", "Test"] -git-tree-sha1 = "9ce05b28f218d833aedbed0a53ca35948275f336" -uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" -version = "0.15.0" - -[[JSON]] -deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] -git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.20.0" - -[[JuMP]] -deps = ["Calculus", "Compat", "ForwardDiff", "Libdl", "MathProgBase", "Pkg", "ReverseDiffSparse", "Serialization"] -git-tree-sha1 = "3bd8e52f7aeb2736a8e1b0d8ae8d01c2c85fea24" -uuid = "4076af6c-e467-56ae-b986-b466b2749572" -version = "0.18.5" - -[[LibCURL]] -deps = ["BinaryProvider", "Compat", "Libdl", "Printf"] -git-tree-sha1 = "6339c87cb76923a3cf947fcd213cbc364355c9c9" -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.4.1" - -[[LibExpat]] -deps = ["Compat"] -git-tree-sha1 = "fde352ec13479e2f90e57939da2440fb78c5e388" -uuid = "522f3ed2-3f36-55e3-b6df-e94fee9b0c07" -version = "0.5.0" - -[[LibGit2]] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[Libz]] -deps = ["BufferedStreams", "Random", "Test"] -git-tree-sha1 = "d405194ffc0293c3519d4f7251ce51baac9cc871" -uuid = "2ec943e9-cfe8-584d-b93d-64dcb6d567b7" -version = "1.0.0" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MathOptInterface]] -deps = ["Compat", "Unicode"] -git-tree-sha1 = "bc8dffc05c4697addeb3c536b303be3f8b16b1ed" -uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" -version = "0.6.4" - -[[MathProgBase]] -deps = ["Compat"] -git-tree-sha1 = "3bf2e534e635df810e5f4b4f1a8b6de9004a0d53" -uuid = "fdba3010-5040-5b88-9595-932c9decdf73" -version = "0.7.7" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[NaNMath]] -deps = ["Compat"] -git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" -uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" -version = "0.3.2" - -[[Nullables]] -deps = ["Compat"] -git-tree-sha1 = "ae1a63457e14554df2159b0b028f48536125092d" -uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" -version = "0.0.8" - -[[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.0.2" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[RecipesBase]] -deps = ["Random", "Test"] -git-tree-sha1 = "0b3cb370ee4dc00f47f1193101600949f3dcf884" -uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" -version = "0.6.0" - -[[ReverseDiffSparse]] -deps = ["Calculus", "Compat", "DataStructures", "ForwardDiff", "MathProgBase", "NaNMath"] -git-tree-sha1 = "2c445d3c0a519376c950023ac67079bb71418f9b" -uuid = "89212889-6d3f-5f97-b412-7825138f6c9c" -version = "0.8.4" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SetRounding]] -deps = ["Test"] -git-tree-sha1 = "faca28c7937138d560ede5bfef2076d0cdf3584b" -uuid = "3cc68bcd-71a2-5612-b932-767ffbe40ab0" -version = "0.2.0" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[SpecialFunctions]] -deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] -git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.7.2" - -[[StaticArrays]] -deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] -git-tree-sha1 = "97c4bf0f647488dd7ac01ea12be5885f88762938" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.10.0" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[URIParser]] -deps = ["Test", "Unicode"] -git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" -uuid = "30578b45-9adc-5946-b283-645ec420af67" -version = "0.4.0" - -[[UUIDs]] -deps = ["Random"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[WinRPM]] -deps = ["BinDeps", "Compat", "HTTPClient", "LibExpat", "Libdl", "Libz", "URIParser"] -git-tree-sha1 = "2a889d320f3b77d17c037f295859fe570133cfbf" -uuid = "c17dfb99-b4f7-5aad-8812-456da1ad7187" -version = "0.4.2" diff --git a/Project.toml b/Project.toml deleted file mode 100644 index f0ccf8f..0000000 --- a/Project.toml +++ /dev/null @@ -1,14 +0,0 @@ -name = "ConditionalJuMP" -uuid = "ea3fa366-ffb9-11e8-1115-f36c47a855cd" -authors = ["Deits, Robin "] -version = "0.1.0" - -[deps] -Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" -IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" -JuMP = "4076af6c-e467-56ae-b986-b466b2749572" -Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From 41cdd5c4138fefe0b397a38a500749138bebef8c Mon Sep 17 00:00:00 2001 From: "Doake, Raja" Date: Wed, 19 Dec 2018 16:11:12 -0600 Subject: [PATCH 05/12] remove LinearAlgebra from Test/REQUIRE --- test/REQUIRE | 1 - 1 file changed, 1 deletion(-) diff --git a/test/REQUIRE b/test/REQUIRE index c94f125..7eaa813 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,4 +1,3 @@ Cbc -LinearAlgebra Polyhedra 0.3 Nullables From 0148d7576e1d022bf8a6e9587425492ced5d724a Mon Sep 17 00:00:00 2001 From: "Doake, Raja" Date: Thu, 20 Dec 2018 08:31:05 -0600 Subject: [PATCH 06/12] don't need to pass seed explicitly --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index e8b5c02..377591e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,10 +33,10 @@ end for (test_name, num_vars_total, num_vars_in_expr, num_trials) in test_cases @testset "$(test_name)" begin m = Model() - seed = Random.seed!(42) + Random.seed!(42) @variable m q[1:num_vars_total] for i in 1:num_trials - N = rand(seed, 1:num_vars_in_expr) + N = rand(1:num_vars_in_expr) x = randn(N)' * rand(q, N) s1 = copy(x) s2 = copy(x) From 5b0a9aea99370604479bc80acf9e183c3999663e Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:35:08 -0500 Subject: [PATCH 07/12] Updated Appveyor to lastest from https://github.com/JuliaCI/Appveyor.jl --- appveyor.yml | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5f99b28..c2588f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,18 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + - julia_version: 0.7 + - julia_version: 1 + - julia_version: nightly + +platform: + - x86 # 32-bit + - x64 # 64-bit + +# # Uncomment the following lines to allow failures on nightly julia +# # (tests will run but not make your overall status red) +# matrix: +# allow_failures: +# - julia_version: nightly branches: only: @@ -24,24 +26,18 @@ notifications: on_build_status_changed: false install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "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(); - using Pkg; Pkg.clone(pwd(), \"ConditionalJuMP\"); Pkg.build(\"ConditionalJuMP\")" + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia -e "using Pkg; Pkg.test(\"ConditionalJuMP\")" + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" + +# # Uncomment to support code coverage upload. Should only be enabled for packages +# # which would have coverage gaps without running on Windows +# on_success: +# - echo "%JL_CODECOV_SCRIPT%" +# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" From 544689954bd5462227fdbb89c471c472cc5125d6 Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:38:11 -0500 Subject: [PATCH 08/12] Test if we need to add ~/.local/bin to PATH --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29bc7d0..ce0d957 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,6 @@ branches: #before_script: # homebrew for mac # - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi -before_script: - - export PATH=$HOME/.local/bin:$PATH script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi From 73fcb3ef750b801431ef67b36ffa3f918068c7ff Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:39:49 -0500 Subject: [PATCH 09/12] Update code coverage command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce0d957..e1ea691 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,4 +33,4 @@ script: #- julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' after_success: # push coverage results to Codecov - - julia -e 'using Pkg; cd(Pkg.dir("ConditionalJuMP")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' + - julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' From 0163f70fd96fb5a08b977a23386e2341a5b9df17 Mon Sep 17 00:00:00 2001 From: "Doake, Raja" Date: Thu, 20 Dec 2018 08:48:24 -0600 Subject: [PATCH 10/12] have @ifelse call ifelse_conditional --- README.md | 6 +++--- src/ConditionalJuMP.jl | 2 +- src/macros.jl | 4 ++-- test/runtests.jl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2a29bea..20064a8 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ solve(m) ## Disjunctions -This package also provides the `@ifelse_conditional` macro to create simple `if` statements which work both on numbers and on optimization variables. For example, let's write a simple update function: +This package also provides the `@ifelse` macro to create simple `if` statements which work both on numbers and on optimization variables. For example, let's write a simple update function: ```julia function update(x) @@ -129,11 +129,11 @@ Stacktrace: [1] update(::JuMP.Variable) at ./REPL[3]:2 ``` -But if we replace the `if` statement with `@ifelse_conditional`, then the function will magically just work in both cases: +But if we replace the `if` statement with `@ifelse`, then the function will magically just work in both cases: ```julia function update(x) - @ifelse_conditional(x <= 0, + @ifelse(x <= 0, 1, -1 ) diff --git a/src/ConditionalJuMP.jl b/src/ConditionalJuMP.jl index eb1e19c..fd5b6df 100644 --- a/src/ConditionalJuMP.jl +++ b/src/ConditionalJuMP.jl @@ -13,7 +13,7 @@ export @disjunction, @implies, @?, @switch, - @ifelse_conditional, + @ifelse, warmstart!, interval, upperbound, diff --git a/src/macros.jl b/src/macros.jl index 599e72f..d0009e6 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -18,7 +18,7 @@ function _conditionalize(ex::Expr) _conditionalize_function_broadcast(ex) elseif is_operator_broadcast(ex) _conditionalize_operator_broadcast(ex) - elseif ex.head == :call + elseif ex.head == :call if ex.args[1] == :(=>) Expr(:call, :(=>), _conditionalize.(ex.args[2:end])...) else @@ -43,6 +43,6 @@ macro switch(args...) Expr(:call, :switch, _conditionalize.(args)...) end -macro ifelse_conditional(c, v1, v2) +macro ifelse(c, v1, v2) Expr(:call, :ifelse_conditional, _conditionalize(c), v1, v2) end diff --git a/test/runtests.jl b/test/runtests.jl index 377591e..108fb70 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -249,7 +249,7 @@ end @testset "dynamics" begin function update(x) - @ifelse_conditional(x <= 0, 1, -1) + @ifelse(x <= 0, 1, -1) end @testset "mixed integer" begin @@ -303,7 +303,7 @@ end @testset "vector" begin function update2(x) - @ifelse_conditional(x[1] <= 0, + @ifelse(x[1] <= 0, [1, 2], [3, 4]) end From 8c320ecb7883a724db27ace0735e5d38c631a7da Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:54:14 -0500 Subject: [PATCH 11/12] Add Nullables to REQUIRE --- REQUIRE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 438d8b5..a14ed10 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,4 @@ julia 1.0 -JuMP 0.16 0.19 IntervalArithmetic 0.9 +JuMP 0.16 0.19 +Nullables From bb04ba735d12c3d0894bf48de20a1b90e68b4edb Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Thu, 20 Dec 2018 09:54:42 -0500 Subject: [PATCH 12/12] Use default test script --- .travis.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1ea691..8722d6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,19 +18,6 @@ branches: only: - master -## uncomment and modify the following lines to manually install system packages -#addons: -# apt: # apt-get for linux -# packages: -# - gfortran -#before_script: # homebrew for mac -# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi - - -script: - - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' - #- julia -e 'Pkg.clone(pwd()); Pkg.build("ConditionalJuMP"); Pkg.test("ConditionalJuMP"; coverage=true)' after_success: # push coverage results to Codecov - julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'