Coverage for docs/source/examples/external_constraint.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1"Can be found in gpkit/docs/source/examples/external_constraint.py" 

2from external_function import external_code 

3 

4 

5class ExternalConstraint: 

6 "Class for external calling" 

7 

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 

14 

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 posynomial approximation around that position 

24 return (self.y >= res * self.x/x_star)