- if inequalities is not None:
- for constraint in inequalities:
- for value in constraint.values():
- if value.denominator != 1:
- raise TypeError('non-integer constraint: '
- '{} <= 0'.format(constraint))
- self._inequalities.append(constraint)
+ string = re.sub(r'^\s*\{\s*(.*?)\s*\}\s*$', lambda m: m.group(1), string)
+ if ':' not in string:
+ string = string + ':'
+ vstr, cstr = re.split(r'\s*:\s*', string)
+ assert vstr != ''
+ vstr = re.sub(r'^\s*\[\s*(.*?)\s*\]\s*$', lambda m: m.group(1), vstr)
+ toks = list(filter(None, re.split(r'\s*,\s*', vstr)))
+ assert len(toks) == len(symbols)
+ for i in range(len(symbols)):
+ symbol = symbols[i]
+ if toks[i] != symbol:
+ expr = Expression._fromiscc(symbols, toks[i])
+ self._equalities.append(Symbol(symbol) - expr)
+ if cstr != '':
+ cstrs = re.split(r'\s*and\s*', cstr)
+ for cstr in cstrs:
+ lhs, op, rhs = re.split(r'\s*(<=|>=|<|>|=)\s*', cstr)
+ lhs = Expression._fromiscc(symbols, lhs)
+ rhs = Expression._fromiscc(symbols, rhs)
+ if op == '=':
+ self._equalities.append(lhs - rhs)
+ elif op == '<=':
+ self._inequalities.append(lhs - rhs)
+ elif op == '>=':
+ self._inequalities.append(rhs - lhs)
+ elif op == '<':
+ self._inequalities.append(lhs - rhs + 1)
+ elif op == '>':
+ self._inequalities.append(rhs - lhs + 1)