Skip to content

Commit 8ad4d37

Browse files
authored
add COPS instances formulated with ExaModels (#11)
1 parent 91878cb commit 8ad4d37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1630
-122
lines changed

Project.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
name = "COPSBenchmark"
22
uuid = "3c263af4-7bba-497b-afe4-00c59a0a48a5"
3-
authors = ["fpacaud <[email protected]>"]
4-
version = "0.1.0"
3+
version = "0.2.0"
4+
authors = ["MadSuite <https://madsuite.org/>"]
55

66
[deps]
7-
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
87
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
98

9+
[weakdeps]
10+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
11+
ExaModels = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
12+
13+
[extensions]
14+
COPSBenchmarkExaModels = "ExaModels"
15+
COPSBenchmarkJuMP = "JuMP"
16+
1017
[compat]
18+
ExaModels = "0.9"
1119
JuMP = "^1.19"
12-
julia = "1.6"
20+
julia = "1.10"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module COPSBenchmarkExaModels
2+
3+
using Random
4+
import COPSBenchmark
5+
import COPSBenchmark: ExaModelsBackend
6+
using ExaModels
7+
8+
include("bearing.jl")
9+
include("camshape.jl")
10+
include("catmix.jl")
11+
include("chain.jl")
12+
include("elec.jl")
13+
include("gasoil.jl")
14+
include("glider.jl")
15+
include("marine.jl")
16+
include("methanol.jl")
17+
include("minsurf.jl")
18+
include("pinene.jl")
19+
include("robot.jl")
20+
include("rocket.jl")
21+
include("steering.jl")
22+
include("pde_models.jl")
23+
24+
end
25+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Journal bearing problem
2+
# Michael Merritt - Summer 2000
3+
# COPS 2.0 - September 2000
4+
# COPS 3.0 - November 2002
5+
# COPS 3.1 - March 2004
6+
7+
function COPSBenchmark.bearing_model(nx, ny, ::ExaModelsBackend; T = Float64, backend = nothing, kwargs...)
8+
b = 10 # grid is (0,2*pi)x(0,2*b)
9+
e = 0.1 # eccentricity
10+
11+
hx = 2*pi / (nx+1) # grid spacing
12+
hy = 2*b / (ny+1) # grid spacing
13+
area = 0.5*hx*hy # area of triangle
14+
15+
wq(i) = (1.0 + e*cos((i-1)*hx))^3
16+
v0 = [max(sin((i-1)*hx), 0.0) for i in 1:nx+2, j in 1:ny+2]
17+
18+
core = ExaModels.ExaCore(T; backend=backend)
19+
20+
v = ExaModels.variable(core, 1:nx+2, 1:ny+2; lvar = 0.0, start=v0)
21+
22+
ExaModels.objective(
23+
core,
24+
0.5*(hx*hy/6.0) * (wq(i) + 2*wq(i+1))*(((v[i+1,j]-v[i,j])/hx)^2 + ((v[i,j+1]-v[i,j])/hy)^2) for i in 1:nx+1, j in 1:ny+1
25+
)
26+
ExaModels.objective(
27+
core,
28+
0.5*(hx*hy/6.0) * (2*wq(i) + 2*wq(i-1))*(((v[i-1,j]-v[i,j])/hx)^2 + ((v[i,j-1]-v[i,j])/hy)^2) for i in 2:nx+2, j in 2:ny+2
29+
)
30+
ExaModels.objective(
31+
core,
32+
-hx*hy*e*sin((i-1)*hx)*v[i, j] for i in 1:nx+2, j in 1:ny+2
33+
)
34+
35+
ExaModels.constraint(core, v[i, 1] for i in 1:nx+2)
36+
ExaModels.constraint(core, v[i, ny+2] for i in 1:nx+2)
37+
ExaModels.constraint(core, v[1, i] for i in 1:ny+2)
38+
ExaModels.constraint(core, v[nx+2, i] for i in 1:ny+2)
39+
40+
return ExaModels.ExaModel(core; kwargs...)
41+
end
42+
43+
44+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Cam Shape Problem
2+
# Alexander S. Bondarenko - Summer 1998
3+
# COPS 2.0 - September 2000
4+
# COPS 3.0 - November 2002
5+
# COPS 3.1 - March 2004
6+
7+
function COPSBenchmark.camshape_model(n, ::ExaModelsBackend; T = Float64, backend = nothing, kwargs...)
8+
9+
R_v = 1.0 # design parameter related to the valve shape
10+
R_max = 2.0 # maximum allowed radius of the cam
11+
R_min = 1.0 # minimum allowed radius of the cam
12+
alpha = 1.5 # curvature limit parameter
13+
14+
d_theta = 2*pi/(5*(n+1)) # angle between discretization points
15+
16+
core = ExaModels.ExaCore(T; backend= backend, minimize=false)
17+
18+
# radius of the cam at discretization points
19+
r= ExaModels.variable(core, 1:n; lvar =R_min, uvar = R_max, start=(R_min+R_max)/2.0)
20+
21+
ExaModels.objective(core, (pi*R_v)/n * r[i] for i in 1:n)
22+
23+
# Convexity
24+
ExaModels.constraint(
25+
core,
26+
- r[i-1]*r[i] - r[i]*r[i+1] + 2*r[i-1]*r[i+1]*cos(d_theta) for i=2:n-1; lcon = -Inf, ucon = 0.0,
27+
)
28+
ExaModels.constraint(
29+
core,
30+
- R_min*r[1] - r[1]*r[2] + 2*R_min*r[2]*cos(d_theta); lcon = -Inf, ucon = 0.0
31+
)
32+
ExaModels.constraint(
33+
core,
34+
- R_min^2 - R_min*r[1] + 2*R_min*r[1]*cos(d_theta); lcon = -Inf, ucon = 0.0
35+
)
36+
ExaModels.constraint(
37+
core,
38+
- r[n-1]*r[n] - r[n]*R_max + 2*r[n-1]*R_max*cos(d_theta); lcon = -Inf, ucon = 0.0
39+
)
40+
ExaModels.constraint(
41+
core,
42+
- 2*R_max*r[n] + 2*r[n]^2*cos(d_theta); lcon = -Inf, ucon = 0.0
43+
)
44+
# Curvature
45+
ExaModels.constraint(
46+
core,
47+
(r[i+1] - r[i]) for i=1:n-1; lcon = -alpha*d_theta, ucon = alpha*d_theta,
48+
)
49+
ExaModels.constraint(
50+
core,
51+
(r[1] - R_min); lcon = -alpha*d_theta, ucon = alpha*d_theta
52+
)
53+
ExaModels.constraint(
54+
core,
55+
(R_max - r[n]); lcon = -alpha*d_theta, ucon = alpha*d_theta
56+
)
57+
58+
return ExaModels.ExaModel(core; kwargs...)
59+
end
60+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Catalyst Mixing Problem
2+
# Collocation formulation
3+
# COPS 3.0 - November 2002
4+
# COPS 3.1 - March 2004
5+
6+
function COPSBenchmark.catmix_model(nh, ::ExaModelsBackend; T = Float64, backend = nothing, kwargs...)
7+
ne = 2
8+
nc = 3
9+
10+
tf = 1
11+
h = tf / nh # Final time
12+
13+
rho = [
14+
0.11270166537926,
15+
0.50000000000000,
16+
0.88729833462074,
17+
]
18+
bc = [1.0, 0.0] # Boundary conditions for x
19+
alpha = 0.0 # Smoothing parameter
20+
rho_index = [(i, rho[i]) for i in 1:nc]
21+
22+
c = ExaModels.ExaCore(T; backend = backend)
23+
u = ExaModels.variable(c, nh, nc; lvar = zeros(nh, nc), uvar = ones(nh, nc), start = zeros(nh, nc))
24+
v = ExaModels.variable(c, nh, ne; start = [mod(j, ne) for i in 1:nh, j in 1:ne])
25+
w = ExaModels.variable(c, nh, nc, ne; start = zeros(nh, nc, ne))
26+
pp = ExaModels.variable(c, nh, nc, ne; start = [mod(k, ne) for i in 1:nh, j in 1:nc, k in 1:ne])
27+
Dpp = ExaModels.variable(c, nh, nc, ne; start = zeros(nh, nc, ne))
28+
ppf = ExaModels.variable(c, ne; start = [mod(i,ne) for i in 1:ne])
29+
30+
ExaModels.objective(c, -1.0 + ppf[1] + ppf[2])
31+
ExaModels.objective(c, alpha/h*(u[i+1, j] - u[i, j])^2 for i in 1:nh-1, j in 1:nc)
32+
33+
ExaModels.constraint(
34+
c,
35+
pp[i, k, s] - v[i, s] - h*sum(w[i, j, s]*(rho^j/factorial(j)) for j in 1:nc) for i=1:nh, (k, rho) in rho_index, s=1:ne
36+
)
37+
38+
ExaModels.constraint(
39+
c,
40+
Dpp[i, k, s] - sum(w[i, j, s]*(rho^(j-1)/factorial(j-1)) for j in 1:nc) for i=1:nh, (k, rho) in rho_index, s=1:ne
41+
)
42+
43+
ExaModels.constraint(
44+
c,
45+
ppf[s] - v[nh, s] - h * sum(w[nh, j, s] / factorial(j) for j in 1:nc) for s in 1:ne
46+
)
47+
48+
ExaModels.constraint(
49+
c,
50+
v[i, s] + sum(w[i, j, s] * h / factorial(j) for j in 1:nc) - v[i+1, s] for i in 1:nh-1, s in 1:ne
51+
)
52+
53+
54+
55+
ExaModels.constraint(
56+
c,
57+
Dpp[i,j,1] - u[i,j] * (10.0*pp[i,j,2] - pp[i,j,1]) for i=1:nh, j=1:nc
58+
)
59+
60+
ExaModels.constraint(
61+
c,
62+
Dpp[i,j,2] - u[i,j] * (pp[i,j,1] - 10.0*pp[i,j,2]) + (1 - u[i,j])*pp[i,j,2] for i=1:nh, j=1:nc
63+
)
64+
65+
66+
ExaModels.constraint(
67+
c,
68+
v[1, s] - bc for (s, bc) in [(i, bc[i]) for i in 1:ne]
69+
)
70+
71+
return ExaModels.ExaModel(c; kwargs...)
72+
end
73+
74+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Hanging Chain
2+
3+
# Find the chain (of uniform density) of length L suspended between two points with minimal
4+
# potential energy.
5+
6+
# This is problem 4 in the COPS (Version 3) collection of
7+
# E. Dolan and J. More'
8+
# see "Benchmarking Optimization Software with COPS"
9+
# Argonne National Labs Technical Report ANL/MCS-246 (2004)
10+
11+
function COPSBenchmark.chain_model(n, ::ExaModelsBackend; T = Float64, backend = nothing, kwargs...)
12+
nh = max(2, div(n - 4, 4))
13+
14+
L = 4
15+
a = 1
16+
b = 3
17+
tmin = b > a ? 1 / 4 : 3 / 4
18+
tf = 1.0
19+
h = tf / nh
20+
21+
c = ExaModels.ExaCore(T; backend = backend)
22+
u = ExaModels.variable(c, nh + 1; start = [4 * abs(b - a) * (k / nh - tmin) for k in 1:nh+1])
23+
x1 = ExaModels.variable(c, nh + 1; start = [4 * abs(b - a) * k / nh * (1 / 2 * k / nh - tmin) + a for k in 1:nh+1])
24+
x2 = ExaModels.variable(c, nh + 1; start = [(4 * abs(b - a) * k / nh * (1 / 2 * k / nh - tmin) + a) *
25+
(4 * abs(b - a) * (k / nh - tmin)) for k in 1:nh+1])
26+
x3 = ExaModels.variable(c, nh + 1; start = [4 * abs(b - a) * (k / nh - tmin) for k in 1:nh+1])
27+
28+
ExaModels.objective(c, x2[nh + 1])
29+
30+
ExaModels.constraint(
31+
c,
32+
x1[j + 1] - x1[j] - 1 / 2 * h * (u[j] + u[j + 1]) for j in 1:nh
33+
)
34+
35+
ExaModels.constraint(
36+
c,
37+
x1[1] - a
38+
)
39+
40+
ExaModels.constraint(
41+
c,
42+
x1[nh + 1] - b
43+
)
44+
45+
ExaModels.constraint(
46+
c,
47+
x2[1]
48+
)
49+
50+
ExaModels.constraint(
51+
c,
52+
x3[1]
53+
)
54+
55+
ExaModels.constraint(
56+
c,
57+
x3[nh+1] - L
58+
)
59+
60+
ExaModels.constraint(
61+
c,
62+
x2[j + 1] - x2[j] - 1 / 2 * h * (x1[j] * sqrt(1 + u[j]^2) + x1[j + 1] * sqrt(1 + u[j + 1]^2)) for j in 1:nh
63+
)
64+
65+
ExaModels.constraint(
66+
c,
67+
x3[j + 1] - x3[j] - 1 / 2 * h * (sqrt(1 + u[j]^2) + sqrt(1 + u[j + 1]^2)) for j in 1:nh
68+
)
69+
70+
return ExaModels.ExaModel(c; kwargs...)
71+
end
72+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Flow in a Channel Problem
2+
# Collocation formulation
3+
# Alexander S. Bondarenko - Summer 1998
4+
# COPS 2.0 - September 2000
5+
# COPS 3.0 - November 2002
6+
# COPS 3.1 - March 2004
7+
8+
function channel_model(nh; T = Float64, backend = nothing, kwargs...)
9+
nc = 4
10+
nd = 4
11+
R = 10.0 # Reynolds number
12+
tf = 1.0
13+
h = tf / nh
14+
15+
bc = [0.0 1.0; 0.0 0.0]
16+
rho = [0.06943184420297, 0.33000947820757, 0.66999052179243, 0.93056815579703]
17+
t = [(i-1)*h for i in 1:nh+1]
18+
19+
# Initial value
20+
v0 = zeros(nh, nd)
21+
for i in 1:nh
22+
v0[i, 1] = t[i]^2*(3.0 - 2.0*t[i])
23+
v0[i, 2] = 6*t[i]*(1.0 - t[i])
24+
v0[i, 3] = 6*(1.0 - 2.0*t[i])
25+
v0[i, 4] = -12.0
26+
end
27+
28+
core = ExaModels.ExaCore(T; backend= backend)
29+
30+
v = ExaModels.variable(model, 1:nh, 1:nd)
31+
w = ExaModels.variable(model, 1:nh, 1:nc; start=0.0)
32+
33+
uc = ExaModels.variable(model, 1:nh, 1:nc, 1:nd; start=[v0[i, s] for i=1:nh, j=1:nc, s=1:nd])
34+
Duv = ExaModels.variable(model, 1:nh, 1:nc, 1:nd; start=0.0)
35+
36+
# Constant objective
37+
ExaModels.objective(model, Min, 1.0)
38+
39+
# Collocation model
40+
ExaModels.constraint(
41+
model,
42+
[i=1:nh, j=1:nc, s=1:nd],
43+
uc[i, j, s] == v[i,s] + h*sum(w[i,k]*(rho[j]^k/factorial(k)) for k in 1:nc),
44+
)
45+
ExaModels.constraint(
46+
model,
47+
[i=1:nh, j=1:nc, s=1:nd],
48+
Duc[i, j, s] == sum(v[i,k]*((rho[j]*h)^(k-s)/factorial(k-s)) for k in s:nd) +
49+
h^(nd-s+1) * sum(w[i, k]*(rho[j]^(k+nd-s)/factorial(k+nd-s)) for k in 1:nc)
50+
)
51+
# Boundary
52+
ExaModels.constraint(model, bc_1, v[1, 1] == bc[1, 1])
53+
ExaModels.constraint(model, bc_2, v[1, 2] == bc[2, 1])
54+
ExaModels.constraint(
55+
model,
56+
bc_3,
57+
sum(v[nh, k]*(h^(k-1)/factorial(k-1)) for k in 1:nd) +
58+
h^nd * sum(w[nh, k]/factorial(k+nd-1) for k in 1:nc) == bc[1, 2]
59+
)
60+
ExaModels.constraint(
61+
model,
62+
bc_4,
63+
sum(v[nh, k]*(h^(k-2)/factorial(k-2)) for k in 2:nd) +
64+
h^(nd-1) * sum(w[nh, k]/factorial(k+nd-2) for k in 1:nc) == bc[2, 2]
65+
)
66+
ExaModels.constraint(
67+
model,
68+
continuity[i=1:nh-1, s=1:nd],
69+
sum(v[i, k]*(h^(k-s)/factorial(k-s)) for k in s:nd)
70+
+ h^(nd-s+1)* sum(w[i, k]/factorial(k+nd-s) for k in 1:nc) == v[i+1, s]
71+
)
72+
ExaModels.constraint(
73+
model,
74+
collocation[i=1:nh, j=1:nc],
75+
sum(w[i, k] * (rho[j]^(k-1)/factorial(k-1)) for k in 1:nc) ==
76+
R * (Duc[i, j, 2] * Duc[i, j, 3] - Duc[i, j, 1] * Duc[i, j, 4])
77+
)
78+
79+
return ExaModels.ExaModel(core; kwargs...)
80+
end
81+

0 commit comments

Comments
 (0)