def insert(self, name): # db에 저장하는 함수 conn = pymysql.connect(host='127.0.0.1', user='******', password='******', db='javap', charset='utf8') try: with conn.cursor() as cursor: sql = "insert into pypeople(person) values(%s)" cursor.execute(sql, name) conn.commit() finally: conn.close() q1.q1(name)
def q2(): from gurobipy import GRB, Model, quicksum, LinExpr import pandas as pd #import numpy # You can either extract A,B,c from q1 if you want from q1 import q1 A, b, c = q1() # Creation of the model m = Model('Dual') # Your code goes here N = len(c) # The following example is here to help you build the model (you must adapt it !!!) # Define decision variables lamb = [] for i in range(len(A)): lamb.append(m.addVar(lb = 0, vtype=GRB.CONTINUOUS, name = 'lamb_{}'.format(i), obj = 1)) # Define constraints: for i in range(len(c)): lhs = LinExpr() for j in range(len(A)): lhs.add(lamb[j], A[j][i]) m.addConstr(lhs, ">=" , rhs=c[i]) # Define objective function: objexpr = LinExpr() for i in range(len(b)): objexpr.add(lamb[i], b[i]) m.setObjective(objexpr, GRB.MINIMIZE) m.update() m.write('q2.lp') m.optimize() z = m.objVal lamb = [v.x for v in lamb[:4]] return ([z, lamb])
from q1 import q1 from q2 import q2 from q3 import q3 from q4 import q4 from q5 import q5 print "Question 1" q1() raw_input() print "Question 2" q2() print "Question 3" q3() print "Question 4" q4() print "Question 5" q5()
import sys import q1 as v file=open(sys.argv[1],'r') m=[] for line in file: m += list(map(int,line.rstrip().split())) p=v.q1(m) print(p)
pyramid_points = np.array([[0, -1, 0], [-1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 3]]) tronco_points = np.array([ [-1.5, -1.5, 0], [1.5, -1.5, 0], [1.5, 1.5, 0], [-1.5, 1.5, 0], [-0.65, -0.65, 2.5], [0.65, -0.65, 2.5], [0.65, 0.65, 2.5], [-0.65, 0.65, 2.5], ]) # # PRIMEIRA QUESTÃO q1(cube_points, parallel_points, pyramid_points, tronco_points) # SEGUNDA QUESTÃO cube_points, parallel_points, pyramid_points, tronco_points = q2( cube_points, parallel_points, pyramid_points, tronco_points) # TERCEIRA QUESTÃO c_points, p_points = q3(copy(cube_points), copy(pyramid_points), copy(parallel_points), copy(tronco_points), np.array([3, -3, 3]), True) # QUARTA QUESTÃO q4(c_points, p_points, True) # OPCIONAL eyes = [np.array([i, -3, 3]) for i in np.arange(-2, 8, .5)] for i, eye in enumerate(eyes):
def main(): q1() q2() q3() q4()
def test_all_zero(): assert q1([0, 0, 0]) == 512
def test_example_2(): assert q1([0, 1, 99]) == 0
def test_example_1(): assert q1([0, 1, 2]) == 3
def test_invalid_args_type(): with pytest.raises(ValueError): q1([0, 0, 'x'])
def test_invalid_args_length(): with pytest.raises(ValueError): q1([0, 0])
def test_not_exist(): assert q1([0, 0, 1000]) == 0