Python 基于纸浆的仓库调度优化

Python 基于纸浆的仓库调度优化,python,pandas,pulp,Python,Pandas,Pulp,我正在尝试使用纸浆模块优化商店时间表,但我面临第四个约束的问题 下文将详细阐述这些制约因素 商店总需求量不应超过一天的容量(如果您希望两天之间的间隔为2,请将限制更改为prob+=storeVars[d][s]+storeVars[d+1][s]+storeVars[d+2][s]==1 import pulp import pandas as pd import numpy as np from pulp import * StoreSched = pd.DataFrame(columns

我正在尝试使用纸浆模块优化商店时间表,但我面临第四个约束的问题 下文将详细阐述这些制约因素


  • 商店总需求量不应超过一天的容量(如果您希望两天之间的间隔为2,请将限制更改为
    prob+=storeVars[d][s]+storeVars[d+1][s]+storeVars[d+2][s]==1

    import pulp
    import pandas as pd
    import numpy as np
    from pulp import *
    
    StoreSched = pd.DataFrame(columns = ["Store_Code","Route","Demand"])
    Capacity =  5000
    route="R1"
    days_list=["SAT","SUN","MON", "TUE","WED","THU"]
    no_days_list = range(1,7)
    Store = ["S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"]
    Store_demand = {
            "S1":400,
            "S2":300,
            "S3":250 ,
            "S4":200 ,
            "S5":300,
         "S6":200 ,
            "S7":300,
         "S8":200 ,
            "S9":300,
        "S10":300,
        
         
        }
    store_Days = {
            "S1":6 ,
            "S2":6,
            "S3":6 ,
            "S4":3,
        "S5":3,
        "S6":3,
           "S7":2,
        "S8":2,
        "S9":2,
            "S10":1 ,
       
        }
        
    prob = LpProblem("store_schedule",LpMaximize)
    storeVars = LpVariable.dicts("Days",(no_days_list,Store),0,1,LpInteger)
        
    for d in no_days_list:
            # The capacity should not exceeed 1500 in one day 
             prob += pulp.lpSum([Store_demand[s] * storeVars[d][s] for s in Store]) <= Capacity
    for s in Store:
            # Every store should be assigned based on its DayNo.
            prob += pulp.lpSum(storeVars[d][s] for d in no_days_list) == store_Days[s]
    for s in Store:  
            # one day gap between the assigned dayes for the stores that have three days 
            if store_Days[s] == 3 :  
                for d in no_days_list[:-1]:
                    prob += storeVars[d][s] + storeVars[d+1][s] == 1          
    for s in Store:
                if store_Days[s] == 2  : 
                     for d in no_days_list[:-2]:
                        prob += storeVars[d][s] + storeVars[d+2][s] == 1   
    prob.solve()
    
    for vi in prob.variables():
            if vi.varValue == 1:
                #print(" On "+days_list[int(vi.name.split("_")[1])-1]+" Pharmacy code: "+vi.name.split("_")[2])
                code= vi.name.split("_")[2];
                #print(code)
                day = days_list[int(vi.name.split("_")[1])-1];
                #print(day)
                if ((StoreSched['Store_Code'] == code).any() == False):
                    StoreSched = StoreSched.append({'Store_Code': code,"Route":route,"Days":store_Days[code],"Demand":Store_demand[code]}, ignore_index=True)
                for index in StoreSched.index:    
                    if StoreSched.loc[index,'Store_Code']== code:                    
                        StoreSched.loc[index,day] = 1                    
    StoreSched.fillna(0,inplace=True)
    StoreSched