Network Models

Connection

OperationsResearchModels.Network.Connection — Type
 Connection

Description

A structure to hold a directed connection between two nodes in a network.

Fields

  • from::Int64: The starting node of the connection.
  • to::Int64: The ending node of the connection.
  • value::Real: The value associated with the connection (e.g. distance, time, capacity).

Example

# Create a connection from node 1 to node 2 with a distance of 5 kms.
conn = Connection(1, 2, 5)
source

ShortestPathProblem

Shortest Path

OperationsResearchModels.solve — Method
solve(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

conns = [
    Connection(1, 2, 3),
    Connection(1, 3, 2),
    Connection(1, 4, 4),
    Connection(2, 5, 3),
    Connection(3, 5, 1),
    Connection(3, 6, 1),
    Connection(4, 6, 2),
    Connection(5, 7, 6),
    Connection(6, 7, 5),
]

result = solve(ShortestPathProblem(conns))

println(result.path)
# 3-element Vector{Connection}:
#  Connection(1, 3, 2)
#  Connection(3, 6, 1)
#  Connection(6, 7, 5)

println(result.cost)
# 8.0
Determining start and finish nodes

In this function it's assumed that the problem has a unique start and finish node. A heuristic approach is used to find the start and finish nodes. If a node has only outcoming connections, it is considered the start node. If a node has only incoming connections, it is considered the finish node. Of course a network can have multiple start and finish nodes, but this heuristic simplifies the problem. Future implementations could explore more complex scenarios with multiple start and finish nodes.

See also ShortestPathResult, solve(::ShortestPathProblem)

source

ShortestPathResult

Maximum Flow Problem

Maximum Flow

OperationsResearchModels.solve — Method
solve(problem)

Description

Solves a maximum flow problem given by an object of in type MaximumFlowProblem.

Arguments

  • problem::MaximumFlowProblem: The problem in type of MaximumFlowProblem

Output

  • MaximumFlowResult: The custom data type that holds path and flow.

Example

conns = [
    Connection(1, 2, 3),
    Connection(1, 3, 2),
    Connection(1, 4, 4),
    Connection(2, 5, 3),
    Connection(3, 5, 1),
    Connection(3, 6, 1),
    Connection(4, 6, 2),
    Connection(5, 7, 6),
    Connection(6, 7, 5),
];

problem = MaximumFlowProblem(conns)

result = solve(problem);

println(result.path)

println(result.flow)
Determining start and finish nodes

In this function it's assumed that the problem has a unique start and finish node. A heuristic approach is used to find the start and finish nodes. If a node has only outcoming connections, it is considered the start node. If a node has only incoming connections, it is considered the finish node. Of course a network can have multiple start and finish nodes, but this heuristic simplifies the problem. Future implementations could explore more complex scenarios with multiple start and finish nodes.

See also MaximumFlowProblem, MaximumFlowResult

source

MaximumFlowResult

MinimumCostFlowProblem

Minimum Cost Flow

OperationsResearchModels.solve — Method
solve(problem)

Description

This function solves the Minimum Cost Flow problem by first solving the Maximum Flow problem and then using the flow value to solve the Minimum Cost Flow problem.

Arguments

  • problem::MinimumCostFlowProblem: The problem in type of MinimumCostFlowProblem
Determining start and finish nodes

In this function it's assumed that the problem has a unique start and finish node. A heuristic approach is used to find the start and finish nodes. If a node has only outcoming connections, it is considered the start node. If a node has only incoming connections, it is considered the finish node. Of course a network can have multiple start and finish nodes, but this heuristic simplifies the problem. Future implementations could explore more complex scenarios with multiple start and finish nodes.

source

MinimumCostFlowResult

MstProblem

OperationsResearchModels.MinimumSpanningTree.MstProblem — Type
MstProblem

Description

Defines the minimum spanning tree problem.

Fields

  • data::Union{Vector{Connection}, AbstractMatrix{<:Real}}: The data representing the network. It can be either a vector of connections or a distance matrix.
Interpreting the Connection object

The Connection object defines a directed edge, but for the minimum spanning tree problem, the edges are considered undirected.

See also MstResult, solve(::MstProblem)

source

Minimum Spanning Tree

OperationsResearchModels.solve — Method
solve(problem::MstProblem)

Description

Obtains the minimum spanning tree.

Arguments

  • problem::MstProblem: The problem in type of MstProblem

Output

  • ::MstResult: A MstResult object that holds the results.

Details

  • This function uses Prim's algorithm to find the minimum spanning tree. It tracks each unvisited node's nearest connection to the growing tree and updates only the connections adjacent to each newly selected node.

Examples

conns = Connection[
    Connection(1, 2, 10),
    Connection(2, 3, 10),
    Connection(3, 4, 10),
    Connection(1, 4, 10)
]

result = solve(MstProblem(conns))

MstResult(Connection[Connection(3, 4, 10), Connection(1, 4, 10), Connection(2, 3, 10)], 30.0)

println(result.distance)

println(result.connections)

See also MstResult, solve(::MstProblem)

source

MstResult