first attempt at using FuncDesigner
This commit is contained in:
parent
2d24e7a920
commit
95c11d0c23
42
Sketch.py
42
Sketch.py
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
from numpy import *
|
from numpy import *
|
||||||
from openopt import SLE
|
from FuncDesigner import *
|
||||||
import scipy.sparse.linalg
|
|
||||||
|
|
||||||
class Sketch(object):
|
class Sketch(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -29,34 +28,25 @@ class Sketch(object):
|
|||||||
shape_vars[shape_var] = varid
|
shape_vars[shape_var] = varid
|
||||||
varid += 1
|
varid += 1
|
||||||
varid_to_shape_var.append(shape_var)
|
varid_to_shape_var.append(shape_var)
|
||||||
dim = max(len(equations), len(shape_vars))
|
dim = len(equations)
|
||||||
C = zeros((dim, dim))
|
if len(shape_vars) > dim:
|
||||||
d = zeros(dim)
|
dim = len(shape_vars)
|
||||||
print 'matrix size (%d, %d)' % (dim, dim)
|
equs = []
|
||||||
for i in range(len(equations)):
|
variables = oovars(dim)
|
||||||
e = equations[i]
|
for e in equations:
|
||||||
coeffs = e[0]
|
coeffs = e[0]
|
||||||
|
equ = -e[1]
|
||||||
for c in coeffs:
|
for c in coeffs:
|
||||||
var_index = shape_vars[c[1]]
|
equ = c[0] * variables[shape_vars[c[1]]] + equ
|
||||||
C[i][var_index] = c[0]
|
equs.append(equ)
|
||||||
if c[0] != 0:
|
if len(equs) < dim:
|
||||||
print c[1][0].name, c[1][1], 'is at', i, var_index, \
|
print 'TODO: pad equation list'
|
||||||
'with coefficient', c[0]
|
s = sle(equs)
|
||||||
d[i] = e[1]
|
|
||||||
print 'equ', i, 'expected value:', e[1]
|
|
||||||
# for row in range(len(equations)):
|
|
||||||
# print '[',
|
|
||||||
# for col in range(len(shape_vars)):
|
|
||||||
# print C[row][col],
|
|
||||||
# print ',',
|
|
||||||
# print '] [%f]' % d[row]
|
|
||||||
s = SLE(C, d)
|
|
||||||
r = s.solve()
|
r = s.solve()
|
||||||
solved_vars = r.xf
|
|
||||||
print 'IGNORED THINGY: ', r.ff
|
print 'IGNORED THINGY: ', r.ff
|
||||||
print "SOLVED: ", solved_vars
|
print "SOLVED: ", r(variables)
|
||||||
for i in range(len(solved_vars)):
|
for i in range(len(variables)):
|
||||||
varid_to_shape_var[i][0].setVar(varid_to_shape_var[i][1],
|
varid_to_shape_var[i][0].setVar(varid_to_shape_var[i][1],
|
||||||
solved_vars[i])
|
r(variables[i]))
|
||||||
for s in self.shapes:
|
for s in self.shapes:
|
||||||
print 'shape:', repr(s.vars)
|
print 'shape:', repr(s.vars)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user