Coverage for docs/source/examples/x_greaterthan_1.py: 100%
8 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-07 22:15 -0500
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-07 22:15 -0500
1"Very simple problem: minimize x while keeping x greater than 1."
2from gpkit import Variable, Model
4# Decision variable
5x = Variable("x")
7# Constraint
8constraints = [x >= 1]
10# Objective (to minimize)
11objective = x
13# Formulate the Model
14m = Model(objective, constraints)
16# Solve the Model
17sol = m.solve(verbosity=0)
19# print selected results
20print(f"Optimal cost: {sol['cost']:.4g}")
21print(f"Optimal x val: {sol['variables'][x]:.4g}")