Exemple #1
0
def opposite_route(r):
    """
    :type r: Route
    :rtype: Route
    """
    orns = []
    if not hasattr(r, 'cfg') or not r.cfg:
        # r.cfg = route_config.create_route_config(r.rnodes, infra_cfg_date=r.rnodes[0].infra_cfg_date)
        r.cfg = route_config.create_route_config(r.rnodes)

    for ns in r.cfg.node_sets:
        if ns.node2.rnode:
            orns.append(ns.node2.rnode)
    opposite_route = Route(name='Opposite Direction of %s' % r.name,
                           desc=r.desc)
    opposite_route.rnodes = list(reversed(orns))
    opposite_route.infra_cfg_date = opposite_route.rnodes[0].infra_cfg_date
    return opposite_route
Exemple #2
0
def _calculate_tt_moe(r, prd, **kwargs):
    """

    :type r: pyticas.ttypes.Route
    :type prd: pyticas.ttypes.Period
    """
    # 1. update lane configuration according to work zone
    cloned_route = r.clone()
    updated_route = cloned_route
    if not kwargs.get('nowz', False):
        try:
            cloned_route.cfg = route_config.create_route_config(cloned_route.rnodes)
            updated_route = cloned_route
        except Exception as e:
            getLogger(__name__).warning(
                'Exception occurred while creating route config for route: {}. Error: {}'.format(r, tb.traceback(e,
                                                                                                                 f_print=False)))
        # Work zone application deactivated as we do not have enough lane closure information
        # try:
        #     updated_route = apply_workzone(cloned_route, prd)
        # except Exception as e:
        #     getLogger(__name__).warning(
        #         'Exception occurred while applying workzone for route: {}. For period: {}. Error: {}'.format(r, prd,
        #                                                                                                      tb.traceback(
        #                                                                                                          e,
        #                                                                                                          f_print=False)))

        # 2. calculate TT and Speed and VMT
    try:
        return {
            "flow_data": total_flow_with_virtual_nodes.run(updated_route, prd),
            "speed_data": speed_with_virtual_nodes.run(updated_route, prd),
            "density_data": density_with_virtual_nodes.run(updated_route, prd),
            "tt": moe.travel_time(updated_route, prd),
            "mrf": moe.mrf(updated_route, prd)
        }

    except Exception as ex:
        getLogger(__name__).warning(tb.traceback(ex))
Exemple #3
0
def _calculate_tt(r, prd, **kwargs):
    """

    :type r: pyticas.ttypes.Route
    :type prd: pyticas.ttypes.Period
    :rtype: (list[pyticas.ttypes.RNodeData], list[pyticas.ttypes.RNodeData], list[pyticas.ttypes.RNodeData])
    """
    # 1. update lane configuration according to work zone
    cloned_route = r.clone()

    if kwargs.get('nowz', False):
        updated_route = cloned_route
    else:
        cloned_route.cfg = route_config.create_route_config(cloned_route.rnodes)
        updated_route = apply_workzone(cloned_route, prd)

    # 2. calculate TT and Speed and VMT
    try:
        return moe.travel_time(updated_route, prd), moe.speed(updated_route, prd), moe.vmt(updated_route, prd)
    except Exception as ex:
        getLogger(__name__).warning(tb.traceback(ex))
        return None, None, None