-
-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate testing of examples #1712
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d2d1aed
Tidy basic.jl
odow 1f12e1a
Tidy cannery.jl
odow 6a57f27
Tidy optcontrol.jl
odow 54aff20
Tidy rosenbrock.jl
odow 157d2be
Add CI tests for examples
odow 5b167b3
Add minellipse.jl and qcp.jl
odow 2ad5ae4
Add docstrings to examples
odow 95cff1d
Remove Manifest.toml
odow 2be409e
Update examples
odow a13772b
Update sudoku.jl
odow 5ff6f27
Update urbanplan.jl
odow 367ce6c
Update robust_uncertainty.jl
odow dfba001
Update cluster.jl and other examples
odow 88fcd14
Update examples
odow b994d51
More updates
odow 4fe59f0
Add diet.jl
odow 6dff2db
Add steelT3 and multi
odow cfb173c
Add prod.jl
odow 8997c86
Update copyright notice and generate EXAMPLES programatically
odow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*.sublime* | ||
*.opf | ||
*.cov | ||
examples/Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[deps] | ||
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" | ||
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" | ||
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,75 @@ | ||
############################################################################# | ||
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# JuMP implementation of the cannery problem | ||
# Dantzig, Linear Programming and Extensions, | ||
# Princeton University Press, Princeton, NJ, 1963. | ||
# | ||
# Author: Louis Luangkesorn | ||
# Date January 30, 2015 | ||
############################################################################# | ||
# JuMP | ||
# An algebraic modeling language for Julia | ||
# See http://github.com/JuliaOpt/JuMP.jl | ||
############################################################################# | ||
|
||
using JuMP, Clp | ||
using JuMP, GLPK, Test | ||
const MOI = JuMP.MathOptInterface | ||
|
||
solver = Clp.Optimizer | ||
|
||
function PrintSolution(is_optimal, plants, markets, ship) | ||
println("RESULTS:") | ||
if is_optimal | ||
for i in 1:length(plants) | ||
for j in 1:length(markets) | ||
println(" $(plants[i]) $(markets[j]) = $(JuMP.value(ship[i,j]))") | ||
end | ||
end | ||
else | ||
println("The solver did not find an optimal solution.") | ||
end | ||
end | ||
""" | ||
example_cannery(; verbose = true) | ||
|
||
function solveCannery(plants, markets, capacity, demand, distance, freight) | ||
numplants = length(plants) | ||
nummarkets = length(markets) | ||
cannery = Model(with_optimizer(solver)) | ||
JuMP implementation of the cannery problem from Dantzig, Linear Programming and | ||
Extensions, Princeton University Press, Princeton, NJ, 1963. | ||
|
||
@variable(cannery, ship[1:numplants, 1:nummarkets] >= 0) | ||
Author: Louis Luangkesorn | ||
Date: January 30, 2015 | ||
""" | ||
function example_cannery(; verbose = true) | ||
plants = ["Seattle", "San-Diego"] | ||
markets = ["New-York", "Chicago", "Topeka"] | ||
|
||
# Ship no more than plant capacity | ||
@constraint(cannery, capacity_con[i in 1:numplants], | ||
sum(ship[i,j] for j in 1:nummarkets) <= capacity[i]) | ||
# Capacity and demand in cases. | ||
capacity = [350, 600] | ||
demand = [300, 300, 300] | ||
|
||
# Ship at least market demand | ||
@constraint(cannery, demand_con[j in 1:nummarkets], | ||
sum(ship[i,j] for i in 1:numplants) >= demand[j]) | ||
# Distance in thousand miles. | ||
distance = [2.5 1.7 1.8; 2.5 1.8 1.4] | ||
|
||
# Minimize transporatation cost | ||
@objective(cannery, Min, | ||
sum(distance[i,j]* freight * ship[i,j] for i in 1:numplants, j in 1:nummarkets)) | ||
# Cost per case per thousand miles. | ||
freight = 90 | ||
|
||
JuMP.optimize!(cannery) | ||
num_plants = length(plants) | ||
num_markets = length(markets) | ||
|
||
term_status = JuMP.termination_status(cannery) | ||
primal_status = JuMP.primal_status(cannery) | ||
is_optimal = term_status == MOI.Optimal | ||
cannery = Model(with_optimizer(GLPK.Optimizer)) | ||
|
||
PrintSolution(is_optimal, plants, markets, ship) | ||
return is_optimal | ||
end | ||
@variable(cannery, ship[1:num_plants, 1:num_markets] >= 0) | ||
|
||
# Ship no more than plant capacity | ||
@constraint(cannery, capacity_con[i in 1:num_plants], | ||
sum(ship[i,j] for j in 1:num_markets) <= capacity[i] | ||
) | ||
|
||
# PARAMETERS | ||
# Ship at least market demand | ||
@constraint(cannery, demand_con[j in 1:num_markets], | ||
sum(ship[i,j] for i in 1:num_plants) >= demand[j] | ||
) | ||
|
||
plants = ["Seattle", "San-Diego"] | ||
markets = ["New-York", "Chicago", "Topeka"] | ||
# Minimize transporatation cost | ||
@objective(cannery, Min, sum(distance[i, j] * freight * ship[i, j] | ||
for i in 1:num_plants, j in 1:num_markets) | ||
) | ||
|
||
# capacity and demand in cases | ||
capacitycases = [350, 600] | ||
demandcases = [300, 300, 300] | ||
JuMP.optimize!(cannery) | ||
|
||
# distance in thousand miles | ||
distanceKmiles = [2.5 1.7 1.8; | ||
2.5 1.8 1.4] | ||
if verbose | ||
println("RESULTS:") | ||
for i in 1:num_plants | ||
for j in 1:num_markets | ||
println(" $(plants[i]) $(markets[j]) = $(JuMP.value(ship[i, j]))") | ||
end | ||
end | ||
end | ||
|
||
# cost per case per thousand miles | ||
freightcost = 90 | ||
@test JuMP.termination_status(cannery) == MOI.OPTIMAL | ||
@test JuMP.primal_status(cannery) == MOI.FEASIBLE_POINT | ||
@test JuMP.objective_value(cannery) == 151200.0 | ||
end | ||
|
||
solveCannery(plants, markets, capacitycases, demandcases, distanceKmiles, freightcost) | ||
example_cannery(verbose = false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
############################################################################# | ||
# JuMP | ||
# An algebraic modeling language for Julia | ||
# See http://github.com/JuliaOpt/JuMP.jl | ||
############################################################################# | ||
|
||
using JuMP, Ipopt, Test | ||
const MOI = JuMP.MathOptInterface | ||
|
||
""" | ||
clnlbeam | ||
Based on AMPL model | ||
Copyright (C) 2001 Princeton University | ||
All Rights Reserved | ||
|
||
Permission to use, copy, modify, and distribute this software and its | ||
documentation for any purpose and without fee is hereby granted, provided that | ||
the above copyright notice appear in all copies and that the copyright notice | ||
and this permission notice appear in all supporting documentation. | ||
|
||
Source: H. Maurer and H.D. Mittelman, "The non-linear beam via optimal control | ||
with bound state variables", Optimal Control Applications and Methods 12, pp. | ||
19-31, 1991. | ||
""" | ||
function example_clnlbeam() | ||
N = 1000 | ||
h = 1/N | ||
alpha = 350 | ||
model = Model(with_optimizer(Ipopt.Optimizer, print_level = 0)) | ||
@variables(model, begin | ||
-1 <= t[1:(N + 1)] <= 1 | ||
-0.05 <= x[1:(N + 1)] <= 0.05 | ||
u[1:(N + 1)] | ||
end) | ||
@NLobjective(model, Min, sum(0.5 * h * (u[i + 1]^2 + u[i]^2) + | ||
0.5 * alpha * h * (cos(t[i + 1]) + cos(t[i])) for i in 1:N) | ||
) | ||
@NLconstraint(model, [i = 1:N], | ||
x[i + 1] - x[i] - 0.5 * h * (sin(t[i + 1]) + sin(t[i])) == 0 | ||
) | ||
@constraint(model, [i = 1:N], | ||
t[i + 1] - t[i] - 0.5 * h * u[i + 1] - 0.5 * h * u[i] == 0 | ||
) | ||
JuMP.optimize!(model) | ||
|
||
@test JuMP.termination_status(model) == MOI.LOCALLY_SOLVED | ||
@test JuMP.primal_status(model) == MOI.FEASIBLE_POINT | ||
@test JuMP.objective_value(model) ≈ 350.0 | ||
end | ||
|
||
example_clnlbeam() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe this typo was still here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1720