Exemple #1
0
def check_solve_f_chain(id_dp, dp):
    with primitive_dp_test(id_dp, dp):

        from mcdp_posets.utils import poset_check_chain

        F = dp.get_fun_space()

        f_chain = F.get_test_chain(n=8)
        poset_check_chain(F, f_chain)

        try:
            trchain = map(dp.solve, f_chain)
        except NotSolvableNeedsApprox:
            return try_with_approximations(id_dp, dp, check_solve_f_chain)

        R = dp.get_res_space()
        UR = UpperSets(R)
        try:
            poset_check_chain(UR, trchain)
        except ValueError as e:
            msg = 'The map solve() for %r is not monotone.' % id_dp
            raise_wrapped(Exception,
                          e,
                          msg,
                          f_chain=f_chain,
                          trchain=trchain,
                          compact=True)
Exemple #2
0
def check_solve_r_chain(id_dp, dp):
    with primitive_dp_test(id_dp, dp):

        from mcdp_posets.utils import poset_check_chain

        R = dp.get_res_space()
        F = dp.get_fun_space()
        LF = LowerSets(F)

        r_chain = R.get_test_chain(n=8)
        poset_check_chain(R, r_chain)

        try:
            lfchain = map(dp.solve_r, r_chain)
        except NotSolvableNeedsApprox:
            return try_with_approximations(id_dp, dp, check_solve_r_chain)

        try:
            # now, notice that we need to reverse this
            lfchain_reversed = list(reversed(lfchain))
            poset_check_chain(LF, lfchain_reversed)
        except ValueError as e:
            msg = 'The map solve_r() for %r is not monotone.' % id_dp
            raise_wrapped(Exception,
                          e,
                          msg,
                          r_chain=r_chain,
                          lfchain=lfchain,
                          lfchain_reversed=lfchain_reversed,
                          compact=True)
Exemple #3
0
def check_solve_r_chain(id_dp, dp):
    with primitive_dp_test(id_dp, dp):
    
        from mcdp_posets.utils import poset_check_chain
    
        R = dp.get_res_space()
        F = dp.get_fun_space()
        LF = LowerSets(F)
        
        r_chain = R.get_test_chain(n=8)
        poset_check_chain(R, r_chain)
    
        try:
            lfchain = map(dp.solve_r, r_chain)
        except NotSolvableNeedsApprox:
            return try_with_approximations(id_dp, dp, check_solve_r_chain)
        
        try:
            # now, notice that we need to reverse this
            lfchain_reversed = list(reversed(lfchain))
            poset_check_chain(LF, lfchain_reversed)
        except ValueError as e:
            msg = 'The map solve_r() for %r is not monotone.' % id_dp
            raise_wrapped(Exception, e, msg, r_chain=r_chain, lfchain=lfchain,
                          lfchain_reversed=lfchain_reversed, compact=True)
Exemple #4
0
def check_solve_f_chain(id_dp, dp):
    with primitive_dp_test(id_dp, dp):
    
        from mcdp_posets.utils import poset_check_chain
    
        F = dp.get_fun_space()
    
        f_chain = F.get_test_chain(n=8)
        poset_check_chain(F, f_chain)
    
        try:
            trchain = map(dp.solve, f_chain)
        except NotSolvableNeedsApprox:
            return try_with_approximations(id_dp, dp, check_solve_f_chain)
    
        R = dp.get_res_space()
        UR = UpperSets(R)
        try:
            poset_check_chain(UR, trchain)
        except ValueError as e:
            msg = 'The map solve() for %r is not monotone.' % id_dp
            raise_wrapped(Exception, e, msg, f_chain=f_chain, 
                          trchain=trchain, compact=True)
