Skip to content

Commit d5c181a

Browse files
committed
(#2) Apply JuliaFormatter on src
1 parent 85a7f78 commit d5c181a

13 files changed

+137
-85
lines changed

src/OperationsResearchModels.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using JuMP, HiGHS
1414
# solve(m::MstProblem)::MstResult
1515
# solve(t::TravelingSalesmanProblem)::TravelingSalesmanResult
1616
# solve(p::JohnsonProblem)::JohnsonResult
17-
solve() = nothing
17+
solve() = nothing
1818

1919
# solve!(s::SimplexProblem)::SimplexProblem
2020
solve!() = nothing
@@ -28,10 +28,10 @@ balance() = nothing
2828
isbalanced() = nothing
2929

3030

31-
export solve
31+
export solve
3232
export solve!
3333
export balance
34-
export isbalanced
34+
export isbalanced
3535

3636

3737
include("utility.jl")
@@ -72,10 +72,11 @@ import .TravelingSalesman
7272

7373

7474
import .Transportation:
75-
TransportationProblem,
76-
TransportationResult,
77-
balance, isbalanced,
78-
northwestcorner,
75+
TransportationProblem,
76+
TransportationResult,
77+
balance,
78+
isbalanced,
79+
northwestcorner,
7980
leastcost
8081

8182
import .ShortestPath: ShortestPathResult, ShortestPathProblem
@@ -94,9 +95,11 @@ import .Latex: latex
9495
import .Johnsons: JohnsonProblem, JohnsonResult, JohnsonException, makespan, johnsons_ga
9596
import .RandomKeyGA: Chromosome, run_ga
9697
import .TravelingSalesman: TravelingSalesmanResult, TravelingSalesmanProblem
97-
import .Simplex: SimplexProblem, simplexiterations, createsimplexproblem, gaussjordan, OptimizationType
98+
import .Simplex:
99+
SimplexProblem, simplexiterations, createsimplexproblem, gaussjordan, OptimizationType
98100

99-
export TransportationProblem, TransportationResult, balance, isbalanced, northwestcorner, leastcost
101+
export TransportationProblem,
102+
TransportationResult, balance, isbalanced, northwestcorner, leastcost
100103
export Connection, ShortestPathResult, MaximumFlowResult, MinimumCostFlowResult, nodes
101104
export ShortestPathProblem, MaximumFlowProblem, MinimumCostFlowProblem
102105
export AssignmentProblem, AssignmentResult, isbalanced, balance
@@ -112,7 +115,8 @@ export latex
112115
export Chromosome, run_ga
113116
export JohnsonProblem, JohnsonResult, JohnsonException, makespan, johnsons_ga
114117
export TravelingSalesmanResult, TravelingSalesmanProblem
115-
export simplexiterations, SimplexProblem, createsimplexproblem, gaussjordan, OptimizationType
118+
export simplexiterations,
119+
SimplexProblem, createsimplexproblem, gaussjordan, OptimizationType
116120

117121
export JuMP, HiGHS
118122

src/assignment.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ function balance(problem::AssignmentProblem)::AssignmentProblem
9292
if n == p
9393
return problem
9494
elseif n < p
95-
new_costs = vcat(problem.costs, zeros(p-n, p))
95+
new_costs = vcat(problem.costs, zeros(p - n, p))
9696
return AssignmentProblem(new_costs)
9797
else
98-
new_costs = hcat(problem.costs, zeros(n, n-p))
98+
new_costs = hcat(problem.costs, zeros(n, n - p))
9999
return AssignmentProblem(new_costs)
100100
end
101101
end
@@ -146,8 +146,8 @@ function solve(a::AssignmentProblem)::AssignmentResult
146146
n, p = size(a.costs)
147147
problem = a
148148

149-
if n != p
150-
problem = balance(a)
149+
if n != p
150+
problem = balance(a)
151151
n, p = size(problem.costs)
152152
end
153153

src/game.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Defines the problem of a zero-sum game.
1717
1818
- `decisionMatrix::Matrix{<:Real}`: The payoff matrix of the game designed for the row player.
1919
"""
20-
struct GameProblem
20+
struct GameProblem
2121
decisionMatrix::Matrix{<:Real}
22-
end
22+
end
2323

2424

2525
"""
@@ -36,8 +36,8 @@ A structure to hold the result of a game.
3636
3737
"""
3838
struct GameResult
39-
probabilities
40-
value
39+
probabilities::Any
40+
value::Any
4141
end
4242

4343

src/johnsons.jl

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import ..OperationsResearchModels: solve
66

77
export JohnsonResult
88
export JohnsonException
9-
export makespan
10-
export johnsons_ga
9+
export makespan
10+
export johnsons_ga
1111

1212

1313
struct JohnsonException <: Exception
@@ -46,10 +46,10 @@ struct JohnsonResult
4646
end
4747

4848
struct Process
49-
start
50-
duration
51-
finish
52-
end
49+
start::Any
50+
duration::Any
51+
finish::Any
52+
end
5353

5454

5555
"""
@@ -91,14 +91,21 @@ result = johnsons_ga(JohnsonProblem(times))
9191
println(result.permutation)
9292
```
9393
"""
94-
function johnsons_ga(problem::JohnsonProblem; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::JohnsonResult
94+
function johnsons_ga(
95+
problem::JohnsonProblem;
96+
popsize = 100,
97+
ngen = 1000,
98+
pcross = 0.8,
99+
pmutate = 0.01,
100+
nelites = 1,
101+
)::JohnsonResult
95102

96103
times = problem.times
97104
n, _ = size(times)
98-
105+
99106
function costfn(perm::Vector{Int})
100107
return makespan(problem, perm)
101-
end
108+
end
102109

103110
finalpop = run_ga(popsize, n, costfn, ngen, pcross, pmutate, nelites)
104111

@@ -163,7 +170,7 @@ function solve(problem::JohnsonProblem)::JohnsonResult
163170
end
164171

165172
function dofirst!(locrow::Int, permutation::Vector{Int})
166-
for i in 1:length(permutation)
173+
for i = 1:length(permutation)
167174
if permutation[i] == -1
168175
permutation[i] = locrow
169176
return
@@ -172,7 +179,7 @@ function dofirst!(locrow::Int, permutation::Vector{Int})
172179
end
173180

174181
function dolast!(locrow::Int, permutation::Vector{Int})
175-
for i in length(permutation):-1:1
182+
for i = length(permutation):-1:1
176183
if permutation[i] == -1
177184
permutation[i] = locrow
178185
return
@@ -187,8 +194,8 @@ function johnsons_2machines(timesmatrix::Matrix)::JohnsonResult
187194

188195
typed_inf = typemax(eltype(times))
189196

190-
permutation = [-1 for i in 1:n]
191-
for i in 1:n
197+
permutation = [-1 for i = 1:n]
198+
for i = 1:n
192199
locrow, loccol = argmin(times).I
193200
if loccol == 1
194201
dofirst!(locrow, permutation)
@@ -207,14 +214,18 @@ function johnsons_nmachines(times::Matrix)::JohnsonResult
207214
maxothers = maximum(times[:, 2:(end-1)])
208215

209216
if !((minfirst >= maxothers) || (minlast >= maxothers))
210-
throw(JohnsonException("The problem cannot be reduced to a 2-machine problem: minfirst >= maxothers and/or minlast >= maxothers"))
217+
throw(
218+
JohnsonException(
219+
"The problem cannot be reduced to a 2-machine problem: minfirst >= maxothers and/or minlast >= maxothers",
220+
),
221+
)
211222
end
212223

213224
Gcollection = times[:, 1:(end-1)]
214225
Hcollection = times[:, 2:end]
215226

216-
G = sum(Gcollection, dims=2)
217-
H = sum(Hcollection, dims=2)
227+
G = sum(Gcollection, dims = 2)
228+
H = sum(Hcollection, dims = 2)
218229

219230
return johnsons_2machines([G H])
220231
end
@@ -257,8 +268,8 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
257268

258269
timetable = Matrix{Process}(undef, m, n)
259270

260-
for machine_id in 1:m
261-
for task_id in 1:n
271+
for machine_id = 1:m
272+
for task_id = 1:n
262273
current_task = permutation[task_id]
263274
if machine_id == 1
264275
if task_id == 1
@@ -270,7 +281,10 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
270281
if task_id == 1
271282
start = timetable[machine_id-1, task_id].finish
272283
else
273-
start = max(timetable[machine_id, task_id-1].finish, timetable[machine_id-1, task_id].finish)
284+
start = max(
285+
timetable[machine_id, task_id-1].finish,
286+
timetable[machine_id-1, task_id].finish,
287+
)
274288
end
275289
end
276290
duration = times[current_task, machine_id]
@@ -282,4 +296,4 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
282296
return timetable[end, end].finish
283297
end
284298

285-
end # end of module Johnsons
299+
end # end of module Johnsons

src/knapsack.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct KnapsackResult
2525
selected::Vector{Bool}
2626
model::JuMP.Model
2727
objective::Float64
28-
end
28+
end
2929

3030

3131

@@ -86,14 +86,14 @@ function solve(problem::KnapsackProblem)::KnapsackResult
8686

8787
n = length(values)
8888
model = Model(HiGHS.Optimizer)
89-
89+
9090
MOI.set(model, MOI.Silent(), true)
9191

9292
@variable(model, x[1:n], Bin)
9393
@objective(model, Max, sum(values[i] * x[i] for i = 1:n))
9494
@constraint(model, sum(weights[i] * x[i] for i = 1:n) <= capacity)
9595
optimize!(model)
96-
96+
9797
selected = value.(x)
9898
return KnapsackResult(selected, model, objective_value(model))
9999
end

src/minimumcostflow.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ A structure to hold the result of the minimum cost flow problem.
4343
- `cost::Float64`: The total cost of the flow.
4444
4545
"""
46-
struct MinimumCostFlowResult
46+
struct MinimumCostFlowResult
4747
path::Vector{Connection}
4848
cost::Float64
49-
end
49+
end
5050

5151

5252

@@ -118,7 +118,7 @@ function solve(problem::MinimumCostFlowProblem, flow::Float64)::MinimumCostFlowR
118118
end
119119

120120
return MinimumCostFlowResult(solutionnodes, cost)
121-
end
121+
end
122122

123123

124124
"""
@@ -152,9 +152,9 @@ function solve(problem::MinimumCostFlowProblem)::MinimumCostFlowResult
152152
f = maximumflowresult.flow
153153

154154
result::MinimumCostFlowResult = solve(problem, f)
155-
155+
156156
return result
157-
end
157+
end
158158

159159

160-
end # end of module MinimumCostFlow
160+
end # end of module MinimumCostFlow

src/network.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ A structure to hold a directed connection between two nodes in a network.
3232
conn = Connection(1, 2, 5)
3333
```
3434
"""
35-
struct Connection
35+
struct Connection
3636
from::Int64
3737
to::Int64
3838
value::Real
@@ -88,7 +88,12 @@ end
8888

8989

9090

91-
function outflow(x::Matrix{JuMP.VariableRef}, node::Int64, nodes::Vector{Connection}, model)::Union{JuMP.AffExpr, Symbol}
91+
function outflow(
92+
x::Matrix{JuMP.VariableRef},
93+
node::Int64,
94+
nodes::Vector{Connection},
95+
model,
96+
)::Union{JuMP.AffExpr,Symbol}
9297
lst = []
9398
for conn in nodes
9499
if conn.from == node
@@ -99,15 +104,20 @@ function outflow(x::Matrix{JuMP.VariableRef}, node::Int64, nodes::Vector{Connect
99104
return :f
100105
end
101106
expr = @expression(model, 0)
102-
for i = eachindex(lst)
107+
for i in eachindex(lst)
103108
expr += x[lst[i].from, lst[i].to]
104109
end
105110
return expr
106111
end
107112

108113

109114

110-
function inflow(x::Matrix{JuMP.VariableRef}, node::Int64, nodes::Vector{Connection}, model)::Union{JuMP.AffExpr, Symbol}
115+
function inflow(
116+
x::Matrix{JuMP.VariableRef},
117+
node::Int64,
118+
nodes::Vector{Connection},
119+
model,
120+
)::Union{JuMP.AffExpr,Symbol}
111121
lst = []
112122
for conn in nodes
113123
if conn.to == node
@@ -118,7 +128,7 @@ function inflow(x::Matrix{JuMP.VariableRef}, node::Int64, nodes::Vector{Connecti
118128
return :f
119129
end
120130
expr = @expression(model, 0)
121-
for i = eachindex(lst)
131+
for i in eachindex(lst)
122132
expr += x[lst[i].from, lst[i].to]
123133
end
124134
return expr

src/pmedian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function pmedian_with_distances(distancematrix::Matrix, ncenters::Int)::PMedianR
148148
optimize!(model)
149149

150150
return PMedianResult(
151-
findall(x -> x == 1, value.(y)),
151+
findall(x -> x == 1, value.(y)),
152152
model,
153153
JuMP.objective_value(model),
154154
value.(z),

0 commit comments

Comments
 (0)