本文整理汇总了Python中Solver.Solver类的典型用法代码示例。如果您正苦于以下问题:Python Solver类的具体用法?Python Solver怎么用?Python Solver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Solver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
while True:
html = self.opener.open(captcha_url).read().decode()
captcha_img_url = host + pq(html)("#captcha_image").attr("src")
captcha_img = self.opener.open(captcha_img_url).read()
try:
solver = Solver(Image.open(BytesIO(captcha_img)), captcha_length)
result = solver.get_result()
if len(solver.char_areas) != captcha_length:
raise IndexError()
except IndexError:
self.queue.put(
(Image.open(BytesIO(captcha_img)), Image.open(BytesIO(captcha_img)), "------", False, True))
continue
payload = {
"do": "contact",
"ct_name": "",
"ct_email": "",
"ct_URL": "",
"ct_message": "",
"ct_captcha": result
}
resp = self.opener.open(captcha_url, urlencode(payload).encode()).read().decode()
print("put!")
img_data = {
'pixels': solver.captcha.tobytes(),
'size': solver.captcha.size,
'mode': solver.captcha.mode,
}
if "captcha was correct" in resp:
self.queue.put((Image.open(BytesIO(captcha_img)), img_data, result, True, False))
print('Corr')
else:
self.queue.put((Image.open(BytesIO(captcha_img)), img_data, result, False, False))
print('Wong')
示例2: __init__
def __init__(self, iters=6000, test='temp', full=True, L=True, OD=True,
CP=True, LP=True, eq='CP', init=False, noise=0,
method='py_oracle'):
Solver.__init__(self, test=test, full=full, L=L, OD=OD, CP=CP, LP=LP,
eq=eq, init=init, noise=noise, method=method)
self.iters = iters
# CS test config
self.CS_PATH = '/Users/cathywu/Dropbox/Fa13/EE227BT/traffic-project'
self.OUT_PATH = '%s/' % c.DATA_DIR
# Test parameters
# self.method = 'cvx_random_sampling_L1_30_replace'
# self.method = method # 'cvx_random_sampling_L1_6000_replace'
# self.method = 'cvx_oracle'
# alg = 'cvx_unconstrained_L1'
# alg = 'cvx_L2'
# alg = 'cvx_raw'
# alg = 'cvx_weighted_L1'
# alg = 'cvx_hot_start_lp'
# alg = 'cvx_single_block_L_infty'
# alg = 'cvx_random_sample_L_infty'
# alg = 'cvx_mult_blocks_L_infty'
# alg = 'cvx_block_descent_L_infty'
# alg = 'cvx_entropy'
self.A, self.b, self.N, self.block_sizes, self.x_true, self.nz, \
self.flow, self.rsort_index, self.x0 = None, None, None, None, \
None, None, None, None, None
self.fname, self.mlab = None, None
示例3: __init__
def __init__(self, name="solvernonlinear"):
"""
Constructor.
"""
Solver.__init__(self, name)
ModuleSolverNonlinear.__init__(self)
return
示例4: mkgoodtrain
def mkgoodtrain():
wps = open("../all_a.txt").readlines()
answs = open("../all_aa.txt").readlines()
goodtrain = open("goodp.txt",'w')
goodtraina = open("gooda.txt",'w')
for k in range(len(wps)):
print(k)
problem = wps[k].lower()
try:
story = nlp.parse(problem)
numbs = setmaker.setmaker(story)
numlist = [cleannum(v.num) for k,v in numbs if setmaker.floatcheck(v.num)]
numlist = [x for x in numlist if x!='']
except:
continue
print(numlist)
signal.signal(signal.SIGALRM, kill)
signal.alarm(10)
try:
ST = Solver(numlist)
answers = ST.solveEquations(float(answs[k]))
print(answers)
except:
continue
if answers != []:
goodtrain.write(problem)
goodtraina.write(answs[k])
goodtrain.close();goodtraina.close()
示例5: __init__
def __init__(self, name, facility="solver"):
Solver.__init__(self, name, facility)
self.coupler = None
self.myPlus = []
self.remotePlus = []
return
示例6: checkpoint
def checkpoint(self, checkpointFrequency):
Solver.checkpoint(self, checkpointFrequency)
if not (self.step % checkpointFrequency):
#TODO: checkpoint for coupler
pass
return
示例7: __init__
def __init__(self, name="solverlinear"):
"""
Constructor.
"""
Solver.__init__(self, name)
ModuleSolverLumped.__init__(self)
return
示例8: _configure
def _configure(self):
"""
Set members based using inventory.
"""
Solver._configure(self)
ModuleSolverNonlinear.skipNullSpaceCreation(self, not self.createNullSpace)
return
示例9: initialize
def initialize(self, application):
Solver.initialize(self, application)
self.coupler = application.coupler
self.myPlus = application.myPlus
self.remotePlus = application.remotePlus
self.coupler.initialize(self)
return
示例10: run
def run(self):
while True:
buffer = BytesIO(urlopen(captcha_url).read())
solver = Solver(Image.open(buffer), captcha_length)
while len(solver.char_areas) != captcha_length:
buffer = BytesIO(urlopen(captcha_url).read())
solver = Solver(Image.open(buffer), captcha_length)
buffer.seek(0)
captcha_result = solver.get_result()
CaptchaGatherThread.captchas.put({"captcha": Image.open(buffer), "solver": solver, "guess": captcha_result})
示例11: run
def run(self):
while True:
solver = None
while solver is None or len(solver.char_areas) != captcha_length:
rep = urlopen(captcha_url)
answer = rep.info()['x-captcha-code']
print(answer)
buffer = BytesIO(rep.read())
solver = Solver(Image.open(buffer), captcha_length)
buffer.seek(0)
captcha_result = solver.get_result()
CaptchaGatherThread.captchas.put({"captcha": Image.open(buffer), "solver": solver, "guess": captcha_result, "answer": answer})
print('Put')
示例12: run
def run(self):
while True:
buffer = BytesIO(self.opener.open(captcha_url).read())
try:
solver = Solver(Image.open(buffer), captcha_length)
except Exception as e:
print("Rate limit exceeded: ", e)
return
while len(solver.char_areas) != captcha_length:
buffer = BytesIO(self.opener.open(captcha_url).read())
solver = Solver(Image.open(buffer), captcha_length)
buffer.seek(0)
captcha_result = solver.get_result()
CaptchaGatherThread.captchas.put({"captcha": Image.open(buffer), "solver": solver, "guess": captcha_result})
示例13: __init__
def __init__(self, test=None, full=True, L=True, OD=True, CP=True, LP=True,
eq='CP', damp=0, noise=0.0):
Solver.__init__(self)
self.test = test
self.eq = eq
self.full = full
self.L = L
self.OD = OD
self.CP = CP
self.LP = LP
self.damp = damp
self.data, self.A, self.b, self.x0, self.x_true = None, None, None, \
None, None
示例14: __init__
def __init__(self,node_set):
self.node_set=node_set
#Initialize all the variables
Initialization.Initialization(self.node_set)
self.solver=Solver(self.node_set)
示例15: Interpreter
inter = Interpreter(vectorial =True)
mass = inter.lumped_mass_matrix(simu)
mass = mass[:,0]
print sum(mass)
for node in range(node_coords.shape[0]):
dofs_past.append(DOF(node, simu, comp = 0, t = 0 * dt))
dofs_past.append(DOF(node, simu, comp = 1, t = 0 * dt))
dofs_present.append(DOF(node, simu, comp = 0, t = 1 * dt))
dofs_present.append(DOF(node, simu, comp = 1, t = 1 * dt))
dofs_future.append(DOF(node, simu, comp = 0, t = 2 * dt))
dofs_future.append(DOF(node, simu, comp = 1, t = 2 * dt))
snapshot = [dofs_past, dofs_present, dofs_future]
from numpy import zeros, append, array
solver = Solver()
quads = solver.substract_1(simu.domain.elements.quads.el_set)
quads = quads[:,1:]
field3 = zeros((simu.domain.nodes.n,3))
for n in times:
print n
field = array([])
# for dof in snapshot[1]:
# print 'dof.node_id',dof.node_id, 'value', dof.value
for dof in range(len(snapshot[0])):
E_past = snapshot[0][dof]
E_present = snapshot[1][dof]
E_future = snapshot[2][dof]
if E_future.check_if_in_boundary(simu, t = n*dt) == False:
Fi = E_present.find_surrounding_elements(snapshot[1], simu)
F = -Fi + 1.0/(dt**2)*mass[dof]*(2*E_present.value - E_past.value)