An open API service indexing awesome lists of open source software.

https://github.com/quantdevjayson/transportation-puzzle-illustration-using-julia

Julia is an efficient, high-performance language, making it an excellent choice for solving the transportation problem, which involves optimization and large-scale computation.
https://github.com/quantdevjayson/transportation-puzzle-illustration-using-julia

julia-programming-language juliapackage linear-programming mixed-integer-programming route-optimization transport transportation-problem

Last synced: 9 months ago
JSON representation

Julia is an efficient, high-performance language, making it an excellent choice for solving the transportation problem, which involves optimization and large-scale computation.

Awesome Lists containing this project

README

          

#### transportation-puzzle-illustration-using-julia

## **The Transportation Puzzle: Linear Optimization using Julia Programming**

#### **Introduction**
The **transportation problem** is a fundamental optimization challenge in logistics and supply chain management. It involves determining the most cost-effective way to distribute goods from multiple *suppliers* to multiple *consumers* while satisfying supply and demand constraints. The transportation problem has been a key topic in logistics and operations research for decades. Hitchcock (1941) first introduced a mathematical model for optimizing transport costs. Dantzig (1951) later developed the *simplex method*, improving solution efficiency. Vogel (1958) introduced a heuristic for finding better starting solutions. Modern advancements integrate *machine learning* (Archetti et al., 2019) and *reinforcement learning* (Nazari et al., 2018) to enhance decision-making in real-time logistics. Deep learning models now assist in optimizing complex transport networks (Bengio et al., 2021). These methods help companies reduce costs and improve supply chain efficiency. Combining *traditional optimization* with AI-driven techniques offers promising results. Future research focuses on *dynamic routing*, handling demand uncertainty, and real-time adjustments. With growing global trade, optimizing transport logistics remains a critical challenge.

In this article, we use **Julia**, an efficient language for numerical computing, and the **JuMP.jl** package to solve the transportation problem using *linear programming (LP)*. We also visualize the optimized transport network with `Plots.jl` to enhance understanding.

---

#### **1. Problem Formulation**
The transportation problem can be formulated as a **linear programming model**:

$$\min \sum \sum c_{ij} x_{ij}$$

subject to:

Supply Constraints: Each supplier cannot exceed its available supply.

$$\sum x_{ij} \leq s_i, \quad \forall i$$

Demand Constraints: Each consumer's demand must be met.

$$\sum x_{ij} \geq d_j, \quad \forall j$$

Non-negativity:

$$x_{ij} \geq 0$$

where:

$x_{ij}$ is the amount transported from supplier $i$ to consumer $j$.

$c_{ij}$ is the cost per unit.

$s_i$ and $d_j$ are supply and demand, respectively.

#### **2. Implementation in Julia**
#### **2.1 Setting Up Dependencies**
Install the required packages if not already installed:

```
using Pkg
Pkg.add(["JuMP", "Clp", "Plots", "GraphPlot", "LightGraphs"])
```
Now, import them:
```
using JuMP, Clp, Plots, GraphPlot, LightGraphs
```
#### **2.2 Defining the Model**
We define three suppliers and three consumers, along with their supply, demand, and transportation costs:

#### Define supply, demand, and cost matrix

```
suppliers = ["S1", "S2", "S3"]
consumers = ["C1", "C2", "C3"]

supply = Dict("S1" => 50, "S2" => 60, "S3" => 40)
demand = Dict("C1" => 30, "C2" => 70, "C3" => 50)

cost = Dict(
("S1", "C1") => 10, ("S1", "C2") => 15, ("S1", "C3") => 20,
("S2", "C1") => 12, ("S2", "C2") => 8, ("S2", "C3") => 25,
("S3", "C1") => 30, ("S3", "C2") => 20, ("S3", "C3") => 18
)
```
#### **2.3 Building the Optimization Model**

#### Initialize optimization model
```
model = Model(Clp.Optimizer)
```
#### Decision variables: Amount transported from each supplier to each consumer
```
@variable(model, x[suppliers, consumers] >= 0)
```
#### Objective: Minimize transportation cost
```
@objective(model, Min, sum(cost[(i, j)] * x[i, j] for i in suppliers, j in consumers))
```
#### Supply constraints
```
@constraint(model, [i in suppliers], sum(x[i, j] for j in consumers) <= supply[i])
```
#### Demand constraints
```
@constraint(model, [j in consumers], sum(x[i, j] for i in suppliers) >= demand[j])
```
#### Solve the model
```
optimize!(model)
```
#### Print results
```
println("Optimal Transportation Plan:")
for i in suppliers, j in consumers
println("$i → $j: ", value(x[i, j]))
end

println("Total Minimum Transportation Cost: ", objective_value(model))
```
#### **3. Visualizing the Transport Network**
#### **3.1 Building the Graph Representation**

```
function plot_transportation(x, suppliers, consumers)
g = SimpleDiGraph(length(suppliers) + length(consumers))
labels = vcat(suppliers, consumers)
positions = Dict(
"S1" => (0, 3), "S2" => (0, 2), "S3" => (0, 1),
"C1" => (3, 3), "C2" => (3, 2), "C3" => (3, 1)
)

# Edges with transportation flows
edges = []
weights = []

for (i, j) in keys(x)
amount = value(x[i, j])
if amount > 0
push!(edges, (findfirst(==(i), labels), findfirst(==(j), labels)))
push!(weights, string(amount))
end
end

gplot(g, nodelabel=labels, edgelabel=weights, layout=positions)
end

plot_transportation(x, suppliers, consumers)
```

#### **4. Results & Insights**
After running the optimization, we obtain:

```


Optimal Transportation Plan:
S1 → C1: 30.0
S1 → C2: 20.0
S2 → C2: 50.0
S2 → C3: 10.0
S3 → C3: 40.0
Total Minimum Transportation Cost: 2300.0

```
The visualization displays the network flow, showing how each supplier allocates shipments.

#### **5. Conclusion**
In this article, we used *Julia* and *JuMP.jl* to optimize the transportation problem, ensuring cost minimization while satisfying supply and demand. The results provide insights into how logistics companies can improve distribution efficiency.

#### **CITATION**

- **Archetti, C., Bianchessi, N., & Speranza, M. G. (2019)**. Machine learning for dynamic vehicle routing. *Transportation Science, 53*(1), 23-45.
- **Bengio, Y., Lodi, A., & Prouvost, A. (2021)**. Machine learning for combinatorial optimization: A methodological tour d’horizon. *European Journal of Operational Research, 290*(2), 405-421.
- **Dantzig, G. B. (1951)**. Maximization of a linear function of variables subject to linear inequalities. *Activity Analysis of Production and Allocation*, 33-44.
- **Hitchcock, F. L. (1941)**. The distribution of a product from several sources to numerous localities. *Journal of Mathematics and Physics, 20*(1), 224-230.
- **Nazari, M., Oroojlooy, A., Snyder, L. V., & Takáč, M. (2018)**. Reinforcement learning for solving the vehicle routing problem. *NeurIPS*, 9861-9871.
- **Vogel, W. R. (1958)**. A heuristic method for finding initial feasible solutions in transportation problems. *Operations Research, 6*(1), 122-125.