CoolFace
Apppublic

zpetrea/LinearInteger_Programming

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py70 linesDownload Raw Back to root
1import gradio as gr2import spencer_shoe3import cell_towers4import rd_projects5import fire_station6import inspect7 8def solve_and_display(problem_name):9    try:10        if problem_name == "SpencerShoe":11            description = (12                "๐Ÿ”ง **Fixed Charge Plant Location**\n\n"13                "Determine which plants to open and how much to ship from each to satisfy demand at minimal cost. "14                "Includes fixed opening costs, production/shipping costs, and logic constraints (e.g., Pontiac always open)."15            )16            result = spencer_shoe.solve_spencer_shoe()17            code = inspect.getsource(spencer_shoe.solve_spencer_shoe)18 19        elif problem_name == "CellTowers":20            description = (21                "๐Ÿ“ก **Cell Tower Placement Optimization**\n\n"22                "Choose which towers to build to maximize covered population within a $20M budget. "23                "Each region is considered covered if at least one selected tower reaches it."24            )25            result = cell_towers.solve_cell_towers()26            code = inspect.getsource(cell_towers.solve_cell_towers)27 28        elif problem_name == "R&DProjects":29            description = (30                "๐Ÿ”ฌ **R&D Project Selection**\n\n"31                "Select R&D projects to maximize Net Present Value while satisfying budget and staffing limits. "32                "Includes logical dependencies like mutual exclusivity and project implication constraints."33            )34            result = rd_projects.solve_rd_projects()35            code = inspect.getsource(rd_projects.solve_rd_projects)36 37        elif problem_name == "Fire":38            description = (39                "๐Ÿš’ **Minimum Fire Station Coverage (Set Covering Problem)**\n\n"40                "Minimize the number of fire stations needed to ensure every region is covered by at least one."41            )42            result = fire_station.solve_fire_station()43            code = inspect.getsource(fire_station.solve_fire_station)44 45        else:46            raise ValueError("Invalid problem selected.")47 48        return description, f"```python\n{code}\n```", result49 50    except Exception as e:51        return "โŒ Error during execution", "```python\n<no code>\n```", f"**Details:** {e}"52 53interface = gr.Interface(54    fn=solve_and_display,55    inputs=gr.Radio(56        ["SpencerShoe", "CellTowers", "R&DProjects", "Fire"],57        label="๐Ÿ“‚ Choose a Problem to Explore"58    ),59    outputs=[60        gr.Markdown(label="๐Ÿ“˜ Problem Description"),61        gr.Code(label="๐Ÿ“„ Pyomo Code (Python version of .mod/.dat)"),62        gr.Markdown(label="๐Ÿ“Š Solution Output")63    ],64    title="๐Ÿ“ˆ Linear & Integer Programming Explorer",65    description="Choose one of the problems to explore the code and view the solution using Pyomo."66)67 68if __name__ == "__main__":69    interface.launch()70