def check_anyof2(): ndp = parse_ndp(""" mcdp { provides x [g x g] x <= any-of({<0g,1g>, <1g, 0g>}) } """) dp = ndp.get_dp() R = dp.get_res_space() F = dp.get_fun_space() UR = UpperSets(R) res = dp.solve((0.5, 0.5)) l = LowerSet(P=F, maximals=[(0.0, 1.0), (1.0, 0.0)]) l.belongs((0.0, 0.5)) l.belongs((0.5, 0.0)) UR.check_equal(res, UpperSet([], R)) res = dp.solve((0.0, 0.5)) UR.check_equal(res, UpperSet([()], R)) res = dp.solve((0.5, 0.0)) UR.check_equal(res, UpperSet([()], R))
def __init__(self, F, values): if do_extra_checks(): for value in values: F.belongs(value) self.limit = LowerSet(values, F) R = PosetProduct(()) M = PosetProduct(()) PrimitiveDP.__init__(self, F=F, R=R, I=M)
class LimitMaximals(PrimitiveDP): """ h: f ⟼ {⟨⟩}, if f \in \downarrow values ø, otherwise h* : ⟨⟩ ⟼ values """ @contract(F='$Poset', values='seq|set') def __init__(self, F, values): if do_extra_checks(): for value in values: F.belongs(value) self.limit = LowerSet(values, F) R = PosetProduct(()) M = PosetProduct(()) PrimitiveDP.__init__(self, F=F, R=R, I=M) def evaluate(self, m): assert m == () lf = self.limit ur = UpperSet(set([()]), self.R) return lf, ur def solve(self, f): try: # check that it belongs self.limit.belongs(f) except NotBelongs: empty = UpperSet(set(), self.R) return empty res = UpperSet(set([()]), self.R) return res def solve_r(self, r): assert r == () return self.limit def __repr__(self): s = len(self.limit.maximals) return 'LimitMaximals(%s, %s els)' % (self.F, s) def repr_h_map(self): LF = LowerSets(self.F) return 'f ⟼ {⟨⟩} if f ∈ %s, else ø' % LF.format(self.limit) def repr_hd_map(self): contents = ", ".join( self.F.format(m) for m in sorted(self.limit.maximals)) return '⟨⟩ ⟼ {%s}' % contents
def evaluate(self, i): if do_extra_checks(): self.I.belongs(i) f = i rs = self.solve(f) fs = LowerSet(set([f]), self.F) return fs, rs
def evaluate(self, m): assert m == () minimals = self.R.get_minimal_elements() ur = UpperSet(minimals, self.R) maximals = self.F.get_maximal_elements() lf = LowerSet(maximals, self.F) return lf, ur
def eval_constant_lowersetfromcollection(op, context): x = eval_constant(op.value, context) v = x.value u = x.unit S = u.S maximals = poset_minima(v.elements, S.leq) value = LowerSet(maximals, S) unit = LowerSets(S) if do_extra_checks(): unit.belongs(value) vu = ValueWithUnits(value, unit) return vu
def evaluate(self, i): if do_extra_checks(): self.I.belongs(i) options_r = [] options_f = [] for name, f_max, r_min in self.entries: if name != i: continue options_f.append(f_max) options_r.append(r_min) rs = poset_minima(options_r, self.R.leq) fs = poset_maxima(options_f, self.F.leq) ur = UpperSet(rs, self.R) lf = LowerSet(fs, self.F) return lf, ur
def Ls(self, elements): from mcdp_posets import LowerSet return LowerSet(elements, self)
def L(self, a): """ Returns the principal lower set corresponding to the given a. """ if do_extra_checks(): self.belongs(a) from mcdp_posets import LowerSet return LowerSet([a], self)
def evaluate(self, i): assert i == '*' rs = UpperSet(set([self.R.get_bottom()]), self.R) fs = LowerSet(set([self.F.get_top()]), self.F) return fs, rs