Dealing with uncertainty in Healthcare logistics using Fuzzy Control

Imagine a robot that must move around a room without bumping into anything. One way to do this is to program the robot with precise instructions on how to move around the room. But what if the room is constantly changing, with objects being moved or added? It would be difficult to keep updating the robot’s instructions every time the environment changes.
This is where fuzzy control comes in handy. Fuzzy control uses a set of rules to make decisions based on incomplete or uncertain information. Instead of precise instructions, the robot is programmed with a set of rules that take into account different levels of input.
This is not unlike your understanding of the words in the initial picture (“Sytem” being spelled wrong). Fuzzy decision making allows you to make a decision based on incomplete information.
For example, one rule might be: if the robot detects an object that is very close, it should stop moving. Another rule might be: if the robot detects an object that is somewhat close, it should slow down. And another rule might be: if the robot detects an object that is far away, it can continue moving at a normal speed.
These rules are “fuzzy” because they don’t give precise instructions on what to do, but rather describe how to react to different levels of input. The robot can then use these rules to make decisions in real-time as it navigates around the room, even if the environment is constantly changing.
In this article, fuzzy logic is defined, its use in healthcare logistics is discussed, and it is demonstrated by building and using a model with Python code.

Fuzzy logic is a mathematical framework that allows for the representation of imprecise or uncertain data. It works by assigning degrees of membership to a set of values, which allows for more nuanced and flexible decision-making. Fuzzy sets that represent linguistic variables are used to express the rules of a fuzzy control system.
Fuzzy logic is used to process the inputs to a fuzzy control system, which are typically measurements from sensors or other sources, to decide what control action should be taken. The output of the system is a control signal that is used to regulate the process or system.
Fuzzy logic is a type of mathematical logic that deals with reasoning that is imprecise or uncertain. Instead of using the traditional binary true or false values of classical logic, fuzzy logic uses a continuous range of values between true and false, representing degrees of truth.
One simple example of fuzzy logic is the temperature control in an air conditioning system. Traditional binary logic would use a simple on/off switch to control the AC system based on whether the current temperature is above or below a set point. In contrast, a fuzzy logic controller might use a range of temperature values and a set of fuzzy rules to determine how much the AC should be turned on or off based on the current temperature, the desired temperature, and the rate of change of the temperature.
For example, a fuzzy rule might say: “If the temperature is very hot, then the AC should be turned on high.” This rule does not have a precise temperature threshold for what “very hot” means, but instead uses a fuzzy set to represent the degree of membership for a range of temperatures. The degree of membership for a given temperature value determines how much the AC should be turned on or off, allowing the system to respond to imprecise or uncertain inputs in a more nuanced and effective way than a simple on/off switch.
Another example of fuzzy logic is in self-driving cars. Fuzzy logic can be used to help a car determine how fast it should go, when it should brake, and how it should navigate obstacles or other vehicles on the road. Fuzzy rules can be used to model a driver’s behavior, such as “If the car in front is moving slowly, and the driver is in a hurry, then the car should change lanes to pass.” By using fuzzy logic to represent the degree of membership for different inputs and rules, the self-driving car can make more sophisticated decisions than a simple “if-then” statement.
The following diagram represents a generic fuzzy control system:

