forked from jump-dev/JuMP.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate testing of examples (jump-dev#1712)
* Tidy basic.jl * Tidy cannery.jl * Tidy optcontrol.jl * Tidy rosenbrock.jl * Add CI tests for examples * Add minellipse.jl and qcp.jl * Add docstrings to examples * Remove Manifest.toml * Update examples * Update sudoku.jl * Update urbanplan.jl * Update robust_uncertainty.jl * Update cluster.jl and other examples * Update examples * More updates * Add diet.jl * Add steelT3 and multi * Add prod.jl * Update copyright notice and generate EXAMPLES programatically
- Loading branch information
Showing
30 changed files
with
1,306 additions
and
1,285 deletions.
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.