Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"Can be found in gpkit/docs/source/examples/external_constraint.py"
2from external_function import external_code
5class ExternalConstraint:
6 "Class for external calling"
8 def __init__(self, x, y):
9 # We need a GPkit variable defined to return in our constraint. The
10 # easiest way to do this is to read in the parameters of interest in
11 # the initiation of the class and store them here.
12 self.x = x
13 self.y = y
15 def as_gpconstr(self, x0):
16 "Returns locally-approximating GP constraint"
17 # Creating a default constraint for the first solve
18 if self.x not in x0:
19 return (self.y >= self.x)
20 # Otherwise calls external code at the current position...
21 x_star = x0[self.x]
22 res = external_code(x_star)
23 # ...and returns a linearized posy <= 1
24 return (self.y >= res * self.x/x_star)