We all have heard about Game Theory. There’s even a famous movie, A Beautiful Mind, which beautifully discusses Nash equilibrium. Game theory is a powerful tool for analyzing people’s ability to make interdependent decisions.

Game theory has a huge application in operations research, particularly inventory management. In this article, we will look at a simple case study in a supply chain setting that was solved using game theory and its implementation in Python.

*Also read: How to optimize Inventory management using Python – AskPython*

## The Nash Equilibrium Concept

We must first understand the Nash equilibrium before exploring the problem statement and its solution.

The Nash equilibrium is a fundamental concept in game theory, named after the mathematician John Nash. It represents a stable state in a non-cooperative game where no player can increase their payoff by unilaterally changing their strategy, given that the other players’ strategies remain unchanged.

In other words, each player is making the best possible decision for themselves, given the other players’ strategies. This concept is crucial in analyzing strategic interactions and finding optimal solutions in various decision-making scenarios.

Let’s take an example of a two-player game where each player can either “Cooperate” or “Defect”. The payoff scenario for each is given as follows:

- If both “Cooperate,” they receive 3 rupees.
- If one “Cooperate” and the other “Defects”, the cooperator gets 1 rupee, and the defector gets rupee 5.
- If both are “Defect,” they each get 2 rupees.

Let us model the above problem in Python.

```
import numpy as np
from scipy.optimize import minimize
# Define the payoff matrix
payoff_matrix = np.array([[3, 1],
[5, 2]])
```

We essentially import the necessary modules and libraries to minimize the objective function. As mentioned above, we also create a payoff matrix.

```
# Define the utility functions for each player
def player_a_utility(x):
return -np.dot(payoff_matrix[0], x)
def player_b_utility(y):
return -np.dot(payoff_matrix[:, 0], y)
# Define the constraints for player B's strategy probabilities
def constraint(y):
return 1 - np.sum(y)
```

Then, we will define each player’s utilities. In this code, we will strategize for player B in terms of his probability of cooperating or defecting.

```
Initial guess for optimization
y_guess = [0.5, 0.5]
# Optimize player B's strategy
result_player_b = minimize(player_b_utility, y_guess, method='SLSQP', bounds=[(0, 1)], constraints={'type': 'eq', 'fun': constraint})
# Nash Equilibrium strategy
nash_equilibrium_strategy = result_player_b.x
# Calculate player A's expected utility given player B's strategy
player_a_expected_utility = -player_a_utility(nash_equilibrium_strategy)
```

In the block of code above, we have assumed initial guesses for each player. We have also defined Player B’s strategy and constraints. Thereafter, we have defined a function calculating Player A’s utility when he knows Player B’s strategy.

```
# Output the results
print("Nash Equilibrium Strategy (Player B):", nash_equilibrium_strategy)
print("Player A's Expected Utility:", player_a_expected_utility)
```

Let us look at the output of the above code.

Thus, player B has a very low probability of tending to 0 of cooperating and tending to 1 likelihood of Defect. Therefore, Player A’s utility is expected to be 1, and his best strategy is to “Defect.” Let us now move on to our problem statement and its solution.

*Recommended: Understanding Probability Density and Distribution Functions*

## Supply Chain Inventory Management Problem

In the supply chain inventory management problem, there are two players: a manufacturer and a distributor. The manufacturer must decide the optimal production quantity, while the distributor must determine the optimal order quantity.

Both players aim to maximize their profits, but their decisions are interdependent.

The manufacturer’s profit depends on the production cost and the distributor’s order quantity. In contrast, the distributor’s profit depends on the purchase cost, demand, and minimum production and order quantities.”

Assumptions:

- We know the manufacturer’s production cost. In addition to that, there are no capacity constraints.
- There are no ordering costs for distributors in this scenario.
- Both the manufacturer and distributor aim to maximize their profits.

Since we know the problem, let us now understand how to implement game theory in Python programming language and solve this problem.

## Modelling and Solving the Problem with Game Theory

The manufacturer and distributor make decisions independently and aim to maximize profits. The decision variable for the manufacturer is the number of units produced, and the distributor’s decision variable is the number of units ordered.

We also use the concept of Nash equilibrium. According to Nash equilibrium, both our participants choose optimal strategies knowing the opponent’s plan, and the strategy remains constant over time. Let us look at the Python code regarding the above problem.

```
import numpy as np
from scipy.optimize import minimize
# Define the manufacturer's profit function
def manufacturer_profit(x):
return - (production_cost * x)
# Define the distributor's profit function
def distributor_profit(y):
revenue = demand * min(x, y) # Revenue is the demand times the minimum of production and order quantity
return revenue - (purchase_cost * y)
# Define the constraint for the distributor's order quantity
def constraint(y):
return y - demand
# Constants
production_cost = 10 # Cost per unit of production
purchase_cost = 15 # Cost per unit of purchase
demand = 100 # Demand from retailers
# Initial guess for optimization
x_guess = 100
y_guess = 100
# Optimize the manufacturer's profit
result_manufacturer = minimize(manufacturer_profit, x_guess, method='SLSQP', bounds=[(0, None)])
# Optimize the distributor's profit with the manufacturer's production quantity fixed at the Nash Equilibrium
x = result_manufacturer.x[0]
result_distributor = minimize(distributor_profit, y_guess, method='SLSQP', bounds=[(0, None)], constraints={'type': 'ineq', 'fun': constraint})
# Output the results
print("Manufacturer's Production Quantity (Nash Equilibrium):", x)
print("Distributor's Order Quantity (Nash Equilibrium):", result_distributor.x[0])
print("Manufacturer's Profit:", -result_manufacturer.fun)
print("Distributor's Profit:", -result_distributor.fun)
```

The code above is almost the same as the Nash equilibrium code; only the characters are different for them. Let us look at the output of the above code.

There you go! The distributor should order 100 units according to Game theory.

*Recommended: Python and Probability: Simulating Blackjack Card Counting with Python Code*

## Conclusion

Here you go! In this article, we have learned how to utilize game theory and, specifically, the concept of Nash equilibrium in inventory management decisions. We discovered the production and order quantities for our manufacturers and distributors.

Hope you enjoyed reading it!!!

*Recommended: Monte-Carlo Simulation to find the probability of Coin toss in python*

*Recommended: 5 Ways to Detect Fake Dollar Bills Using Python Machine Learning*