OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Linear programming - Why the optimal solutions are in my case the minimum observed values in the dataset?

  • Thread starter Thread starter Heus
  • Start date Start date
H

Heus

Guest
Code:
import pandas as pd
from pulp import LpProblem, LpVariable, lpSum, LpMinimize, LpStatus

# Sample hospital data

data1 = {
'Hospital_ID': range(1, 11),
'Cost_Per_Nurse_Hour': [50, 55, 60, 45, 52, 58, 53, 49, 56, 54],
'Cost_Per_Doctor_Hour': [5000, 4500, 4000, 5500, 4800, 5100, 4700, 4900, 5200, 4600],
'Doctor_Hours': [100, 110, 95, 105, 108, 115, 98, 102, 107, 103],
'Nurse_Hours': [200, 190, 180, 210, 195, 205, 198, 215, 190, 200],
'Total_Patients': [150, 160, 145, 155, 148, 162, 149, 153, 158, 146],
'Hospital_Revenue': [80000, 75000, 82000, 78000, 79000, 81000, 79000, 80500, 79500, 81500],
}
data = pd.DataFrame(data1)
# Create the optimization problem
prob = LpProblem("Maximize_Margin_Labor", LpMinimize)

# Define decision variables 
nurse_hours_ = LpVariable("Nurse_Hours",lowBound=0, cat='Continuous')
doctor_hours_ = LpVariable("Doctor_Hours",lowBound=0, cat='Continuous')

# Objective function (minimize labor cost/ revenue ratio)
total_labor_cost = nurse_hours_ * lpSum(data.loc[i,"Cost_Per_Nurse_Hour"] for i in  
data.index) + doctor_hours_ * lpSum(data.loc[i,"Cost_Per_Doctor_Hour"] for i in data.index)
margin_labor = total_labor_cost / lpSum(data["Hospital_Revenue"])*100
prob += margin_labor
prob +=nurse_hours_>=190# minimum nurse hours observed
prob +=nurse_hours_<=215# maximum nurse hours observed
prob+=doctor_hours_>=95# minimum doctor hours observed
prob+=doctor_hours_<=115# maximum doctor hours observed
prob +=nurse_hours_-2.1*doctor_hours_<=0 #2.1 maximum observed Nurse Hours/Doctor Hours
prob +=nurse_hours_-1.73*doctor_hours_>=0 #1.73 minimum observed Nurse Hours/Doctor Hours
# Solve the problem
status = prob.solve()

# Print the results
print("Solver status:", LpStatus[status])


optimal_nurse_hours = int(nurse_hours_.value())
optimal_doctor_hours = int(doctor_hours_.value())

# Calculate labor cost and labor cost/revenue ratio for the optimal solutions
total_labor_cost = optimal_nurse_hours * lpSum(data["Cost_Per_Nurse_Hour"]) +          
optimal_doctor_hours * lpSum(data["Cost_Per_Doctor_Hour"])

print("Optimal Nurse Hours:", optimal_nurse_hours)#190 minimum nurse hours observed
print("Optimal Doctor Hours:", optimal_doctor_hours)#95 minimum doctor hours observed
print("Margin Labor Percentage:", margin_labor_percentage, "%")

This code gives the optimal solutions being the minimum observed values. How can I avoid this? I would expect at least one solution to be different than the minimum observed value. What other constraints can be added? Thank you.
<pre><code>import pandas as pd
from pulp import LpProblem, LpVariable, lpSum, LpMinimize, LpStatus

# Sample hospital data

data1 = {
'Hospital_ID': range(1, 11),
'Cost_Per_Nurse_Hour': [50, 55, 60, 45, 52, 58, 53, 49, 56, 54],
'Cost_Per_Doctor_Hour': [5000, 4500, 4000, 5500, 4800, 5100, 4700, 4900, 5200, 4600],
'Doctor_Hours': [100, 110, 95, 105, 108, 115, 98, 102, 107, 103],
'Nurse_Hours': [200, 190, 180, 210, 195, 205, 198, 215, 190, 200],
'Total_Patients': [150, 160, 145, 155, 148, 162, 149, 153, 158, 146],
'Hospital_Revenue': [80000, 75000, 82000, 78000, 79000, 81000, 79000, 80500, 79500, 81500],
}
data = pd.DataFrame(data1)
# Create the optimization problem
prob = LpProblem("Maximize_Margin_Labor", LpMinimize)

# Define decision variables
nurse_hours_ = LpVariable("Nurse_Hours",lowBound=0, cat='Continuous')
doctor_hours_ = LpVariable("Doctor_Hours",lowBound=0, cat='Continuous')

# Objective function (minimize labor cost/ revenue ratio)
total_labor_cost = nurse_hours_ * lpSum(data.loc[i,"Cost_Per_Nurse_Hour"] for i in
data.index) + doctor_hours_ * lpSum(data.loc[i,"Cost_Per_Doctor_Hour"] for i in data.index)
margin_labor = total_labor_cost / lpSum(data["Hospital_Revenue"])*100
prob += margin_labor
prob +=nurse_hours_>=190# minimum nurse hours observed
prob +=nurse_hours_<=215# maximum nurse hours observed
prob+=doctor_hours_>=95# minimum doctor hours observed
prob+=doctor_hours_<=115# maximum doctor hours observed
prob +=nurse_hours_-2.1*doctor_hours_<=0 #2.1 maximum observed Nurse Hours/Doctor Hours
prob +=nurse_hours_-1.73*doctor_hours_>=0 #1.73 minimum observed Nurse Hours/Doctor Hours
# Solve the problem
status = prob.solve()

# Print the results
print("Solver status:", LpStatus[status])


optimal_nurse_hours = int(nurse_hours_.value())
optimal_doctor_hours = int(doctor_hours_.value())

# Calculate labor cost and labor cost/revenue ratio for the optimal solutions
total_labor_cost = optimal_nurse_hours * lpSum(data["Cost_Per_Nurse_Hour"]) +
optimal_doctor_hours * lpSum(data["Cost_Per_Doctor_Hour"])

print("Optimal Nurse Hours:", optimal_nurse_hours)#190 minimum nurse hours observed
print("Optimal Doctor Hours:", optimal_doctor_hours)#95 minimum doctor hours observed
print("Margin Labor Percentage:", margin_labor_percentage, "%")
</code></pre>
<p>This code gives the optimal solutions being the minimum observed values. How can I avoid this? I would expect at least one solution to be different than the minimum observed value. What other constraints can be added? Thank you.</p>
 

Latest posts

Top