Algorithms
Assignment Problem
OperationsResearchModels.solve
— Methodsolve(a)
Arguments
a::AssignmentProblem
: The problem in type of AssignmentProblem
Output
AssignmentResult
: The custom data type that holds problem, solution, and optimum cost.
Description
Solves an assignment problem given by an object of in type AssignmentProblem
.
Example
julia> mat = [
+Algorithms · OperationsResearchModels.jl Algorithms
Assignment Problem
OperationsResearchModels.solve
— Methodsolve(a)
Arguments
a::AssignmentProblem
: The problem in type of AssignmentProblem
Output
AssignmentResult
: The custom data type that holds problem, solution, and optimum cost.
Description
Solves an assignment problem given by an object of in type AssignmentProblem
.
Example
julia> mat = [
4 8 1;
3 1 9;
1 6 7;
@@ -18,7 +18,7 @@
julia> result.cost
-3.0
sourceTransportation Problem
OperationsResearchModels.solve
— Methodsolve(t)
Arguments
a::TransportationProblem
: The problem in type of TransportationProblem
Output
TransportationResult
: The custom data type that holds problem, solution, and optimum cost.
Description
Solves a transportation problem given by an object of in type TransportationProblem
.
Example
julia> t = TransportationProblem(
+3.0
sourceTransportation Problem
OperationsResearchModels.solve
— Methodsolve(t)
Arguments
a::TransportationProblem
: The problem in type of TransportationProblem
Output
TransportationResult
: The custom data type that holds problem, solution, and optimum cost.
Description
Solves a transportation problem given by an object of in type TransportationProblem
.
Example
julia> t = TransportationProblem(
[ 1 1 1 1;
2 2 2 2;
3 3 3 3],
@@ -49,7 +49,7 @@
Cost:
600.0
Solution:
-[-0.0 -0.0 -0.0 100.0; 100.0 -0.0 -0.0 -0.0; -0.0 -0.0 100.0 -0.0; -0.0 100.0 -0.0 -0.0]
sourceShortest Path
OperationsResearchModels.solve
— Methodsolve(problem)
Description
Solves a shortest path problem given by an object of in type ShortestPathProblem
.
Arguments
problem::ShortestPathProblem
: The problem in type of ShortestPathProblem
Output
ShortestPathResult
: The custom data type that holds path and cost.
Example
julia> conns = [
+[-0.0 -0.0 -0.0 100.0; 100.0 -0.0 -0.0 -0.0; -0.0 -0.0 100.0 -0.0; -0.0 100.0 -0.0 -0.0]
sourceShortest Path
OperationsResearchModels.solve
— Methodsolve(problem)
Description
Solves a shortest path problem given by an object of in type ShortestPathProblem
.
Arguments
problem::ShortestPathProblem
: The problem in type of ShortestPathProblem
Output
ShortestPathResult
: The custom data type that holds path and cost.
Example
julia> conns = [
Connection(1, 2, 3),
Connection(1, 3, 2),
Connection(1, 4, 4),
@@ -70,7 +70,7 @@
Connection(6, 7, 5, "x67")
julia> result.cost
-8.0
sourceMaximum Flow
OperationsResearchModels.solve
— Methodsolve(problem)
Arguments
problem::MaximumFlowProblem
: The problem in type of MaximumFlowProblem
Output
MaximumFlowResult
: The custom data type that holds path and flow.
Example
julia> conns = [
+8.0
sourceMaximum Flow
OperationsResearchModels.solve
— Methodsolve(problem)
Arguments
problem::MaximumFlowProblem
: The problem in type of MaximumFlowProblem
Output
MaximumFlowResult
: The custom data type that holds path and flow.
Example
julia> conns = [
Connection(1, 2, 3),
Connection(1, 3, 2),
Connection(1, 4, 4),
@@ -97,7 +97,7 @@
Connection(6, 7, 3.0, "x67")
julia> result.flow
-7.0
sourceMinimum Spanning Tree
OperationsResearchModels.solve
— Methodsolve(problem::MstProblem)
Arguments
problem::MstProblem
: The problem in type of MstProblem
Description
Obtains the minimum spanning tree.
Output
::MstResult
: A MstResult object that holds the results.
Examples
julia> conns = Connection[
+7.0
sourceMinimum Spanning Tree
OperationsResearchModels.solve
— Methodsolve(problem::MstProblem)
Arguments
problem::MstProblem
: The problem in type of MstProblem
Description
Obtains the minimum spanning tree.
Output
::MstResult
: A MstResult object that holds the results.
Examples
julia> conns = Connection[
Connection(1, 2, 10),
Connection(2, 3, 10),
Connection(3, 4, 10),
@@ -120,7 +120,7 @@
3-element Vector{Connection}:
Connection(3, 4, 10, "x34")
Connection(1, 4, 10, "x14")
- Connection(2, 3, 10, "x23")
sourcepmedian
OperationsResearchModels.PMedian.pmedian
— Functionpmedian(data, ncenters)
Arguments
data::Matrix
: Coordinates of locations ncenters::Int
: Number of centers
Description
The function calculates Euclidean distances between all possible rows of the matrix data. ncenters
locations are then selected that minimizes the total distances to the nearest rows.
Output
PMedianResult
: PMedianResult object.
Example
julia> data1 = rand(10, 2);
+ Connection(2, 3, 10, "x23")
sourcepmedian
OperationsResearchModels.PMedian.pmedian
— Functionpmedian(data, ncenters)
Arguments
data::Matrix
: Coordinates of locations ncenters::Int
: Number of centers
Description
The function calculates Euclidean distances between all possible rows of the matrix data. ncenters
locations are then selected that minimizes the total distances to the nearest rows.
Output
PMedianResult
: PMedianResult object.
Example
julia> data1 = rand(10, 2);
julia> data2 = rand(10, 2) .+ 50;
@@ -137,7 +137,7 @@
21
julia> result.objective
- 11.531012240599605
sourcepmedian with distances
OperationsResearchModels.PMedian.pmedian_with_distances
— Functionpmedian_with_distances(distancematrix, ncenters)
Arguments
distancematrix::Matrix
: n x n matrix of distancesncenters::Int
: Number of centers
Description
ncenters
locations are selected that minimizes the total distances to the nearest rows.
Output
PMedianResult
: PMedianResult object.
sourceCPM (Critical Path Method)
OperationsResearchModels.solve
— Methodsolve(problem)
Arguments
problem::CpmProblem
: The problem in type of CpmProblem.
Output
::CpmResult
: The object holds the results
Description
Calculates CPM (Critical Path Method) and reports the critical path for a given set of activities.
Example
julia> A = CpmActivity("A", 2);
+ 11.531012240599605
sourcepmedian with distances
OperationsResearchModels.PMedian.pmedian_with_distances
— Functionpmedian_with_distances(distancematrix, ncenters)
Arguments
distancematrix::Matrix
: n x n matrix of distancesncenters::Int
: Number of centers
Description
ncenters
locations are selected that minimizes the total distances to the nearest rows.
Output
PMedianResult
: PMedianResult object.
sourceCPM (Critical Path Method)
OperationsResearchModels.solve
— Methodsolve(problem)
Arguments
problem::CpmProblem
: The problem in type of CpmProblem.
Output
::CpmResult
: The object holds the results
Description
Calculates CPM (Critical Path Method) and reports the critical path for a given set of activities.
Example
julia> A = CpmActivity("A", 2);
julia> B = CpmActivity("B", 3);
julia> C = CpmActivity("C", 2, [A]);
julia> D = CpmActivity("D", 3, [B]);
@@ -162,12 +162,12 @@
"I"
julia> result.path == [B, E, G, I]
-true
sourceCPM Activity
OperationsResearchModels.CPM.CpmActivity
— TypeCpmActivity(name::String, time::Float64, dependencies)
Description
The object that represents an activity in CPM (Critical Path Method).
Arguments
name::String
: The name of the activity.time::Float64
: The time of the activity.dependencies
: The dependencies of the activity in type of Vector{CpmActivity}
.
Example
julia> A = CpmActivity("A", 2, []);
+true
sourceCPM Activity
OperationsResearchModels.CPM.CpmActivity
— TypeCpmActivity(name::String, time::Float64, dependencies)
Description
The object that represents an activity in CPM (Critical Path Method).
Arguments
name::String
: The name of the activity.time::Float64
: The time of the activity.dependencies
: The dependencies of the activity in type of Vector{CpmActivity}
.
Example
julia> A = CpmActivity("A", 2, []);
julia> B = CpmActivity("B", 3, []);
julia> C = CpmActivity("C", 2, [A, B]);
-
sourcePERT (Project Evalutation and Review Technique)
OperationsResearchModels.solve
— Methodsolve(problem::PertProblem)::PertResult
Arguments
problem::PertProblem
: The problem in type of PertProblem.
Example
julia> A = PertActivity("A", 1, 2, 3)
+
sourcePERT (Project Evalutation and Review Technique)
OperationsResearchModels.solve
— Methodsolve(problem::PertProblem)::PertResult
Arguments
problem::PertProblem
: The problem in type of PertProblem.
Example
julia> A = PertActivity("A", 1, 2, 3)
PertActivity("A", 1.0, 2.0, 3.0, PertActivity[])
julia> B = PertActivity("B", 3, 3, 3)
@@ -191,12 +191,12 @@
8.0
julia> result.stddev
-0.0
sourcePERT Activity
OperationsResearchModels.CPM.PertActivity
— TypePertActivity(name::String, o::Float64, m::Float64, p::Float64)::PertActivity
Description
The object that represents an activity in PERT (Program Evaluation and Review Technique).
Arguments
name::String
: The name of the activity.o::Float64
: The optimistic time of the activity.m::Float64
: The most likely time of the activity.p::Float64
: The pessimistic time of the activity.dependencies
: The dependencies of the activity in type of Vector{PertActivity}
.
Example
julia> A = PertActivity("A", 1, 2, 3);
+0.0
sourcePERT Activity
OperationsResearchModels.CPM.PertActivity
— TypePertActivity(name::String, o::Float64, m::Float64, p::Float64)::PertActivity
Description
The object that represents an activity in PERT (Program Evaluation and Review Technique).
Arguments
name::String
: The name of the activity.o::Float64
: The optimistic time of the activity.m::Float64
: The most likely time of the activity.p::Float64
: The pessimistic time of the activity.dependencies
: The dependencies of the activity in type of Vector{PertActivity}
.
Example
julia> A = PertActivity("A", 1, 2, 3);
julia> B = PertActivity("B", 3, 3, 4);
-julia> C = PertActivity("C", 5, 6, 7, [A, B]);
sourceKnapsack
OperationsResearchModels.solve
— Methodsolve(problem::KnapsackProblem)::KnapsackResult
Description
Solves the knapsack problem.
Arguments
problem::KnapsackProblem
: The problem in type of KnapsackProblem.
Output
KnapsackResult
: The custom data type that holds selected items, model, and objective value.
Example
julia> values = [10, 20, 30, 40, 50];
+julia> C = PertActivity("C", 5, 6, 7, [A, B]);
sourceKnapsack
OperationsResearchModels.solve
— Methodsolve(problem::KnapsackProblem)::KnapsackResult
Description
Solves the knapsack problem.
Arguments
problem::KnapsackProblem
: The problem in type of KnapsackProblem.
Output
KnapsackResult
: The custom data type that holds selected items, model, and objective value.
Example
julia> values = [10, 20, 30, 40, 50];
julia> weights = [1, 2, 3, 4, 5];
julia> capacity = 10;
-julia> solve(KnapsackProblem(values, weights, capacity));
sourceJohnson's Rule
OperationsResearchModels.Johnsons.johnsons
— Functionjohnsons(times::Matrix)
Given a matrix of times, returns a JohnsonResult with the permutation of the jobs. If number of machines is 2, it uses the Johnson's algorithm for 2 machines. If number of machines is greater than 2, it uses the Johnson's algorithm by transforming the problem into a 2-machine problem. In order to reduce the original problem to a 2-machine problem, the algorithm checks if the minimum time of the first machine is greater or equal than the maximum time of the other machines and/or if the minimum time of the last machine is greater or equal than the maximum time of the other machines.
For example if we have 4 machines, namely, A, B, C, and D at least one of the following conditions must be satisfied:
- min(A) >= max(B, C)
- min(D) >= max(B, C)
The function throws a JohnsonException if the problem cannot be reduced to a 2-machine problem.
Arguments
times::Matrix
: a matrix of times
Returns
JohnsonResult
: a custom data type that holds the permutation of the jobs
Example
times = Float64[
+julia> solve(KnapsackProblem(values, weights, capacity));
sourceJohnson's Rule
OperationsResearchModels.Johnsons.johnsons
— Functionjohnsons(times::Matrix)
Given a matrix of times, returns a JohnsonResult with the permutation of the jobs. If number of machines is 2, it uses the Johnson's algorithm for 2 machines. If number of machines is greater than 2, it uses the Johnson's algorithm by transforming the problem into a 2-machine problem. In order to reduce the original problem to a 2-machine problem, the algorithm checks if the minimum time of the first machine is greater or equal than the maximum time of the other machines and/or if the minimum time of the last machine is greater or equal than the maximum time of the other machines.
For example if we have 4 machines, namely, A, B, C, and D at least one of the following conditions must be satisfied:
- min(A) >= max(B, C)
- min(D) >= max(B, C)
The function throws a JohnsonException if the problem cannot be reduced to a 2-machine problem.
Arguments
times::Matrix
: a matrix of times
Returns
JohnsonResult
: a custom data type that holds the permutation of the jobs
Example
times = Float64[
3.1 2.8;
4.0 7.0;
8.0 3.0;
@@ -208,7 +208,7 @@
result = johnsons(times)
-println(result.permutation)
sourceGenetic Algorithm for the problems that cannot be solved with using Johnson's Rule
OperationsResearchModels.Johnsons.johnsons_ga
— Functionjohnsons_ga(times::Matrix; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::JohnsonResult
Given a matrix of times, returns a JohnsonResult with the permutation of the jobs. The function uses a genetic algorithm to find the best permutation of the jobs. The genetic algorithm is implemented in the RandomKeyGA module.
Arguments
times::Matrix
: a matrix of timespopsize::Int
: the population size. Default is 100ngen::Int
: the number of generations. Default is 1000pcross::Float64
: the crossover probability. Default is 0.8pmutate::Float64
: the mutation probability. Default is 0.01nelites::Int
: the number of elites. Default is 1
Returns
JohnsonResult
: a custom data type that holds the permutation of the jobs
Example
times = Float64[
+println(result.permutation)
sourceGenetic Algorithm for the problems that cannot be solved with using Johnson's Rule
OperationsResearchModels.Johnsons.johnsons_ga
— Functionjohnsons_ga(times::Matrix; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::JohnsonResult
Given a matrix of times, returns a JohnsonResult with the permutation of the jobs. The function uses a genetic algorithm to find the best permutation of the jobs. The genetic algorithm is implemented in the RandomKeyGA module.
Arguments
times::Matrix
: a matrix of timespopsize::Int
: the population size. Default is 100ngen::Int
: the number of generations. Default is 1000pcross::Float64
: the crossover probability. Default is 0.8pmutate::Float64
: the mutation probability. Default is 0.01nelites::Int
: the number of elites. Default is 1
Returns
JohnsonResult
: a custom data type that holds the permutation of the jobs
Example
times = Float64[
3.1 2.8;
4.0 7.0;
8.0 3.0;
@@ -220,7 +220,7 @@
result = johnsons(times)
-println(result.permutation)
sourceMakespan
OperationsResearchModels.Johnsons.makespan
— Functionmakespan(times::Matrix, permutation::Vector{Int})
+println(result.permutation)
sourceMakespan
OperationsResearchModels.Johnsons.makespan
— Functionmakespan(times::Matrix, permutation::Vector{Int})
Given a matrix of times and a permutation of the jobs, returns the makespan of the jobs.
Arguments
times::Matrix
: a matrix of timespermutation::Vector{Int}
: a permutation of the jobs
Returns
Float64
: the makespan of the jobs
Example
julia> times = Float64[
@@ -231,7 +231,7 @@
2 5 6
]
-julia> result = makespan(times, [1, 4, 5, 3, 2])
sourceTraveling Salesman
OperationsResearchModels.TravelingSalesman.travelingsalesman
— Functiontravelingsalesman(distancematrix::Matrix; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::TravelinSalesmenResult
Given a matrix of distances, returns a TravelinSalesmenResult with the best route and its cost.
Arguments
distancematrix::Matrix
: a matrix of distancespopsize::Int
: the population size. Default is 100ngen::Int
: the number of generations. Default is 1000pcross::Float64
: the crossover probability. Default is 0.8pmutate::Float64
: the mutation probability. Default is 0.01nelites::Int
: the number of elites. Default is 1
Returns
TravelinSalesmenResult
: a custom data type that holds the best route and its cost
Example
pts = Float64[
+julia> result = makespan(times, [1, 4, 5, 3, 2])
sourceTraveling Salesman
OperationsResearchModels.TravelingSalesman.travelingsalesman
— Functiontravelingsalesman(distancematrix::Matrix; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::TravelinSalesmenResult
Given a matrix of distances, returns a TravelinSalesmenResult with the best route and its cost.
Arguments
distancematrix::Matrix
: a matrix of distancespopsize::Int
: the population size. Default is 100ngen::Int
: the number of generations. Default is 1000pcross::Float64
: the crossover probability. Default is 0.8pmutate::Float64
: the mutation probability. Default is 0.01nelites::Int
: the number of elites. Default is 1
Returns
TravelinSalesmenResult
: a custom data type that holds the best route and its cost
Example
pts = Float64[
0 0;
0 1;
0 2;
@@ -257,4 +257,4 @@
end
end
-result = travelingsalesman(distmat, ngen = 1000, popsize = 100, pcross = 1.0, pmutate = 0.10)
sourceSettings
This document was generated with Documenter.jl version 1.5.0 on Friday 2 August 2024. Using Julia version 1.9.4.
+result = travelingsalesman(distmat, ngen = 1000, popsize = 100, pcross = 1.0, pmutate = 0.10)