Fuzzification: Using membership functions, this component transforms the crisp input variables (such as temperature, pressure, and speed) into fuzzy variables. Membership functions are used to determine the degree of membership of an input to a fuzzy set. For example, a temperature of 75 degrees might have a high degree of membership in a fuzzy set called “warm” but a low degree of membership in a set called "hot."
Inference: This component takes the fuzzy variables and applies a set of fuzzy rules to generate a fuzzy output. Fuzzy rules are statements of the form “If (condition), then (action).” For example, “If the temperature is warm and the pressure is high, then reduce the speed.” Fuzzy inference involves combining the degrees of membership of the input variables to generate a degree of membership for the output variable.
Defuzzification: This component takes the fuzzy output and converts it back into a crisp value that can be used to control the process. There are several methods for defuzzification, but one common method is the centroid method, which finds the center of mass of the output fuzzy set.
Process under control: This is the physical system being controlled, such as a heater, a motor, or a chemical process. The output of the defuzzification process is used to control the system, either directly or through a feedback loop.
An example in hospital logistics
Let’s say we have a hospital that needs to manage the inventory of medical supplies and equipment. One of the key challenges is ensuring that the right items are always available in the right quantities to meet patient needs, while avoiding overstocking, which can lead to waste and unnecessary expenses.
To address this challenge, the hospital can use a fuzzy control system that takes into account various factors such as patient demand, lead time, storage capacity, and supply chain disruptions.
The system would work as follows:
- The hospital would set up a set of rules that define the inventory management policy. These rules would be expressed in terms of linguistic variables, such as “low stock”, “medium stock”, and “high stock”, and would be based on factors such as the rate of item consumption, the frequency of orders, and the lead time for replenishment.
- The system would monitor the inventory levels of each item and use fuzzy logic to determine the appropriate level of stock to maintain. For example, if the system determines that the consumption rate for a particular item is high, and that the lead time for replenishment is long, it might recommend a “high stock” level for that item to avoid stockouts.
- The system would take into account any supply chain disruptions, such as delays in delivery or unexpected increases in demand, and adjust the inventory levels accordingly. For example, if there is a delay in the delivery of a critical item, the system might increase the stock level of that item to ensure that it is available when needed.
- The system would generate alerts or recommendations for ordering new supplies based on the inventory levels and the rules defined in step 1. For example, if the system determines that the stock level of a particular item is approaching the “low stock” threshold, it might generate an alert to the inventory manager to place an order for that item.
In this way, a fuzzy control system can help optimize the inventory management process in a hospital or other healthcare facility, ensuring that the right items are always available when needed, while minimizing waste and unnecessary expenses.
Implementation of Fuzzy logic
The steps involved in putting into practice a fuzzy control system for a logistics process in healthcare include defining the linguistic variables, membership functions, and system rules. Here’s a possible mathematical representation of the fuzzy control system for this example:
Defining the linguistic variables: Let’s assume that we have two linguistic variables for inventory management: “inventory level” and “order quantity." Each of these variables can take on several values, which are defined using fuzzy sets.
Defining the fuzzy sets: For the “inventory level” variable, we could define three fuzzy sets: "low," "medium," and "high." The membership functions for each of these sets could be defined as follows:



where L1, L2, L3, and L4 are the thresholds for low, medium, and high inventory levels, respectively.
For the “order quantity” variable, we could define two fuzzy sets: “small” and "large." The membership functions for each of these sets could be defined as follows:


where Q1 and Q2 are the thresholds for small and large order quantities, respectively.
Defining the rules: The rules for the fuzzy control system could be expressed as a set of “if-then” statements that relate the input variables (inventory level and order quantity) to the output variable (recommended order quantity). For example:
- Rule 1: If inventory level is low, then order quantity is large.
- Rule 2: If inventory level is medium, and order quantity is small, then order quantity is small.
- Rule 3: If inventory level is high, and order quantity is small, then order quantity is small.
- Rule 4: If inventory level is high, and order quantity is large, then order quantity is large.
Implementing the defuzzification method: Once the rules have been defined and the fuzzy inference engine has produced a set of fuzzy outputs, a defuzzification method must be used to map the fuzzy outputs to a crisp output. One possible method is the centroid method, which calculates the centroid of the area under the curve of the fuzzy output.
The centroid method is a defuzzification method used in fuzzy logic systems to convert a fuzzy output set into a crisp numerical value.
In a fuzzy logic system, the output of a rule is typically represented as a fuzzy set, which describes the degree of membership of the output to each of the output’s linguistic values. For example, if the output of a rule is “speed,” the output fuzzy set might include linguistic values such as “slow,” “medium,” and “fast,” each with a degree of membership that represents the rule’s confidence in that output value.
To obtain a single numerical output value from the fuzzy set, the centroid method calculates the “center of gravity” of the fuzzy set by finding its weighted average. This is done by first determining the “crisp” output value associated with each linguistic value and then calculating the weighted average of these crisp values using the degree of membership of each value. The formula for calculating the centroid is:

