예제 #1
0
파일: builder.py 프로젝트: lp249839965/CSUR
 def get_variants(self):
     if not self.built:
         raise Exception("Asset pack not built; use self.build() to build")
     variants = {}
     assets = self.get_assets()
     right = lambda x: max(
         [block[-1].x_right for block in x.get_all_blocks()])
     # ground express, all single-carriageway roads <= 3.5L
     variants['express'] = [x for x in assets['base'] + assets['shift'] \
         + assets['trans'] + assets['ramp'] + assets['twoway'] if right(x) <= 5 * SW.LANE]
     # ground compact, all roads w/ traffic lights <= 3.5L
     variants['compact'] = [
         x for x in assets['base'] + assets['twoway']
         if x.has_trafficlight() and right(x) <= 3.5 * SW.LANE
     ]
     # uturn lanes, with median size 3L, 4L and 5L
     variants['uturn'] = []
     # BRT stations, comp segment with 2DC in the middle
     variants['brt'] = []
     for x in assets['twoway']:
         if str(x.left) == str(
                 x.right) and x.right.x0() / SW.LANE in ALLOWED_UTURN:
             y = Asset(x.right.x0(), x.right.nl(),
                       x.right.x0() - SW.LANE,
                       x.right.nl() + 1)
             variants['uturn'].append(TwoWayAsset(y, y))
         if str(x.left) == str(x.right) and x.right.x0() == 0 and len(
                 x.right.nlanes[0]) > 1:
             y = Asset(x.right.x0(), x.right.nlanes[0], medians=[2, 2])
             variants['brt'].append(TwoWayAsset(y, y))
     return variants
예제 #2
0
파일: compiler.py 프로젝트: luoxz-ai/CSUR
def asset_from_blocks(block_start, block_end=None):
    if block_end:
        x0, n0, m0 = parse_blocks(block_start)
        x1, n1, m1 = parse_blocks(block_end)
        return Asset(x0, n0, x1, n1, medians=[m0, m1])
    else:
        x, n, m = parse_blocks(block_start)
        return BaseAsset(x, *n, median=m)
예제 #3
0
파일: builder.py 프로젝트: lp249839965/CSUR
def find_access(nlane, base, name=None, codes=['3', '3P', '4P', '5P', '6P']):
    access_roads = []
    nlane_g = base.get_blocks()[0].nlanes
    x0 = base.x0()
    offsets = [offset_x(code) for code in codes]
    for i_a in range(2, nlane_g - nlane):
        if x0 + (i_a + nlane - 1) * SW.LANE + SW.MEDIAN in offsets:
            access_roads.append(
                Asset(x0, nlane_g, x0,
                      [i_a - 1, nlane, nlane_g - nlane - i_a]))
    return access_roads
예제 #4
0
파일: builder.py 프로젝트: lp249839965/CSUR
def connect(start, end):
    x0_l = start.x0()
    x1_l = end.x0()
    x0_r = start.get_blocks()[-1].x_right
    x1_r = end.get_blocks()[-1].x_right

    if len(start.get_blocks()) == 1 and len(end.get_blocks()) == 1:
        n0 = start.get_blocks()[0].nlanes
        n1 = end.get_blocks()[0].nlanes
        # Look for shift
        if n0 == n1:
            if abs(x0_l - x1_l) > N_SHIFT_MAX * SW.LANE:
                raise ValueError("Invalid shift increment! %s=%s" %
                                 (start, end))
            return Asset(x0_l, n0, x1_l, n0)
        # Look for transition
        else:
            if abs(n0 - n1) > DN_TRANS:
                raise ValueError("Invalid transition increment! %s=%s" %
                                 (start, end))
            elif x0_l != x1_l and x0_r != x1_r:
                raise ValueError("Invalid transition alignment! %s=%s" %
                                 (start, end))
            return Asset(x0_l, n0, x1_l, n1)
    else:
        # Look for ramp
        n0 = [c.nlanes for c in start.get_blocks()]
        n1 = [c.nlanes for c in end.get_blocks()]
        if abs(sum(n0) - sum(n1)) > DN_RAMP or (x0_l != x1_l and x0_r != x1_r):
            raise ValueError("Invalid ramp combination! %s=%s" % (start, end))
        n_medians = [1, 1]
        if len(n0) > 1:
            n_medians[0] = int(
                (start.get_blocks()[1].x_left - start.get_blocks()[0].x_right)
                // SW.MEDIAN)
        if len(n1) > 1:
            n_medians[1] = int(
                (end.get_blocks()[1].x_left - end.get_blocks()[0].x_right) //
                SW.MEDIAN)
        return Asset(x0_l, n0, x1_l, n1, medians=n_medians)
예제 #5
0
import os, sys

WORKDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(WORKDIR)

from core.csur import LANEWIDTH as LW
from core.assets import Asset
from modeling import Modeler

asset = Asset(LW / 2, 4, LW / 2, [2, 3])

mode = 'e'

seg = asset.get_model(mode)

modeler = Modeler(os.path.join(WORKDIR, "csur.ini"))
modeler.make(seg, mode)