My code seems to be stuck in an infinite loop, sorry for putting all the code here but it's the only way i can help you help me.


def loader(data,truck):

    item_m = data["Weight"]
    item_v = data["Volume"]
    truck_m = truck["Weight"]
    truck_v = truck["Volume"]
    truck_c = truck["Price"]
    id_s = data["Pid"]

    item_mass,item_vol,truck_mass,truck_vol,truck_cost, id_series = tolist_converter(item_m,item_v,truck_m,truck_v,truck_c, id_s)
    lpstatus,total_cost,trucks_used, trucks_status, output_dict = allocator(item_mass,item_vol,truck_mass,

    items_dict = data[["Length","Width","Height","Pid" ]].set_index('Pid', drop =False).T.to_dict('list')
    truck[""] = truck.index
    truck_dict = truck[["","Length(ft)","Breadth(ft)","Height(ft)","TruckID"]].set_index('').T.to_dict('list')

    string_d = string_preprocessing(output_dict, items_dict, truck_dict)
    left, loaded = packer(string_d)
    packed = packed_items(loaded)

    while len(left)>0:
        df1 = pd.DataFrame({'Pid': packed})
        df1['g'] = df1.groupby('Pid').cumcount()
        data['g'] = data.groupby('Pid').cumcount()
        dat = data[data.merge(df1, indicator=True, how='left')['_merge'].eq('left_only')]
        dat = dat.reset_index(drop=True)

        item_m1 = dat["Weight"].tolist()
        item_v1 = dat["Volume"].tolist()

        # Mass & volume capacities of trucks
        truck_m = truck["Weight"].tolist()
        truck_v = truck["Volume"].tolist()

        # Cost of using each truck
        truck_c = truck["Price"].tolist()
        id_seri1 = dat["Pid"]

        items_dict1 = dat[["Length","Width","Height","Pid" ]].set_index('Pid', drop =False).T.to_dict('list')
        print("items_dc", items_dict)
        truck_dict1 = truck[["","Length(ft)","Breadth(ft)","Height(ft)","TruckID"]].set_index('').T.to_dict('list')

        # print(item_mass)
        lpstatus,value_obj,trucks_used, trucks_status, output_dict1 = allocator(item_m1,item_v1,truck_m,truck_v,truck_c,id_seri1)
        string_d1 = string_preprocessing(output_dict1, items_dict1, truck_dict1)
        lef, loade = packer(string_d1)
        packed1 = packed_items(loade)

        left = lef
        packed = packed1
        loaded.update((k + '_1' if k in loaded else k, v) for k, v in loade.items())
    return loaded

I am not sure whether I am applying while loop the correct way or not. It's not a typical stack question but I am going on it for quite a while and not able to understand what's wrong.

My objective:

def loader(data, truck): run a code which returns a list packed removes the items of packed from original dataframe rerun the code

0 Answers