Skip to content

Commit 2581809

Browse files
committed
(#2) Add and update documentation in Simplex module
1 parent d81fe67 commit 2581809

File tree

4 files changed

+70
-16
lines changed

4 files changed

+70
-16
lines changed

docs/src/simplex.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
# The Simplex Method
22

3-
## Simplex
3+
4+
## createsimplexproblem
45

56
```@docs
67
OperationsResearchModels.createsimplexproblem
78
```
89

10+
## solve!
11+
12+
```@docs
13+
OperationsResearchModels.solve!(s::SimplexProblem)
14+
```
15+
16+
## simplexiterations
17+
18+
```@docs
19+
OperationsResearchModels.simplexiterations
20+
```
21+
22+
923
## Gauss Jordan steps for matrix inversion
1024

1125
```@docs

src/OperationsResearchModels.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ using JuMP, HiGHS
1212
# solve(a::AssignmentProblem)::AssignmentResult
1313
# solve(g::Game)::GameResult
1414
# solve(m::MstProblem)::MstResult
15+
# solve(t::TravelingSalesmanProblem)::TravelingSalesmanResult
1516
solve() = nothing
1617

18+
# solve!(s::SimplexProblem)::SimplexProblem
19+
solve!() = nothing
20+
1721
# balance(m::TransportationProblem)::TransportationProblem
1822
# balance(a::AssignmentProblem)::AssignmentProblem
1923
balance() = nothing
@@ -24,6 +28,7 @@ isbalanced() = nothing
2428

2529

2630
export solve
31+
export solve!
2732
export balance
2833
export isbalanced
2934

@@ -88,7 +93,7 @@ import .Latex: latex
8893
import .Johnsons: JohnsonResult, johnsons, JohnsonException, makespan, johnsons_ga
8994
import .RandomKeyGA: Chromosome, run_ga
9095
import .TravelingSalesman: TravelingSalesmanResult, TravelingSalesmanProblem
91-
import .Simplex: SimplexProblem, simplexiterations, createsimplexproblem, gaussjordan
96+
import .Simplex: SimplexProblem, simplexiterations, createsimplexproblem, gaussjordan, OptimizationType
9297

9398
export TransportationProblem, TransportationResult, balance, isbalanced, northwestcorner, leastcost
9499
export Connection, ShortestPathResult, MaximumFlowResult, MinimumCostFlowResult, nodes
@@ -106,7 +111,7 @@ export latex
106111
export Chromosome, run_ga
107112
export JohnsonResult, johnsons, JohnsonException, makespan, johnsons_ga
108113
export TravelingSalesmanResult, TravelingSalesmanProblem
109-
export simplexiterations, SimplexProblem, createsimplexproblem, gaussjordan
114+
export simplexiterations, SimplexProblem, createsimplexproblem, gaussjordan, OptimizationType
110115

111116
export JuMP, HiGHS
112117

src/simplex.jl

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export singleiteration!
1111
export simplexiterations
1212
export simplexpretty
1313
export createsimplexproblem
14-
export solve!
1514
export gaussjordan
1615

17-
import ..Utility: numround
1816

17+
import ..Utility: numround
18+
import ..OperationsResearchModels: solve!
1919

2020
@enum OptimizationType begin
2121
Maximize
@@ -412,6 +412,22 @@ function singleiteration!(s::SimplexProblem)
412412
update!(s, enteringvariableindex, rowindex)
413413
end
414414

415+
"""
416+
solve!(s::SimplexProblem)::SimplexProblem
417+
418+
# Description
419+
420+
Solves the given SimplexProblem using the Simplex algorithm. The `solve!` function
421+
modifies the input SimplexProblem in place.
422+
423+
# Arguments
424+
425+
- `s::SimplexProblem`: The SimplexProblem to solve.
426+
427+
# Returns
428+
429+
- `SimplexProblem`: The solved SimplexProblem.
430+
"""
415431
function solve!(s::SimplexProblem)::SimplexProblem
416432
standardform!(s)
417433

@@ -424,6 +440,24 @@ function solve!(s::SimplexProblem)::SimplexProblem
424440
return s
425441
end
426442

443+
444+
"""
445+
simplexiterations(s::SimplexProblem)::Vector{SimplexProblem}
446+
447+
# Description
448+
449+
This function performs the Simplex iterations on the given SimplexProblem and returns the
450+
history of SimplexProblem states.
451+
452+
# Arguments
453+
454+
- `s::SimplexProblem`: The SimplexProblem to iterate.
455+
456+
# Returns
457+
458+
- `Vector{SimplexProblem}`: The history of SimplexProblem states (by iterations).
459+
460+
"""
427461
function simplexiterations(s::SimplexProblem)::Vector{SimplexProblem}
428462
iterations = Vector{SimplexProblem}(undef, 0)
429463

@@ -484,23 +518,23 @@ end
484518
"""
485519
createsimplexproblem(obj::Vector, amat::Matrix, rhs::Vector, dir::Vector, opttype::OptimizationType)::SimplexProblem
486520
487-
Description:
521+
# Description
488522
489523
This function creates a SimplexProblem object from the given parameters.
490524
491-
Arguments:
525+
# Arguments
492526
493527
- `obj::Vector`: The objective function coefficients.
494528
- `amat::Matrix`: The LHS of the constraints.
495529
- `rhs::Vector`: The RHS of the constraints.
496530
- `dir::Vector`: The directions of the constraints. Can be a vector of LE (<=), GE (>=), or EQ (==).
497531
- `opttype::OptimizationType`: The type of the optimization. Can be Maximize or Minimize.
498532
499-
Returns:
533+
# Returns
500534
501535
A SimplexProblem object.
502536
503-
Example:
537+
# Example
504538
505539
Suppose the linear programming problem is as follows:
506540
@@ -549,20 +583,20 @@ end
549583
"""
550584
gaussjordan(A::Matrix; verbose::Bool = true)::Matrix
551585
552-
Description:
586+
# Description
553587
554588
Attaches an Identity matrix to the right of the given matrix A and applies the Gauss-Jordan elimination method to find the inverse of the given matrix.
555589
556-
Arguments:
590+
# Arguments
557591
558592
- `A::Matrix`: The matrix to find the inverse.
559593
- `verbose::Bool`: If true, the intermediate steps are displayed. Default is true.
560594
561-
Returns:
595+
# Returns
562596
563597
The inverse of the given matrix.
564598
565-
Example:
599+
# Example
566600
567601
```julia
568602
julia> A = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 10.0]

src/travelingsalesman.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export TravelingSalesmanResult
1616
A data structure to hold the problem definition of the traveling salesman problem.
1717
1818
# Fields
19-
- `distancematrix::Matrix{Real}`: The distance matrix representing the distances between cities.
19+
20+
- `distancematrix::Matrix{Real}`: The distance matrix representing the distances between cities.
2021
"""
2122
struct TravelingSalesmanProblem
2223
distancematrix::Matrix{Real}
@@ -32,8 +33,8 @@ end
3233
A data structure to hold the result of the traveling salesman problem.
3334
3435
# Fields
35-
- `route::Vector{Int}`: The best route found.
36-
- `cost::Float64`: The cost of the best route.
36+
- `route::Vector{Int}`: The best route found.
37+
- `cost::Float64`: The cost of the best route.
3738
"""
3839
struct TravelingSalesmanResult
3940
route::Vector{Int}

0 commit comments

Comments
 (0)