CoolFace
Apppublic

seraycengiz/ISE426-Logistics-Tool

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
2 commits on main
c02f8189mo ago

import gradio as gr def solve_logistics(item_weights_str, v1_800_cost, v1_500_cost, v2_800_cost, v2_500_cost): try: # Create item list from input string items = [{"id": i+1, "weight": int(w.strip())} for i, w in enumerate(item_weights_str.split(','))] def run_algorithm(cost_800, cost_500): # Define vehicle types and calculate efficiency ($/kg) v_types = [ {'cap': 800, 'cost': cost_800, 'count': 5, 'eff': cost_800/800}, {'cap': 500, 'cost': cost_500, 'count': 7, 'eff': cost_500/500} ] # Sort vehicles by efficiency (lowest $/kg first) v_types = sorted(v_types, key=lambda x: x['eff']) # Sort items in descending order (Best Fit Decreasing) sorted_items = sorted(items, key=lambda x: x['weight'], reverse=True) remaining = sorted_items[:] fleet = [] while remaining: found = False for vt in v_types: if vt['count'] > 0: truck = {'cap': vt['cap'], 'parcels': [], 'rem': vt['cap'], 'cost': vt['cost']} i = 0 while i < len(remaining): if remaining[i]['weight'] <= truck['rem']: item = remaining.pop(i) truck['parcels'].append(item['id']) truck['rem'] -= item['weight'] else: i += 1 fleet.append(truck) vt['count'] -= 1 found = True break if not found: return "Insufficient Capacity in Fleet!", "0" # Format detailed breakdown detail = "" truck_counts = {800: 0, 500: 0} for idx, t in enumerate(fleet): detail += f"Truck {idx+1} ({t['cap']} kg): Parcels {', '.join(map(str, t['parcels']))}\n" truck_counts[t['cap']] += 1 summary = f"{truck_counts[800]} trucks of 800 kg, {truck_counts[500]} trucks of 500 kg.\nTotal Cost: ${sum(t['cost'] for t in fleet)}" return detail, summary # Run for both versions res1_det, res1_sum = run_algorithm(v1_800_cost, v1_500_cost) res2_det, res2_sum = run_algorithm(v2_800_cost, v2_500_cost) return res1_det, res1_sum, res2_det, res2_sum except Exception as e: return f"Error: {str(e)}", "Please check your input format.", "", "" with gr.Blocks(title="ISE426 Logistics Solver") as demo: gr.Markdown("# ISE426 Logistics Systems - Heterogeneous Bin Packing Tool") gr.Markdown("Based on Ghiani et al. Exercise 5.9. Enter weights separated by commas.") weights = gr.Textbox(label="Parcel Weights (comma separated)", value="400, 350, 300, 250, 250, 200, 150, 150, 100, 100, 50") with gr.Row(): with gr.Column(): gr.Markdown("### Version 1 Settings ($3 vs $1)") v1_800 = gr.Number(label="800kg Van Cost", value=3) v1_500 = gr.Number(label="500kg Van Cost", value=1) out1_det = gr.Textbox(label="V1 Vehicle Breakdown", lines=8) out1_sum = gr.Textbox(label="V1 Financial Summary") with gr.Column(): gr.Markdown("### Version 2 Settings ($4 vs $3)") v2_800 = gr.Number(label="800kg Van Cost", value=4) v2_500 = gr.Number(label="500kg Van Cost", value=3) out2_det = gr.Textbox(label="V2 Vehicle Breakdown", lines=8) out2_sum = gr.Textbox(label="V2 Financial Summary") btn = gr.Button("CALCULATE SOLUTIONS", variant="primary") btn.click(solve_logistics, inputs=[weights, v1_800, v1_500, v2_800, v2_500], outputs=[out1_det, out1_sum, out2_det, out2_sum]) demo.launch()

seraycengiz
caa6ea89mo ago

initial commit

seraycengiz