コード例 #1
0
def check_makecanonical(_, ndp):
    # TODO: just return itself?
    if not isinstance(ndp, CompositeNamedDP):
        return

    from mocdp.comp.composite_makecanonical import cndp_makecanonical
    try:
        ndp2 = cndp_makecanonical(ndp)
        check_same_interface(ndp, ndp2)
    except DPSemanticErrorNotConnected:
        pass
コード例 #2
0
ファイル: test_operations.py プロジェクト: AndreaCensi/mcdp
def check_makecanonical(_, ndp):
    # TODO: just return itself?
    if not isinstance(ndp, CompositeNamedDP):
        return

    from mocdp.comp.composite_makecanonical import cndp_makecanonical
    try:
        ndp2 = cndp_makecanonical(ndp)
        check_same_interface(ndp, ndp2)
    except DPSemanticErrorNotConnected:
        pass
コード例 #3
0
ファイル: test_imp_space.py プロジェクト: AndreaCensi/mcdp
def test_imp_dict_2_makecanonical(id_ndp, ndp0):
    """ This one also canonicalizes. """
    if '_inf' in id_ndp:  # infinite
        return

    if not isinstance(ndp0, CompositeNamedDP):
        print('skipping because not CompositeNamedDP: %s' % type(ndp0).__name__)
        return

    try:
        ndp0.check_fully_connected()
    except NotConnected:
        print('skipping because not connected')
        return

    ndp_labeled = get_labelled_version(ndp0)
    _ndp = cndp_makecanonical(ndp0)
    dp0 = ndp_labeled.get_dp()
    F = dp0.get_fun_space()
    I = dp0.get_imp_space()
    assert isinstance(I, SpaceProduct)
#     print ndp.repr_long()
    print('I: %s' % I)
    print('get_names_used: %s' % get_names_used(I))

    f = list(F.get_minimal_elements())[0]

    try:
        ur = dp0.solve(f)
    except NotSolvableNeedsApprox:
        return

    for r in ur.minimals:
        imps = dp0.get_implementations_f_r(f, r)
        for imp in imps:
            I.belongs(imp)
            context = {}
            imp_dict = get_imp_as_recursive_dict(I, imp)
            artifact = ndp_make(ndp0, imp_dict, context)
            print('artifact: %s' % artifact)
コード例 #4
0
ファイル: test_imp_space.py プロジェクト: rusi/mcdp
def test_imp_dict_2_makecanonical(id_ndp, ndp0):
    """ This one also canonicalizes. """
    if '_inf' in id_ndp:  # infinite
        return

    if not isinstance(ndp0, CompositeNamedDP):
        print('skipping because not CompositeNamedDP: %s' % type(ndp0).__name__)
        return

    try:
        ndp0.check_fully_connected()
    except NotConnected:
        print('skipping because not connected')
        return

    ndp_labeled = get_labelled_version(ndp0)
    _ndp = cndp_makecanonical(ndp0)
    dp0 = ndp_labeled.get_dp()
    F = dp0.get_fun_space()
    I = dp0.get_imp_space()
    assert isinstance(I, SpaceProduct)
#     print ndp.repr_long()
    print('I: %s' % I)
    print('get_names_used: %s' % get_names_used(I))

    f = list(F.get_minimal_elements())[0]

    try:
        ur = dp0.solve(f)
    except NotSolvableNeedsApprox:
        return

    for r in ur.minimals:
        imps = dp0.get_implementations_f_r(f, r)
        for imp in imps:
            I.belongs(imp)
            context = {}
            imp_dict = get_imp_as_recursive_dict(I, imp)
            artifact = ndp_make(ndp0, imp_dict, context)
            print('artifact: %s' % artifact)
コード例 #5
0
ファイル: eval_ndp_imp.py プロジェクト: AndreaCensi/mcdp
def eval_ndp_makecanonical(r, context):
    ndp = eval_ndp(r.dp_rvalue, context)
    return cndp_makecanonical(ndp)
コード例 #6
0
def eval_ndp_makecanonical(r, context):
    ndp = eval_ndp(r.dp_rvalue, context)
    return cndp_makecanonical(ndp)
