zpetrea's picture
Update app.py
f30c578 verified
Raw
History Blame Contribute Delete
2.88 kB
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()