Ejemplo n.º 1
0
def check_compose():
    from mocdp.example_battery.dp_bat import BatteryDP
    from mocdp.example_battery.dp_bat2 import Mobility

    actuation = dpwrap(Mobility(), 'weight', 'actuation_power')

    check_ftype(actuation, 'weight', R_Weight_g)
    check_rtype(actuation, 'actuation_power', R_Power)

    battery = dpwrap(BatteryDP(energy_density=100.0),
                     'capacity', 'weight')

    check_ftype(battery, 'capacity', R_Energy)
    check_rtype(battery, 'weight', R_Weight_g)

    times = dpwrap(Product(R_Time, R_Power, R_Energy),
                   ['mission_time', 'power'], 'energy')

    check_ftype(times, 'mission_time', R_Time)
    check_ftype(times, 'power', R_Power)
    check_rtype(times, 'energy', R_Energy)

    c = Connection('actuation', 'actuation_power', 'times', 'power')
    x = dpconnect(dict(actuation=actuation, times=times), [c])

    print('WE have obtained x')
    print('x = %s' % x)
    print('x fun: %s' % x.get_dp().get_fun_space())
    print('x res: %s' % x.get_dp().get_res_space())

    # "battery.capacity >= x.energy"
    c = Connection('x', 'energy', 'battery', 'capacity')
    _y = dpconnect(dict(battery=battery, x=x), [c])
Ejemplo n.º 2
0
def check_compose2_fail():
    """ Fails because there is a recursive constraint """

    actuation = dpwrap((Mobility()),
                       'weight', 'actuation_power')

    battery = dpwrap((BatteryDP(energy_density=100.0)),
                     'capacity', 'weight')

    times = dpwrap((Product(R_Time, R_Power, R_Energy)),
                   ['mission_time', 'power'], 'energy')

    try:
        c1 = Connection('actuation', 'actuation_power', 'times', 'power')
        c2 = Connection('times', 'energy', 'battery', 'capacity')
        c3 = Connection('battery', 'weight', 'actuation', 'weight')
        dpconnect(dict(actuation=actuation, times=times, battery=battery),
                  [c1, c2, c3])
    except TheresALoop:
        pass
Ejemplo n.º 3
0
def check_compose2_loop2():
    actuation = dpwrap(Mobility(),
                       'weight', 'actuation_power')

    battery = dpwrap((BatteryDP(energy_density=100.0)),
                     'capacity', 'battery_weight')

    times = dpwrap((Product(R_Time, R_Power, R_Energy)),
                   ['mission_time', 'power'], 'energy')

    # 'times.power >= actuation.actuation_power',
    c1 = Connection('actuation', 'actuation_power', 'times', 'power')
    c2 = Connection('times', 'energy', 'battery', 'capacity')
    x = dpconnect(dict(actuation=actuation, times=times, battery=battery),
              [c1,c2])

    y = dploop0(x, 'battery_weight', 'weight')

    print y.desc()

    assert y.get_fnames() == ['mission_time'], y.get_fnames()
    assert y.get_rnames() == ['battery_weight'], y.get_rnames()

    check_ftype(x, 'mission_time', R_Time)
#     check_ftype(x, 'weight', R_Weight)
    check_rtype(x, 'battery_weight', R_Weight_g)


    dp = y.get_dp()

    funsp = dp.get_fun_space()
    ressp = dp.get_res_space()
    print('funsp: %s' % funsp)
    print('ressp: %s' % ressp)
    assert funsp == R_Time, funsp
    assert ressp == R_Weight_g, ressp