Skip to content

Instantly share code, notes, and snippets.

@francoisstamant
Created September 5, 2022 19:44
Show Gist options
  • Save francoisstamant/21f400eda458d7e069c953071d412fd7 to your computer and use it in GitHub Desktop.
Save francoisstamant/21f400eda458d7e069c953071d412fd7 to your computer and use it in GitHub Desktop.
#Add constraints to the model
#The values
x = knapsack_model.addVars(N, vtype = GRB.INTEGER, name="x")
#The total cost must be inferior to our budget
knapsack_model.addConstr(sum(cost_dollars[i]*x[i] for i in range(N)) <= total_budget)
#Minimum for each aspect must be filled
knapsack_model.addConstrs(x[i] >= minimum_time[i] for i in range(N))
#Maximum for each aspect must be respected
knapsack_model.addConstrs(x[i] <= maximum_time[i] for i in range(N))
#Sum of hours must be equal to total possible hours
knapsack_model.addConstr(sum(x[i] for i in range(N)) == total_hours)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment