diff --git a/Sketch.py b/Sketch.py index 8918dc7..2e54334 100644 --- a/Sketch.py +++ b/Sketch.py @@ -1,7 +1,6 @@ from numpy import * -from openopt import SLE -import scipy.sparse.linalg +from FuncDesigner import * class Sketch(object): def __init__(self): @@ -29,34 +28,25 @@ class Sketch(object): shape_vars[shape_var] = varid varid += 1 varid_to_shape_var.append(shape_var) - dim = max(len(equations), len(shape_vars)) - C = zeros((dim, dim)) - d = zeros(dim) - print 'matrix size (%d, %d)' % (dim, dim) - for i in range(len(equations)): - e = equations[i] + dim = len(equations) + if len(shape_vars) > dim: + dim = len(shape_vars) + equs = [] + variables = oovars(dim) + for e in equations: coeffs = e[0] + equ = -e[1] for c in coeffs: - var_index = shape_vars[c[1]] - C[i][var_index] = c[0] - if c[0] != 0: - print c[1][0].name, c[1][1], 'is at', i, var_index, \ - 'with coefficient', c[0] - 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) + equ = c[0] * variables[shape_vars[c[1]]] + equ + equs.append(equ) + if len(equs) < dim: + print 'TODO: pad equation list' + s = sle(equs) r = s.solve() - solved_vars = r.xf print 'IGNORED THINGY: ', r.ff - print "SOLVED: ", solved_vars - for i in range(len(solved_vars)): + print "SOLVED: ", r(variables) + for i in range(len(variables)): varid_to_shape_var[i][0].setVar(varid_to_shape_var[i][1], - solved_vars[i]) + r(variables[i])) for s in self.shapes: print 'shape:', repr(s.vars)