For example, suppose the output fuzzy set for a rule has the linguistic values “low,” “medium,” and “high,” with degrees of membership of 0.4, 0.7, and 0.2, respectively. Suppose further that the crisp output values associated with each linguistic value are 10, 20, and 30, respectively. The centroid method would then calculate the weighted average as follows:

This means that the crisp output value for this rule would be 18.5, which is the center of gravity of the fuzzy set.
Putting it all together: To implement the fuzzy control system, we would need to:
- Collect data on inventory levels and order quantities.
- Fuzzify the input data by assigning membership values to the relevant fuzzy sets.
- Apply the rules to generate a set of fuzzy outputs.
- Use a defuzzification method to map the fuzzy outputs to a crisp output (i.e., the recommended order quantity).
- Use the recommended order quantity to place orders for medical supplies and equipment.
A possible implementation in Python is shown next. The input and output variables in this code are defined, along with their ranges and membership functions. The output variable is then calculated by combining the input variables after applying the fuzzy rules to them. Finally, the result is defuzzified using the centroid method to produce a precise value for the suggested order quantity. The code also includes a visualization of the membership functions and the aggregated result.
import numpy as np
import skfuzzy as fuzz
# Define the input variables and their ranges
inventory = np.arange(0, 101, 1)
order_qty = np.arange(0, 101, 1)
# Define the output variable and its range
recommended_order_qty = np.arange(0, 101, 1)
# Define the membership functions for the input and output variables
inventory_lo = fuzz.trimf(inventory, [0, 0, 50])
inventory_md = fuzz.trimf(inventory, [0, 50, 100])
inventory_hi = fuzz.trimf(inventory, [50, 100, 100])
order_qty_small = fuzz.trimf(order_qty, [0, 0, 50])
order_qty_large = fuzz.trimf(order_qty, [0, 50, 100])
recommended_order_qty_small = fuzz.trimf(recommended_order_qty, [0, 0, 50])
recommended_order_qty_large = fuzz.trimf(recommended_order_qty, [0, 50, 100])
# Visualize the membership functions
import matplotlib.pyplot as plt
fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(8, 9))
ax0.plot(inventory, inventory_lo, 'b', linewidth=1.5, label='Low')
ax0.plot(inventory, inventory_md, 'g', linewidth=1.5, label='Medium')
ax0.plot(inventory, inventory_hi, 'r', linewidth=1.5, label='High')
ax0.set_title('Inventory Level')
ax0.legend()
ax1.plot(order_qty, order_qty_small, 'b', linewidth=1.5, label='Small')
ax1.plot(order_qty, order_qty_large, 'r', linewidth=1.5, label='Large')
ax1.set_title('Order Quantity')
ax1.legend()
ax2.plot(recommended_order_qty, recommended_order_qty_small, 'b',
linewidth=1.5, label='Small')
ax2.plot(recommended_order_qty, recommended_order_qty_large, 'r',
linewidth=1.5, label='Large')
ax2.set_title('Recommended Order Quantity')
ax2.legend()
# Define the fuzzy rules
rule1 = np.fmax(inventory_lo, order_qty_large)
rule2 = np.fmin(inventory_md, order_qty_small)
rule3 = np.fmin(inventory_hi, order_qty_small)
rule4 = np.fmax(np.fmin(inventory_hi, order_qty_large), 0)
# Apply the rules to the input variables
active_rule1 = rule1
active_rule2 = rule2
active_rule3 = rule3
active_rule4 = rule4
# Calculate the output variable by aggregating the rules
recommended_order_qty_activation_small = np.fmin(active_rule1,
recommended_order_qty_small)
recommended_order_qty_activation_large = np.fmin(np.fmax(active_rule2,
active_rule3, active_rule4), recommended_order_qty_large)
recommended_order_qty0 = np.zeros_like(recommended_order_qty)
# Visualize the aggregated membership functions
fig, ax0 = plt.subplots(figsize=(8, 3))
ax0.fill_between(recommended_order_qty, recommended_order_qty0,
recommended_order_qty_activation_small, facecolor='b', alpha=0.7)
ax0.plot(recommended_order_qty, recommended_order_qty_small, 'b',
linewidth=0.5, linestyle='--', )
ax0.fill_between(recommended_order_qty, recommended_order_qty0,
recommended_order_qty_activation_large, facecolor='r', alpha=0.7)
ax0.plot(recommended_order_qty, recommended_order_qty_large, 'r',
linewidth=0.5, linestyle='--')
ax0.set_title('Aggregated Recommended Order Quantity')
# Calculate the defuzzified result using the centroid method
recommended_order_qty_result = fuzz.defuzz(recommended_order_qty,
recommended_order_qty_activation_large, 'centroid')
print("Recommended order quantity (centroid):", recommended_order_qty_result)
# Visualize the result
recommended_order_qty_activation =
fuzz.interp_membership(recommended_order_qty,
recommended_order_qty_activation_large, recommended_order_qty_result)
fig, ax0 = plt.subplots(figsize=(8, 3))
ax0.plot(recommended_order_qty, recommended_order_qty_small, 'b',
linewidth=0.5, linestyle='--', )
ax0.plot(recommended_order_qty, recommended_order_qty_large, 'r',
linewidth=0.5, linestyle='--')
ax0.fill_between(recommended_order_qty, recommended_order_qty0,
recommended_order_qty_activation_large, facecolor='Orange', alpha=0.7)
ax0.plot([recommended_order_qty_result, recommended_order_qty_result],
[0, recommended_order_qty_activation], 'k', linewidth=1.5, alpha=0.9)
ax0.set_title('Recommended Order Quantity')
plt.show()
This program, when executed using, for example, Google colaboratory produces the following outcome:

