Example #1
0
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
Example #2
0
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
Example #3
0
    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)
Example #4
0
def eval_rvalue_anyofres(r, context):
    from mcdp_posets import FiniteCollectionsInclusion
    from mcdp_posets import FiniteCollection
    from mcdp_dp.dp_constant import ConstantMinimals

    assert isinstance(r, CDP.AnyOfRes)
    constant = eval_constant(r.value, context)
    if not isinstance(constant.unit, FiniteCollectionsInclusion):
        msg = ('I expect that the argument to any-of evaluates to '
              'a finite collection.')
        raise_desc(DPSemanticError, msg, constant=constant)
    assert isinstance(constant.unit, FiniteCollectionsInclusion)
    P = constant.unit.S
    assert isinstance(constant.value, FiniteCollection)

    elements = constant.value.elements
    minimals = poset_minima(elements, P.leq)
    if len(elements) != len(minimals):
        msg = 'The elements are not minimal.'
        raise_desc(DPSemanticError, msg, elements=elements, minimals=minimals)

    dp = ConstantMinimals(R=P, values=minimals)
    return create_operation(context, dp=dp, resources=[],
                               name_prefix='_anyof', op_prefix='_',
                                res_prefix='_result')
Example #5
0
    def solve(self, f):
        R = self.R
        F = self.F
        options_r = []
        for _name, f_max, r_min in self.entries:
            if F.leq(f, f_max):
                options_r.append(r_min)

        rs = poset_minima(options_r, R.leq)
        return R.Us(rs)
Example #6
0
    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)
Example #7
0
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
Example #8
0
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
Example #9
0
 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)
Example #10
0
    def solve(self, f):
        R = self.get_res_space()

        s = []

        mcdp_dev_warning('use specific operation on antichains')
        for dp in self.dps:
            rs = dp.solve(f)
            s.extend(rs.minimals)

        res = R.Us(poset_minima(s, R.leq))

        return res
Example #11
0
    def solve(self, f):
        R = self.get_res_space()

        s = []

        mcdp_dev_warning('use specific operation on antichains')
        for dp in self.dps:
            rs = dp.solve(f)
            s.extend(rs.minimals)

        res = R.Us(poset_minima(s, R.leq))

        return res
Example #12
0
    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
Example #13
0
    def evaluate(self, m):
        from mcdp_posets.category_product import get_product_compact
        _, _, unpack = get_product_compact(self.M0, self.F2, self.R2)
        m0, _f2, _r2 = unpack(m)

        LF0, UR0 = self.dp1.evaluate(m0)
        assert isinstance(LF0, LowerSet), (LF0, self.dp1)
        assert isinstance(UR0, UpperSet), (UR0, self.dp1)

        # now extract first components f1 and r1
        f1s = set()
        for fi in LF0.maximals:
            fi1, _ = fi
            f1s.add(fi1)
        f1s = poset_maxima(f1s, self.F.leq)
        LF = self.F.Ls(f1s)
        r1s = set()
        for ri in UR0.minimals:
            ri1, _ = ri
            r1s.add(ri1)
        r1s = poset_minima(r1s, self.F.leq)
        UR = self.R.Us(r1s)
        return LF, UR
Example #14
0
    def evaluate(self, m):
        from mcdp_posets.category_product import get_product_compact
        _, _, unpack = get_product_compact(self.M0, self.F2, self.R2)
        m0, _f2, _r2 = unpack(m)

        LF0, UR0 = self.dp1.evaluate(m0)
        assert isinstance(LF0, LowerSet), (LF0, self.dp1)
        assert isinstance(UR0, UpperSet), (UR0, self.dp1)

        # now extract first components f1 and r1
        f1s = set()
        for fi in LF0.maximals:
            fi1, _ = fi
            f1s.add(fi1)
        f1s = poset_maxima(f1s, self.F.leq)
        LF = self.F.Ls(f1s)
        r1s = set()
        for ri in UR0.minimals:
            ri1, _ = ri
            r1s.add(ri1)
        r1s = poset_minima(r1s, self.F.leq)
        UR = self.R.Us(r1s)
        return LF, UR
Example #15
0
def eval_rvalue_anyofres(r, context):
    from mcdp_posets import FiniteCollectionsInclusion
    from mcdp_posets import FiniteCollection
    from mcdp_dp.dp_constant import ConstantMinimals

    assert isinstance(r, CDP.AnyOfRes)
    constant = eval_constant(r.value, context)
    if not isinstance(constant.unit, FiniteCollectionsInclusion):
        msg = ('I expect that the argument to any-of evaluates to '
               'a finite collection.')
        raise_desc(DPSemanticError, msg, constant=constant)
    assert isinstance(constant.unit, FiniteCollectionsInclusion)
    P = constant.unit.S
    assert isinstance(constant.value, FiniteCollection)

    elements = constant.value.elements
    minimals = poset_minima(elements, P.leq)
    if len(elements) != len(minimals):
        msg = 'The elements are not minimal.'
        raise_desc(DPSemanticError, msg, elements=elements, minimals=minimals)

    dp = ConstantMinimals(R=P, values=minimals)
    return create_operation(context, dp=dp, resources=[], name_prefix='_anyof')