コード例 #7
0
ファイル: test_imp_space.py プロジェクト: AndreaCensi/mcdp
def test_imp_space_2():
    ndp0 = parse_ndp("""
addmake(root: code mocdp.comp.tests.test_imp_space.make_root)
mcdp {
    a = instance 
        
        addmake(root: code mocdp.comp.tests.test_imp_space.make_a)
        mcdp {
        
        a2 = instance 
        
        addmake(root: code mocdp.comp.tests.test_imp_space.make_a2) 
        catalogue {
            provides capacity [J]
            requires mass [g]
            
            model1 | 1 J | 200 g
            model2 | 2 J | 300 g
        }
        
        provides capacity using a2
        requires mass >= 10g + a2.mass 
    }
    
    b = instance 
    addmake(root: code mocdp.comp.tests.test_imp_space.make_b)
    catalogue {
        provides capacity [J]
        requires mass [g]
        
        model3 | 1 J | 200 g
        model4 | 2 J | 300 g
    }
    
    provides capacity <= a.capacity + b.capacity
    requires mass >= a.mass + b.mass
}

    """)
    assert isinstance(ndp0, CompositeNamedDP)
    ndp_labeled = get_labelled_version(ndp0)
    ndp_canonical = cndp_makecanonical(ndp_labeled)
    dp0 = ndp_canonical.get_dp()
#     print dp0.repr_long()
    dp, _ = get_dp_bounds(dp0, 5, 5)
    f = 0.0
    R = dp.get_res_space()
    ur = dp.solve(f)
    I = dp.get_imp_space()
    assert isinstance(I, SpaceProduct)

    print('I: %s' % I)
    print('get_names_used: %s' % get_names_used(I))

    for r in ur.minimals:
        print('r = %s' % R.format(r))
        imps = dp.get_implementations_f_r(f, r)
        print('imps: %s' % imps)

        for imp in imps:
            I.belongs(imp)
            imp_dict = get_imp_as_recursive_dict(I, imp)  # , ignore_hidden=False)
            print('imp dict: %r' % imp_dict)
            assert set(imp_dict) == set(['a', 'b', '_sum1', '_invplus1', '_fun_capacity', '_res_mass']), imp_dict
            assert set(imp_dict['a']) == set(['_plus1', 'a2', '_fun_capacity', '_res_mass' ]), imp_dict['a']
            context = {}
            artifact = ndp_make(ndp0, imp_dict, context)
            print('artifact: %s' % artifact)
コード例 #8
0
ファイル: test_imp_space.py プロジェクト: rusi/mcdp
def test_imp_space_2():
    ndp0 = parse_ndp("""
addmake(root: code mcdp_comp_tests.test_imp_space.make_root)
mcdp {
    a = instance 
        
        addmake(root: code mcdp_comp_tests.test_imp_space.make_a)
        mcdp {
        
        a2 = instance 
        
        addmake(root: code mcdp_comp_tests.test_imp_space.make_a2) 
        catalogue {
            provides capacity [J]
            requires mass [g]
            
            model1 | 1 J | 200 g
            model2 | 2 J | 300 g
        }
        
        provides capacity using a2
        requires mass >= 10g + a2.mass 
    }
    
    b = instance 
    addmake(root: code mcdp_comp_tests.test_imp_space.make_b)
    catalogue {
        provides capacity [J]
        requires mass [g]
        
        model3 | 1 J | 200 g
        model4 | 2 J | 300 g
    }
    
    provides capacity <= a.capacity + b.capacity
    requires mass >= a.mass + b.mass
}

    """)
    assert isinstance(ndp0, CompositeNamedDP)
    ndp_labeled = get_labelled_version(ndp0)
    ndp_canonical = cndp_makecanonical(ndp_labeled)
    dp0 = ndp_canonical.get_dp()
#     print dp0.repr_long()
    dp, _ = get_dp_bounds(dp0, 5, 5)
    f = 0.0
    R = dp.get_res_space()
    ur = dp.solve(f)
    I = dp.get_imp_space()
    assert isinstance(I, SpaceProduct)

    print('I: %s' % I)
    print('get_names_used: %s' % get_names_used(I))

    for r in ur.minimals:
        print('r = %s' % R.format(r))
        imps = dp.get_implementations_f_r(f, r)
        print('imps: %s' % imps)

        for imp in imps:
            I.belongs(imp)
            imp_dict = get_imp_as_recursive_dict(I, imp)  # , ignore_hidden=False)
            print('imp dict: %r' % imp_dict)
            assert set(imp_dict) == set(['a', 'b', '_sum1', '_invplus1', '_fun_capacity', '_res_mass']), imp_dict
            assert set(imp_dict['a']) == set(['_plus1', 'a2', '_fun_capacity', '_res_mass' ]), imp_dict['a']
            context = {}
            artifact = ndp_make(ndp0, imp_dict, context)
            print('artifact: %s' % artifact)