Keep in mind that you will need to install the scikit-fuzzy package in Google Colaboratory:
!pip install scikit-fuzzy
Pros and Cons of Fuzzy Control
Fuzzy control has several advantages and disadvantages:
Pros:
- Flexibility: Fuzzy control allows for the incorporation of imprecise or uncertain information into the decision-making process, which can be particularly useful in complex systems that are difficult to model using traditional mathematical methods. This flexibility makes fuzzy control applicable to a wide range of applications.
- Robustness: Fuzzy control is often more robust than traditional control methods because it is able to handle a wider range of inputs and can adapt to changing conditions more effectively.
- Intuitive: Fuzzy control is often more intuitive and easier to understand than traditional control methods because it uses linguistic variables, which can be more easily understood by humans.
- Nonlinear Systems: Fuzzy control is particularly effective in handling nonlinear systems, which can be difficult to model using traditional control methods.
Cons:
- Complexity: Fuzzy control can be more complex than traditional control methods, and requires more computational resources to implement.
- Difficulty in Tuning: Fuzzy control systems can be difficult to tune, as the rules and membership functions used in the system need to be carefully calibrated to ensure optimal performance.
- Interpretability: Fuzzy control can sometimes be less interpretable than traditional control methods, as the linguistic variables used in the system can be more difficult to understand than simple mathematical models.
- Limited Success Stories: There is a lack of widespread success stories in industries or other domains as fuzzy control has not been implemented in many commercial applications.
In conclusion, fuzzy control can handle complex and nonlinear systems with flexibility and robustness, but it can also be more challenging to tune and interpret than conventional control methods. As with any control system, the pros and cons of using fuzzy control depend on the specific application and context in which it is used.