import gpkit import gpkit.interactive # transporting gravel across a river: # how large of a box should be used / how many trips should be taken? V1 = gpkit.Variable("V_1", 400, "cubic yards", "volume of gravel to transport") l = gpkit.Variable("l", "yards", "box length") w = gpkit.Variable("w", "yards", "box width") h = gpkit.Variable("h", "yards", "box height") c_sides = gpkit.Variable("c_{sides}", 10, "1/yard^2", "cost of box sides and bottom") c_ends = gpkit.Variable("c_{ends}", 20, "1/yard^2", "cost of box ends") c_ferry = gpkit.Variable("c_{ferry}", 0.10, "-", "cost of ferry trip") A_end = w*h A_side = l*h A_bottom = w*l total_cost = c_ferry*V1/(l*w*h) + c_ends*2*A_end + c_sides*(2*A_side + A_bottom) gp = gpkit.GP(total_cost) sol = gp.solve() print sol.table() gp.sub(h, 1) sol = gp.solve() print sol.table() A_scrap = gpkit.Variable("A_{scrap}", 4, "yards^2", "scrap material available") gp = gpkit.GP(c_ferry*V1/(l*w*h) + c_ends*2*A_end, [2*A_side + A_bottom <= A_scrap]) gp print gp.solve().table() L = gpkit.Variable("L", 1, "yards", "total fence length") l = gpkit.Variable("l", "yards", "plot side parallel to river") w = gpkit.Variable("w", "yards", "plot side perpendicular to river") A_plot = l*w gp = gpkit.GP(1/A_plot, [2*w + l <= L]) sol = gp.solve() print sol.table() R = gpkit.Variable("R", 1, "inches", "log radius") d = gpkit.Variable("d", "inches", "beam depth") w = gpkit.Variable("w", "inches", "beam width") gp = gpkit.GP(1/(w*d**3), [(d/2)**2 + (w/2)**2 <= R**2]) sol = gp.solve() print sol.table() L = gpkit.Variable("L", 1, "inches", "tin sheet side length") l = gpkit.Variable("l", "inches", "box length") w = gpkit.Variable("w", "inches", "box width") h = gpkit.Variable("h", "inches", "box height") cx = gpkit.Variable("c_x", "inches", "corner cutout length in x dimension") cy = gpkit.Variable("c_y", "inches", "corner cutout length in y dimension") gp = gpkit.GP(1/(l*w*h), [L >= w + 2*cx, L >= l + 2*cy, cx >= h, cy >= h]) sol = gp.solve() print sol.table() tw = gpkit.Variable("\\tau_W", "-", "hours spent working") ts = gpkit.Variable("\\tau_S", "-", "hours spent sleeping") to = gpkit.Variable("\\tau_O", "-", "hours spent eating and/or listening") tm = gpkit.Variable("\\tau_M", "-", "hours spent listening to music") s = gpkit.Variable("s", "-", "savings accrued per day") p = gpkit.Variable("p", 0.5, "-", "pay rate per unit productivity") c = gpkit.Variable("c", 5, "-", "cost of new records, per hour") te = gpkit.Variable("\\tau_E", 3 ,"-", "hours required to be spent eating") gp = gpkit.GP( 1/s, [p*tw**1.5*ts**0.75*tm**0.1 >= s + c*tm, tw + ts + to <= 24, to >= tm, to >= te]) sol = gp.solve() print sol.table() from IPython import utils from IPython.core.display import HTML import os def css_styling(): """Load default custom.css file from ipython profile""" base = utils.path.get_ipython_dir() styles = "" % (open(os.path.join(base,'profile_default/static/custom/custom.css'),'r').read()) return HTML(styles) css_styling()