Calmcode - cvxpy one: constraints

Constraints

1 2 3 4 5 6 7

This is the new problem definition with constraints;

import cvxpy as cp
import pandas as pd

df = pd.read_csv("/path/to/stigler.csv")
price = df['price_cents'].values

x = cp.Variable(price.shape[0])
objective = cp.Minimize(cp.sum(price*x))
constraints = [
    x >= 0,
    cp.sum(df['vitamin_c_mg'].values * x) >= 75,
    cp.sum(df['iron_mg'].values * x) >= 12,
]
prob = cp.Problem(objective, constraints)
prob.solve()