The goal of this routing problem is to determine the optimal path from an origin node to a destination node in a network while passing through various middle points. The problem minimizes the total distance traveled and is modeled as a Mixed-Integer Linear Programming (MILP) problem using JuMP and the GLPK solver.
- Nodes and Arcs: Data about the nodes (origin, middle points, and destination) and the arcs (routes between nodes with distances) are read from an Excel file using the XLSX package.
x[a]
(Binary Variable): Represents whether the arca
is included in the optimal route (1 if used, 0 otherwise).
-
Unique Exit from Origin and Entry to Destination:
- Exactly one arc exiting the origin and one arc entering the destination must be selected.
- This is enforced using the constraints
sum(x[a] for a in nodesExitingOrigin) == 1
andsum(x[a] for a in nodesEnteringDest) == 1
.
-
Flow Conservation at Middle Points:
- Ensures that the number of arcs entering a middle point equals the number of arcs exiting. This models the preservation of flow through the network.
- Minimize Total Distance: The function minimizes the weighted sum of the arcs used, weighted by their respective distances, i.e.,
sum(x[a] * D[a] for a in setArcs)
.
- GLPK Solver: Configured for efficient solving of binary linear problems. Solver messages are set to display all outputs (
msg_lev
set toGLPK.GLP_MSG_ALL
).
- After solving the optimization problem, the resulting network of activated routes (arcs) is visualized using Graphs and GraphPlot. Nodes and arcs are color-coded to indicate their role and status in the optimal solution:
- Red node: Origin
- Green node: Destination
- Blue edges: Activated arcs
- Gray edges: Inactive arcs
- The model is optimized using the
optimize!
function. The DataFrame of arcs, including whether each arc is activated in the optimal solution, is displayed and used for visualization.
dfArcs = run() plot_network(dfArcs)