Exemple #5
0
def dual01_chain(id_dp, dp):
    try:
        with primitive_dp_test(id_dp, dp):
            print('Starting testing with %r' % id_dp)
            # get a chain of resources
            F = dp.get_fun_space()
            R = dp.get_res_space()
            
            # try to solve
            try: 
                dp.solve(F.witness())
                dp.solve_r(R.witness())
            except NotSolvableNeedsApprox:
                print('NotSolvableNeedsApprox - doing  lower bound ')
                n = 5
                dpL, dpU = get_dp_bounds(dp, nl=n, nu=n)
                dual01_chain(id_dp+'_L%s'%n, dpL)
                dual01_chain(id_dp+'_U%s'%n, dpU)
                return
            
            LF = LowerSets(F)
            UR = UpperSets(R)
        
            rchain = R.get_test_chain(n=8)
            poset_check_chain(R, rchain)
        
            try:
                lfchain = list(map(dp.solve_r, rchain))
                for lf in lfchain:
                    LF.belongs(lf)
            except NotSolvableNeedsApprox as e:
                print('skipping because %s'  % e)
                return
        
            try:
                poset_check_chain(LF, list(reversed(lfchain)))
                
            except ValueError as e:
                msg = 'The results of solve_r() are not a chain.'
                raise_wrapped(Exception, e, msg, chain=rchain, lfchain=lfchain)
        
            # now, for each functionality f, 
            # we know that the corresponding resource should be feasible
            
            for lf, r in zip(lfchain, rchain):
                print('')
                print('r: %s' % R.format(r))
                print('lf = h*(r) = %s' % LF.format(lf))
                
                for f in lf.maximals:
                    print('  f = %s' % F.format(f))
                    f_ur = dp.solve(f)
                    print('  f_ur = h(f) =  %s' % UR.format(f_ur))
                     
                    try:
                        f_ur.belongs(r)
                    except NotBelongs as e:
                        
                        try:
                            Rcomp.tolerate_numerical_errors = True
                            f_ur.belongs(r)
                            logger.info('In this case, there was a numerical error')
                            logger.info('Rcomp.tolerate_numerical_errors = True solved the problem')                    
                        except:
                            msg = ''
                            raise_wrapped(AssertionError, e, msg,
                                          lf=lf, r=r, f_ur=f_ur,
                                          r_repr=r.__repr__(),
                                          f_ur_minimals=f_ur.minimals.__repr__())
    finally:
        Rcomp.tolerate_numerical_errors = False
Exemple #6
0
def dual01_chain(id_dp, dp):
    try:
        with primitive_dp_test(id_dp, dp):
            print('Starting testing with %r' % id_dp)
            # get a chain of resources
            F = dp.get_fun_space()
            R = dp.get_res_space()
            
            # try to solve
            try: 
                dp.solve(F.witness())
                dp.solve_r(R.witness())
            except NotSolvableNeedsApprox:
                print('NotSolvableNeedsApprox - doing  lower bound ')
                n = 5
                dpL, dpU = get_dp_bounds(dp, nl=n, nu=n)
                dual01_chain(id_dp+'_L%s'%n, dpL)
                dual01_chain(id_dp+'_U%s'%n, dpU)
                return
            
            LF = LowerSets(F)
            UR = UpperSets(R)
        
            rchain = R.get_test_chain(n=8)
            poset_check_chain(R, rchain)
        
            try:
                lfchain = list(map(dp.solve_r, rchain))
                for lf in lfchain:
                    LF.belongs(lf)
            except NotSolvableNeedsApprox as e:
                print('skipping because %s'  % e)
                return
        
            try:
                poset_check_chain(LF, list(reversed(lfchain)))
                
            except ValueError as e:
                msg = 'The results of solve_r() are not a chain.'
                raise_wrapped(Exception, e, msg, chain=rchain, lfchain=lfchain)
        
            # now, for each functionality f, 
            # we know that the corresponding resource should be feasible
            
            for lf, r in zip(lfchain, rchain):
                print('')
                print('r: %s' % R.format(r))
                print('lf = h*(r) = %s' % LF.format(lf))
                
                for f in lf.maximals:
                    print('  f = %s' % F.format(f))
                    f_ur = dp.solve(f)
                    print('  f_ur = h(f) =  %s' % UR.format(f_ur))
                     
                    try:
                        f_ur.belongs(r)
                    except NotBelongs as e:
                        
                        try:
                            Rcomp.tolerate_numerical_errors = True
                            f_ur.belongs(r)
                            logger.info('In this case, there was a numerical error')
                            logger.info('Rcomp.tolerate_numerical_errors = True solved the problem')                    
                        except:
                            msg = ''
                            raise_wrapped(AssertionError, e, msg,
                                          lf=lf, r=r, f_ur=f_ur,
                                          r_repr=r.__repr__(),
                                          f_ur_minimals=f_ur.minimals.__repr__())
    finally:
        Rcomp.tolerate_numerical_errors = False