Skip to content

Commit 25785fd

Browse files
authored
Add JuliaFormatter (#2)
1 parent 9b08c35 commit 25785fd

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

.JuliaFormatter.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Configuration file for JuliaFormatter.jl
2+
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/
3+
4+
always_for_in = true
5+
always_use_return = true
6+
margin = 80
7+
remove_extra_newlines = true
8+
short_to_long_function_def = true

.github/workflows/format_check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v1
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="0.22.10"))
22+
using JuliaFormatter
23+
format(".", verbose=true)
24+
out = String(read(Cmd(`git diff`)))
25+
if isempty(out)
26+
exit(0)
27+
end
28+
@error "Some files have not been formatted !!!"
29+
write(stdout, out)
30+
exit(1)

src/Benchmarks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function _rebuild_data_json()
146146
end
147147
end
148148
open(joinpath(dirname(@__DIR__), "docs", "data.json"), "w") do io
149-
write(io, JSON.json(output))
149+
return write(io, JSON.json(output))
150150
end
151151
return dates, output
152152
end
@@ -161,7 +161,7 @@ function _normalized_data(dates, data)
161161
output[key] = _normalized_data(dates_to_index, data, key)
162162
end
163163
open(joinpath(dirname(@__DIR__), "docs", "summary_data.json"), "w") do io
164-
write(io, JSON.json(output))
164+
return write(io, JSON.json(output))
165165
end
166166
return output
167167
end

src/latency/gurobi_facility.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ function main()
1919
d
2020
end)
2121
@objective(model, Min, d)
22-
@constraint(model, [i in 0:G, j in 0:G], sum(z[i,j,f] for f in 1:F) == 1)
22+
@constraint(model, [i in 0:G, j in 0:G], sum(z[i, j, f] for f in 1:F) == 1)
2323
M = 2 * sqrt(2)
2424
for i in 0:G, j in 0:G, f in 1:F
25-
@constraints(model, begin
26-
s[i, j, f] == d + M * (1 - z[i, j, f])
27-
r[i, j, f, 1] == i / G - y[f, 1]
28-
r[i, j, f, 2] == j / G - y[f, 2]
29-
sum(r[i, j, f, k]^2 for k in 1:2) <= s[i, j, f]^2
30-
end)
25+
@constraints(
26+
model,
27+
begin
28+
s[i, j, f] == d + M * (1 - z[i, j, f])
29+
r[i, j, f, 1] == i / G - y[f, 1]
30+
r[i, j, f, 2] == j / G - y[f, 2]
31+
sum(r[i, j, f, k]^2 for k in 1:2) <= s[i, j, f]^2
32+
end
33+
)
3134
end
3235
optimize!(model)
3336
return

src/latency/ipopt_jump_2788.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ function main()
2525
@NLexpression(model, expr, sum(x[i] * p[i] for i in 1:n))
2626
@NLexpression(model, expr_c1[j = 1:k], sum(x[i] * c1[j, i] for i in 1:n))
2727
@NLexpression(model, expr_c2[j = 1:k], sum(x[i] * c2[j, i] for i in 1:n))
28-
@NLconstraint(model, expr - sum(b[j] / (1 + var1)^j for j in 1:k) == 0)
29-
@NLconstraint(model, expr - sum(expr_c1[j] / (1 + var2)^j for j in 1:k) == 0)
30-
@NLconstraint(model, expr - sum(expr_c2[j] / (1 + var3)^j for j in 1:k) == 0)
31-
@NLconstraint(model, [j=1:k], expr_c1[j] >= b[j])
28+
@NLconstraint(model, expr == sum(b[j] / (1 + var1)^j for j in 1:k))
29+
@NLconstraint(model, expr == sum(expr_c1[j] / (1 + var2)^j for j in 1:k))
30+
@NLconstraint(model, expr == sum(expr_c2[j] / (1 + var3)^j for j in 1:k))
31+
@NLconstraint(model, [j = 1:k], expr_c1[j] >= b[j])
3232
optimize!(model)
3333
return
3434
end

src/micro/JuMP.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ function benchmark_jump_creating_small_constraints()
3737
@objective(model, Min, sum(x))
3838
return
3939
end
40-

0 commit comments

Comments
 (0)