예제 #1
0
def check_uncertainty3():

    s = """
mcdp {
  provides capacity [J]
  requires mass     [kg]

  required mass * Uncertain(2 J/kg, 3 J/kg) >= provided capacity
}
"""
    ndp = parse_ndp(s)
    dp = ndp.get_dp()
    R = dp.get_res_space()
    UR = UpperSets(R)
    dpl, dpu = get_dp_bounds(dp, 100, 100)
    f0 = 1.0  # J
    sl = dpl.solve(f0)
    su = dpu.solve(f0)
    print sl
    print su
    UR.check_leq(sl, su)

    real_lb = UpperSet(set([0.333333]), R)
    real_ub = UpperSet(set([0.500000]), R)

    # now dpl will provide a lower bound from below
    UR.check_leq(sl, real_lb)
    # and dpu will provide the upper bound from above
    UR.check_leq(real_ub, su)
예제 #2
0
def check_uncertainty2():
    ndp = parse_ndp("""
        mcdp {
            provides f1 [N]
            f1 <= Uncertain(1 N, 2 N)
        }
    """)

    dp = ndp.get_dp()
    dpl, dpu = get_dp_bounds(dp, 1, 1)

    R = dp.get_res_space()
    UR = UpperSets(R)
    f0 = 0.0  # N
    sl = dpl.solve(f0)
    su = dpu.solve(f0)
    UR.check_leq(sl, su)
    print sl
    print su

    f0 = 1.5  # N
    sl = dpl.solve(f0)
    su = dpu.solve(f0)
    UR.check_leq(sl, su)
    print sl
    print su
    feasible = UpperSet(set([()]), R)
    infeasible = UpperSet(set([]), R)
    sl_expected = feasible
    su_expected = infeasible
    print sl_expected
    print su_expected
    UR.check_equal(sl, sl_expected)
    UR.check_equal(su, su_expected)
예제 #3
0
파일: syntax_anyof.py 프로젝트: rusi/mcdp
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))
예제 #4
0
파일: dp_limit.py 프로젝트: rusi/mcdp
 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
예제 #5
0
def new_uncertainty01use():
    s = """mcdp {
        requires r1 = 10 kg ± 50 g
    }
    """
    ndp = parse_ndp(s)
    dp = ndp.get_dp()

    dpl, dpu = get_dp_bounds(dp, 1, 1)
    rl = dpl.solve(())
    ru = dpu.solve(())

    R = dp.get_res_space()
    UR = UpperSets(R)
    UR.check_equal(rl, UpperSet([9.95], R))
    UR.check_equal(ru, UpperSet([10.05], R))
예제 #6
0
파일: dp_dummy.py 프로젝트: rusi/mcdp
 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
예제 #7
0
파일: poset.py 프로젝트: rusi/mcdp
 def Us(self, elements):
     elements = list(elements)
     if do_extra_checks():
         for e in elements:
             self.belongs(e)
             # XXX n^2
         from mcdp_posets import check_minimal
         check_minimal(elements, poset=self)
     from mcdp_posets import UpperSet
     return UpperSet(elements, self)
예제 #8
0
def check_join_not_existence():
    """ A test for finite posets where the join might not exist. """
    from mcdp_library.library import MCDPLibrary
    l = MCDPLibrary()

    add_def_poset(
        l, 'P', """
    finite_poset {
        a <= b <= c
        A <= B <= C
    }
    """)

    #     parse_wrap(Syntax.LOAD, '`')
    #     parse_wrap(Syntax.posetname, 'P')
    #     print Syntax.load_poset
    #     parse_wrap(Syntax.load_poset, '`P')
    #     parse_wrap(Syntax.space_operand, '`P')
    #     parse_wrap(Syntax.fun_statement, "provides x [`P]")

    ndp = l.parse_ndp("""
        mcdp {
            provides x [`P]
            provides y [`P]
            requires z [`P]
            
            z >= x
            z >= y
        }
    """,
                      context=Context())
    dp = ndp.get_dp()

    res1 = dp.solve(('a', 'b'))

    P = l.load_poset('P')
    UR = UpperSets(P)
    UR.check_equal(res1, UpperSet(['b'], P))

    res2 = dp.solve(('a', 'A'))

    UR.check_equal(res2, UpperSet([], P))
예제 #9
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
예제 #10
0
파일: syntax_anyof.py 프로젝트: rusi/mcdp
def check_anyof1():
    ndp = parse_ndp("""
        mcdp {
            requires x [g x g]
            
            x >= any-of({<0g,1g>, <1g, 0g>})
        }
    """)
    dp = ndp.get_dp()
    R = dp.get_res_space()
    UR = UpperSets(R)
    res = dp.solve(())
    UR.check_equal(res, UpperSet([(0.0, 1.0), (1.0, 0.0)], R))
예제 #11
0
파일: dp_catalogue.py 프로젝트: rusi/mcdp
    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
예제 #12
0
파일: poset.py 프로젝트: rusi/mcdp
 def U(self, a):
     """ Returns the principal upper set corresponding to the given a. """
     if do_extra_checks():
         self.belongs(a)
     from mcdp_posets import UpperSet
     return UpperSet([a], self)
예제 #13
0
파일: dp_limit.py 프로젝트: rusi/mcdp
 def evaluate(self, m):
     assert m == ()
     lf = self.limit
     ur = UpperSet(set([()]), self.R)
     return lf, ur
예제 #14
0
 def solve(self, f):  # @UnusedVariable
     minimals = [self.R.get_bottom()]
     return UpperSet(set(minimals), self.R)
예제 #15
0
 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