I want to have a fun date without spending too much money and time.
Budget: Up to 5,000 yen because it is before salary at the end of the month. Time required: Weekdays and early morning the next day, so if you meet at 7:00, it will be until 12:00. Course: If possible, a cooking date at your home condominium is short and easy.
I summarized the popular courses from this statistical data, and added the cost per hour and the required time from the rule of thumb, and made the following table in CSV format. ninki Number of women who do 2-3 times a month (thousands) jikan, cost Add the normally required time and budget (¥ / h) as a rule of thumb Get this as a DataFrame with pandas and incorporate it into the optimization model. In addition, ninki was treated as a categorical variable by binning as a feature rather than measuring a little as a numerical value.
import pandas as pd
from pulp import LpVariable,LpStatus,value
from ortoolpy import model_min
syuko = pd.read_csv('C:\StaticData\syuko.csv',index_col='estat')
ninki = []
syumi = []
for i in syuko.columns:
ninki.append(syuko.iloc[0][i])
# binning
bin=pd.cut(ninki,3,labels=False,precision=0,duplicates='drop')+1
syumi=list(syuko.columns)
dic = dict(zip(syumi,bin))
Now let's start creating an optimization model. Let the variables x, y, and z be the scheduled times for movies, karaoke, and cooking, respectively. I want to focus on cooking, so let's increase the variable Z.
#Minimization model definition
mod = model_min()
#Variable setting
x=LpVariable('x',lowBound=0)
y=LpVariable('y',lowBound=0)
z=LpVariable('z',lowBound=0)
#Objective function setting
mod += syuko.iloc[2][0]*x + syuko.iloc[2][1]*y + syuko.iloc[2][2]*z
#Constraints
mod += x + y <= 3
mod += y + z >= 3.5
mod += z + x >= 4
mod += x + y + z <= 5
#Solver execution
mod.solve()
mst = mod.status
st = LpStatus[mst]
After changing the constraints, if Optimal is returned from LpStatus, the optimum solution has been obtained. So it's interesting to use it as a simulator. By the way Impossible if Infensible is returned Unbounded is unbounded (unlimited and optimal solution can be improved) Optimal outputs the combination of the cost and required time of the optimal solution.
#Optimal solution output
if st=='Optimal' and value(mod.objective) < 5000:
print("Optimal budget" + str(value(mod.objective))+"Circle")
plist=[]
con=0
for k,v in dic.items():
print(k,"Recommendation level",v,"Efficient travel time",value(mod.variables()[con]),"h")
con += 1
Output result It seems that cooking will cost 3,320 yen for 4 hours at home apartment! (Does that work?)
Recommended Posts