Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import spencer_shoe | |
| import cell_towers | |
| import rd_projects | |
| import fire_station | |
| import inspect | |
| def solve_and_display(problem_name): | |
| try: | |
| if problem_name == "SpencerShoe": | |
| description = ( | |
| "π§ **Fixed Charge Plant Location**\n\n" | |
| "Determine which plants to open and how much to ship from each to satisfy demand at minimal cost. " | |
| "Includes fixed opening costs, production/shipping costs, and logic constraints (e.g., Pontiac always open)." | |
| ) | |
| result = spencer_shoe.solve_spencer_shoe() | |
| code = inspect.getsource(spencer_shoe.solve_spencer_shoe) | |
| elif problem_name == "CellTowers": | |
| description = ( | |
| "π‘ **Cell Tower Placement Optimization**\n\n" | |
| "Choose which towers to build to maximize covered population within a $20M budget. " | |
| "Each region is considered covered if at least one selected tower reaches it." | |
| ) | |
| result = cell_towers.solve_cell_towers() | |
| code = inspect.getsource(cell_towers.solve_cell_towers) | |
| elif problem_name == "R&DProjects": | |
| description = ( | |
| "π¬ **R&D Project Selection**\n\n" | |
| "Select R&D projects to maximize Net Present Value while satisfying budget and staffing limits. " | |
| "Includes logical dependencies like mutual exclusivity and project implication constraints." | |
| ) | |
| result = rd_projects.solve_rd_projects() | |
| code = inspect.getsource(rd_projects.solve_rd_projects) | |
| elif problem_name == "Fire": | |
| description = ( | |
| "π **Minimum Fire Station Coverage (Set Covering Problem)**\n\n" | |
| "Minimize the number of fire stations needed to ensure every region is covered by at least one." | |
| ) | |
| result = fire_station.solve_fire_station() | |
| code = inspect.getsource(fire_station.solve_fire_station) | |
| else: | |
| raise ValueError("Invalid problem selected.") | |
| return description, f"```python\n{code}\n```", result | |
| except Exception as e: | |
| return "β Error during execution", "```python\n<no code>\n```", f"**Details:** {e}" | |
| interface = gr.Interface( | |
| fn=solve_and_display, | |
| inputs=gr.Radio( | |
| ["SpencerShoe", "CellTowers", "R&DProjects", "Fire"], | |
| label="π Choose a Problem to Explore" | |
| ), | |
| outputs=[ | |
| gr.Markdown(label="π Problem Description"), | |
| gr.Code(label="π Pyomo Code (Python version of .mod/.dat)"), | |
| gr.Markdown(label="π Solution Output") | |
| ], | |
| title="π Linear & Integer Programming Explorer", | |
| description="Choose one of the problems to explore the code and view the solution using Pyomo." | |
| ) | |
| if __name__ == "__main__": | |
| interface.launch() | |