def solve_trace(self, func, trace): if func in self._solve_cache: # trace.log('using cache for %s' % str(func)) return trace.result(self._solve_cache[func]) trace.values(type='series') with trace.child('dp1') as t: u1 = self.dp1.solve_trace(func, t) if do_extra_checks(): R1 = self.dp1.get_res_space() tr1 = UpperSets(R1) tr1.belongs(u1) mcdp_dev_warning('rewrite this keeping structure') mins = set([]) for u in u1.minimals: with trace.child('dp2') as t: v = self.dp2.solve_trace(u, t) mins.update(v.minimals) R = self.get_res_space() minimals = poset_minima(mins, R.leq) us = UpperSet(minimals, R) self._solve_cache[func] = us return trace.result(us)
def solve_f_iterate(dp0, f1, R, S, trace): """ Returns the next iteration si \in UR Min ( h(f1, r20) \cup !r20 ) """ UR = UpperSets(R) if do_extra_checks(): UR.belongs(S) R2 = R[1] converged = set() # subset of solutions for which they converged nextit = set() # find the set of all r2s for ra in S.minimals: hr = dp0.solve_trace((f1, ra[1]), trace) for rb in hr.minimals: valid = R.leq(ra, rb) if valid: nextit.add(rb) feasible = R2.leq(rb[1], ra[1]) if feasible: converged.add(rb) nextit = R.Us(poset_minima(nextit, R.leq)) converged = R.Us(poset_minima(converged, R.leq)) return nextit, converged
def check_evaluate(id_dp, dp): """ Test for PrimitiveDP:evaluate() """ print('Testing %s: %s' % (id_dp, dp)) F = dp.get_fun_space() R = dp.get_res_space() UR = UpperSets(R) LF = LowerSets(F) M = dp.get_imp_space() # We get a random m m0 = M.witness() try: lf, ur = dp.evaluate(m0) except NotSolvableNeedsApprox: return UR.belongs(ur) LF.belongs(lf) if not lf.maximals or not ur.minimals: msg = 'The point m0 gave empty lf, ur.' raise_desc(Exception, msg, lf=lf, ur=ur, m0=M.format(m0), M=M, dp=dp.repr_long()) # take one possible feasible pair _f = list(lf.maximals)[0] _r = list(ur.minimals)[0]
def eval_constant_uppersetfromcollection(op, context): x = eval_constant(op.value, context) v = x.value u = x.unit S = u.S minimals = poset_minima(v.elements, S.leq) value = UpperSet(minimals, S) unit = UpperSets(S) if do_extra_checks(): unit.belongs(value) vu = ValueWithUnits(value, unit) return vu
def solveU(self, ufunc): if do_extra_checks(): UF = UpperSets(self.get_fun_space()) UF.belongs(ufunc) res = set([]) for m in ufunc.minimals: u = self.solve(m) res.update(u.minimals) ressp = self.get_res_space() minima = poset_minima(res, ressp.leq) return ressp.Us(minima)