Supply Chain optimization with FlexSim and mixed integer programming (MIP) in Python





Introduction

In the digital transformation era, supply chain optimisation has become a key element with regard to improving operational efficiency and reducing costs. Thanks to the integration of FlexSim and mixed integer programming (MIP) in Python, complex distribution scenarios can be modelled and optimised, ensuring more effective data-driven decisions.

This article presents a proof-of-concept that combines FlexSim’s GIS capabilities with a minimum cost flow optimization algorithm, demonstrating how it is possible to improve production and distribution management in the Supply Chain.

The Simulation Model

The proposed model simulates a distribution network consisting of:

  • Factories (red icons), responsible for production.
  • Warehouses (blue icons), which receive and distribute the product.

The goal is to minimize total production and shipping costs.
Each day, warehouses generate a random demand for the product. The Demand Dispatcher determines which factory should produce and how much should be shipped to each warehouse, optimizing costs.

The solution takes into account:

  • Daily production capacity and unit production cost of each factory.
  • Shipping costs between factories and warehouses.

This problem translates into the well-known minimum cost flow problem in optimization.

Integration Between FlexSim and Python for Optimization

To solve this problem, a Python script has been developed using cvxpy to handle the minimum cost flow problem as a Mixed Integer Program (MIP). This model differs from the standard version because:

  • The total factory capacity can exceed the total warehouse demand.
  • It uses integer variables instead of continuous ones.

Despite these differences, the model effectively demonstrates optimization capabilities.



Modello di ottimizzazione della Supply Chain aperto in FlexSim, con visualizzazione della rete di distribuzione tra fabbriche e magazzini.
Supply Chain optimization model open in FlexSim, displaying the distribution network between factories and warehouses.
The Supply Chain Optimization Model in FlexSim

Calculation Flow

  • Demand Generation: The Process Flow for the warehouse generates daily demand and sends it to a shared list.
  • Data Processing: The Demand Dispatcher collects data on production capacity, demand, and costs, and passes it to a Python script using the getMinCostFlow function.
  • Optimization Problem Solving: The getMinCostFlow function, defined in the MinCostFlow.py module, formulates and solves the MIP using cvxpy, returning the optimal shipping quantities for each factory-warehouse pairing.
  • Visualization and Analysis: The model creates and animates “virtual trucks” to simulate transportation and provides dashboards with detailed data on production, distribution, and costs.

The model could be extended with inventory management strategies or simulations of random delivery times.
Charts and dashboards from the Supply Chain optimization model provide analysis of shipments, costs, and resource allocation between factories and warehouses.




Grafici e dashboard del modello di ottimizzazione della Supply Chain, con analisi delle spedizioni, costi e assegnazione delle risorse tra fabbriche e magazzini.


Strategic Insights: Balancing Production and Shipping Costs

The model enables analysis of the trade-off between shipping and production costs:

  • When shipping costs are low compared to production costs, the algorithm prioritizes factories with lower production costs, even if they are farther from the warehouses.
  • Conversely, if shipping costs are high, the algorithm favors factories closer to the warehouses, reducing the reliance on distant or more expensive production sites.

This cost balance drives optimal production and shipping decisions.

Try the Supply Chain Optimization Model

If you’re already a FlexSim user, you can contact us to receive the model and test it directly in your simulation environment.

To run the model, you need:

  • Python (versions 3.7-3.10) with the cvxpy and cvxopt packages installed.
  • Python path configured in the system and FlexSim (version 22.1 or later).

Don’t have FlexSim? Try it for free!

If you’re not using FlexSim yet, you can download the Express version for free. While it has some limitations, it still allows you to test the model.


Download it ➡ here. You can also check out the FlexSim forum https://answers.flexsim.com for this and other useful models!


Logo flexcon