import pyomo.environ as pyo
model = pyo.ConcreteModel(name='Bubbles Brewery')

# Data coefficients
beer_types = ['light', 'dark']
ingredients = ['corn', 'hops', 'malt']

profit = {'light': 13, 'dark': 23}
recipe = {'light': {'corn': 5, 'hops': 4, 'malt': 35},
          'dark': {'corn': 15, 'hops': 4, 'malt': 20}}
on_hand = {'corn': 480, 'hops': 160, 'malt': 1190}

# Decision variables
model.x = pyo.Var(beer_types, within=pyo.NonNegativeReals)

# Objective function
model.objective = pyo.Objective(expr=sum(profit[bt] * model.x[bt] for bt in beer_types),
                                sense=pyo.maximize)


# Constraints
def resource_constraint(mdl, ingredient):
    return (sum(recipe[beer_type][ingredient] * mdl.x[beer_type]
                for beer_type in beer_types)
            <= on_hand[ingredient])


model.resources = pyo.Constraint(ingredients, rule=resource_constraint)

# Export the model
model.write('bubbles_brewery.mps', io_options={'symbolic_solver_labels': True})

# Optionally print the model to verify
model.pprint()
