timfuz: begin converting to fractions

Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
John McMaster 2018-08-24 12:51:21 -07:00
parent b3f881a54c
commit 8c5436916c
2 changed files with 22 additions and 3 deletions

View File

@ -8,7 +8,7 @@ import math
from collections import OrderedDict
# check for issues that may be due to round off error
STRICT = 1
STRICT = 0
def Adi2matrix_random(A_ubd, b_ub, names):
# random assignment
@ -92,6 +92,8 @@ def row_sub_syms(row, sub_json, verbose=False):
assert pivot not in row
# after all constants are applied, the row should end up positive?
# numeric precision issues may limit this
# Ex: AssertionError: ('PIP_BSW_2ELSING0', -2.220446049250313e-16)
if STRICT:
for k, v in sorted(row.items()):
assert v > 0, (k, v)

View File

@ -12,8 +12,22 @@ import math
import json
import sympy
from collections import OrderedDict
from fractions import Fraction
STRICT = 1
STRICT = 0
def fracr(r):
DELTA = 0.0001
for i, x in enumerate(r):
if type(x) is float:
xi = int(x)
assert abs(xi - x) < DELTA
r[i] = xi
return [Fraction(x) for x in r]
def fracm(m):
return [fracr(r) for r in m]
class State(object):
def __init__(self, Ads, drop_names=[]):
@ -97,10 +111,13 @@ def comb_corr_sets(state, verbose=False):
mnp = Anp2matrix(Anp)
print('Matrix: %u rows x %u cols' % (len(mnp), len(mnp[0])))
print('Converting np to sympy matrix')
msym = sympy.Matrix(mnp)
mfrac = fracm(mnp)
print('mfrac', type(mfrac[0][0]))
msym = sympy.Matrix(mfrac)
print('Making rref')
rref, pivots = msym.rref()
if verbose:
print('names')
print(names)