diff --git a/.gitignore b/.gitignore index fd8f542..ef11bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,354 @@ -__pycache__ + +.vscode + +# Do not edit below!! + +# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,intellij+all,jupyternotebooks +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,python,windows,intellij+all,jupyternotebooks + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +.idea/artifacts +.idea/compiler.xml +.idea/jarRepositories.xml +.idea/modules.xml +.idea/*.iml +.idea/modules +*.iml +*.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### JupyterNotebooks ### +# gitignore template for Jupyter Notebooks +# website: http://jupyter.org/ + +.ipynb_checkpoints +*/.ipynb_checkpoints/* + +# IPython +profile_default/ +ipython_config.py + +# Remove previous ipynb_checkpoints +# git rm -r .ipynb_checkpoints/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ +develop-eggs/ dist/ -*.egg-info -.ipynb_checkpoints -.build-sentinel -.vscode \ No newline at end of file +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook + +# IPython + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/linux,macos,python,windows,intellij+all,jupyternotebooks diff --git a/matsim/calibration.py b/matsim/calibration.py index 0380ef3..770e5ea 100644 --- a/matsim/calibration.py +++ b/matsim/calibration.py @@ -322,6 +322,8 @@ def create_mode_share_study(name: str, jar: str, config: str, storage = optuna.storages.RDBStorage(url="sqlite:///%s.db" % name, engine_kwargs={"connect_args": {"timeout": 100}, "isolation_level": "AUTOCOMMIT"}) + # TODO: normalize target share for given modes + study = optuna.create_study( study_name=name, storage=storage, diff --git a/matsim/cli/clean_iters.py b/matsim/cli/clean_iters.py index f9153ff..4c15ddd 100644 --- a/matsim/cli/clean_iters.py +++ b/matsim/cli/clean_iters.py @@ -1,35 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - Command line tool remove iterations directotries. See help usage for details: + Command line tool remove iterations directories. See help usage for details: >> python3.9 clean_iters.py -h """ -import re import os +import re import shutil - from argparse import ArgumentParser - METADATA = "clean-iters", "Remove all iterations directories except the last one" -def setup(parser : ArgumentParser): - + +def setup(parser: ArgumentParser): parser.add_argument("dirs", nargs="+", help="Directories to scan") parser.add_argument("-f", "--force", action='store_true', default=False, help="Don't ask for confirmation") - parser.add_argument("-d", "--dry-run", action='store_true', default=False, help="Don't remove anything, only print for information") + parser.add_argument("-d", "--dry-run", action='store_true', default=False, + help="Don't remove anything, only print for information") -def main(args): +def main(args): pattern = re.compile(r"it\.(\d+)") for d in args.dirs: for dirpath, dirnames, filenames in os.walk(os.path.abspath(d)): matches = [pattern.match(it) for it in dirnames] - - iters = [(m.group(0), int(m.group(1)) ) for m in matches if m is not None] + + iters = [(m.group(0), int(m.group(1))) for m in matches if m is not None] iters = sorted(iters, key=lambda k: k[1]) if len(iters) > 1: @@ -62,10 +61,9 @@ def main(args): if __name__ == "__main__": - parser = ArgumentParser(prog=METADATA[0], description=METADATA[1]) setup(parser) - args= parser.parse_args() + args = parser.parse_args() main(args) diff --git a/matsim/cli/main.py b/matsim/cli/main.py index 8004f0c..4e1dc5f 100644 --- a/matsim/cli/main.py +++ b/matsim/cli/main.py @@ -5,10 +5,11 @@ import clean_iters as ci + def main(): """ Main entry point. """ - parser = ArgumentParser(prog='matsim-tools', description="MATSim ommand line util") + parser = ArgumentParser(prog='matsim-tools', description="MATSim command line util") subparsers = parser.add_subparsers(title="Subcommands") s1 = subparsers.add_parser(ci.METADATA[0], help=ci.METADATA[1]) @@ -20,4 +21,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/matsim/pb/__init__.py b/matsim/pb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/matsim/scenariogen/__init__.py b/matsim/scenariogen/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/matsim/scenariogen/__main__.py b/matsim/scenariogen/__main__.py new file mode 100644 index 0000000..90ffdee --- /dev/null +++ b/matsim/scenariogen/__main__.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +from .data import run_create_ref_data +from .data import run_extract_activities +from .data import run_lookup_regiostar +from .network import run_collect_results +from .network import run_edges as sumo_edges +from .network import run_intersections as sumo_intersections +from .network import run_routes as sumo_routes +from .network import run_train_model + + +def _add(subparsers, m): + """ Adds module to as subcommand""" + s1 = subparsers.add_parser(m.METADATA[0], help=m.METADATA[1]) + m.setup(s1) + s1.set_defaults(func=m.main) + + +def main(): + """ Main entry point. """ + + parser = argparse.ArgumentParser(prog='matsim-scenariogen', + description="MATSim scenario command line utility") + + subparsers = parser.add_subparsers(title="Subcommands") + + _add(subparsers, sumo_edges) + _add(subparsers, sumo_routes) + _add(subparsers, sumo_intersections) + _add(subparsers, run_train_model) + _add(subparsers, run_collect_results) + + try: + from .network import run_opt_freespeed + _add(subparsers, run_opt_freespeed) + except Exception as e: + print("Opt freespeed not available", e) + + _add(subparsers, run_extract_activities) + _add(subparsers, run_create_ref_data) + _add(subparsers, run_lookup_regiostar) + + args = parser.parse_args() + + if not hasattr(args, 'func'): + parser.print_help() + else: + args.func(args) + + +if __name__ == "__main__": + main() diff --git a/matsim/scenariogen/data/__init__.py b/matsim/scenariogen/data/__init__.py new file mode 100644 index 0000000..38c2dfb --- /dev/null +++ b/matsim/scenariogen/data/__init__.py @@ -0,0 +1,342 @@ +""" This module contains dataclasses and methods for reading and processing survey data. +""" + +__all__ = ["read_all", "ParkingPosition", "HouseholdType", "EconomicStatus", "Gender", "Employment", "Availability", "Purpose", + "TripMode", "DistanceGroup", "DurationGroup", "SourceDestinationGroup", + "Household", "Person", "Trip", "Activity"] + +import os +from typing import List, Union, Tuple + +from dataclasses import dataclass +from enum import Enum, auto + +import numpy as np +import pandas as pd + + +def _batch(iterable: list, max_batch_size: int): + """ Batches an iterable into lists of given maximum size, yielding them one by one. """ + batch = [] + for element in iterable: + batch.append(element) + if len(batch) >= max_batch_size: + yield batch + batch = [] + if len(batch) > 0: + yield batch + + +def read_all(dirs: Union[str, List[str]], regio=None) -> Tuple[pd.DataFrame]: + """ Scan directories and read everything into one dataframe """ + + from .formats import srv, mid + + hh = [] + pp = [] + tt = [] + + # Allow to use without list + if type(dirs) == str: + dirs = [dirs] + + for d in dirs: + + files = [] + + for format in (srv, mid): + + # Collect all files for each format + for f in os.scandir(d): + fp = f.name + if not f.is_file(): + continue + if format.is_format(f): + files.append(f.path) + + files = sorted(files) + + if len(files) % format.INPUT_FILES != 0: + print(files) + raise ValueError("File structure is wrong. Need exactly %d files per region." % format.INPUT_FILES) + + for input_files in _batch(files, format.INPUT_FILES): + print("Reading", *input_files) + + data = format.read_raw(*input_files) + df = format.convert(data, regio) + + hh.append(df[0]) + pp.append(df[1]) + tt.append(df[2]) + + hh = pd.concat(hh, axis=0) + hh = hh[~hh.index.duplicated(keep='first')] + print("Households: ", len(hh)) + + pp = pd.concat(pp, axis=0) + pp = pp[~pp.index.duplicated(keep='first')] + pp.sort_index(inplace=True) + print("Persons: ", len(pp)) + + tt = pd.concat(tt, axis=0) + tt = tt[~tt.index.duplicated(keep='first')] + tt.sort_values(["p_id", "n"], inplace=True) + print("Trips: ", len(tt)) + + return hh, pp, tt + + +class StrEnum(str, Enum): + pass + + +# this creates nice lowercase and JSON serializable names +# https://docs.python.org/3/library/enum.html#using-automatic-values +class AutoNameLower(StrEnum): + def _generate_next_value_(name, start, count, last_values): + return name.lower() + + +class AutoNameLowerStrEnum(AutoNameLower): + pass + + +class ParkingPosition(AutoNameLowerStrEnum): + PRIVATE = auto() + PUBLIC = auto() + DIFFERENT = auto() + NA = auto() + + +class HouseholdType(AutoNameLowerStrEnum): + MULTI_W_CHILDREN = auto() + MULTI_WO_CHILDREN = auto() + SINGLE = auto() + + +class EconomicStatus(AutoNameLowerStrEnum): + VERY_LOW = auto() + LOW = auto() + MEDIUM = auto() + HIGH = auto() + VERY_HIGH = auto() + UNKNOWN = auto() + + +class Gender(AutoNameLowerStrEnum): + M = auto() + F = auto() + OTHER = auto() + + +class Employment(AutoNameLowerStrEnum): + CHILD = auto() + HOMEMAKER = auto() + RETIREE = auto() + UNEMPLOYED = auto() + SCHOOL = auto() + STUDENT = auto() + TRAINEE = auto() + + JOB_FULL_TIME = auto() + JOB_PART_TIME = auto() + OTHER = auto() + + +class Availability(AutoNameLowerStrEnum): + YES = auto() + NO = auto() + UNKNOWN = auto() + + +class Purpose(AutoNameLowerStrEnum): + WORK = auto() + WORK_BUSINESS = auto() + EDU_KIGA = auto() + """ Kinderkrippe/-garten """ + EDU_PRIMARY = auto() + """ Grundschule """ + EDU_SECONDARY = auto() + """ Weiterführende Schule """ + EDU_HIGHER = auto() + """ Berufs-, Fach-, Hochschule """ + EDU_OTHER = auto() + """ Andere Bildungseinrichtung """ + EDU = auto() + """ All Edu """ + + SHOPPING = auto() + """ General non differentiated shopping """ + + SHOP_DAILY = auto() + SHOP_OTHER = auto() + PERSONAL_BUSINESS = auto() + TRANSPORT = auto() + LEISURE = auto() + DINING = auto() + OUTSIDE_RECREATION = auto() + VISIT = auto() + HOME = auto() + WAYBACK = auto() + OTHER = auto() + + +class TripMode(AutoNameLowerStrEnum): + WALK = auto() + BIKE = auto() + CAR = auto() + RIDE = auto() + PT = auto() + OTHER = auto() + + +class DistanceGroup(AutoNameLowerStrEnum): + """ These distance groups are designed so that they are roughly equally populated. """ + + ZERO = auto() + G_500M = auto() + G_1KM = auto() + G_2KM = auto() + G_3KM = auto() + G_5KM = auto() + G_10KM = auto() + G_25KM = auto() + G_50KM = auto() + G_100KM = auto() + OVER_100KM = auto() + + @staticmethod + def cut(values): + bins = [0, 0.5, 1, 2, 3, 5, 10, 25, 50, 100] + values = np.asarray(values) + + idx = np.digitize(values, bins, right=True) + # Set ZERO group manually + idx[np.where(values <= 0)] = 0 + return np.take(np.asarray(DistanceGroup, dtype=object), idx, axis=0) + + +class DurationGroup(AutoNameLowerStrEnum): + """ Most common duration groups, right side is inclusive e.g <= 5 min """ + + G_5MIN = auto() + G_15MIN = auto() + G_30MIN = auto() + G_60MIN = auto() + G_120MIN = auto() + G_180MIN = auto() + G_300MIN = auto() + G_420MIN = auto() + G_480MIN = auto() + G_510MIN = auto() + G_570MIN = auto() + G_660MIN = auto() + G_750MIN = auto() + REST_OF_DAY = auto() + + @staticmethod + def cut(values): + bins = [5, 15, 30, 60, 120, 180, 300, 420, 480, 510, 570, 660, 750] + + values = np.asarray(values) + idx = np.digitize(values, bins, right=True) + return np.take(np.asarray(DurationGroup, dtype=object), idx, axis=0) + + +class SourceDestinationGroup(AutoNameLowerStrEnum): + HOME_WORK = auto() + HOME_CHILDCARE = auto() + HOME_EDU = auto() + HOME_BUSINESS = auto() + HOME_SHOP = auto() + HOME_LEISURE = auto() + HOME_OTHER = auto() + WORK_HOME = auto() + CHILDCARE_HOME = auto() + EDU_HOME = auto() + BUSINESS_HOME = auto() + SHOP_HOME = auto() + LEISURE_HOME = auto() + OTHER_HOME = auto() + OTHER_WORK = auto() + WORK_OTHER = auto() + OTHER_OTHER = auto() + + UNKNOWN = auto() + + def source(self): + if self.name.startswith("HOME"): + return Purpose.HOME + elif self.name.startswith("WORK"): + return Purpose.WORK + + return Purpose.OTHER + + +@dataclass +class Household: + """ Universal definition of household attributes """ + hh_id: str + h_weight: float + n_persons: int + n_cars: int + n_bikes: int + n_other_vehicles: int + car_parking: ParkingPosition + economic_status: EconomicStatus + type: HouseholdType + region_type: int + location: str + geom: object = None + + +@dataclass +class Person: + """ Universal definition of person attributes.""" + p_id: str + p_weight: float + hh_id: str + age: int + gender: Gender + employment: Employment + restricted_mobility: bool + driving_license: Availability + car_avail: Availability + bike_avail: Availability + pt_abo_avail: Availability + mobile_on_day: bool + present_on_day: bool + reporting_day: int + n_trips: int + + +@dataclass +class Trip: + """ Universal definition of trip attributes""" + t_id: str + t_weight: float + p_id: str + hh_id: str + n: int + day_of_week: int + departure: int + duration: int + gis_length: float + main_mode: TripMode + purpose: Purpose + sd_group: SourceDestinationGroup + valid: bool + + +@dataclass +class Activity: + """ Activity information (including leg) """ + a_id: str + p_id: str + n: int + type: Purpose + duration: int + leg_dist: float + leg_duration: float + leg_mode: TripMode diff --git a/matsim/scenariogen/data/formats/__init__.py b/matsim/scenariogen/data/formats/__init__.py new file mode 100644 index 0000000..9d826bc --- /dev/null +++ b/matsim/scenariogen/data/formats/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +__all__ = ["srv", "mid"] \ No newline at end of file diff --git a/matsim/scenariogen/data/formats/mid.py b/matsim/scenariogen/data/formats/mid.py new file mode 100644 index 0000000..e291dc4 --- /dev/null +++ b/matsim/scenariogen/data/formats/mid.py @@ -0,0 +1,291 @@ +# -*- coding: utf-8 -*- + +import os +import pandas as pd +import pyproj +import re +from collections import Counter +from shapely.geometry import box +from shapely.ops import transform + +from .. import * + +INPUT_FILES = 3 + + +def is_format(f: os.DirEntry): + return f.name.startswith("MiD2017_") and f.path.endswith(".csv") + + +def read_raw(household_file, person_file, trip_file): + hh = pd.read_csv(household_file, delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + p = pd.read_csv(person_file, delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + t = pd.read_csv(trip_file, delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + return hh, p, t + + +def convert(data: tuple, regio=None): + hh, pp, tt = data + + hhs = [] + for h in hh.itertuples(): + hh_id = str(int(h.H_ID_Lok)) + hhs.append(Household(hh_id, h.H_GEW, int(h.hhgr_gr2), int(h.anzauto_gr3), int(h.pedrad), int(h.motmop), + ParkingPosition.NA, + Mid2017.economic_status(h), Mid2017.household_type(h), 0, "", Mid2017.geom(h))) + + ps = [] + for p in pp.itertuples(): + p_id = str(int(p.HP_ID_Lok)) + hh_id = str(int(p.H_ID_Lok)) + + # exlucde business trips + ps.append(Person( + p_id, p.P_GEW, hh_id, Mid2017.age(p), Mid2017.gender(p), Mid2017.employment(p), None, + Mid2017.driving_license(p), Mid2017.car_avail(p), Mid2017.bike_avail(p), Mid2017.pt_abo_avail(p), + Mid2017.mobile(p), Mid2017.present_on_day(p), int(p.ST_WOTAG), int(p.anzwege1) + )) + + ts = [] + + counts = Counter() + + for t in tt.itertuples(): + + # business trips are not accounted + if t.W_RBW == 1.0: + continue + + # Person might have multiple days + p_id = str(int(t.HP_ID_Lok)) + t_id = p_id + "%d%d" % (t.ST_WOCHE, t.ST_WOTAG) + + n = counts[t_id] + counts[t_id] += 1 + + depature = Mid2017.parse_time(t.W_SZ) + + trip = Trip( + t_id + "_" + str(n), + t.W_GEW, p_id, str(int(t.H_ID_Lok)), + n, int(t.ST_WOTAG),depature, int(t.wegmin), float(t.wegkm), + Mid2017.main_mode(t), Mid2017.purpose(t), None, + float(t.wegkm) < 1000 and int(t.wegmin) < 1000 and depature is not None + ) + + if trip.purpose == Purpose.WAYBACK: + if trip.n >= 3: + # Use purpose of previous trip + trip.purpose = ts[-2].purpose + else: + trip.purpose = Purpose.HOME + + ts.append(trip) + + return pd.DataFrame(hhs).set_index("hh_id"), pd.DataFrame(ps).set_index("p_id"), pd.DataFrame(ts).set_index("t_id") + +def flip(x, y): + """Flips the x and y coordinate values""" + return y, x + +class Mid2017: + """ Converter for 2017 MID format """ + + ct = pyproj.Transformer.from_proj( + pyproj.Proj('epsg:3035'), # source coordinate system + pyproj.Proj('epsg:4326'), + always_xy=True) # destination coordinate system + + @staticmethod + def coordinate(value, grid_size, scale): + # EPSG:3035, coordinate is left lower point + split = re.split(r"N|E", value) + x = float(split[2]) * scale + y = float(split[1]) * scale + + geom = box(x, y, x + grid_size, y + grid_size) + + return transform(Mid2017.ct.transform, geom).wkt + + @staticmethod + def geom(h): + if h.GITTER_500m.strip(): + return Mid2017.coordinate(h.GITTER_500m, 500, 100) + elif h.GITTER_1km.strip(): + return Mid2017.coordinate(h.GITTER_1km, 1000, 1000) + elif h.GITTER_5km.strip(): + return Mid2017.coordinate(h.GITTER_5km, 5000, 1000) + + return None + + @staticmethod + def economic_status(h): + return list(EconomicStatus)[int(h.oek_status) - 1] + + @staticmethod + def household_type(h): + x = int(h.hhtyp2) + + if x == 2: + return HouseholdType.MULTI_W_CHILDREN + elif x == 3: + return HouseholdType.MULTI_WO_CHILDREN + + return HouseholdType.SINGLE if int(h.hhgr_gr2) == 1 else HouseholdType.MULTI_WO_CHILDREN + + @staticmethod + def age(p): + x = int(p.alter_gr) + if x == 1: + return 0 + elif x == 2: + return 18 + elif x == 3: + return 30 + elif x == 4: + return 40 + elif x == 5: + return 50 + elif x == 6: + return 60 + elif x == 7: + return 70 + elif x == 8: + return 80 + + return -1 + + @staticmethod + def gender(p): + if p.HP_SEX == 1.0: + return Gender.M + elif p.HP_SEX == 2.0: + return Gender.F + + return Gender.OTHER + + @staticmethod + def employment(p): + x = int(p.taet) + if x == 1: + return Employment.JOB_FULL_TIME + elif x == 2: + return Employment.STUDENT + elif x == 3: + return Employment.HOMEMAKER + elif x == 4: + return Employment.RETIREE + + return Employment.OTHER + + @staticmethod + def driving_license(p): + x = int(p.P_FSCHEIN) + if x == 1: + return Availability.YES + elif x == 2: + return Availability.NO + + return Availability.UNKNOWN + + @staticmethod + def car_avail(p): + x = int(p.P_STKFZ) + if x == 1 or x == 2: + return Availability.YES + elif x == 3: + return Availability.NO + + return Availability.UNKNOWN + + @staticmethod + def bike_avail(p): + x = int(p.vpedrad) + if x == 1 or x == 2 or x == 3: + return Availability.YES + elif x == 4: + return Availability.NO + + return Availability.UNKNOWN + + @staticmethod + def pt_abo_avail(p): + x = int(p.P_FKARTE) + if x == 4 or x == 5: + return Availability.YES + elif x > 8: + return Availability.UNKNOWN + + return Availability.NO + + @staticmethod + def mobile(p): + x = int(p.mobil) + if x == 0: + return False + elif x == 1: + return True + return None + + @staticmethod + def present_on_day(p): + x = int(p.P_STUM) + if x == 3: + return True + elif x == 1 or x == 2: + return False + return None + + @staticmethod + def parse_time(x): + t = x.strip().split(":") + if len(t) < 2: + return None + + return int(t[0]) * 60 + int(t[1]) + + @staticmethod + def main_mode(t): + x = int(t.hvm) + if x == 1: + return TripMode.WALK + elif x == 2: + return TripMode.BIKE + elif x == 3: + return TripMode.RIDE + elif x == 4: + return TripMode.CAR + elif x == 5: + return TripMode.PT + + return TripMode.OTHER + + @staticmethod + def purpose(t): + x = int (t.zweck) + if x == 1: + return Purpose.WORK + elif x == 2: + return Purpose.WORK_BUSINESS + elif x == 3: + return Purpose.EDU + elif x == 4: + return Purpose.SHOPPING + elif x == 5: + return Purpose.PERSONAL_BUSINESS + elif x == 6: + return Purpose.TRANSPORT + elif x == 7: + return Purpose.LEISURE + elif x == 8: + return Purpose.HOME + elif x == 9: # trip back to previous + return Purpose.WAYBACK + + return Purpose.OTHER \ No newline at end of file diff --git a/matsim/scenariogen/data/formats/srv.py b/matsim/scenariogen/data/formats/srv.py new file mode 100644 index 0000000..3ed4d99 --- /dev/null +++ b/matsim/scenariogen/data/formats/srv.py @@ -0,0 +1,390 @@ +# -*- coding: utf-8 -*- + +import os + +from .. import * + +# Has households, persons and trips +INPUT_FILES = 3 + +def is_format(f: os.DirEntry): + fp = f.name + if not f.path.endswith(".csv"): + return False + if "MiD" in f.name: + return False + + return "_HH" in fp or "_P" in fp or "_W" in fp or "H2018" in fp or "P2018" in fp or "W2018" in fp + + +def read_raw(household_file, person_file, trip_file): + """ Read the input files into format used by conversion """ + + hh = pd.read_csv(household_file, encoding="windows-1252", delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + p = pd.read_csv(person_file, encoding="windows-1252", delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + t = pd.read_csv(trip_file, encoding="windows-1252", delimiter=";", decimal=",", + quotechar="\"", low_memory=False, quoting=2) + + return hh, p, t + + +def convert(data: tuple, regio=None): + """ Convert srv data to standardized survey format """ + + (hh, pp, tt) = data + + if regio is not None: + regio = pd.read_csv(regio) + + ps = [] + for p in pp.itertuples(): + ps.append( + Person( + str(int(p.HHNR)) + "_" + str(int(p.PNR)), + p.GEWICHT_P, + str(int(p.HHNR)), + int(p.V_ALTER), + SrV2018.gender(p.V_GESCHLECHT), + SrV2018.employment(p.V_ERW), + False if p.V_EINSCHR_NEIN else True, + SrV2018.yes_no(p.V_FUEHR_PKW), + SrV2018.veh_avail(p.V_PKW_VERFUEG), + Availability.YES if SrV2018.veh_avail(p.V_RAD_VERFUEG) == Availability.YES or SrV2018.veh_avail( + p.V_ERAD_VERFUEG) == Availability.YES else SrV2018.veh_avail(p.V_RAD_VERFUEG), + SrV2018.veh_avail(p.V_FK_VERFUEG), + p.V_WOHNUNG == 1, + p.V_WOHNORT == 1, + int(p.STICHTAG_WTAG), + int(p.E_ANZ_WEGE) + ) + ) + + ps = pd.DataFrame(ps).set_index("p_id") + + random_state = np.random.RandomState(0) + + hhs = [] + for h in hh.itertuples(): + + # Invalid entries in certain files + if np.isnan(h.HHNR): + continue + + hh_id = str(int(h.HHNR)) + hhs.append( + Household( + hh_id, + h.GEWICHT_HH, + pint(h.V_ANZ_PERS), + pint(h.V_ANZ_PKW_PRIV + h.V_ANZ_PKW_DIENST), + pint(h.V_ANZ_RAD + h.V_ANZ_ERAD), + pint(h.V_ANZ_MOT125 + h.V_ANZ_MOPMOT + h.V_ANZ_SONST), + SrV2018.parking_position(h.V_STELLPL1), + SrV2018.economic_status(h.E_OEK_STATUS if "E_OEK_STATUS" in hh.keys() else -1, h.V_EINK, + ps[ps.hh_id == hh_id]), + SrV2018.household_type(h.E_HHTYP), + SrV2018.region_type(h, regio, random_state), + h.ST_CODE_NAME, + ) + ) + + ts = [] + for t in tt.itertuples(): + # TODO: E_DAUER, E_GESCHW + # E_ANKUNFT + # TODO: double check + ts.append( + Trip( + str(int(t.HHNR)) + "_" + str(int(t.PNR)) + "_" + str(int(t.WNR)), + t.GEWICHT_W, + str(int(t.HHNR)) + "_" + str(int(t.PNR)), + str(int(t.HHNR)), + int(t.WNR), + int(t.STICHTAG_WTAG), + int(t.E_BEGINN), + int(t.E_DAUER), + float(t.GIS_LAENGE), + SrV2018.trip_mode(t.E_HVM), + SrV2018.trip_purpose(t.V_ZWECK), + SrV2018.sd_group(int(t.E_QZG_17)), + t.E_WEG_GUELTIG != 0 and t.GIS_LAENGE_GUELTIG != 0 + ) + ) + + return pd.DataFrame(hhs).set_index("hh_id"), ps, pd.DataFrame(ts).set_index("t_id") + +def pint(x): + """ Convert to positive integer""" + return max(0, int(x)) + + +class SrV2018: + """ Maps SrV data to standard format""" + + # Fallback regiostar codes hard-coded + CODES = { + 'Berlin': 1, + 'Potsdam': 2, + 'Cottbus': 4, + 'Frankfurt (Oder)': 2, + 'Kleinmachnow/Stahnsdorf/Teltow': 3, + 'Werder (Havel)/Schwielowsee': 3, + 'Michendorf/Nuthetal': 3, + 'Bernau': 3, + 'Blankenfelde-Mahlow/Rangsdorf': 3, + 'Dallgow/Falkensee/Wustermark': 3, + 'Eichwalde/Zeuthen': 3, + 'Fürstenwalde': 3, + 'Spremberg': 3, + 'Strausberg': 3, + 'Rüdersdorf': 3, + 'Oranienburg': 3, + 'Hennigsdorf/Velten': 3, + 'Brandenburg (Havel)': 5, + 'Schönefeld': 3, + 'Königs Wusterhausen': 3, + 'Eberswalde': 3, + 'Lübben/Lübbenau': 6, + 'Ludwigsfelde': 3, + 'Leipzig': 1 + } + + @staticmethod + def parking_position(x): + + if x == 1: + return ParkingPosition.PRIVATE + elif x == 2: + return ParkingPosition.PUBLIC + elif x == 3: + return ParkingPosition.DIFFERENT + + return ParkingPosition.NA + + @staticmethod + def economic_status(status, eink, persons): + + if status >= 1: + return list(EconomicStatus)[int(status) - 1] + + # Calculated according to Srv 2018 + # https://tu-dresden.de/bu/verkehr/ivs/srv/ressourcen/dateien/SrV2018_Tabellenbericht_Oberzentren_500TEW-_flach.pdf?lang=de + + if eink < 1: + return EconomicStatus.UNKNOWN + + if eink == 1 or eink == 2: + return EconomicStatus.VERY_LOW + + children = (persons.age < 14).sum() + rest = len(persons) - children - 1 + + w = 0.3 * children + 1 + 0.5 * rest + + if eink == 3: + if w < 1.3: + return EconomicStatus.LOW + + return EconomicStatus.VERY_LOW + + elif eink == 4: + if w < 1.3: + return EconomicStatus.MEDIUM + elif w < 1.6: + return EconomicStatus.LOW + + return EconomicStatus.VERY_LOW + + elif eink == 5: + if w < 1.6: + return EconomicStatus.MEDIUM + elif w < 2.3: + return EconomicStatus.LOW + + return EconomicStatus.VERY_LOW + + elif eink == 6: + if w < 1.3: + return EconomicStatus.HIGH + elif w < 2.3: + return EconomicStatus.MEDIUM + elif w < 3.0: + return EconomicStatus.LOW + + return EconomicStatus.VERY_LOW + + elif eink == 7: + if w < 1.6: + return EconomicStatus.HIGH + elif w < 2.3: + return EconomicStatus.MEDIUM + elif w < 3.5: + return EconomicStatus.LOW + + return EconomicStatus.VERY_LOW + + elif eink == 8: + if w < 2.1: + return EconomicStatus.HIGH + elif w < 3.0: + return EconomicStatus.MEDIUM + + return EconomicStatus.LOW + + elif eink == 9: + if w < 1.3: + return EconomicStatus.VERY_HIGH + if w < 2.8: + return EconomicStatus.HIGH + return EconomicStatus.MEDIUM + + elif eink == 10: + if w < 2.5: + return EconomicStatus.VERY_HIGH + + return EconomicStatus.HIGH + + return EconomicStatus.UNKNOWN + + @staticmethod + def household_type(x): + if x == 1: + return HouseholdType.MULTI_W_CHILDREN + elif x == 2: + return HouseholdType.MULTI_WO_CHILDREN + + return HouseholdType.SINGLE + + @staticmethod + def gender(x): + if x == 1: + return Gender.M + elif x == 2: + return Gender.F + + return Gender.OTHER + + @staticmethod + def employment(x): + if x == 1: + return Employment.CHILD + elif x == 2: + return Employment.HOMEMAKER + elif x == 3: + return Employment.RETIREE + elif x == 5: + return Employment.UNEMPLOYED + elif x == 6: + return Employment.SCHOOL + elif x == 7: + return Employment.STUDENT + elif x == 8: + return Employment.TRAINEE + elif x == 9: + return Employment.JOB_FULL_TIME + elif x == 10 or x == 11: + return Employment.JOB_PART_TIME + + return Employment.OTHER + + @staticmethod + def yes_no(x): + if x == 1: + return Availability.YES + elif x == 2: + return Availability.NO + + return Availability.UNKNOWN + + @staticmethod + def veh_avail(x): + if x == 1 or x == 2: + return Availability.YES + elif x == 3: + return Availability.NO + + return Availability.UNKNOWN + + @staticmethod + def trip_mode(x): + if x == 1: + return TripMode.WALK + if x == 2 or x == 18 or x == 19: + return TripMode.BIKE + if x == 4 or x == 5 or x == 6: + return TripMode.CAR + elif x == 7 or x == 8 or x == 9: + return TripMode.RIDE + elif 10 <= x <= 17: + return TripMode.PT + + return TripMode.OTHER + + @staticmethod + def trip_purpose(x): + if x == 1: + return Purpose.WORK + elif x == 2: + return Purpose.WORK_BUSINESS + elif x == 3: + return Purpose.EDU_KIGA + elif x == 4: + return Purpose.EDU_PRIMARY + elif x == 5: + return Purpose.EDU_SECONDARY + elif x == 6: + return Purpose.EDU_HIGHER + elif x == 7: + return Purpose.EDU_OTHER + elif x == 8: + return Purpose.SHOP_DAILY + elif x == 9: + return Purpose.SHOP_OTHER + elif x == 19 or x == 10: + return Purpose.PERSONAL_BUSINESS + elif x == 11: + return Purpose.TRANSPORT + elif x == 15: + return Purpose.OUTSIDE_RECREATION + elif x == 13: + return Purpose.DINING + elif 12 <= x <= 17: + return Purpose.LEISURE + elif x == 18: + return Purpose.HOME + + return Purpose.OTHER + + @staticmethod + def sd_group(x): + if x <= 0: + return SourceDestinationGroup.UNKNOWN + + return list(SourceDestinationGroup)[int(x) - 1] + + @staticmethod + def region_type(d, regio, random_state): + + if "PLZ" in dir(d) and regio is not None: + plz = int(d.PLZ) + + r = regio[regio.plz == plz] + if len(r) == 0: + raise ValueError("Unknown PLZ: %d" % plz) + + if len(r) > 1: + r = r.sample(n=1, random_state=random_state) + + r = r.iloc[0].RegioStaR7 + if np.isnan(r): + raise ValueError("No RegioStar value available for: %d" % plz) + + return int(r) - 70 + + else: + name = d.ST_CODE_NAME + return SrV2018.CODES[name] diff --git a/matsim/scenariogen/data/preparation.py b/matsim/scenariogen/data/preparation.py new file mode 100644 index 0000000..c79e7f5 --- /dev/null +++ b/matsim/scenariogen/data/preparation.py @@ -0,0 +1,271 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import functools +import numpy as np +import pandas as pd +from sklearn.utils import shuffle + +from . import * + +def prepare_persons(hh, pp, tt, augment=5, max_hh_size=5, core_weekday=False, remove_with_invalid_trips=False): + """ Cleans common data errors and fill missing values """ + df = pp.join(hh, on="hh_id", lsuffix="hh_") + + # Augment data using p_weight + if augment > 1: + df = augment_persons(df, augment) + df = shuffle(df, random_state=0).reset_index(drop=True) + + # set car avail + df.loc[df.age < 17, "driving_license"] = Availability.NO + _fill(df, "driving_license", Availability.UNKNOWN) + + df["car_avail"] = (df.n_cars > 0) & (df.driving_license == Availability.YES) + df["bike_avail"] = (df.n_bikes > 0) | (df.bike_avail == Availability.YES) + + # small children don't have pt abo + df.loc[df.age < 6, "pt_abo_avail"] = Availability.NO + _fill(df, "pt_abo_avail", Availability.UNKNOWN) + + # Replace unknown income group + _fill(df, "economic_status", EconomicStatus.UNKNOWN) + + # Large households are underrepresented and capped + df.n_persons = np.minimum(df.n_persons, max_hh_size) + + if core_weekday: + df = df[df.reporting_day <= 4] + + if remove_with_invalid_trips: + invalid = set(tt[~tt.valid].p_id) + df = df[~df.p_id.isin(invalid)] + + mobile = set(tt[tt.valid].p_id) + + # Filter persons that are supposed to be mobile but have no trips + df = df[ (df.p_id.isin(mobile) | (~df.mobile_on_day) )] + + + df = df.drop(columns=['hh_id', 'present_on_day', 'reporting_day', 'location', 'h_weight', + 'n_cars', 'n_bikes', 'n_other_vehicles', 'car_parking']) + + # Move the region type variable to the front because it is used as conditional + df.insert(3, 'region_type', df.pop('region_type')) + + # Regions other than 1 and 3 are massively under-represented + # Regions are reduced to 1 (Berlin) and 3 (Outside Berlin) + df.loc[df.region_type != 1, "region_type"] = 3 + + # Maximum age is 99, also to be able to encode age with two tokens + df.loc[df.age >= 99, "age"] = 99 + + return df + + +def augment_persons(pp, factor=1, permute_age=0.5): + """ Augment persons using p weight + + :param pp Person table + :param factor multiply weight by this factor + :param permute_age if larger 0 add gaussian noise to the age with parameter as scale + """ + pp = pp.reset_index() + + duplicated = pp.loc[pp.index.repeat(np.maximum(1, np.rint(pp.p_weight * factor)))] + + if permute_age > 0: + np.random.seed(0) + + age_permute = np.rint(np.random.normal(0, permute_age, len(duplicated))).astype(np.int32) + duplicated.age += age_permute + + # 0 age is minimum + duplicated.age = np.maximum(0, duplicated.age) + + # Filter invalid options + return duplicated[check_age_employment(None, duplicated)] + + +def prepare_trips(pp, trips, core_weekday=True): + """ Create trip data frame """ + + df = trips.join(pp, on="p_id") + + # remove person if any trip is invalid + invalid = set(trips[~trips.valid].p_id) + df = df[~df.p_id.isin(invalid)] + + df = df.drop(columns=["t_weight", "sd_group", "mobile_on_day", "valid"]) + + if core_weekday: + # Monday - Thursday + df = df[df.day_of_week <= 4] + df = df.drop(columns=["day_of_week"]) + + # reverse columns so activities are at the end + return df[df.columns[::-1]] + + +def _fill(df, col, val=None): + """ Fill null values with dist of the rest (or replace val)""" + if val is not None: + df.loc[df[col] == val, col] = None + + isnull = df[col].isnull() + sample = df[col].dropna().sample(isnull.sum(), replace=True).values + df.loc[isnull, col] = sample + + +def create_activities(all_persons: pd.DataFrame, tt: pd.DataFrame, core_weekday=True, cut_groups=True, + include_person_context=True): + """ Create activity representation from trip table """ + + tt = tt.reset_index().set_index("p_id") + + import multiprocess as mp + + def convert(persons): + res = [] + + for p in persons.itertuples(): + + acts = [] + valid = True + + # Filter if not done yet + if "present_on_day" in persons.keys() and not p.present_on_day: + continue + + p_id = p.p_id if "p_id" in persons.keys() else p.Index + + try: + # trips = tt[tt.p_id == p_id] + trips = tt.loc[[p_id]] + except KeyError: + # Empty dataframe of same type + trips = tt.iloc[:0, :].copy() + + if (~trips.valid).any(): + continue + + if core_weekday: + # Monday - Thursday + if (trips.day_of_week > 4).any(): + continue + + # id generator + def a_id(t_i): + return "%s_%d" % (p.Index, t_i) + + if len(trips) == 0: + acts.append(Activity(a_id(0), p.Index, 0, Purpose.HOME, 1440, 0, 0, TripMode.OTHER)) + else: + acts.append( + Activity(a_id(0), p.Index, 0, trips.iloc[0].sd_group.source(), trips.iloc[0].departure, 0, 0, + TripMode.OTHER)) + + for i in range(len(trips) - 1): + t0 = trips.iloc[i] + t1 = trips.iloc[i + 1] + + duration = t1.departure - t0.departure - t0.duration + + if duration < 0 or t0.gis_length < 0: + valid = False + + acts.append(Activity(a_id(i + 1), p.Index, i + 1, t0.purpose, + duration, t0.gis_length, t0.duration, t0.main_mode)) + + if len(trips) > 1: + i += 1 + # last trip + tl = trips.iloc[i] + + if tl.gis_length < 0: + valid = False + + # Duration is set to rest of day + acts.append( + Activity(a_id(i + 1), p.Index, i + 1, tl.purpose, 1440, tl.gis_length, tl.duration, tl.main_mode)) + + if valid: + res.extend(acts) + + return res + + with mp.Pool(8) as pool: + docs = pool.map(convert, np.array_split(all_persons, 16)) + result = functools.reduce(lambda a, b: a + b, docs) + + activities = pd.DataFrame(result).set_index("a_id") + # Reverse columns because it will be reversed again at the end + activities = activities.iloc[:, ::-1] + persons = all_persons.iloc[:, ::-1].drop(columns=["p_id"], errors="ignore") + + if include_person_context: + df = activities.join(persons, on="p_id", rsuffix="_p") + else: + df = activities + + df = df.drop(columns=["mobile_on_day", "p_weight", "hh_id", "present_on_day"], errors="ignore") + + # TODO: permute length and dist + + if cut_groups: + df.duration = DurationGroup.cut(df.duration) + df.leg_dist = DistanceGroup.cut(df.leg_dist) + + # reverse columns so activities are at the end + return df.iloc[:, ::-1] + + +def check_age_employment(column_names, df): + """ Check if age vs. employment status is valid""" + + invalid = (df.employment == Employment.CHILD) & (df.age > 7) + invalid |= (df.employment == Employment.RETIREE) & (df.age < 30) + invalid |= (df.employment == Employment.STUDENT) & ((df.age < 17) | (df.age > 55)) + invalid |= (df.employment == Employment.SCHOOL) & ((df.age < 5) | (df.age > 25)) + invalid |= (df.employment == Employment.UNEMPLOYED) & ((df.age < 17) | (df.age > 66)) + invalid |= (df.employment == Employment.JOB_PART_TIME) & (df.age < 18) + invalid |= (df.employment == Employment.JOB_FULL_TIME) & (df.age < 18) + invalid |= (df.employment == Employment.HOMEMAKER) & (df.age < 18) + invalid |= (df.employment == Employment.TRAINEE) & (df.age < 16) + + return ~invalid + + +def check_age_license(column_names, df): + """ Check driving license and age is valid """ + + invalid = (df.driving_license == Availability.YES) & (df.age < 17) + invalid |= df.car_avail & (df.age < 17) + + return ~invalid + + +def check_positive(column_names, df): + """ Check for plausible number of vehicles""" + + invalid = (df.n_persons <= 0) + # invalid |= (df.n_cars < 0) + # invalid |= (df.n_bikes < 0) + # invalid |= (df.n_other_vehicles < 0) + + invalid |= (df.n_persons <= 1) & (df["type"] != HouseholdType.SINGLE) + + return ~invalid + + +def calc_commute(pp, tt): + """ Calculate commute distances """ + + work = tt[tt.valid & + ((tt.sd_group == SourceDestinationGroup.HOME_WORK) | (tt.sd_group == SourceDestinationGroup.WORK_HOME))] + + edu = tt[tt.valid & + ((tt.sd_group == SourceDestinationGroup.HOME_EDU) | (tt.sd_group == SourceDestinationGroup.EDU_HOME))] + + return work.groupby("p_id").agg(work_commute=("gis_length", "max")), \ + edu.groupby("p_id").agg(edu_commute=("gis_length", "max")) diff --git a/matsim/scenariogen/data/run_create_ref_data.py b/matsim/scenariogen/data/run_create_ref_data.py new file mode 100644 index 0000000..2769f54 --- /dev/null +++ b/matsim/scenariogen/data/run_create_ref_data.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +import numpy as np +import pandas as pd + +from . import * +from .preparation import _fill + +METADATA = "data-create-ref", "Extract and create reference data from surveys." + + +def weighted(x): + data = dict(n=x.t_weight.sum(), mean_dist=np.average(x.gis_length * 1000, weights=x.t_weight)) + return pd.Series(data=data) + + +def summarize_purposes(x): + x["departure_h"] = x.departure // 60 + x["arrival_h"] = (x.departure + x.duration) // 60 + + d = x.groupby(["purpose", "departure_h"]).agg(n=("t_weight", "sum")) + d["departure"] = d.n / d.n.sum() + d = d.drop(columns=["n"]) + d.index.rename(names=["purpose", "h"], inplace=True) + + a = x.groupby(["purpose", "arrival_h"]).agg(n=("t_weight", "sum")) + a["arrival"] = a.n / a.n.sum() + a = a.drop(columns=["n"]).rename(index={"arrival_h": "h"}) + a.index.rename(names=["purpose", "h"], inplace=True) + + m = pd.merge(a, d, left_index=True, right_index=True, how="outer") + m.fillna(0, inplace=True) + + return m + + +def mode_usage(mode): + def f(x): + return (x == mode).any() + + return f + + +def summarize_mode_usage(x, trips): + total_mobile = x[x.mobile_on_day].p_weight.sum() + + args = {k.value: ("main_mode", mode_usage(k)) for k in set(trips.main_mode)} + + p_trips = trips[trips.p_id.isin(x.index)] + + mode_user = p_trips.groupby(["p_id"]).agg(**args) + joined = x.join(mode_user, how="inner") + + data = {} + for c in mode_user.columns: + share = joined[joined[c]].p_weight.sum() / total_mobile + data[c] = share + + return pd.DataFrame(data={"main_mode": data.keys(), "user": data.values()}).set_index("main_mode") + + +def setup(parser: argparse.ArgumentParser): + parser.add_argument("dirs", nargs="+", help="Directories with survey data") + +def create(hh, persons, trips): + pass + # TODO + + +def main(args): + all_hh, all_persons, all_trips = read_all(args.dirs) + + # Filter person ad trips for area + df = all_persons.join(all_hh, on="hh_id") + + # TODO: configurable filter + persons = df[df.present_on_day & + (df.reporting_day <= 4) & + (df.region_type == 1)] + + # TODO: configurable attributes + persons["age_group"] = pd.cut(persons.age, [0, 18, 66, np.inf], labels=["0 - 17", "18 - 65", "65+"], right=False) + + invalid = set(all_trips[~all_trips.valid].p_id) + + persons = persons[~persons.index.isin(invalid)] + + trips = all_trips.drop(columns=["hh_id"]).join(persons, on="p_id", how="inner") + + _fill(trips, "main_mode", TripMode.OTHER) + + # TODO: configurable dist binds + labels = ["0 - 1000", "1000 - 2000", "2000 - 5000", "5000 - 10000", "10000 - 20000", "20000+"] + bins = [0, 1000, 2000, 5000, 10000, 20000, np.inf] + + trips["dist_group"] = pd.cut(trips.gis_length * 1000, bins, labels=labels, right=False) + + aggr = trips.groupby(["dist_group", "main_mode"]).apply(weighted) + + aggr["share"] = aggr.n / aggr.n.sum() + aggr["share"].fillna(0, inplace=True) + + aggr = aggr.drop(columns=["n"]) + + # TODO: configurable output + + aggr.to_csv("mode_share_ref.csv") + + # Also normalize der distance group + for dist_group in aggr.index.get_level_values(0).categories: + sub = aggr.loc[dist_group, :] + sub.share /= sub.share.sum() + + aggr.to_csv("mode_share_per_dist_ref.csv") + + aggr = summarize_purposes(trips) + + aggr.to_csv("trip_purposes_by_hour_ref.csv") + + aggr = summarize_mode_usage(persons, trips) + aggr.to_csv("mode_users_ref.csv") + + # TODO: ref data per attribute ? diff --git a/matsim/scenariogen/data/run_extract_activities.py b/matsim/scenariogen/data/run_extract_activities.py new file mode 100644 index 0000000..ee2f646 --- /dev/null +++ b/matsim/scenariogen/data/run_extract_activities.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +from . import read_all +from .preparation import prepare_persons, create_activities + +METADATA = "data-extract-activities", "Extract activities and persons from survey data." + + +def setup(parser: argparse.ArgumentParser): + parser.add_argument("dirs", nargs="+", help="Directories with survey data") + parser.add_argument("--regiostar", default=None) + + parser.add_argument("--output", default="table", help="Output prefix") + + +def main(args): + hh, persons, trips = read_all(args.dirs, regio=args.regiostar) + + hh.to_csv(args.output + "-households.csv") + trips.to_csv(args.output + "-trips.csv") + persons.to_csv(args.output + "-unscaled-persons.csv") + + print("Written survey csvs") + + df = prepare_persons(hh, persons, trips, augment=5, core_weekday=True, remove_with_invalid_trips=True) + + df.to_csv(args.output + "-persons.csv", index_label="idx") + print("Created %d synthetics persons" % len(df)) + + activities = create_activities(df, trips, include_person_context=False, cut_groups=False) + activities.to_csv(args.output + "-activities.csv", index=False) diff --git a/matsim/scenariogen/data/run_lookup_regiostar.py b/matsim/scenariogen/data/run_lookup_regiostar.py new file mode 100644 index 0000000..f897d91 --- /dev/null +++ b/matsim/scenariogen/data/run_lookup_regiostar.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse + +import pandas as pd + +METADATA = "data-plz-regiostar", "Create regiostar lookup for plz." + + +def prepare_regiostar_lookup(plz, regiostar) -> pd.DataFrame: + plz = pd.read_csv(plz) + + regiostar = pd.read_excel(regiostar, sheet_name="ReferenzGebietsstand2020") + df = plz.merge(regiostar, how="left", left_on="ags", right_on="gem_20") + + df = df[["plz", "ags", "RegioStaR2", "RegioStaR4", "RegioStaR5", "RegioStaR7", "RegioStaR17"]] + + return df + + +def setup(parser: argparse.ArgumentParser): + pass + + +def main(args): + d = "/Users/rakow/Development/matsim-scenarios/shared-svn/projects/matsim-germany/" + + # FIXME: use args + + df = prepare_regiostar_lookup(d + "zuordnung_plz_ort.csv", d + "RegioStaR-Referenzdateien.xlsx") + + df.to_csv(d + "zuordnung_plz_regiostar.csv", index=False) diff --git a/matsim/scenariogen/network/Makefile b/matsim/scenariogen/network/Makefile new file mode 100644 index 0000000..f5e0166 --- /dev/null +++ b/matsim/scenariogen/network/Makefile @@ -0,0 +1,83 @@ + +# Setup the sumo environment +# Deprecated: You can install sumo via pip + +export SUMO_HOME="env" + +PREFIX=$(abspath env) + +.ONESHELL: # Applies to every targets in the file! +.DEFAULT_GOAL := all + +download: + mkdir -p build + mkdir -p env + + cd build + + wget -nc https://sumo.dlr.de/releases/1.17.0/sumo-src-1.17.0.tar.gz + tar -xf sumo-src-1.17.0.tar.gz + + wget -nc https://dlcdn.apache.org//xerces/c/3/sources/xerces-c-3.2.4.tar.gz + tar -xf xerces-c-3.2.4.tar.gz + + wget -nc https://src.fedoraproject.org/repo/pkgs/fox/fox-1.6.57.tar.gz/sha512/e7b91054a9ea674818803415284cb61572935d22466e446cb37ef68344e2684e8acd567f7c8a6912f939dcbcc37455119ad6a01ac30513f460d0b3937b7e6087/fox-1.6.57.tar.gz + tar -xf fox-1.6.57.tar.gz + + wget -nc https://github.com/OSGeo/gdal/releases/download/v3.7.0/gdal-3.7.0.tar.gz + tar -xf gdal-3.7.0.tar.gz + + wget -nc https://download.osgeo.org/proj/proj-9.2.1.tar.gz + tar -xf proj-9.2.1.tar.gz + + wget -nc https://www.sqlite.org/2023/sqlite-autoconf-3420000.tar.gz + tar -xf sqlite-autoconf-3420000.tar.gz + +sqlite: + cd build/sqlite-autoconf-3420000 + + SQLITE_ENABLE_COLUMN_METADATA=1 ./configure --prefix=$(PREFIX) + SQLITE_ENABLE_COLUMN_METADATA=1 make install + +xerces: + cd build/xerces-c-3.2.4 + + ./configure --prefix=$(PREFIX) + make install + +fox: + cd build/fox-1.6.57 + + ./configure --prefix=$(PREFIX) + make install + +proj: + cd build/proj-9.2.1 + + mkdir -p cmake-build && cd cmake-build + cmake -DCMAKE_INSTALL_PREFIX=$(PREFIX) -DCMAKE_PREFIX_PATH=$(PREFIX)\ + ../ + make install + +gdal: sqlite proj + cd build/gdal-3.7.0 + + mkdir -p cmake-build && cd cmake-build + cmake -DCMAKE_INSTALL_PREFIX=$(PREFIX) -DCMAKE_PREFIX_PATH=$(PREFIX)\ + -DSQLite3_INCLUDE_DIR=$(PREFIX)/include -DSQLite3_LIBRARY=$(PREFIX)/lib/libsqlite3.so\ + -DPROJ_INCLUDE_DIR=$(PREFIX)/include -DPROJ_LIBRARY=$(PREFIX)/lib64/libproj.so.25\ + ../ + make install + +sumo: gdal fox xerces + cd build/sumo-1.17.0 + + mkdir -p cmake-build && cd cmake-build + cmake -DCMAKE_INSTALL_PREFIX=$(PREFIX) -DCMAKE_PREFIX_PATH=$(PREFIX)\ + -DSQLite3_INCLUDE_DIR=$(PREFIX)/include -DSQLite3_LIBRARY=$(PREFIX)/lib/libsqlite3.so\ + -DGDAL_INCLUDE_DIR=$(PREFIX)/include -DGDAL_LIBRARY=$(PREFIX)/lib64/libgdal.so\ + -DPROJ_INCLUDE_DIR=$(PREFIX)/include -DPROJ_LIBRARY=$(PREFIX)/lib64/libproj.so.25\ + ../ + make install + +all: download sumo \ No newline at end of file diff --git a/matsim/scenariogen/network/__init__.py b/matsim/scenariogen/network/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/matsim/scenariogen/network/features.py b/matsim/scenariogen/network/features.py new file mode 100644 index 0000000..219a59e --- /dev/null +++ b/matsim/scenariogen/network/features.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os.path + +import pandas as pd + + +def build_datasets(network, inter, routes, model_type): + """ Build all datasets needed for training models""" + ft = pd.concat([pd.read_csv(n) for n in network]) + + df_i = pd.concat([pd.merge(pd.read_csv(i), ft, left_on="fromEdgeId", right_on="linkId") for i in inter]) + df_r = pd.concat( + [pd.merge(pd.read_csv(r).drop(columns=["speed"]), ft, left_on="edgeId", right_on="linkId") for r in routes]) + + result = {} + + aggr = df_r.groupby(["junction_type"]) + for g in aggr.groups: + if str(g) == "dead_end": + continue + + result["speedRelative_" + str(g)] = prepare_dataframe(aggr.get_group(g), model_type, target="speedRelative") + + aggr = df_i.groupby(["junction_type"]) + df_i["norm_cap"] = df_i.capacity / df_i.num_lanes + for g in aggr.groups: + result["capacity_" + str(g)] = prepare_dataframe(aggr.get_group(g), model_type, target="norm_cap") + + return result + + +def prepare_dataframe(df, model_type, target): + """ Simple preprocessing """ + + df = df.rename(columns={target: "target"}) + + # Drop length outliers + df = df[df.length < 500] + + # drop 2.5% smallest and largest + drop = len(df) // 40 + df = df.drop(df.nsmallest(drop, ["target"]).index) + df = df.drop(df.nlargest(drop, ["target"]).index) + + s = df['target'] + q1 = s.quantile(0.25) + q3 = s.quantile(0.75) + iqr = q3 - q1 + iqr_lower = q1 - 1.5 * iqr + iqr_upper = q3 + 1.5 * iqr + outliers = s[(s < iqr_lower) | (s > iqr_upper)] + + df = df.drop(outliers.index) + + # select features based on model + if model_type == "extended": + df = df[["target", "length", "speed", "change_speed", "num_lanes", "change_num_lanes", "num_to_links", + "dir_l", "dir_r", "dir_s", "dir_multiple_s", "dir_exclusive", "num_foes", + "junction_inc_lanes", "priority_lower", "priority_equal", "priority_higher", + "is_secondary_or_higher", "is_primary_or_higher", "is_motorway", "is_link"]] + elif model_type == "default": + df = df[["target", "length", "speed", "change_speed", "num_lanes", "change_num_lanes", "num_to_links", + "junction_inc_lanes", "priority_lower", "priority_equal", "priority_higher", + "is_secondary_or_higher", "is_primary_or_higher", "is_motorway", "is_link"]] + + else: + raise ValueError("Illegal model type:" + model_type) + + return df + + +def read_edges(folder): + """ Combine resulting files for edges """ + + data = [] + for f in os.listdir(folder): + if not f.endswith(".csv"): + continue + + df = pd.read_csv(os.path.join(folder, f)) + edge_id = df.iloc[0].edgeId + + aggr = df.groupby("laneId").agg(capacity=("flow", "max")) + + data.append({ + "edgeId": edge_id, + "capacity": float(aggr.capacity.mean()) + }) + + return pd.DataFrame(data) + + +def read_intersections(folder): + """ Read intersection results """ + + data = [] + for f in os.listdir(folder): + if not f.endswith(".csv"): + continue + + try: + df = pd.read_csv(os.path.join(folder, f)) + except pd.errors.EmptyDataError: + print("Empty csv", f) + continue + + # there could be exclusive lanes and the capacity to two edges completely additive + # however if the capacity is shared one direction could use way more than physical possible + aggr = df.groupby("fromEdgeId").agg(capacity=("flow", "max")).reset_index() + aggr.rename(columns={"fromEdgeId": "edgeId"}) + + data.append(aggr) + + return pd.concat(data) + + +def read_routes(folder): + """ Read routes from folder """ + data = [] + for f in os.listdir(folder): + if not f.endswith(".csv"): + continue + + try: + df = pd.read_csv(os.path.join(folder, f)) + except pd.errors.EmptyDataError: + print("Empty csv", f) + continue + + data.append(df) + + df = pd.concat(data) + aggr = df.groupby("edgeId").mean() + + return aggr.reset_index() diff --git a/matsim/scenariogen/network/models.py b/matsim/scenariogen/network/models.py new file mode 100644 index 0000000..4b02502 --- /dev/null +++ b/matsim/scenariogen/network/models.py @@ -0,0 +1,371 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import itertools +import re + +import sklearn +import sklearn.compose +import sklearn.ensemble +import sklearn.linear_model +import sklearn.svm + + +try: + import lightning.regression + import lightning.classification +except ValueError as e: + print("Error during lightning import", e) + + +import xgboost as xgb +import lightgbm as lgb + +from sympy.utilities.codegen import codegen + + +def powerset(iterable): + s = list(iterable) + return itertools.chain.from_iterable(itertools.combinations(s, r) for r in range(len(s) + 1)) + + + +def create_regressor(trial, classifier_name, random_state): + """ Create regressor model from given classifier """ + + if classifier_name == 'mean': + model = sklearn.dummy.DummyRegressor() + + elif classifier_name == 'SVR': + kernel = trial.suggest_categorical('kernel', ['linear', 'poly', 'rbf', 'sigmoid']) + svc_c = trial.suggest_float('svc_r', 1e-10, 1e10, log=True) + model = sklearn.svm.SVR(C=svc_c, gamma='auto', kernel=kernel) + + elif classifier_name == 'QLatticeRegressor': + from .models_feyn import QLatticeRegressor + + model = QLatticeRegressor(trial.suggest_int('complexity', 3, 6, step=1), random_state=random_state) + + elif classifier_name == 'RandomForestRegressor': + rf_max_depth = trial.suggest_int('rf_max_depth', 2, 4) + rf_n = trial.suggest_int('rf_n', 5, 30, step=5) + min_samples_split = trial.suggest_int('min_samples_split', 2, 8, step=1) + b = trial.suggest_categorical('bootstrap', [True, False]) + + model = sklearn.ensemble.RandomForestRegressor(max_depth=rf_max_depth, n_estimators=rf_n, + oob_score=b, min_samples_split=min_samples_split, + random_state=random_state) + elif classifier_name == 'XGBRFRegressor': + + params = { + 'objective': 'reg:squarederror', + 'eval_metric': 'mae', + 'max_depth': trial.suggest_int('max_depth', low=2, high=4), + 'min_child_weight': trial.suggest_int('min_child_weight', low=1, high=10), + 'eta': trial.suggest_float('eta', 0.01, 1, log=True), + 'lambda': trial.suggest_float('lambda', 0.01, 1, log=True), + 'alpha': trial.suggest_float('alpha', 0.01, 1, log=True), + 'gamma': trial.suggest_float('gamma', 0.01, 1, log=True), + 'n_estimators': trial.suggest_int('rf_n', 5, 30, step=5), + 'subsample': 0.9, + 'colsample_bytree': 0.9, + 'colsample_bynode': 0.9, + 'random_state': random_state + } + + model = xgb.XGBRFRegressor(**params) + + elif classifier_name == 'XGBRegressor': + + params = { + 'objective': 'reg:squarederror', + 'eval_metric': 'mae', + 'max_depth': trial.suggest_int('max_depth', low=2, high=4), + 'min_child_weight': trial.suggest_int('min_child_weight', low=1, high=10), + 'eta': trial.suggest_float('eta', 0.01, 1, log=True), + 'lambda': trial.suggest_float('lambda', 0.01, 1, log=True), + 'alpha': trial.suggest_float('alpha', 0.01, 1, log=True), + 'gamma': trial.suggest_float('gamma', 0.01, 1, log=True), + 'n_estimators': trial.suggest_int('rf_n', 5, 30, step=5), + 'subsample': 0.9, + 'colsample_bytree': 0.9, + 'colsample_bynode': 0.9, + 'random_state': random_state + } + + model = xgb.XGBRegressor(**params) + + elif classifier_name == 'ExtraTreesRegressor': + + rf_n = trial.suggest_int('rf_n', 5, 30, step=5) + min_samples_split = trial.suggest_int('min_samples_split', 2, 8, step=1) + max_depth = trial.suggest_int('max_depth', 2, 4) + b = trial.suggest_categorical('bootstrap', [True, False]) + + model = sklearn.ensemble.ExtraTreesRegressor(n_estimators=rf_n, + min_samples_split=min_samples_split, + max_depth=max_depth, + bootstrap=b, oob_score=b, + random_state=random_state) + + elif classifier_name == 'LGBMRegressor': + + params = { + 'objective': 'regression', + 'num_leaves': trial.suggest_int('num_leaves', 2, 32, log=True), + 'n_estimators': trial.suggest_int('n_estimators', 5, 30, step=5), + # 'min_child_weight': trial.suggest_loguniform('min_child_weight', 0.0001, 1), + # 'min_child_samples': trial.suggest_int('min_child_samples', low=5, high=30, step=5), + 'subsample': 0.9, + 'subsample_freq': 10, + 'colsample_bytree': 0.9, + 'reg_alpha': trial.suggest_float('alpha', 1e-10, 1, log=True), + 'random_state': random_state + } + + model = lgb.LGBMRegressor(**params) + + elif classifier_name == "DecisionTreeRegressor": + + min_samples_split = trial.suggest_int('min_samples_split', 2, 8, step=1) + max_depth = trial.suggest_int('max_depth', 2, 4) + + model = sklearn.tree.DecisionTreeRegressor(max_depth=max_depth, min_samples_split=min_samples_split, + random_state=random_state) + + + elif classifier_name == "BaggingRegressor": + + reg = sklearn.linear_model.PassiveAggressiveRegressor(C=trial.suggest_float('C', 0.0001, 100, log=True)) + model = sklearn.ensemble.BaggingRegressor(reg, + n_estimators=trial.suggest_int('rf_n', 5, 30, step=5), + max_samples=trial.suggest_float('alpha', 0.2, 1), + random_state=random_state) + + elif classifier_name == 'Ridge': + + model = sklearn.linear_model.Ridge(alpha=trial.suggest_float('alpha', 0.001, 1000, log=True), solver='saga', + random_state=random_state) + + elif classifier_name == 'Lasso': + + model = sklearn.linear_model.Lasso(alpha=trial.suggest_float('alpha', 0.001, 1000, log=True), + random_state=random_state) + + + elif classifier_name == 'ElasticNet': + + model = sklearn.linear_model.ElasticNet(alpha=trial.suggest_float('alpha', 0.01, 1, log=True), + l1_ratio=trial.suggest_float('ratio', 0, 1), + random_state=random_state) + elif classifier_name == 'SGDRegressor': + + model = sklearn.linear_model.SGDRegressor(alpha=trial.suggest_float('alpha', 0.0001, 1, log=True), + random_state=random_state) + + elif classifier_name == "LinearSVR": + + model = sklearn.svm.LinearSVR(C=trial.suggest_float('C', 0.001, 1000, log=True), dual=False, max_iter=2000, + loss="squared_epsilon_insensitive", random_state=random_state) + + elif classifier_name == 'PassiveAggressiveRegressor': + + model = sklearn.linear_model.PassiveAggressiveRegressor(C=trial.suggest_float('C', 0.0001, 100, log=True), + random_state=random_state) + + elif classifier_name == 'LogisticRegression': + + model = sklearn.linear_model.LogisticRegression(C=trial.suggest_float('C', 0.0001, 100, log=True), + solver='saga', random_state=random_state) + + elif classifier_name == 'AdaGradRegressor': + + model = lightning.regression.AdaGradRegressor(eta=trial.suggest_float('eta', 0.0001, 10, log=True), + alpha=trial.suggest_float('alpha', 0.0001, 10, log=True), + random_state=random_state) + + elif classifier_name == 'CDClassifier': + + model = lightning.regression.CDClassifier(C=trial.suggest_float('C', 0.0001, 10, log=True), + alpha=trial.suggest_float('alpha', 0.0001, 10, log=True), + random_state=random_state) + + elif classifier_name == 'FistaClassifier': + + model = lightning.regression.FistaClassifier(C=trial.suggest_float('C', 0.0001, 10, log=True), + alpha=trial.suggest_float('alpha', 0.0001, 10, log=True), + random_state=random_state) + + elif classifier_name == 'SDCAClassifier': + + model = lightning.regression.SDCAClassifier(alpha=trial.suggest_float('alpha', 0.0001, 10, log=True), + random_state=random_state) + + elif classifier_name == 'OneClassSVM': + + kernel = trial.suggest_categorical('kernel', ['linear', 'poly', 'rbf', 'sigmoid']) + gamma = trial.suggest_categorical('gamma', ['scale', 'auto']) + nu = trial.suggest_float('nu', 0, 1) + + model = sklearn.svm.OneClassSVM(kernel=kernel, gamma=gamma, nu=nu, random_state=random_state) + + elif classifier_name == 'KernelSVC': + + kernel = trial.suggest_categorical('kernel', ['linear', 'poly', 'rbf', 'sigmoid', 'cosine']) + model = lightning.regression.KernelSVC(alpha=trial.suggest_float('alpha', 0.0001, 10, log=True), + kernel=kernel, random_state=random_state) + + else: + raise Exception("Unknown regressor: " + classifier_name) + + return model + + +def sympy_to_c(model): + # classifier can also be used directly if only 2 classes + [(c_name, c_code), (h_name, c_header)] = codegen(("score", model.sympify()), "C89", "model", header=False, + empty=False) + c_code = re.sub(r"data([0-9]+)", r"data[\1]", c_code) + + return c_code + + +def model_to_java(name, package, model, scaler, df): + """ Convert to java source file """ + import m2cgen as m2c + + code = m2c.export_to_java(model, package, name) + + code, params = replace_params(code) + + imp = """import org.matsim.application.prepare.network.opt.FeatureRegressor; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; + +/** +* Generated model, do not modify. +*/ +public final class""" + + code = code.replace("public class", imp) + code = code.replace(name, name + " implements FeatureRegressor") + + features = [f"data[{i}] = {s};\n" for i, s in enumerate(model_features(scaler, df))] + + idx = code.index("public static double score") + + pre = """ + public static %s INSTANCE = new %s(); + public static final double[] DEFAULT_PARAMS = %s; + + @Override + public double predict(Object2DoubleMap ft) { + return predict(ft, DEFAULT_PARAMS); + } + + @Override + public double[] getData(Object2DoubleMap ft) { + double[] data = new double[%d]; +""" % (name, name, str(params).replace("[", "{").replace("]", "}"), len(features)) + + for ft in features: + pre += "\t\t" + ft + + pre += """ + return data; + } + + @Override + public double predict(Object2DoubleMap ft, double[] params) { + + double[] data = getData(ft); + for (int i = 0; i < data.length; i++) + if (Double.isNaN(data[i])) throw new IllegalArgumentException("Invalid data at index: " + i); + + return score(data, params); + } + """ + + code = code.replace("score(double[] input)", "score(double[] input, double[] params)") + + return f"{code[:idx]}{pre}{code[idx:]}" + + +def model_to_py(name, model, scaler, df): + import m2cgen as m2c + + code = m2c.export_to_python(model, function_name="score") + + code, params = replace_params(code) + + code = code.replace("input", "inputs") + code = code.replace("(inputs):", "(params, inputs):") + + features = "\t\t".join([f"data[{i}] = {s}\n" for i, s in enumerate(model_features(scaler, df))]) + features = features.replace(".getDouble(", ".get(") + + code = """def features(ft, data): +\t\t%s +params = %s +""" % (features, params) + code + + code += """ +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error +""" + + return code + + +def replace_params(code): + """ Replaces and collects model parameters """ + + pattern = re.compile(r"(var\d+) = (-?\d+.\d+)") + + params = [] + new_code = '' + start = 0 + + for m in pattern.finditer(code): + end, newstart = m.span() + new_code += code[start:end] + rep = "%s = params[%d]" % (m.group(1), len(params)) + new_code += rep + start = newstart + + params.append(float(m.group(2))) + + new_code += code[start:] + + return new_code, params + + +def model_features(scaler, df): + for name, t, ids in scaler.transformers_: + + for i, idx in enumerate(ids): + + c = df.columns[idx] + + if name == "scale": + + t = scaler.named_transformers_[name] + + with_mean = t.get_params()["with_mean"] + + if with_mean: + yield f"(ft.getDouble(\"{c}\") - {t.mean_[i]}) / {t.scale_[i]}" + else: + yield f"ft.getDouble(\"{c}\") / {t.scale_[i]}" + + elif t == "passthrough": + yield f"ft.getDouble(\"{c}\")" + + elif t == "drop": + continue + + else: + raise Exception("Unknown transformer: " + t) diff --git a/matsim/scenariogen/network/models_feyn.py b/matsim/scenariogen/network/models_feyn.py new file mode 100644 index 0000000..74df311 --- /dev/null +++ b/matsim/scenariogen/network/models_feyn.py @@ -0,0 +1,170 @@ +# -*- coding: utf-8 -*- +"""These models depend on the feyn package which is not listed and only optional due to its licensing""" + +from time import time + +import numpy as np +import pandas as pd + +from sklearn.base import BaseEstimator, RegressorMixin, ClassifierMixin +from sklearn.metrics import mean_squared_error + +import feyn + +class QLatticeBase(BaseEstimator): + _kind = None + _loss = None + + @staticmethod + def as_df(X, y=None): + tf = pd.DataFrame(X, dtype=np.float64) + if y is not None: + tf["y"] = y + + tf.columns = tf.columns.map(lambda x: "data%s" % x if x != "y" else "y") + + return tf + + def __init__(self, max_complexity, n_epochs, criterion, progress, random_state) -> None: + super().__init__() + + self.ql = feyn.QLattice(random_state) + self.n_epochs = n_epochs + self.max_complexity = max_complexity + self.criterion = criterion + self.progress = progress + self.random_state = random_state + + def fit(self, X, y, sample_weight=None, test=None, val=None, f=None, ftest=None, fval=None, val_interval=10): + + tf = self.as_df(X, y) + + if test is not None: + test = self.as_df(*test) + + if val is not None: + val = self.as_df(*val) + + models = [] + m_count = 0 + + start = time() + for i in range(1, self.n_epochs + 1): + + new_sample = self.ql.sample_models( + input_names=tf.columns, + output_name='y', + kind=self._kind, + max_complexity=self.max_complexity + ) + + models += new_sample + m_count += len(new_sample) + + models = feyn.fit_models( + models=models, + data=tf, + sample_weights=sample_weight, + loss_function=self._loss, + criterion=self.criterion, + threads=8 + ) + + # Sort for val method for pruning + if test is not None: + if f is None: + f = lambda pred: mean_squared_error(tf["y"], pred) + + if ftest is None: + ftest = lambda pred: mean_squared_error(test["y"], pred) + + if fval is None: + fval = lambda pred: mean_squared_error(val["y"], pred) + + # Custom prune / sorting + if val is not None and ((i - 1) % val_interval == 0 or i == self.n_epochs): + models = list(sorted( + models, key=lambda m: ftest(m.predict(test)) + fval(m.predict(val)) + )) + else: + models = list(sorted( + models, key=lambda m: f(m.predict(tf)) + ftest(m.predict(test)) + )) + + models = feyn.prune_models(models) + + info = "" + if ftest is not None: + # Custom label + info += " Test: %.2f" % ftest(models[0].predict(test)) + + if val is not None and fval is not None: + # Custom label + info += " Val: %.2f" % fval(models[0].predict(val)) + + elapsed = time() - start + if len(models) > 0 and self.progress: + feyn.show_model( + models[0], + feyn.tools.get_progress_label(i, self.n_epochs, elapsed, m_count) + info, + update_display=True, + ) + + self.ql.update(models) + + self.best = [models[0]] + feyn.get_diverse_models(models[1:], n=5) + + return self + + def predict(self, X): + return self.best[0].predict(self.as_df(X)) + + def show(self): + feyn.show_model(self.best[0]) + + def sympify(self): + return self.best[0].sympify(signif=9, symbolic_lr=True, include_weights=True) + + def plot(self, X, y, Xval, yval): + + train = self.as_df(X, y) + test = self.as_df(Xval, yval) + + self.best[0].plot( + data=train, + compare_data=test + ) + + +class QLatticeClassifier(QLatticeBase, ClassifierMixin): + + def __init__(self, max_complexity=10, n_epochs=30, criterion="bic", progress=False, random_state=-1) -> None: + super().__init__(max_complexity, n_epochs, criterion, progress, random_state) + + self._kind = "classification" + self._loss = "binary_cross_entropy" + + def copy(self, n=0): + """ Make new model by copying the best n""" + + other = QLatticeClassifier(self.max_complexity, self.n_epochs, self.progress, self.random_state) + other.best = [self.best[n]] + + return other + + +class QLatticeRegressor(QLatticeBase, RegressorMixin): + + def __init__(self, max_complexity=10, n_epochs=30, criterion="bic", progress=False, random_state=-1) -> None: + super().__init__(max_complexity, n_epochs, criterion, progress, random_state) + + self._kind = "regression" + self._loss = "squared_error" + + def copy(self, n=0): + """ Make new model by copying the best n""" + + other = QLatticeRegressor(self.max_complexity, self.n_epochs, self.progress, self.random_state) + other.best = [self.best[n]] + + return other \ No newline at end of file diff --git a/matsim/scenariogen/network/randomTrips.py b/matsim/scenariogen/network/randomTrips.py new file mode 100644 index 0000000..9f322c8 --- /dev/null +++ b/matsim/scenariogen/network/randomTrips.py @@ -0,0 +1,946 @@ +#!/usr/bin/env python +# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo +# Copyright (C) 2010-2023 German Aerospace Center (DLR) and others. +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# https://www.eclipse.org/legal/epl-2.0/ +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the Eclipse +# Public License 2.0 are satisfied: GNU General Public License, version 2 +# or later which is available at +# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later + +# @file randomTrips.py +# @author Daniel Krajzewicz +# @author Jakob Erdmann +# @author Michael Behrisch +# @date 2010-03-06 + + +from __future__ import print_function +from __future__ import absolute_import +import os +import sys +import random +import bisect +import subprocess +from collections import defaultdict +import math + +import sumolib # noqa +from sumolib.miscutils import euclidean, parseTime, intIfPossible # noqa +from sumolib.geomhelper import naviDegree, minAngleDegreeDiff # noqa +from sumolib.net.lane import is_vehicle_class # noqa + +DUAROUTER = sumolib.checkBinary('duarouter') + +SOURCE_SUFFIX = ".src.xml" +DEST_SUFFIX = ".dst.xml" +VIA_SUFFIX = ".via.xml" + +MAXIMIZE_FACTOR = "max" + + +def get_options(args=None): + op = sumolib.options.ArgumentParser(description="Generate trips between random locations", + allowed_programs=['duarouter']) + # input + op.add_argument("-n", "--net-file", category="input", dest="netfile", required=True, type=op.net_file, + help="define the net file (mandatory)") + op.add_argument("-a", "--additional-files", category="input", dest="additional", type=op.additional_file, + help="define additional files to be loaded by the router") + op.add_argument("--weights-prefix", category="input", dest="weightsprefix", type=op.file, + help="loads probabilities for being source, destination and via-edge from the files named " + + "'prefix'.src.xml, 'prefix'.dst.xml and 'prefix'.via.xml") + # output + op.add_argument("-o", "--output-trip-file", category="output", dest="tripfile", type=op.route_file, + default="trips.trips.xml", + help="define the output trip filename") + op.add_argument("-r", "--route-file", category="output", dest="routefile", type=op.route_file, + help="generates route file with duarouter") + op.add_argument("--vtype-output", category="output", dest="vtypeout", type=op.file, + help="Store generated vehicle types in a separate file") + op.add_argument("--weights-output-prefix", category="output", dest="weights_outprefix", type=op.file, + help="generates weights files for visualisation") + # persons + op.add_argument("--pedestrians", category="persons", action="store_true", default=False, + help="create a person file with pedestrian trips instead of vehicle trips") + op.add_argument("--personrides", category="persons", + help="create a person file with rides using STR as lines attribute") + op.add_argument("--persontrips", category="persons", action="store_true", default=False, + help="create a person file with person trips instead of vehicle trips") + op.add_argument("--persontrip.transfer.car-walk", category="persons", dest="carWalkMode", + help="Where are mode changes from car to walking allowed " + + "(possible values: 'ptStops', 'allJunctions' and combinations)") + op.add_argument("--persontrip.walkfactor", category="persons", dest="walkfactor", metavar="FLOAT", type=float, + help="Use FLOAT as a factor on pedestrian maximum speed during intermodal routing") + op.add_argument("--persontrip.walk-opposite-factor", category="persons", dest="walkoppositefactor", + metavar="FLOAT", type=float, + help="Use FLOAT as a factor on pedestrian maximum speed against vehicle traffic direction") + op.add_argument("--from-stops", category="persons", dest="fromStops", + help="Create trips that start at stopping places of the indicated type(s). i.e. 'busStop'") + op.add_argument("--to-stops", category="persons", dest="toStops", + help="Create trips that end at stopping places of the indicated type(s). i.e. 'busStop'") + # attributes + op.add_argument("--prefix", category="attributes", dest="tripprefix", default="", + help="prefix for the trip ids") + op.add_argument("-t", "--trip-attributes", category="attributes", dest="tripattrs", default="", + help="additional trip attributes. When generating pedestrians, attributes for " + + "'person' and 'walk' are supported.") + op.add_argument("--fringe-start-attributes", category="attributes", dest="fringeattrs", default="", + help="additional trip attributes when starting on a fringe.") + op.add_argument("--vehicle-class", + help="The vehicle class assigned to the generated trips (adds a standard vType definition " + + "to the output file).") + op.add_argument("--random-departpos", category="attributes", dest="randomDepartPos", action="store_true", + default=False, help="Randomly choose a position on the starting edge of the trip") + op.add_argument("--random-arrivalpos", category="attributes", dest="randomArrivalPos", action="store_true", + default=False, help="Randomly choose a position on the ending edge of the trip") + op.add_argument("--junction-taz", category="attributes", dest="junctionTaz", action="store_true", default=False, + help="Write trips with fromJunction and toJunction") + # weights + op.add_argument("-l", "--length", category="weights", action="store_true", default=False, + help="weight edge probability by length") + op.add_argument("-L", "--lanes", category="weights", action="store_true", default=False, + help="weight edge probability by number of lanes") + op.add_argument("--edge-param", category="weights", dest="edgeParam", + help="use the given edge parameter as factor for edge") + op.add_argument("--speed-exponent", category="weights", dest="speed_exponent", metavar="FLOAT", type=float, + default=0.0, help="weight edge probability by speed^'FLOAT' (default 0)") + op.add_argument("--fringe-speed-exponent", category="weights", dest="fringe_speed_exponent", metavar="FLOAT", + help="weight fringe edge probability by speed^'FLOAT' (default: speed exponent)") + op.add_argument("--angle", category="weights", dest="angle", default=90.0, type=float, + help="weight edge probability by angle [0-360] relative to the network center") + op.add_argument("--angle-factor", category="weights", dest="angle_weight", default=1.0, type=float, + help="maximum weight factor for angle") + op.add_argument("--random-factor", category="weights", dest="randomFactor", default=1.0, type=float, + help="edge weights are dynamically disturbed by a random factor drawn uniformly from [1,FLOAT]") + op.add_argument("--fringe-factor", category="weights", dest="fringe_factor", default="1.0", + help="multiply weight of fringe edges by 'FLOAT' (default 1)" + + " or set value 'max' to force all traffic to start/end at the fringe.") + op.add_argument("--fringe-threshold", category="weights", dest="fringe_threshold", default=0.0, type=float, + help="only consider edges with speed above 'FLOAT' as fringe edges (default 0)") + op.add_argument("--allow-fringe", category="weights", dest="allow_fringe", action="store_true", default=False, + help="Allow departing on edges that leave the network and arriving on edges " + + "that enter the network (via turnarounds or as 1-edge trips") + op.add_argument("--allow-fringe.min-length", category="weights", dest="allow_fringe_min_length", type=float, + help="Allow departing on edges that leave the network and arriving on edges " + + "that enter the network, if they have at least the given length") + op.add_argument("--fringe-junctions", category="weights", action="store_true", dest="fringeJunctions", + default=False, help="Determine fringe edges based on junction attribute 'fringe'") + op.add_argument("--vclass", "--edge-permission", category="weights", default="passenger", + help="only from and to edges which permit the given vehicle class") + op.add_argument("--via-edge-types", category="weights", dest="viaEdgeTypes", + help="Set list of edge types that cannot be used for departure or arrival " + + "(unless being on the fringe)") + op.add_argument("--allow-roundabouts", category="weights", dest="allowRoundabouts", action="store_true", + default=False, help="Permit trips that start or end inside a roundabout") + # processing + op.add_argument("-s", "--seed", default=42, type=int, + help="random seed") + op.add_argument("--random", action="store_true", default=False, + help="use a random seed to initialize the random number generator") + op.add_argument("--min-distance", dest="min_distance", metavar="FLOAT", default=0.0, + type=float, help="require start and end edges for each trip to be at least 'FLOAT' m apart") + op.add_argument("--min-distance.fringe", dest="min_dist_fringe", metavar="FLOAT", type=float, + help="require start and end edges for each fringe to fringe trip to be at least 'FLOAT' m apart") + op.add_argument("--max-distance", dest="max_distance", metavar="FLOAT", type=float, + help="require start and end edges for each trip to be at most 'FLOAT' m " + + "apart (default 0 which disables any checks)") + op.add_argument("-i", "--intermediate", default=0, type=int, + help="generates the given number of intermediate way points") + op.add_argument("--jtrrouter", action="store_true", default=False, + help="Create flows without destination as input for jtrrouter") + op.add_argument("--maxtries", default=100, type=int, + help="number of attemps for finding a trip which meets the distance constraints") + op.add_argument("--remove-loops", dest="remove_loops", action="store_true", default=False, + help="Remove loops at route start and end") + op.add_argument("--random-routing-factor", dest="randomRoutingFactor", default=1, type=float, + help="Edge weights for routing are dynamically disturbed " + "by a random factor drawn uniformly from [1,FLOAT)") + op.add_argument("--validate", default=False, action="store_true", + help="Whether to produce trip output that is already checked for connectivity") + op.add_argument("-v", "--verbose", action="store_true", default=False, + help="tell me what you are doing") + # flow + op.add_argument("-b", "--begin", category="flow", default=0, type=op.time, + help="begin time") + op.add_argument("-e", "--end", category="flow", default=3600, type=op.time, + help="end time (default 3600)") + group = op.add_mutually_exclusive_group() + group.add_argument("-p", "--period", nargs="+", metavar="FLOAT", category="flow", + action=sumolib.options.SplitAction, + help="Generate vehicles with equidistant departure times and period=FLOAT (default 1.0). " + + "If option --binomial is used, the expected arrival rate is set to 1/period.") + group.add_argument("--insertion-rate", dest="insertionRate", nargs="+", metavar="FLOAT", category="flow", + action=sumolib.options.SplitAction, + help="How much vehicles arrive in the simulation per hour (alternative to the period option).") + group.add_argument("--insertion-density", dest="insertionDensity", nargs="+", metavar="FLOAT", category="flow", + action=sumolib.options.SplitAction, + help="How much vehicles arrive in the simulation per hour per kilometer of road " + + "(alternative to the period option).") + op.add_argument("--flows", category="flow", default=0, type=int, + help="generates INT flows that together output vehicles with the specified period") + op.add_argument("--random-depart", category="flow", action="store_true", dest="randomDepart", default=False, + help="Distribute departures randomly between begin and end") + op.add_argument("--binomial", category="flow", metavar="N", type=int, + help="If this is set, the number of departures per second will be drawn from a binomial " + + "distribution with n=N and p=PERIOD/N where PERIOD is the argument given to --period") + + try: + options = op.parse_args(args=args) + except (NotImplementedError, ValueError) as e: + print(e, file=sys.stderr) + sys.exit(1) + + if options.vclass: + if not is_vehicle_class(options.vclass): + print("Error: The string '%s' doesn't correspond to a legit vehicle class" % options.vclass, + file=sys.stderr) + sys.exit(1) + + if options.persontrips or options.personrides: + options.pedestrians = True + + if options.pedestrians: + options.vclass = 'pedestrian' + if options.flows > 0: + print("Error: Person flows are not supported yet", file=sys.stderr) + sys.exit(1) + + if options.validate and options.routefile is None: + options.routefile = "routes.rou.xml" + + if options.period is None and options.insertionRate is None and options.insertionDensity is None: + options.period = [1.] + + options.net = sumolib.net.readNet(options.netfile) + if options.insertionDensity: + # Compute length of the network + length = 0. # In meters + for edge in options.net.getEdges(): + if edge.allows(options.vclass): + length += edge.getLaneNumber() * edge.getLength() + options.insertionRate = [density * (length / 1000.0) for density in options.insertionDensity] + + if options.insertionRate: + options.period = [3600.0 / rate for rate in options.insertionRate] + + if options.period: + if any(options.period) <= 0: + print("Error: Period must be positive", file=sys.stderr) + sys.exit(1) + options.period = list(map(intIfPossible, options.period)) + if options.binomial is not None: + for p in options.period: + if 1.0 / p / options.binomial >= 1: + print(("Warning: Option --binomial %s is too low for insertion period %s." % ( + options.binomial, p)) + + " Insertions will not be randomized.", file=sys.stderr) + + if options.jtrrouter and options.flows <= 0: + print("Error: Option --jtrrouter must be used with option --flows", file=sys.stderr) + sys.exit(1) + + if options.vehicle_class: + if not is_vehicle_class(options.vehicle_class): + print("Error: The string '%s' doesn't correspond to a legit vehicle class" % + options.vehicle_class, file=sys.stderr) + sys.exit(1) + + if options.tripprefix: + options.vtypeID = "%s_%s" % (options.tripprefix, options.vehicle_class) + else: + options.vtypeID = options.vehicle_class + + if 'type=' in options.tripattrs: + print("Error: trip-attribute 'type' cannot be used together with option --vehicle-class", file=sys.stderr) + sys.exit(1) + + if options.randomDepartPos: + if 'departPos' in options.tripattrs: + print("Error: trip-attribute 'departPos' cannot be used together with option --random-departpos", + file=sys.stderr) + sys.exit(1) + + if options.randomArrivalPos: + if 'arrivalPos' in options.tripattrs: + print("Error: trip-attribute 'arrivalPos' cannot be used together with option --random-arrivalpos", + file=sys.stderr) + sys.exit(1) + + if options.weightsprefix: + weight_files = [options.weightsprefix + s for s in (SOURCE_SUFFIX, DEST_SUFFIX, VIA_SUFFIX)] + if not any([os.path.isfile(w) for w in weight_files]): + print("Error: None of the weight files '%s' exists." % "', '".join(weight_files), file=sys.stderr) + sys.exit(1) + + if options.randomFactor < 1: + print("Error: Option --random-factor requires a value >= 1.") + sys.exit(1) + + if options.fromStops or options.toStops: + options.edgeFromStops, options.edgeToStops = loadStops(options) + + if options.viaEdgeTypes: + options.viaEdgeTypes = options.viaEdgeTypes.split(',') + if options.fringe_speed_exponent is None: + options.fringe_speed_exponent = options.speed_exponent + + if options.fringe_factor.lower() == MAXIMIZE_FACTOR: + options.fringe_factor = MAXIMIZE_FACTOR + else: + try: + options.fringe_factor = float(options.fringe_factor) + if options.fringe_factor < 0: + print("Error: --fringe-factor argument may not be negative", file=sys.stderr) + sys.exit(1) + except ValueError: + print("Error: --fringe-factor argument must be a float or 'max'", file=sys.stderr) + sys.exit(1) + + return options + + +class InvalidGenerator(Exception): + pass + + +def loadStops(options): + edgeFromStops = defaultdict(list) # edge -> [(stopType1, stopID1), ...] + edgeToStops = defaultdict(list) # edge -> [(stopType1, stopID1), ...] + if options.additional is None: + print("Error: Option %s requires option --additional-files for loading infrastructure elements" % + ("--from-stops" if options.fromStops else "--to-stops"), file=sys.stderr) + sys.exit(1) + stopTypes = [] + if options.fromStops: + options.fromStops = options.fromStops.split(',') + stopTypes += options.fromStops + else: + options.fromStops = [] + if options.toStops: + options.toStops = options.toStops.split(',') + stopTypes += options.toStops + else: + options.toStops = [] + stopTypes = list(set(stopTypes)) + typeCounts = defaultdict(lambda: 0) + for additional in options.additional.split(','): + for stop in sumolib.xml.parse(additional, stopTypes): + edgeID = stop.lane.rsplit('_', 1)[0] + if stop.name in options.fromStops: + edgeFromStops[edgeID].append((stop.name, stop.id)) + if stop.name in options.toStops: + edgeToStops[edgeID].append((stop.name, stop.id)) + typeCounts[stop.name] += 1 + + if options.fromStops: + available = sum([typeCounts[t] for t in options.fromStops]) + if available == 0: + print("No stops of type%s '%s' were found in additional-files %s" % ( + ('' if len(options.fromStops) == 1 else 's'), + options.fromStops[0], options.additional), file=sys.stderr) + sys.exit(1) + if options.toStops: + available = sum([typeCounts[t] for t in options.toStops]) + if available == 0: + print("No stops of type%s '%s' were found in additional-files %s" % ( + ('' if len(options.toStops) == 1 else 's'), + options.toStops[0], options.additional), file=sys.stderr) + sys.exit(1) + return edgeFromStops, edgeToStops + + +# assigns a weight to each edge using weight_fun and then draws from a discrete +# distribution with these weights + + +class RandomEdgeGenerator: + + def __init__(self, net, weight_fun): + self.net = net + self.weight_fun = weight_fun + self.cumulative_weights = [] + self.total_weight = 0 + for edge in self.net._edges: + # print edge.getID(), weight_fun(edge) + self.total_weight += weight_fun(edge) + self.cumulative_weights.append(self.total_weight) + if self.total_weight == 0: + raise InvalidGenerator() + + def get(self): + r = random.random() * self.total_weight + index = bisect.bisect(self.cumulative_weights, r) + return self.net._edges[index] + + def write_weights(self, fname, interval_id, begin, end): + # normalize to [0,100] + normalizer = 100.0 / max(1, max(map(self.weight_fun, self.net._edges))) + weights = [(self.weight_fun(e) * normalizer, e.getID()) for e in self.net.getEdges()] + weights.sort(reverse=True) + with open(fname, 'w+') as f: + f.write('\n') + f.write(' \n' % ( + interval_id, begin, end)) + for weight, edgeID in weights: + f.write(' \n' % + (edgeID, weight)) + f.write(' \n') + f.write('\n') + + +class RandomTripGenerator: + + def __init__(self, source_generator, sink_generator, via_generator, intermediate, pedestrians): + self.source_generator = source_generator + self.sink_generator = sink_generator + self.via_generator = via_generator + self.intermediate = intermediate + self.pedestrians = pedestrians + + def get_trip(self, min_distance, max_distance, maxtries=100, junctionTaz=False, min_dist_fringe=None): + for min_dist in [min_distance, min_dist_fringe]: + if min_dist is None: + break + for _ in range(maxtries): + source_edge = self.source_generator.get() + intermediate = [self.via_generator.get() for __ in range(self.intermediate)] + sink_edge = self.sink_generator.get() + is_fringe2fringe = source_edge.is_fringe() and sink_edge.is_fringe() and not intermediate + if min_dist == min_dist_fringe and not is_fringe2fringe: + continue + if self.pedestrians: + destCoord = sink_edge.getFromNode().getCoord() + else: + destCoord = sink_edge.getToNode().getCoord() + coords = ([source_edge.getFromNode().getCoord()] + + [e.getFromNode().getCoord() for e in intermediate] + + [destCoord]) + distance = sum([euclidean(p, q) + for p, q in zip(coords[:-1], coords[1:])]) + if (distance >= min_dist + and (not junctionTaz or source_edge.getFromNode() != sink_edge.getToNode()) + and (max_distance is None or distance < max_distance)): + return source_edge, sink_edge, intermediate + raise Exception("Warning: no trip found after %s tries" % maxtries) + + +def get_prob_fun(options, fringe_bonus, fringe_forbidden, max_length): + # fringe_bonus None generates intermediate way points + randomProbs = defaultdict(lambda: 1) + if options.randomFactor != 1: + for edge in options.net.getEdges(): + randomProbs[edge.getID()] = random.uniform(1, options.randomFactor) + + roundabouts = set() + if not options.allowRoundabouts: + for roundabout in options.net.getRoundabouts(): + roundabouts.update(roundabout.getEdges()) + + stopDict = None + if options.fromStops and fringe_bonus == "_incoming": + stopDict = options.edgeFromStops + elif options.toStops and fringe_bonus == "_outgoing": + stopDict = options.edgeToStops + + # IDEA: source and sink are not allowed as well, but that might also remove worthwile routes + def edge_probability(edge): + bonus_connections = None if fringe_bonus is None else getattr(edge, fringe_bonus) + forbidden_connections = None if fringe_forbidden is None else getattr(edge, fringe_forbidden) + if options.vclass and not edge.allows(options.vclass) and not stopDict: + return 0 # not allowed + if fringe_bonus is None and edge.is_fringe() and not options.pedestrians: + return 0 # not suitable as intermediate way point + if (fringe_forbidden is not None and + edge.is_fringe(forbidden_connections) and + not options.pedestrians and + (options.allow_fringe_min_length is None or edge.getLength() < options.allow_fringe_min_length)): + return 0 # the wrong kind of fringe + if (fringe_bonus is not None and options.viaEdgeTypes is not None and + not edge.is_fringe(bonus_connections, checkJunctions=options.fringeJunctions) and + edge.getType() in options.viaEdgeTypes): + return 0 # the wrong type of edge (only allows depart and arrival on the fringe) + if fringe_bonus is not None and edge.getID() in roundabouts: + return 0 # traffic typically does not start/end inside a roundabout + prob = randomProbs[edge.getID()] + if stopDict: + prob *= len(stopDict[edge.getID()]) + if options.length: + if (options.fringe_factor != 1.0 and fringe_bonus is not None and + edge.is_fringe(bonus_connections, checkJunctions=options.fringeJunctions)): + # short fringe edges should not suffer a penalty + prob *= max_length + else: + prob *= edge.getLength() + if options.lanes: + prob *= edge.getLaneNumber() + if edge.is_fringe(bonus_connections, checkJunctions=options.fringeJunctions): + prob *= (edge.getSpeed() ** options.fringe_speed_exponent) + else: + prob *= (edge.getSpeed() ** options.speed_exponent) + if options.fringe_factor != 1.0 and fringe_bonus is not None: + isFringe = (edge.getSpeed() > options.fringe_threshold and + edge.is_fringe(bonus_connections, checkJunctions=options.fringeJunctions)) + if isFringe and options.fringe_factor != MAXIMIZE_FACTOR: + prob *= options.fringe_factor + elif not isFringe and options.fringe_factor == MAXIMIZE_FACTOR: + prob = 0 + if options.edgeParam is not None: + prob *= float(edge.getParam(options.edgeParam, 1.0)) + if options.angle_weight != 1.0 and fringe_bonus is not None: + xmin, ymin, xmax, ymax = edge.getBoundingBox() + ex, ey = ((xmin + xmax) / 2, (ymin + ymax) / 2) + nx, ny = options.angle_center + edgeAngle = naviDegree(math.atan2(ey - ny, ex - nx)) + angleDiff = minAngleDegreeDiff(options.angle, edgeAngle) + # print("e=%s nc=%s ec=%s ea=%s a=%s ad=%s" % ( + # edge.getID(), options.angle_center, (ex,ey), edgeAngle, + # options.angle, angleDiff)) + # relDist = 2 * euclidean((ex, ey), options.angle_center) / max(xmax - xmin, ymax - ymin) + # prob *= (relDist * (options.angle_weight - 1) + 1) + if fringe_bonus == "_incoming": + # source edge + prob *= (angleDiff * (options.angle_weight - 1) + 1) + else: + prob *= ((180 - angleDiff) * (options.angle_weight - 1) + 1) + + return prob + return edge_probability + + +class LoadedProps: + + def __init__(self, fname): + self.weights = defaultdict(lambda: 0) + for edge in sumolib.output.parse_fast(fname, 'edge', ['id', 'value']): + self.weights[edge.id] = float(edge.value) + + def __call__(self, edge): + return self.weights[edge.getID()] + + +def buildTripGenerator(net, options): + try: + max_length = 0 + for edge in net.getEdges(): + if not edge.is_fringe(): + max_length = max(max_length, edge.getLength()) + forbidden_source_fringe = None if options.allow_fringe else "_outgoing" + forbidden_sink_fringe = None if options.allow_fringe else "_incoming" + source_generator = RandomEdgeGenerator( + net, get_prob_fun(options, "_incoming", forbidden_source_fringe, max_length)) + sink_generator = RandomEdgeGenerator( + net, get_prob_fun(options, "_outgoing", forbidden_sink_fringe, max_length)) + if options.weightsprefix: + if os.path.isfile(options.weightsprefix + SOURCE_SUFFIX): + source_generator = RandomEdgeGenerator( + net, LoadedProps(options.weightsprefix + SOURCE_SUFFIX)) + if os.path.isfile(options.weightsprefix + DEST_SUFFIX): + sink_generator = RandomEdgeGenerator( + net, LoadedProps(options.weightsprefix + DEST_SUFFIX)) + except InvalidGenerator: + print("Error: no valid edges for generating source or destination. Try using option --allow-fringe", + file=sys.stderr) + return None + + try: + via_generator = RandomEdgeGenerator( + net, get_prob_fun(options, None, None, 1)) + if options.weightsprefix and os.path.isfile(options.weightsprefix + VIA_SUFFIX): + via_generator = RandomEdgeGenerator( + net, LoadedProps(options.weightsprefix + VIA_SUFFIX)) + except InvalidGenerator: + if options.intermediate > 0: + print("Error: no valid edges for generating intermediate points", file=sys.stderr) + return None + else: + via_generator = None + + return RandomTripGenerator( + source_generator, sink_generator, via_generator, options.intermediate, options.pedestrians) + + +def is_walk_attribute(attr): + for cand in ['arrivalPos', 'speed=', 'duration=', 'busStop=']: + if cand in attr: + return True + return False + + +def is_persontrip_attribute(attr): + for cand in ['vTypes', 'modes']: + if cand in attr: + return True + return False + + +def is_person_attribute(attr): + for cand in ['departPos', 'type']: + if cand in attr: + return True + return False + + +def is_vehicle_attribute(attr): + # speedFactor could be used in vType and vehicle but we need it in the vType + # to allow for the multi-parameter version + for cand in ['depart', 'arrival', 'line', 'personNumber', 'containerNumber', 'type']: + if cand in attr: + return True + return False + + +def split_trip_attributes(tripattrs, pedestrians, hasType, verbose): + # handle attribute values with a space + # assume that no attribute value includes an '=' sign + allattrs = [] + for a in tripattrs.split(): + if "=" in a: + allattrs.append(a) + else: + if len(allattrs) == 0: + print("Warning: invalid trip-attribute '%s'" % a) + else: + allattrs[-1] += ' ' + a + + # figure out which of the tripattrs belong to the or , + # which belong to the and which belong to the or + vehicleattrs = [] + personattrs = [] + vtypeattrs = [] + otherattrs = [] + for a in allattrs: + if pedestrians: + if is_walk_attribute(a) or is_persontrip_attribute(a): + otherattrs.append(a) + elif is_person_attribute(a): + personattrs.append(a) + else: + vtypeattrs.append(a) + else: + if is_vehicle_attribute(a): + vehicleattrs.append(a) + else: + vtypeattrs.append(a) + + if not hasType: + if pedestrians: + personattrs += vtypeattrs + else: + vehicleattrs += vtypeattrs + vtypeattrs = [] + + return (prependSpace(' '.join(vtypeattrs)), + prependSpace(' '.join(vehicleattrs)), + prependSpace(' '.join(personattrs)), + prependSpace(' '.join(otherattrs))) + + +def prependSpace(s): + if len(s) == 0 or s[0] == " ": + return s + else: + return " " + s + + +def samplePosition(edge): + return random.uniform(0.0, edge.getLength()) + + +def main(options): + if not options.random: + random.seed(options.seed) + + if options.min_distance > options.net.getBBoxDiameter() * (options.intermediate + 1): + options.intermediate = int(math.ceil(options.min_distance / options.net.getBBoxDiameter())) - 1 + print(("Warning: Using %s intermediate waypoints to achieve a minimum trip length of %s in a network " + "with diameter %.2f.") % (options.intermediate, options.min_distance, options.net.getBBoxDiameter()), + file=sys.stderr) + + if options.angle_weight != 1: + xmin, ymin, xmax, ymax = options.net.getBoundary() + options.angle_center = (xmin + xmax) / 2, (ymin + ymax) / 2 + + trip_generator = buildTripGenerator(options.net, options) + idx = 0 + + vtypeattrs, options.tripattrs, personattrs, otherattrs = split_trip_attributes( + options.tripattrs, options.pedestrians, options.vehicle_class, options.verbose) + + vias = {} + + time_delta = (parseTime(options.end) - parseTime(options.begin)) / len(options.period) + times = [parseTime(options.begin) + i*time_delta for i in range(len(options.period)+1)] + times = list(map(intIfPossible, times)) + + def generate_origin_destination(trip_generator, options): + source_edge, sink_edge, intermediate = trip_generator.get_trip( + options.min_distance, options.max_distance, options.maxtries, + options.junctionTaz, options.min_dist_fringe) + return source_edge, sink_edge, intermediate + + def generate_attributes(idx, departureTime, arrivalTime, origin, destination, intermediate, options): + label = "%s%s" % (options.tripprefix, idx) + combined_attrs = options.tripattrs + if options.randomDepartPos: + randomPosition = samplePosition(origin) + combined_attrs += ' departPos="%.2f"' % randomPosition + if options.randomArrivalPos: + randomPosition = samplePosition(destination) + combined_attrs += ' arrivalPos="%.2f"' % randomPosition + if options.fringeattrs and origin.is_fringe( + origin._incoming, checkJunctions=options.fringeJunctions): + combined_attrs += " " + options.fringeattrs + if options.junctionTaz: + attrFrom = ' fromJunction="%s"' % origin.getFromNode().getID() + attrTo = ' toJunction="%s"' % destination.getToNode().getID() + else: + attrFrom = ' from="%s"' % origin.getID() + attrTo = ' to="%s"' % destination.getID() + if options.fromStops: + attrFrom = ' %s="%s"' % random.choice(options.edgeFromStops[origin.getID()]) + if options.toStops: + attrTo = ' %s="%s"' % random.choice(options.edgeToStops[destination.getID()]) + via = "" + if intermediate: + via = ' via="%s" ' % ' '.join( + [e.getID() for e in intermediate]) + if options.validate: + vias[label] = via + return label, combined_attrs, attrFrom, attrTo, via + + def generate_one_person(label, combined_attrs, attrFrom, attrTo, departureTime, intermediate, options): + fouttrips.write( + ' \n' % (label, departureTime, personattrs)) + element = "walk" + attrs = otherattrs + if options.fromStops: + fouttrips.write(' \n' % attrFrom) + attrFrom = '' + if options.persontrips: + element = "personTrip" + elif options.personrides: + element = "ride" + attrs = ' lines="%s%s"' % (options.personrides, otherattrs) + if intermediate: + fouttrips.write(' <%s%s to="%s"%s/>\n' % (element, attrFrom, intermediate[0].getID(), attrs)) + for edge in intermediate[1:]: + fouttrips.write(' <%s to="%s"%s/>\n' % (element, edge.getID(), attrs)) + fouttrips.write(' <%s%s%s/>\n' % (element, attrTo, attrs)) + else: + fouttrips.write(' <%s%s%s%s/>\n' % (element, attrFrom, attrTo, attrs)) + fouttrips.write(' \n') + + def generate_one_flow(label, combined_attrs, departureTime, arrivalTime, period, options, timeIdx): + if len(options.period) > 1: + label = label + "#%s" % timeIdx + if options.binomial: + for j in range(options.binomial): + fouttrips.write((' \n') % ( + label, j, departureTime, arrivalTime, 1.0 / period / options.binomial, + combined_attrs)) + else: + fouttrips.write((' \n') % ( + label, departureTime, arrivalTime, intIfPossible(period * options.flows), combined_attrs)) + + def generate_one_trip(label, combined_attrs, departureTime): + fouttrips.write(' \n' % ( + label, departureTime, combined_attrs)) + + def generate_one(idx, departureTime, arrivalTime, period, origin, destination, intermediate, timeIdx=None): + try: + label, combined_attrs, attrFrom, attrTo, via = generate_attributes( + idx, departureTime, arrivalTime, origin, destination, intermediate, options) + + if options.pedestrians: + generate_one_person(label, combined_attrs, attrFrom, attrTo, departureTime, intermediate, options) + else: + if options.jtrrouter: + attrTo = '' + + combined_attrs = attrFrom + attrTo + via + combined_attrs + + if options.flows > 0: + generate_one_flow(label, combined_attrs, departureTime, arrivalTime, period, options, timeIdx) + else: + generate_one_trip(label, combined_attrs, departureTime) + + except Exception as exc: + if options.verbose: + print(exc, file=sys.stderr) + + return idx + 1 + + with open(options.tripfile, 'w') as fouttrips: + sumolib.writeXMLHeader(fouttrips, "$Id$", "routes", options=options) + if options.vehicle_class: + vTypeDef = ' \n' % ( + options.vtypeID, options.vehicle_class, vtypeattrs) + if options.vtypeout: + # ensure that trip output does not contain types, file may be + # overwritten by later call to duarouter + if options.additional is None: + options.additional = options.vtypeout + else: + options.additional = options.additional + "," + options.vtypeout + with open(options.vtypeout, 'w') as fouttype: + sumolib.writeXMLHeader(fouttype, "$Id$", "additional", options=options) + fouttype.write(vTypeDef) + fouttype.write("\n") + else: + fouttrips.write(vTypeDef) + options.tripattrs += ' type="%s"' % options.vtypeID + personattrs += ' type="%s"' % options.vtypeID + + if trip_generator: + if options.flows == 0: + for i in range(len(times)-1): + time = departureTime = parseTime(times[i]) + arrivalTime = parseTime(times[i+1]) + period = options.period[i] + if options.binomial is None: + departures = [] + if options.randomDepart: + subsecond = math.fmod(period, 1) + while time < arrivalTime: + rTime = random.randrange(int(departureTime), int(arrivalTime)) + time += period + if subsecond != 0: + # allow all multiples of subsecond to appear + rSubSecond = math.fmod( + subsecond * random.randrange(int(departureTime), int(arrivalTime)), 1) + rTime = min(arrivalTime, rTime + rSubSecond) + departures.append(rTime) + departures.sort() + else: + while departureTime < arrivalTime: + departures.append(departureTime) + departureTime += period + + for time in departures: + # generate with constant spacing + try: + origin, destination, intermediate = generate_origin_destination(trip_generator, options) + idx = generate_one(idx, time, arrivalTime, period, origin, destination, intermediate) + except Exception as exc: + print(exc, file=sys.stderr) + else: + time = departureTime + while time < arrivalTime: + # draw n times from a Bernoulli distribution + # for an average arrival rate of 1 / period + prob = 1.0 / period / options.binomial + for _ in range(options.binomial): + if random.random() < prob: + try: + origin, destination, intermediate = generate_origin_destination( + trip_generator, options) + idx = generate_one(idx, time, arrivalTime, period, + origin, destination, intermediate) + except Exception as exc: + if options.verbose: + print(exc, file=sys.stderr) + time += 1.0 + else: + try: + origins_destinations = [generate_origin_destination( + trip_generator, options) for _ in range(options.flows)] + for i in range(len(times)-1): + for j in range(options.flows): + departureTime = times[i] + arrivalTime = times[i+1] + period = options.period[i] + origin, destination, intermediate = origins_destinations[j] + generate_one(j, departureTime, arrivalTime, period, origin, destination, intermediate, i) + except Exception as exc: + if options.verbose: + print(exc, file=sys.stderr) + + fouttrips.write("\n") + + # call duarouter for routes or validated trips + args = [DUAROUTER, '-n', options.netfile, '-r', options.tripfile, '--ignore-errors', + '--begin', str(options.begin), '--end', str(options.end), + '--alternatives-output', 'NUL', + '--no-step-log'] + if options.additional is not None: + args += ['--additional-files', options.additional] + if options.carWalkMode is not None: + args += ['--persontrip.transfer.car-walk', options.carWalkMode] + if options.walkfactor is not None: + args += ['--persontrip.walkfactor', str(options.walkfactor)] + if options.walkoppositefactor is not None: + args += ['--persontrip.walk-opposite-factor', str(options.walkoppositefactor)] + if options.remove_loops: + args += ['--remove-loops'] + if options.randomRoutingFactor != 1: + args += ['--weights.random-factor', str(options.randomRoutingFactor)] + if options.vtypeout is not None: + args += ['--vtype-output', options.vtypeout] + if options.junctionTaz: + args += ['--junction-taz'] + if not options.verbose: + args += ['--no-warnings'] + else: + args += ['-v'] + + options_to_forward = sumolib.options.get_prefixed_options(options) + if 'duarouter' in options_to_forward: + for option in options_to_forward['duarouter']: + option[0] = '--' + option[0] + if option[0] not in args: + args += option + else: + raise ValueError("The argument '%s' has already been passed without the duarouter prefix." % option[0]) + + if options.routefile: + args2 = args + ['-o', options.routefile] + if options.verbose: + print("calling", " ".join(args2)) + sys.stdout.flush() + subprocess.call(args2) + sys.stdout.flush() + sumolib.xml.insertOptionsHeader(options.routefile, options) + + if options.validate: + # write to temporary file because the input is read incrementally + tmpTrips = options.tripfile + ".tmp" + args2 = args + ['-o', tmpTrips, '--write-trips'] + if options.junctionTaz: + args2 += ['--write-trips.junctions'] + if options.verbose: + print("calling", " ".join(args2)) + sys.stdout.flush() + subprocess.call(args2) + sys.stdout.flush() + os.remove(options.tripfile) # on windows, rename does not overwrite + os.rename(tmpTrips, options.tripfile) + sumolib.xml.insertOptionsHeader(options.tripfile, options) + + if trip_generator and options.weights_outprefix: + idPrefix = "" + if options.tripprefix: + idPrefix = options.tripprefix + "." + trip_generator.source_generator.write_weights( + options.weights_outprefix + SOURCE_SUFFIX, + idPrefix + "src", options.begin, options.end) + trip_generator.sink_generator.write_weights( + options.weights_outprefix + DEST_SUFFIX, + idPrefix + "dst", options.begin, options.end) + if trip_generator.via_generator: + trip_generator.via_generator.write_weights( + options.weights_outprefix + VIA_SUFFIX, + idPrefix + "via", options.begin, options.end) + + # return wether trips could be generated as requested + return trip_generator is not None + + +if __name__ == "__main__": + if not main(get_options()): + print("Error: Trips couldn't be generated as requested. " + "Try the --verbose option to output more details on the failure.") + sys.exit(1) diff --git a/matsim/scenariogen/network/ref_model/__init__.py b/matsim/scenariogen/network/ref_model/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/matsim/scenariogen/network/ref_model/germany/__init__.py b/matsim/scenariogen/network/ref_model/germany/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/matsim/scenariogen/network/ref_model/germany/capacity_dead_end.py b/matsim/scenariogen/network/ref_model/germany/capacity_dead_end.py new file mode 100644 index 0000000..d934a7f --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/capacity_dead_end.py @@ -0,0 +1,674 @@ +# -*- coding: utf-8 -*- +"""XGBRegressor(alpha=0.07346195485353985, base_score=0.5, booster='gbtree', + callbacks=None, colsample_bylevel=1, colsample_bynode=0.9, + colsample_bytree=0.9, early_stopping_rounds=None, + enable_categorical=False, eta=0.9005496527242473, + eval_metric='mae', feature_types=None, gamma=0.3913205082310667, + gpu_id=-1, grow_policy='depthwise', importance_type=None, + interaction_constraints='', lambda=0.03399177215713073, + learning_rate=0.90054965, max_bin=256, max_cat_threshold=64, + max_cat_to_onehot=4, max_delta_step=0, max_depth=4, max_leaves=0, + min_child_weight=1, missing=nan, monotone_constraints='()', + n_estimators=20, n_jobs=0, ...) +Error: 17.650743""" +def features(ft, data): + data[0] = (ft.get("length") - 121.64943999999997) / 102.75395159548076 + data[1] = (ft.get("speed") - 15.9616) / 4.368329731144388 + data[2] = (ft.get("num_lanes") - 1.856) / 0.8551397546600205 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [859.6049, 1368.6547, 317.08328, 602.73334, 1051.5116, 1365.0673, 479.5267, 1510.9359, 1261.82, 586.93774, 1752.8143, 345.83023, 251.44379, 196.05144, -100.92311, 556.4511, 248.56212, 8.751958, -112.63192, 353.46375, -499.09198, 67.84669, 238.25359, 69.855865, -147.35197, -24.82771, -398.5832, -312.16702, 645.81635, -429.90787, -56.959373, 73.37216, -8.621415, -20.72194, -5.8856874, -45.02695, 673.52795, 73.94616, -51.44936, 27.939749, -1045.293, 100.6221, 41.877926, 176.6136, 102.3786, -0.9688834, -220.64973, 137.63858, 215.92377, 41.44684, -20.3626, 16.380981, -151.44092, 52.8146, 10.459056, -165.38365, 34.63168, 32.307022, 218.85617, -109.07436, 67.68019, 6.774578, 178.27382, -206.08951, -1.2301626, 391.88242, -192.48239, 76.81782, -80.081535, -117.16598, 35.795372, 11.609657, -67.645164, -4.0473456, 189.128, -27.950788, 1.5682833, -23.019985, 382.52103, -4.099745, 68.12114, -223.34529, 273.18823, -89.40101, -5.440557, -10.679427, 109.98401, -64.30533, 71.05594, 27.412102, 4.8957453, 4.3622723, -190.4019, 233.06438, -11.0441675, -344.44733, 147.786, -23.268576, -33.001354, -1.6072537, -189.9128, -6.27801, -1.5817443, 91.38268, -136.90344, 66.1445, 155.11888, -52.789665, 12.548233, -99.26018, -10.74564, 7.0323977, 30.524338, -34.451485, -76.895966, 25.581684, -2.531495, 16.72898, 29.978521, -14.7835455, -68.298965, -2.481075, 15.709786, 101.65081, -137.88113, 3.3836243, 2.924429, -12.824084, -1.1771411, 21.445478, 31.226662, -12.21468, 11.967453, 5.482041, 50.30282, -0.40552256, -25.395111, -51.44317, -0.99815965, 9.2745495, -6.7587147, -23.885403, 3.0521197, -16.76911, 78.22408, 34.127068, -3.9190707, -75.568504, 8.654165, -3.9965763, -0.9473669, -9.223031, -3.693175, 9.046608, -67.85387, 2.1328363, 8.552537, 63.788208, 13.773914, -23.446692, -0.35650137, -4.8897696, 12.350961, -36.01829, -3.3446863, 13.035452, 2.4459727, -1.5044533, 25.509474, -0.022190453, -9.799512, 12.084186, 0.5939214, -38.01811, -8.539415, 25.965952, -14.307394, 6.077125, 0.27664867, 3.100341, -21.760082, 3.2573829, 1.4723984, -4.4738817, 9.860579, -11.05045, -0.23873898, -17.215534, -1.7263151, 1.2006466, -1.0414621, 3.6885643, -2.7444, 0.22894292, -48.507504, 17.920248, 0.692537, 4.6048656, -4.2964005, -0.4720382, 21.348267, 9.8496065, -2.6010177, 10.099594, -12.914126, 47.707207, -13.917312, 0.0, -0.051987253, 12.860103, 2.255951, -5.9641266, 21.498459, 4.267856, -19.037823, 2.985492, -0.44421604, 2.0518365, 1.7539244, 0.74282753, 7.382213, -5.6273985, -2.0897858, -0.048497323, -4.767571] +def score(params, inputs): + if inputs[0] >= -0.8462881: + if inputs[6] >= 1.5: + if inputs[0] >= -0.76468533: + if inputs[0] >= -0.68789995: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[0] >= -0.8073114: + var0 = params[2] + else: + var0 = params[3] + else: + if inputs[0] >= -0.82147145: + if inputs[0] >= 1.1191838: + var0 = params[4] + else: + var0 = params[5] + else: + var0 = params[6] + else: + if inputs[0] >= -1.0267677: + if inputs[0] >= -1.002243: + if inputs[0] >= -0.96248794: + var0 = params[7] + else: + var0 = params[8] + else: + var0 = params[9] + else: + var0 = params[10] + if inputs[0] >= 0.46680015: + if inputs[0] >= 1.0344182: + if inputs[1] >= 0.47922206: + if inputs[2] >= -0.41630626: + var1 = params[11] + else: + var1 = params[12] + else: + if inputs[0] >= 1.3222904: + var1 = params[13] + else: + var1 = params[14] + else: + if inputs[2] >= -0.41630626: + var1 = params[15] + else: + var1 = params[16] + else: + if inputs[0] >= -0.69982165: + if inputs[1] >= -0.792431: + if inputs[2] >= 0.75309324: + var1 = params[17] + else: + var1 = params[18] + else: + var1 = params[19] + else: + if inputs[2] >= 1.9224927: + if inputs[0] >= -0.76804286: + var1 = params[20] + else: + var1 = params[21] + else: + if inputs[0] >= -0.82147145: + var1 = params[22] + else: + var1 = params[23] + if inputs[0] >= 1.4293422: + if inputs[1] >= -0.15603217: + if inputs[0] >= 1.4803379: + if inputs[2] >= 0.1683935: + var2 = params[24] + else: + var2 = params[25] + else: + var2 = params[26] + else: + var2 = params[27] + else: + if inputs[0] >= 1.3335794: + var2 = params[28] + else: + if inputs[11] >= 0.5: + if inputs[0] >= 0.04920064: + var2 = params[29] + else: + var2 = params[30] + else: + if inputs[0] >= -0.45715457: + var2 = params[31] + else: + var2 = params[32] + if inputs[0] >= 1.3335794: + if inputs[0] >= 2.015451: + if inputs[0] >= 2.0768113: + if inputs[2] >= -0.41630626: + var3 = params[33] + else: + var3 = params[34] + else: + var3 = params[35] + else: + if inputs[0] >= 1.6961446: + var3 = params[36] + else: + var3 = params[37] + else: + if inputs[0] >= -0.87937677: + if inputs[0] >= -0.86414623: + if inputs[0] >= -0.28796402: + var3 = params[38] + else: + var3 = params[39] + else: + var3 = params[40] + else: + if inputs[0] >= -0.90594506: + if inputs[0] >= -0.8935368: + var3 = params[41] + else: + var3 = params[42] + else: + if inputs[0] >= -0.96248794: + var3 = params[43] + else: + var3 = params[44] + if inputs[1] >= -0.15603217: + if inputs[2] >= 0.75309324: + if inputs[0] >= -0.4062563: + if inputs[0] >= 1.246089: + var4 = params[45] + else: + var4 = params[46] + else: + if inputs[0] >= -0.5137947: + var4 = params[47] + else: + var4 = params[48] + else: + if inputs[4] >= -0.5: + if inputs[1] >= 1.7508751: + var4 = params[49] + else: + var4 = params[50] + else: + if inputs[0] >= 1.2568915: + var4 = params[51] + else: + var4 = params[52] + else: + if inputs[2] >= 0.75309324: + if inputs[0] >= -0.040090334: + if inputs[0] >= 0.20423117: + var4 = params[53] + else: + var4 = params[54] + else: + if inputs[0] >= -0.8073114: + var4 = params[55] + else: + var4 = params[56] + else: + if inputs[0] >= -0.45715457: + if inputs[0] >= 0.47254202: + var4 = params[57] + else: + var4 = params[58] + else: + if inputs[0] >= -0.74955213: + var4 = params[59] + else: + var4 = params[60] + if inputs[0] >= -0.82750535: + if inputs[0] >= -0.680601: + if inputs[0] >= -0.41589096: + if inputs[0] >= -0.28796402: + var5 = params[61] + else: + var5 = params[62] + else: + if inputs[0] >= -0.44343248: + var5 = params[63] + else: + var5 = params[64] + else: + if inputs[0] >= -0.68989503: + var5 = params[65] + else: + if inputs[0] >= -0.69982165: + var5 = params[66] + else: + var5 = params[67] + else: + if inputs[0] >= -0.87937677: + if inputs[0] >= -0.86414623: + var5 = params[68] + else: + var5 = params[69] + else: + if inputs[0] >= -0.96248794: + if inputs[0] >= -0.9273068: + var5 = params[70] + else: + var5 = params[71] + else: + if inputs[0] >= -1.0267677: + var5 = params[72] + else: + var5 = params[73] + if inputs[0] >= -0.7369492: + if inputs[0] >= -0.70867777: + if inputs[10] >= 0.5: + if inputs[0] >= -0.10972269: + var6 = params[74] + else: + var6 = params[75] + else: + if inputs[0] >= -0.5848869: + var6 = params[76] + else: + var6 = params[77] + else: + if inputs[0] >= -0.7131058: + var6 = params[78] + else: + if inputs[0] >= -0.7254168: + var6 = params[79] + else: + var6 = params[80] + else: + if inputs[0] >= -0.74955213: + var6 = params[81] + else: + if inputs[0] >= -0.77728826: + var6 = params[82] + else: + if inputs[2] >= 0.1683935: + var6 = params[83] + else: + var6 = params[84] + if inputs[1] >= -0.15603217: + if inputs[0] >= -0.3979841: + if inputs[0] >= -0.16801728: + if inputs[0] >= 0.1484669: + var7 = params[85] + else: + var7 = params[86] + else: + var7 = params[87] + else: + if inputs[0] >= -0.4428972: + var7 = params[88] + else: + if inputs[0] >= -0.68989503: + var7 = params[89] + else: + var7 = params[90] + else: + if inputs[0] >= -0.22996137: + if inputs[0] >= 0.04920064: + if inputs[0] >= 0.14014605: + var7 = params[91] + else: + var7 = params[92] + else: + if inputs[0] >= -0.10972269: + var7 = params[93] + else: + var7 = params[94] + else: + if inputs[0] >= -0.2746312: + var7 = params[95] + else: + if inputs[0] >= -0.34275508: + var7 = params[96] + else: + var7 = params[97] + if inputs[0] >= -0.4512667: + if inputs[2] >= -0.41630626: + if inputs[0] >= -0.43516028: + if inputs[0] >= 1.7182848: + var8 = params[98] + else: + var8 = params[99] + else: + if inputs[0] >= -0.44343248: + var8 = params[100] + else: + var8 = params[101] + else: + if inputs[0] >= -0.01722017: + if inputs[0] >= 0.47254202: + var8 = params[102] + else: + var8 = params[103] + else: + var8 = params[104] + else: + if inputs[2] >= -0.41630626: + if inputs[0] >= -0.48907548: + if inputs[0] >= -0.4726284: + var8 = params[105] + else: + var8 = params[106] + else: + if inputs[0] >= -0.52839273: + var8 = params[107] + else: + var8 = params[108] + else: + if inputs[0] >= -0.5803615: + var8 = params[109] + else: + if inputs[0] >= -0.82147145: + var8 = params[110] + else: + var8 = params[111] + if inputs[2] >= 0.75309324: + if inputs[0] >= 0.29619843: + if inputs[0] >= 1.3367424: + var9 = params[112] + else: + if inputs[0] >= 0.46680015: + var9 = params[113] + else: + var9 = params[114] + else: + if inputs[0] >= 0.20423117: + var9 = params[115] + else: + if inputs[4] >= -2.5: + var9 = params[116] + else: + var9 = params[117] + else: + if inputs[0] >= 1.3335794: + if inputs[0] >= 1.7471402: + if inputs[4] >= -0.5: + var9 = params[118] + else: + var9 = params[119] + else: + if inputs[0] >= 1.4293422: + var9 = params[120] + else: + var9 = params[121] + else: + if inputs[0] >= 1.1876483: + if inputs[0] >= 1.221759: + var9 = params[122] + else: + var9 = params[123] + else: + if inputs[0] >= 1.1512506: + var9 = params[124] + else: + var9 = params[125] + if inputs[1] >= -0.15603217: + if inputs[0] >= -0.68989503: + if inputs[2] >= 0.75309324: + if inputs[0] >= -0.61958146: + var10 = params[126] + else: + var10 = params[127] + else: + if inputs[0] >= 1.1512506: + var10 = params[128] + else: + var10 = params[129] + else: + if inputs[2] >= -0.41630626: + var10 = params[130] + else: + if inputs[0] >= -0.90594506: + var10 = params[131] + else: + var10 = params[132] + else: + if inputs[0] >= -0.45715457: + if inputs[1] >= -1.4288299: + if inputs[0] >= -0.42426047: + var10 = params[133] + else: + var10 = params[134] + else: + if inputs[0] >= 1.8040724: + var10 = params[135] + else: + var10 = params[136] + else: + if inputs[2] >= -0.41630626: + if inputs[0] >= -0.6213819: + var10 = params[137] + else: + var10 = params[138] + else: + if inputs[0] >= -0.92930186: + var10 = params[139] + else: + var10 = params[140] + if inputs[1] >= 3.3407278: + var11 = params[141] + else: + if inputs[0] >= 0.85053235: + if inputs[0] >= 1.1512506: + if inputs[0] >= 1.1876483: + var11 = params[142] + else: + var11 = params[143] + else: + if inputs[0] >= 1.1044399: + var11 = params[144] + else: + var11 = params[145] + else: + if inputs[0] >= -0.6213819: + if inputs[0] >= -0.5848869: + var11 = params[146] + else: + var11 = params[147] + else: + if inputs[0] >= -0.77728826: + var11 = params[148] + else: + var11 = params[149] + if inputs[0] >= -0.44343248: + if inputs[0] >= -0.43516028: + if inputs[4] >= -1.5: + if inputs[0] >= 0.64917755: + var12 = params[150] + else: + var12 = params[151] + else: + if inputs[0] >= 0.04920064: + var12 = params[152] + else: + var12 = params[153] + else: + var12 = params[154] + else: + if inputs[0] >= -0.4856693: + if inputs[1] >= -0.15603217: + var12 = params[155] + else: + if inputs[0] >= -0.4726284: + var12 = params[156] + else: + var12 = params[157] + else: + if inputs[10] >= 0.5: + var12 = params[158] + else: + if inputs[0] >= -0.52839273: + var12 = params[159] + else: + var12 = params[160] + if inputs[0] >= -1.0065739: + if inputs[0] >= 1.2568915: + if inputs[0] >= 1.4803379: + if inputs[0] >= 2.015451: + var13 = params[161] + else: + var13 = params[162] + else: + if inputs[0] >= 1.4293422: + var13 = params[163] + else: + var13 = params[164] + else: + if inputs[0] >= 1.1876483: + var13 = params[165] + else: + if inputs[0] >= -0.123736754: + var13 = params[166] + else: + var13 = params[167] + else: + var13 = params[168] + if inputs[0] >= -0.28796402: + if inputs[0] >= -0.22996137: + if inputs[0] >= 0.3694316: + if inputs[0] >= 0.64917755: + var14 = params[169] + else: + var14 = params[170] + else: + if inputs[0] >= 0.3540551: + var14 = params[171] + else: + var14 = params[172] + else: + if inputs[0] >= -0.27424192: + var14 = params[173] + else: + var14 = params[174] + else: + if inputs[0] >= -0.32484823: + var14 = params[175] + else: + if inputs[0] >= -0.41589096: + var14 = params[176] + else: + if inputs[0] >= -0.5848869: + var14 = params[177] + else: + var14 = params[178] + if inputs[10] >= 0.5: + if inputs[2] >= 1.9224927: + var15 = params[179] + else: + if inputs[2] >= 0.75309324: + if inputs[0] >= 0.04920064: + var15 = params[180] + else: + var15 = params[181] + else: + var15 = params[182] + else: + if inputs[1] >= 2.0690746: + if inputs[1] >= 3.3407278: + var15 = params[183] + else: + var15 = params[184] + else: + if inputs[2] >= 1.9224927: + var15 = params[185] + else: + if inputs[0] >= -0.9273068: + var15 = params[186] + else: + var15 = params[187] + if inputs[0] >= -1.0267677: + if inputs[1] >= -0.15603217: + if inputs[0] >= -0.52839273: + if inputs[2] >= -0.41630626: + var16 = params[188] + else: + var16 = params[189] + else: + if inputs[1] >= 0.47922206: + var16 = params[190] + else: + var16 = params[191] + else: + if inputs[0] >= -0.92930186: + if inputs[2] >= 0.75309324: + var16 = params[192] + else: + var16 = params[193] + else: + var16 = params[194] + else: + var16 = params[195] + if inputs[0] >= -0.123736754: + if inputs[0] >= 0.04920064: + if inputs[2] >= -0.41630626: + if inputs[0] >= 1.0344182: + var17 = params[196] + else: + var17 = params[197] + else: + if inputs[0] >= 1.7471402: + var17 = params[198] + else: + var17 = params[199] + else: + if inputs[0] >= -0.034445778: + var17 = params[200] + else: + var17 = params[201] + else: + if inputs[0] >= -0.74955213: + if inputs[0] >= -0.7369492: + if inputs[0] >= -0.7254168: + var17 = params[202] + else: + var17 = params[203] + else: + var17 = params[204] + else: + if inputs[0] >= -0.77728826: + var17 = params[205] + else: + if inputs[0] >= -0.80127764: + var17 = params[206] + else: + var17 = params[207] + if inputs[0] >= -0.69982165: + if inputs[0] >= -0.680601: + if inputs[0] >= -0.5848869: + if inputs[0] >= -0.52839273: + var18 = params[208] + else: + var18 = params[209] + else: + if inputs[11] >= 0.5: + var18 = params[210] + else: + var18 = params[211] + else: + if inputs[0] >= -0.68989503: + var18 = params[212] + else: + var18 = params[213] + else: + if inputs[0] >= -0.70867777: + var18 = params[214] + else: + if inputs[2] >= 1.9224927: + var18 = params[215] + else: + if inputs[0] >= -1.0267677: + var18 = params[216] + else: + var18 = params[217] + if inputs[0] >= 2.0768113: + if inputs[4] >= -1.5: + if inputs[0] >= 2.8893833: + var19 = params[218] + else: + var19 = params[219] + else: + var19 = params[220] + else: + if inputs[1] >= -1.4288299: + if inputs[0] >= 2.015451: + var19 = params[221] + else: + if inputs[11] >= 0.5: + var19 = params[222] + else: + var19 = params[223] + else: + var19 = params[224] + return 0.5 + (var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19) + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/capacity_priority.py b/matsim/scenariogen/network/ref_model/germany/capacity_priority.py new file mode 100644 index 0000000..3bd43a6 --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/capacity_priority.py @@ -0,0 +1,2851 @@ +# -*- coding: utf-8 -*- +"""LGBMRegressor(colsample_bytree=0.9, n_estimators=30, num_leaves=32, + objective='regression', random_state=1373158606, + reg_alpha=0.014490058917520315, subsample=0.9, subsample_freq=10) +Error: 86.108464""" +def features(ft, data): + data[0] = (ft.get("length") - 140.91374966725232) / 113.09700132654554 + data[1] = (ft.get("speed") - 17.315611457168714) / 6.460215616713478 + data[2] = (ft.get("num_lanes") - 1.4162274397061172) / 0.7453179157424549 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [1767.3695633827278, 1811.5273612880271, 1757.5880797775521, 1773.850780326021, 1749.8471454865478, 1781.4893514477765, 1805.964622790866, 1771.0005204318536, 1805.9376672865124, 1811.5545602813763, 1807.7955381067238, 1808.4814791987335, 1842.014288930537, 1849.5294602540107, 1833.5415279301687, 1832.8480380747665, 1843.3345259172886, 1835.6589021328305, 1845.4978793029343, 1823.2657367554266, 1851.5827789254217, 1890.964775838754, 1857.9783438684233, 1794.7187940973977, 1848.4993219498967, 1861.942325395404, 1886.4358778320757, 1880.6809076598129, 1853.1267683575707, 1820.2378931396981, 1851.999278904619, 1853.4774832845847, -54.69491511477343, -14.952893287109266, -63.498249305886795, -48.86181645229029, -70.46509292674844, -41.98710408590753, -19.95935883171663, -51.42705566359561, -19.98361839464748, -14.928414993956103, -18.311534349643743, -22.698695913194697, 11.235078192365727, 0.49191082455431334, 11.314355216489831, 17.938762932035235, 12.39527978841621, 18.297314935920248, 21.768043338156517, 61.073830871122006, 22.681061458706004, -30.08060617826899, 18.21045914742283, 26.58016329716441, 51.01825006219045, 49.157285245513854, 22.51461135142422, -15.176876762664723, 17.027715096506384, 23.390056814596775, 22.40115810421746, -27.35830258615927, -49.22542319214298, -13.457603659669525, -57.14842630783992, -43.97563486156685, -63.41858412192437, -37.78839383963801, -17.963422356837892, -46.28434726953077, -24.215866308435395, -12.511950075598438, -13.435573366338259, -16.480381484101756, -5.565031186173137, -29.042581515483814, 11.074314034684013, 17.510586423443456, 8.40209978351158, 14.05683590805522, -6.304364362492991, 19.04196386296601, 54.966445617215754, 20.41295537960444, -34.53045377534651, 16.47944917163163, 26.622800106122977, 50.05622729159367, 23.861373409605974, -13.659189384735033, 14.877210231150588, 21.050996679396178, 20.16104122189324, -24.62247321081888, -44.302880202664056, -12.11184406673444, -51.43358255783992, -39.57807211933358, -57.07672025662399, -34.009554573337816, -16.167080221139027, -41.65591335876235, -16.186731250446538, -14.756290202588753, -12.28360643739365, 17.3682990290438, 0.1935366738043478, -49.95896870782027, 0.8491962079365907, -15.590529513530687, 10.831638110473119, 2.8845979321507746, 12.886569267024868, -12.915315126673262, 14.642165746274351, 45.997374182196495, 21.41354001539226, -31.077408121049633, 14.940482443186369, 36.15391004645465, 19.746711215998328, -9.703932779449426, 17.43899574985967, 18.811544152875424, 18.214704761733948, -22.160225171573273, -39.87259185185701, -10.900659395182737, -46.290223182839924, -35.6202642679414, -51.36904819161803, -39.711629390843676, -15.472428864299824, -13.982227668730804, -37.49032124486892, -14.56805839260101, -10.944046626901219, -13.284514851109652, 7.973540418933019, 8.220226087270428, -29.114855896654912, 1.1214580858354324, 10.686627458342851, 14.200606993731979, 15.423787508904528, 11.288590797286412, 41.397636633368364, 19.27218610303874, -22.05569978507112, 13.312707057536727, 32.634840503051535, 34.33721036451335, 14.953017052575, -8.733539751190149, 15.714779712620468, 16.96156926255897, 16.393234119644102, -19.944203355026175, -35.88533259524218, -9.810593603762989, -54.24412757775778, -24.5792988296282, -36.64651249030197, -46.23214620207623, -28.605157235396792, -13.050558477940005, -33.74128933532484, -13.111252321936659, -14.091022492039261, -12.114068649791786, 14.462692273398147, -4.30844337341616, -14.108547244243576, 8.8955703959419, 1.7545502060039817, 10.446593128931612, -10.529378949303089, 12.050042660317212, 30.564472588027815, -25.764097302907274, 12.115163512147834, -13.251767336095723, 12.91316938684841, 16.03306648918068, 31.830941972190892, 12.024630143409848, -4.251487611363667, 15.446894706568628, 14.753910694351134, -17.949782144370374, -32.29680110110156, -8.829534328210714, -37.933161423554616, -17.189924523341627, -31.23024168493815, -41.60893163362288, -34.08975276606521, -12.566493524053577, -11.228502000270403, -30.367159769530765, -17.407675409660087, -6.874150994902543, 7.062255745276229, -11.568046482437722, -18.33365494222956, 5.8556083164779595, 11.463353607443254, 5.75888762355646, 10.868000790971323, 34.201426235720454, 14.288519969158125, -23.187687187347375, 10.90364640595285, -11.92659040511371, 11.62185239835006, 30.558190745568762, 9.488918261025729, 20.59338031247658, -3.826338405837951, 13.902204899133446, 13.278520069351135, -16.15480466282177, -47.89540139035027, -25.564490752236157, -9.454750128906843, -30.506466539832584, -37.4480397354823, -24.965939242056105, -24.258571207183806, -10.464416394077169, -21.543708806089032, -44.88691443477622, -8.181049177177306, -27.33044338805922, -15.666908433345567, -6.18673569804238, -13.338909158200934, 6.567799340080436, -10.452572592002753, -8.986411262223756, 3.9981095655790178, 8.99643421796618, 2.516661701911211, 11.096060972304448, 6.989158917500245, 12.342215732777758, 34.771019843146355, 12.673452610923473, -3.6667107049407583, -8.977536954074367, 9.07255506502411, 12.945669992550478, 11.919035696245196, -21.340787458705826, -26.25786867508077, -7.001105688723925, -41.26932699105734, -17.571364731121047, -26.82020604028312, -25.649788569491655, -34.28751414420071, -22.46934517896068, -21.83271454252621, -8.988306240556971, -8.751614044153035, -31.831314132673807, -9.558103673618536, -12.005018230920236, -27.541390877113248, 12.070692056037576, -8.04439473063256, -14.995578511655518, -10.788596512985158, 7.078384140056276, 5.411585164010169, 0.9473167342983567, 13.052060368281156, -0.14594378289048543, 7.7381790091320966, 11.360628756895302, 31.293917541043868, 11.406107327152089, 0.3768817976071709, 8.548475584366605, -7.194912206627286, 11.57977834102218, -39.699478782928395, -20.521696208685942, -7.518631884917354, -24.834826206371286, -30.332911359054904, -20.222410968224864, -23.632490123341817, -8.519144086593814, -25.378689584688253, -6.651893815527451, -11.077509174575745, -31.105314899320817, -13.144406724169258, -4.612251818152149, -10.80451654034944, -6.479877030957519, -18.329827725011594, 1.7826912219880269, 16.340421550888024, 1.098039477239943, 8.11896811608596, 1.6103167101985845, 9.190657211917678, 6.4466608480395955, 25.524147300565673, 10.545211758785202, -18.980226837713012, 2.372209462689832, 8.492556888904126, 10.278216725091507, 9.630293242365457, -12.416886022409836, -24.0317815746825, -5.626772396178357, -18.257115649616424, -27.50900231977861, -7.56087305343306, -19.56813943255927, -7.8178061451734635, -11.179244739081279, -5.7284049200999085, -38.38952377183326, -4.733118591423003, 3.7997704324762474, 3.1279140477400276, 5.299928874472152, -32.60215933922071, -3.1814414867763543, 4.95602008379262, 4.670068210955057, 8.390290894933932, -16.94943246513091, 7.219426299601938, 19.618109281915014, -3.6089840759426575, -10.894984687398214, 6.739785901202762, -13.211467473496999, 31.260846427470216, 26.332807387296555, -10.050183172569183, 11.081407022194687, 9.315811793386635, -3.8141589539403093, -33.26947091596599, -19.688452319332754, -5.0640950482275375, -16.43140439407767, -24.758102056368223, -9.359479426910324, -22.957720611535848, -4.8629528417900865, -30.843517738795228, -2.7984740547978397, -13.739425263313331, -4.954266877561722, -10.06132034450127, -5.1555642752968, -10.959366901368291, 12.695633252788637, -35.72803621318517, -17.601144784903468, 3.741916937773754, 6.326873156793451, 4.262664876559159, 8.670889274272794, -5.931613550105837, 6.784047249794916, 7.921156379212822, -15.254489527552437, 6.497483602349391, 17.6562987280464, -3.2480855943118456, 1.7133564761167763, 8.491299254088645, -29.644290596282886, -16.46100345743305, -5.208648928218929, -17.757164734461206, -22.28229192388648, -6.1377350391784855, -2.046207456931975, -22.937346375131572, -6.142145307949365, -9.05518824315271, -4.640007878915497, -0.3510693450115701, -32.15523308266853, -14.880896071439745, 3.3677250772128007, 5.649778810072448, 3.42097149115155, 9.647541929216594, -4.851574382469213, 4.046670766595191, 6.364666744503534, 8.157228910174743, -23.304263691166433, 5.058504011126922, 6.029054134698306, 25.04275433585475, 28.0301765378491, -8.286617132597632, 7.622389459960096, -17.655473416437356, 4.4962392939532805, 7.437407856661764, -26.679861645853926, -17.75946426325934, -4.036820701585159, -13.16940384218518, -20.054062942685064, -5.355821085143322, -11.610066990384567, -3.6369166366106533, -27.5903992541198, 13.371626490569057, -18.312734745158238, -33.65779577184153, 13.16484391301905, 4.872472100429489, -18.428550888038348, 3.8215297066660536, -14.807603628210977, 7.93320167402994, -18.110122160259845, -12.950973487071947, 3.211361082270354, 11.611351683676531, -3.4414626575247, 8.897840126744198, -17.473226644880466, 7.797429118470838, 15.854133386905119, -7.801347742920967, 4.27899407366003, 23.538976387905365, 7.310702219934561, 6.337708685571998, -24.01187529782097, -26.922324297000973, -5.806492126097983, -19.38107719279948, -12.32016525358173, -18.04865684705961, -15.306792305129969, -5.7711404373145285, -17.21459512538399, -3.0512453059186537, -14.456802915225285, -4.801529634013626, 17.951825191139427, -0.29076039775090895, 4.263143760818444, 17.17547684543871, 6.988431384667246, -11.07422363701394, 7.3438153923929095, -23.82136118923178, -7.024243341647228, 4.768382879519709, -0.9969281598448397, 9.709661658293326, 5.188822681158346, -6.732372539058938, -9.434638206278452, -1.4828838636744928, -14.722783300865954, 2.9826818436885096, 7.781950769390621, 3.574833825975974, -23.13787177829735, 1.235623269322312, -25.273748272524337, -9.330415566029215, -31.56515589902536, -13.76083030304833, -18.956136690028618, -0.5211609122525442, -22.244472445238486, -10.129328391741483, -2.9696446809867174, -11.57115325131609, -20.621664776760312, -10.4088772400385, 1.9587884859131681, 23.979706067102775, 2.0646115164590517, -29.991460773249948, -11.541534611276127, 0.8058377637346625, -2.153022004536465, 11.642037775625788, -19.37935517777656, -4.532456665875223, -4.075983344843618, 4.508985674407504, -6.216833255663194, -7.489204250099242, -13.477044514316521, 3.426571860561921, 3.1931903611550454, 5.190969995256267, -19.410207166946336, -21.594255555492822, -4.643012622877856, -11.901537016436519, -15.356818629733887, -4.0775528401120145, 11.453389192268757, -18.687384437039665, -3.693503046166126, -23.32057732418816, 13.199891299223843, -14.95095038236527, -28.71237339772307, -0.6913923147987575, 3.978482104068504, 7.522313332843703, -15.60350165561942, 6.235129356047593, -15.688233328008614, -5.726548939021409, 3.061752268005522, -2.6154340709331736, 7.019279635620108, -18.57523132343832, 3.7124478696785355, 4.164571006000287, 19.52828904723567, 5.625819452187308, -19.908441472238497, -2.0524043073557925, 3.007759131043981, 5.524315828669165, -21.688588602204675, -12.091984604749335, -4.485197878754913, -13.214988425422375, -3.1139990427464768, -7.761738327349767, -14.232853183371066, -6.021580096131204, -18.028598486001062, -1.9203242168950672, -24.072996843075696, -0.34107005208732405, 10.308050804481415, -16.818645766690544, -3.3518238165654965, -20.98851967648308, 13.189182433003328, -11.992849342903654, -25.84113614141287, -11.456467722176571, 1.5227049643733714, 3.6018878991277554, -6.581249422656947, -3.933888506067923, 1.9266202095828406, 4.040387157622585, 3.827778279377121, 17.037217823936555, 23.586761053913975, -6.526751314940748, 5.552555143919686, 4.279935252048252, -19.519729155072216, -18.22563167270155, -3.563113545904617, -9.834930856117126, -12.439023357840625, -16.348099546775725, -0.9733770514224753, -22.423262411769684, 0.16393322752356865, -5.054804341765359, -8.00384408539073, -1.204394328939539, -15.306904237341474, 3.163552334582141, 0.12713749834688703, 14.098442419462016, 4.633502353245653, -5.510842336027491, 8.27168683898836, 3.5077351352301975, -5.395963527125899, -23.172132633483812, -3.577495175804564, 0.9468815342485443, -10.914572041377246, -6.087796435553883, -11.308878369706617, 4.640517138717828, 9.367820346441247, -0.8846302584959699, 4.988184086888915, 4.918749629974307, -15.37209030021024, -10.114840669656473, -1.5699618700283273, 0.3606914291585863, 3.615701701736366, -12.013490570494653, 1.0369404412564025, -12.795721573087432, -11.195121118212604, -2.885584001356259, 9.601669216499236, -14.755696064745557, -2.583343832133586, -17.35897658566277, 12.20231525181731, -11.303183885985083, -22.518431468599456, -10.175816338259285, 1.07797327375669, 2.9782523924513367, -11.657221900249063, 5.219704956442371, -7.109070273307227, 6.806983189951025, -1.8858400813839546, 5.408078658993634, -14.669662747005844, 5.3275280464584265, 2.7450311720930505, -3.924743002856476, 5.8622463881840305, 3.667754930727992, -16.11636440134907, -8.676175398504595, -2.950580776160807, -9.681615168012957, -17.855024955954885, -13.011705229938281, 10.591211505023562, 5.4314407427672595, -10.511172529007174, 14.58649889980307, 1.6384331010215818, -3.4127661957008537, -2.9274220167114935, -11.840803977908756, 20.014944046950284, -41.95098560002637, -9.78935427892995, 3.2567635207596433, 10.006205420691929, 10.209032676571491, 3.1508950381418463, -4.638274340920346, -15.623829805198012, -0.7264477579510996, -10.267446249937954, -6.906511605127474, -5.2387542757289145, 4.055275965145635, 8.02946976105948, -0.7489271394586392, 4.106441033421752, 4.291352289054573, -15.222854105917534, -9.180354910657249, -3.1385525782115815, -7.780744017805162, -16.06952327227956, -11.603987638129212, 1.425482716876682, 1.4832588180757986, -3.5048495726278652, -2.6560952164022145, -3.6650185242091724, -17.158375195421403, 6.136202140236846, 6.18840651054922, 18.001263609282155, 3.7445850631005735, 0.23862405394459962, -16.894994157384176, 19.9662201884841, -5.8724094987048545, 11.107620455800536, 4.2751915344600695, 21.09978902232517, 3.203035109157947, -17.409440722111206, 4.606779023005443, -1.5141913101985187, 2.160644941488656, 4.25128567935384, -4.174446828141859, -3.842571359393363, 1.7839454733996405, -13.700568396139069, -7.302015662479324, 8.587900943516713, 2.353876116033255, -17.06958553337091, -11.028611257680241, -6.019883735947687, 0.23567671028418916, -23.093085836626056, -5.043163288312197, -20.431315858350395, -5.3634409006977535, -17.10464131965629, -0.5472640551794794, 5.891055417912786, -5.495798972166817, 3.612123969144603, -4.192460823305203, -22.722749799704495, 5.10789430786931, -6.95096798371446, 1.8855067056176686, -2.9435204386361082, 0.28829812760724643, 8.359691097056041, -11.844516343092861, -9.209923829850872, -0.2948042242990447, 6.416504326655782, -4.793124402743405, 0.5222902296139444, 2.5888651095736583, -11.047924232757495, -2.8812054870719894, -1.6249561759409965, -7.441071830812618, -8.364850896025455, -16.682293379706486, -0.016568295819839863, 7.419717423586282, -1.480931525680827, -0.34582426837815333, -3.484696045013553, -13.622143470809684, 3.7545594888080043, -3.469689239775082, -1.8832558951695244, 10.213107777369157, -3.691530629503239, 10.6297789977023, -7.78844366998214, 2.6938761352992113, -9.77050240691633, 1.5942162950170304, -0.3045814224053922, -12.546140624745632, -9.554843683586027, 1.8849194471281927, -1.4183525018647716, -9.024979479232023, 0.4868122665542208, 4.396613495669479, 2.06770433868977, 3.147333779240955, -11.45287126728686, -2.0321537315869995, -6.3474690072690345, -1.8874953366482288, -19.501931684621127, -8.045895757620638, 6.4589009765242595, -17.68787431295477, 16.90495794934351, -1.89796170191077, -5.6493750405218695, 5.428974325906296, -1.6176052585757397, 1.0660474967129805, -4.786807781694721, 3.7038703429541124, 3.0979645812731573, 1.41562374185309, -7.1973825764563175, 7.247182714814016, -1.5406981023311035, -25.178717341468243, -5.066437323495535, 11.249875512179763, -7.30633070574787, -9.071743503136037, 2.7720122714546673, 8.190234015833163, -5.421853189853557, 4.965363460650575, -1.1096731898456669, 2.60883867478117, -10.307583960183385, -12.664489487065978, -0.9601728209247442, -4.657926438514647, 2.268607779312079, -6.6472840185620585, -12.006208338383178, 0.8908495387952965, 5.9573644020457275, -1.9806963197539051, -32.72014581640914, 1.244137288609741, -5.786439898919818, -2.377516729949643, 1.9287645300934502, -7.082888127267527, -7.807297905242845, 6.857645771911975, 14.609950190965765, 2.880005312041705, 5.523959788981646, 8.404440500556694, 1.1113071679441782, 6.466286563387013, 2.1513056538339224, -13.050003047332673, 13.711774753786088, -4.684608202141697, -11.520741025892818, -1.0047039884474491, -3.9854187659079976, 1.3191712915463762, -9.132333493518752, -11.398040453768951, -0.7022429160079957, 5.37128594542855, -6.082368797980346, -6.731983269164087, 6.263283049132565, 6.012382780129481, 1.7584995426280576, -9.343408578585729, 2.0417469699859074, -5.982555533368066, -10.414711511278114, 11.682981859481737, 0.518342305514821, -1.6302242605307997, -2.121468004529438, -4.341399462486474, 2.767722746589623, -18.412228186532644, -7.123139618179144, 7.476786605246151, 2.4735574295882117, -17.751566505759016, 3.0972087786559315, -12.20830705921331, 0.2627005066370304, -7.269051739501889, -6.45801641624989, -12.216475500917367, 6.760444329754709, -17.810171782750587, 2.0973145028073654, -5.0258611666476325, -3.778488479610904, -0.05835244305614239, -5.208910624227999, -9.373240673685036, -1.119279886992781, 2.4064624312972094, -10.452215415382348, -21.286410265312103, 9.585143442497161, -9.287521337187233, 11.779600461500072, -22.93764644847556, -2.1126104137419937, 1.1825829857872399, -3.649811045554115, 0.8845491957834286, -8.981153644527003, -18.135242645231806, -1.642656417061886, 0.8486531937694395, 8.763458627851026, -3.5353938399258236, 22.71296492446256, 15.895486477770035, -5.619378631567127, 19.071137456794954, 9.065273378009255, 1.6179661755587185, -0.21367377081155806, 1.7501281159867774, -10.897085112103465, -9.755650725907499, -9.113978967007666, -1.6126244165084445, 3.5674244540099354, -4.838119622478276, -8.435916563018123, 10.626611561096118, 0.5784360444107689, -8.071536579683954, -9.103456218041083, -0.9060371285754644, 1.8259092332111617, 2.1148928773365276, -7.54211651239426, 2.1658161262129805, -9.40699375981486, -18.05123764262839, -5.914432566362707, 5.5944782546614675, -16.301567221031096, 5.724742116390283, 2.417056121571122, 0.3705732947302734, -15.1980761492614, -1.8092260466818315, 2.547546960299565, 7.200506365058448, -27.05268730953972, -0.045084452995398566, 0.9458530043332675, -0.8676832799054783, 1.62757134644459, -1.2049670455234818, -3.8963057618149968, -10.79012497641514, -4.230758595752639, 14.23254657583898, 2.8257259079787294, -1.1521617051755508, -43.56981262058068, 1.2086588443737594, -4.666815985236946, -1.7646224026638881, -3.918234071647295, 2.2079022783040303, -16.746832333738826, -6.159885739795087, 2.4563952104244957, 1.6630114450107076, -11.291371878866675, 4.107633381699683, -31.550823137333005, 2.8274580003737886, -3.9739832580347896, 8.276056085477512, -13.491860454018866, 10.3528090809748, -0.07524960728767772, -24.783608382415682, -11.796615644246799, 2.6215895365714363, 5.647703587564294, -0.13795591741222238, 1.3430259927969228] +def score(params, inputs): + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[2] > 2.7958170819201564: + var0 = params[2] + else: + var0 = params[3] + else: + var0 = params[4] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 7.22: + var0 = params[5] + else: + var0 = params[6] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var0 = params[7] + else: + var0 = params[8] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[9] + else: + if inputs[3] <= -4.164999999999998: + var0 = params[10] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9943123897915209: + var0 = params[11] + else: + var0 = params[12] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[13] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 2.5000000000000004: + var0 = params[14] + else: + if inputs[0] > 0.052576551659217236: + if inputs[5] > 1.5000000000000002: + var0 = params[15] + else: + var0 = params[16] + else: + if inputs[0] <= -0.9789715763336068: + var0 = params[17] + else: + var0 = params[18] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[19] + else: + var0 = params[20] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var0 = params[21] + else: + var0 = params[22] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[23] + else: + var0 = params[24] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 0.544004836887963: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var0 = params[25] + else: + var0 = params[26] + else: + if inputs[3] > 8.335000000000003: + var0 = params[27] + else: + var0 = params[28] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[29] + else: + var0 = params[30] + else: + var0 = params[31] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var1 = params[32] + else: + var1 = params[33] + else: + if inputs[2] > 2.7958170819201564: + var1 = params[34] + else: + var1 = params[35] + else: + var1 = params[36] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 7.22: + var1 = params[37] + else: + var1 = params[38] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var1 = params[39] + else: + var1 = params[40] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[41] + else: + if inputs[3] <= -4.164999999999998: + var1 = params[42] + else: + if inputs[0] <= -1.060096627328628: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[43] + else: + var1 = params[44] + else: + if inputs[6] > 3.5000000000000004: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var1 = params[45] + else: + var1 = params[46] + else: + var1 = params[47] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 2.5000000000000004: + var1 = params[48] + else: + var1 = params[49] + else: + var1 = params[50] + else: + if inputs[1] > 2.0493725485847785: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[51] + else: + var1 = params[52] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[53] + else: + var1 = params[54] + else: + if inputs[6] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 0.544004836887963: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var1 = params[55] + else: + var1 = params[56] + else: + if inputs[3] > 8.335000000000003: + var1 = params[57] + else: + var1 = params[58] + else: + if inputs[6] > 3.5000000000000004: + if inputs[3] <= -2.774999999999998: + var1 = params[59] + else: + var1 = params[60] + else: + var1 = params[61] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[62] + else: + var1 = params[63] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var2 = params[64] + else: + var2 = params[65] + else: + if inputs[2] > 2.7958170819201564: + var2 = params[66] + else: + var2 = params[67] + else: + var2 = params[68] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 7.22: + var2 = params[69] + else: + var2 = params[70] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var2 = params[71] + else: + if inputs[1] <= -0.3150996155456951: + var2 = params[72] + else: + var2 = params[73] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[74] + else: + if inputs[3] <= -4.164999999999998: + var2 = params[75] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9943123897915209: + if inputs[6] > 3.5000000000000004: + var2 = params[76] + else: + var2 = params[77] + else: + var2 = params[78] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[79] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 2.5000000000000004: + var2 = params[80] + else: + var2 = params[81] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[82] + else: + var2 = params[83] + else: + if inputs[1] > 2.0493725485847785: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[84] + else: + var2 = params[85] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[86] + else: + var2 = params[87] + else: + if inputs[6] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var2 = params[88] + else: + var2 = params[89] + else: + var2 = params[90] + else: + if inputs[6] > 3.5000000000000004: + if inputs[3] <= -2.774999999999998: + var2 = params[91] + else: + var2 = params[92] + else: + var2 = params[93] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[94] + else: + var2 = params[95] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var3 = params[96] + else: + var3 = params[97] + else: + if inputs[2] > 2.7958170819201564: + var3 = params[98] + else: + var3 = params[99] + else: + var3 = params[100] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 7.22: + var3 = params[101] + else: + var3 = params[102] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var3 = params[103] + else: + var3 = params[104] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var3 = params[105] + else: + if inputs[6] > 2.5000000000000004: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[106] + else: + var3 = params[107] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + var3 = params[108] + else: + var3 = params[109] + else: + var3 = params[110] + else: + if inputs[5] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[111] + else: + if inputs[0] <= -0.19292067350446304: + var3 = params[112] + else: + var3 = params[113] + else: + var3 = params[114] + else: + var3 = params[115] + else: + var3 = params[116] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var3 = params[117] + else: + var3 = params[118] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[119] + else: + var3 = params[120] + else: + if inputs[6] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 0.544004836887963: + var3 = params[121] + else: + var3 = params[122] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[123] + else: + var3 = params[124] + else: + var3 = params[125] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[126] + else: + var3 = params[127] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var4 = params[128] + else: + var4 = params[129] + else: + if inputs[2] > 2.7958170819201564: + var4 = params[130] + else: + var4 = params[131] + else: + var4 = params[132] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[0] <= -0.8365274813439836: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[133] + else: + var4 = params[134] + else: + var4 = params[135] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var4 = params[136] + else: + var4 = params[137] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[138] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[139] + else: + var4 = params[140] + else: + if inputs[0] > 0.2796824846082225: + var4 = params[141] + else: + if inputs[6] > 3.5000000000000004: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -0.8676954164674114: + var4 = params[142] + else: + var4 = params[143] + else: + var4 = params[144] + else: + var4 = params[145] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[146] + else: + var4 = params[147] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var4 = params[148] + else: + var4 = params[149] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[150] + else: + var4 = params[151] + else: + if inputs[6] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 0.544004836887963: + var4 = params[152] + else: + if inputs[0] <= -0.6870098124256391: + var4 = params[153] + else: + var4 = params[154] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[155] + else: + var4 = params[156] + else: + var4 = params[157] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var4 = params[158] + else: + var4 = params[159] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var5 = params[160] + else: + var5 = params[161] + else: + if inputs[2] > 4.13752641008496: + var5 = params[162] + else: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[163] + else: + var5 = params[164] + else: + var5 = params[165] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 7.22: + var5 = params[166] + else: + var5 = params[167] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var5 = params[168] + else: + var5 = params[169] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var5 = params[170] + else: + if inputs[6] > 2.5000000000000004: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[171] + else: + var5 = params[172] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9789715763336068: + var5 = params[173] + else: + if inputs[5] > 1.5000000000000002: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[174] + else: + if inputs[0] <= -0.19292067350446304: + var5 = params[175] + else: + var5 = params[176] + else: + var5 = params[177] + else: + var5 = params[178] + else: + var5 = params[179] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[180] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[181] + else: + var5 = params[182] + else: + if inputs[6] > 1.5000000000000002: + if inputs[5] > 1.5000000000000002: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[183] + else: + var5 = params[184] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var5 = params[185] + else: + var5 = params[186] + else: + var5 = params[187] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[188] + else: + var5 = params[189] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[190] + else: + var5 = params[191] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var6 = params[192] + else: + var6 = params[193] + else: + if inputs[2] > 2.7958170819201564: + var6 = params[194] + else: + if inputs[5] > 1.5000000000000002: + var6 = params[195] + else: + var6 = params[196] + else: + var6 = params[197] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[0] <= -0.8365274813439836: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[198] + else: + var6 = params[199] + else: + var6 = params[200] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var6 = params[201] + else: + if inputs[1] <= -0.3150996155456951: + var6 = params[202] + else: + var6 = params[203] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[204] + else: + var6 = params[205] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.0491767975761646: + var6 = params[206] + else: + var6 = params[207] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[208] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[209] + else: + var6 = params[210] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var6 = params[211] + else: + var6 = params[212] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[213] + else: + var6 = params[214] + else: + if inputs[6] > 1.5000000000000002: + if inputs[5] > 1.5000000000000002: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[215] + else: + var6 = params[216] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var6 = params[217] + else: + if inputs[0] > 0.6208055873208026: + var6 = params[218] + else: + var6 = params[219] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[220] + else: + var6 = params[221] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[222] + else: + var6 = params[223] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 2.7958170819201564: + if inputs[2] > 4.13752641008496: + var7 = params[224] + else: + var7 = params[225] + else: + var7 = params[226] + else: + var7 = params[227] + else: + var7 = params[228] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[229] + else: + if inputs[3] > 7.22: + var7 = params[230] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + var7 = params[231] + else: + if inputs[6] > 3.5000000000000004: + var7 = params[232] + else: + var7 = params[233] + else: + var7 = params[234] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var7 = params[235] + else: + if inputs[1] <= -0.3150996155456951: + var7 = params[236] + else: + var7 = params[237] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var7 = params[238] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[239] + else: + var7 = params[240] + else: + if inputs[6] > 3.5000000000000004: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 4.500000000000001: + var7 = params[241] + else: + var7 = params[242] + else: + var7 = params[243] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[244] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[245] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[246] + else: + var7 = params[247] + else: + if inputs[1] > 2.0493725485847785: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[248] + else: + var7 = params[249] + else: + if inputs[6] > 4.500000000000001: + var7 = params[250] + else: + if inputs[3] <= -2.774999999999998: + if inputs[5] > 1.5000000000000002: + var7 = params[251] + else: + var7 = params[252] + else: + if inputs[6] > 1.5000000000000002: + var7 = params[253] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[254] + else: + var7 = params[255] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 2.7958170819201564: + var8 = params[256] + else: + var8 = params[257] + else: + if inputs[2] > 4.13752641008496: + var8 = params[258] + else: + if inputs[5] > 1.5000000000000002: + var8 = params[259] + else: + var8 = params[260] + else: + if inputs[0] > 0.6889771560588532: + var8 = params[261] + else: + var8 = params[262] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[263] + else: + if inputs[3] > 7.22: + var8 = params[264] + else: + var8 = params[265] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + if inputs[0] <= -0.7870566736799897: + var8 = params[266] + else: + var8 = params[267] + else: + var8 = params[268] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var8 = params[269] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9224714045779462: + var8 = params[270] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[271] + else: + var8 = params[272] + else: + if inputs[0] <= -1.060096627328628: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[273] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[274] + else: + var8 = params[275] + else: + if inputs[0] > 0.2796824846082225: + var8 = params[276] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9789715763336068: + var8 = params[277] + else: + var8 = params[278] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 2.5000000000000004: + var8 = params[279] + else: + var8 = params[280] + else: + var8 = params[281] + else: + if inputs[1] > 2.0493725485847785: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[282] + else: + var8 = params[283] + else: + if inputs[0] <= -1.0706185685476008: + var8 = params[284] + else: + if inputs[3] <= -2.774999999999998: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[285] + else: + var8 = params[286] + else: + var8 = params[287] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 2.7958170819201564: + if inputs[2] > 4.13752641008496: + var9 = params[288] + else: + var9 = params[289] + else: + var9 = params[290] + else: + var9 = params[291] + else: + var9 = params[292] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[293] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + if inputs[3] > 7.22: + var9 = params[294] + else: + var9 = params[295] + else: + var9 = params[296] + else: + var9 = params[297] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + if inputs[1] > 2.0493725485847785: + var9 = params[298] + else: + var9 = params[299] + else: + if inputs[1] <= -0.3150996155456951: + var9 = params[300] + else: + var9 = params[301] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var9 = params[302] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[303] + else: + if inputs[6] > 3.5000000000000004: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var9 = params[304] + else: + var9 = params[305] + else: + if inputs[3] > 5.55: + var9 = params[306] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[307] + else: + var9 = params[308] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[309] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[310] + else: + var9 = params[311] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + var9 = params[312] + else: + var9 = params[313] + else: + if inputs[6] > 3.5000000000000004: + if inputs[5] > 1.5000000000000002: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[314] + else: + var9 = params[315] + else: + var9 = params[316] + else: + if inputs[6] > 1.5000000000000002: + var9 = params[317] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[318] + else: + var9 = params[319] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var10 = params[320] + else: + if inputs[1] > 0.544004836887963: + var10 = params[321] + else: + var10 = params[322] + else: + var10 = params[323] + else: + if inputs[1] <= -1.1757520039296843: + var10 = params[324] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var10 = params[325] + else: + var10 = params[326] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var10 = params[327] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var10 = params[328] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -0.6288738766989617: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -0.7710085028292034: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var10 = params[329] + else: + var10 = params[330] + else: + var10 = params[331] + else: + var10 = params[332] + else: + var10 = params[333] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9613760611859128: + if inputs[6] > 2.5000000000000004: + var10 = params[334] + else: + var10 = params[335] + else: + var10 = params[336] + else: + if inputs[0] > 0.09011070331849418: + var10 = params[337] + else: + var10 = params[338] + else: + if inputs[0] <= -1.0706185685476008: + if inputs[6] > 2.5000000000000004: + var10 = params[339] + else: + var10 = params[340] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var10 = params[341] + else: + if inputs[6] > 4.500000000000001: + var10 = params[342] + else: + if inputs[3] <= -2.774999999999998: + if inputs[5] > 1.5000000000000002: + var10 = params[343] + else: + var10 = params[344] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9613760611859128: + var10 = params[345] + else: + if inputs[1] > 0.544004836887963: + var10 = params[346] + else: + if inputs[0] <= -0.6870098124256391: + var10 = params[347] + else: + if inputs[0] <= -0.48284878490792343: + var10 = params[348] + else: + var10 = params[349] + else: + if inputs[6] > 1.5000000000000002: + var10 = params[350] + else: + var10 = params[351] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + if inputs[2] > 4.13752641008496: + var11 = params[352] + else: + var11 = params[353] + else: + if inputs[1] > 0.544004836887963: + var11 = params[354] + else: + var11 = params[355] + else: + var11 = params[356] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[0] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[357] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + if inputs[3] > 7.22: + var11 = params[358] + else: + var11 = params[359] + else: + var11 = params[360] + else: + var11 = params[361] + else: + if inputs[2] > 1.4541077537553535: + if inputs[1] <= -0.3150996155456951: + var11 = params[362] + else: + var11 = params[363] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var11 = params[364] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[365] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[6] > 2.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0706185685476008: + var11 = params[366] + else: + var11 = params[367] + else: + var11 = params[368] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[369] + else: + var11 = params[370] + else: + var11 = params[371] + else: + if inputs[0] > 0.01309716716954198: + var11 = params[372] + else: + if inputs[6] > 3.5000000000000004: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[373] + else: + if inputs[5] > 1.5000000000000002: + var11 = params[374] + else: + var11 = params[375] + else: + var11 = params[376] + else: + if inputs[0] <= -1.0706185685476008: + if inputs[6] > 2.5000000000000004: + var11 = params[377] + else: + var11 = params[378] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[379] + else: + if inputs[6] > 4.500000000000001: + var11 = params[380] + else: + if inputs[3] <= -9.724999999999998: + var11 = params[381] + else: + var11 = params[382] + else: + var11 = params[383] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 2.7958170819201564: + var12 = params[384] + else: + var12 = params[385] + else: + var12 = params[386] + else: + var12 = params[387] + else: + if inputs[1] <= -1.1757520039296843: + var12 = params[388] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + if inputs[0] <= -0.7870566736799897: + var12 = params[389] + else: + var12 = params[390] + else: + var12 = params[391] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var12 = params[392] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[393] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[6] > 2.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + var12 = params[394] + else: + var12 = params[395] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[396] + else: + var12 = params[397] + else: + var12 = params[398] + else: + if inputs[0] > 0.2796824846082225: + var12 = params[399] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[400] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[6] > 3.5000000000000004: + var12 = params[401] + else: + var12 = params[402] + else: + var12 = params[403] + else: + var12 = params[404] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[405] + else: + var12 = params[406] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + if inputs[3] <= -5.549999999999998: + var12 = params[407] + else: + var12 = params[408] + else: + if inputs[3] > 8.335000000000003: + var12 = params[409] + else: + if inputs[5] > 1.5000000000000002: + var12 = params[410] + else: + var12 = params[411] + else: + if inputs[6] > 3.5000000000000004: + if inputs[3] <= -2.774999999999998: + var12 = params[412] + else: + var12 = params[413] + else: + var12 = params[414] + else: + var12 = params[415] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var13 = params[416] + else: + if inputs[1] > 0.544004836887963: + var13 = params[417] + else: + var13 = params[418] + else: + var13 = params[419] + else: + if inputs[1] <= -0.7454258097376898: + var13 = params[420] + else: + if inputs[2] > 1.4541077537553535: + if inputs[1] <= -0.3150996155456951: + var13 = params[421] + else: + var13 = params[422] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 2.5000000000000004: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0902035263627476: + var13 = params[423] + else: + if inputs[0] <= -1.0189372690308816: + var13 = params[424] + else: + var13 = params[425] + else: + var13 = params[426] + else: + var13 = params[427] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0189372690308816: + var13 = params[428] + else: + var13 = params[429] + else: + var13 = params[430] + else: + if inputs[5] > 1.5000000000000002: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[431] + else: + var13 = params[432] + else: + if inputs[6] > 4.500000000000001: + var13 = params[433] + else: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -0.23757260892951562: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[434] + else: + var13 = params[435] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[436] + else: + var13 = params[437] + else: + var13 = params[438] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.3335963750119059: + var13 = params[439] + else: + var13 = params[440] + else: + if inputs[1] > 2.0493725485847785: + var13 = params[441] + else: + if inputs[3] <= -2.779999999999999: + if inputs[1] <= -0.3150996155456951: + var13 = params[442] + else: + var13 = params[443] + else: + if inputs[1] > 0.544004836887963: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[444] + else: + var13 = params[445] + else: + var13 = params[446] + else: + var13 = params[447] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 4.13752641008496: + var14 = params[448] + else: + var14 = params[449] + else: + if inputs[2] > 2.7958170819201564: + var14 = params[450] + else: + var14 = params[451] + else: + var14 = params[452] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[453] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + var14 = params[454] + else: + var14 = params[455] + else: + var14 = params[456] + else: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var14 = params[457] + else: + var14 = params[458] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 2.0493725485847785: + var14 = params[459] + else: + if inputs[1] > 0.544004836887963: + if inputs[3] <= -11.384999999999996: + var14 = params[460] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var14 = params[461] + else: + var14 = params[462] + else: + var14 = params[463] + else: + if inputs[3] <= -5.555: + var14 = params[464] + else: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[465] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[6] > 4.500000000000001: + var14 = params[466] + else: + var14 = params[467] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[468] + else: + var14 = params[469] + else: + var14 = params[470] + else: + var14 = params[471] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[472] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 4.500000000000001: + var14 = params[473] + else: + if inputs[3] <= -5.555: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[474] + else: + var14 = params[475] + else: + if inputs[6] > 2.5000000000000004: + var14 = params[476] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[477] + else: + var14 = params[478] + else: + var14 = params[479] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.3035336858148408: + if inputs[6] > 2.5000000000000004: + if inputs[1] > 2.0493725485847785: + var15 = params[480] + else: + if inputs[0] <= -0.9880345929297808: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.0189372690308816: + if inputs[0] <= -1.0706185685476008: + var15 = params[481] + else: + var15 = params[482] + else: + var15 = params[483] + else: + var15 = params[484] + else: + if inputs[2] > 2.7958170819201564: + var15 = params[485] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -0.9447089526163635: + var15 = params[486] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[487] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[488] + else: + var15 = params[489] + else: + if inputs[0] <= -0.415915091607399: + var15 = params[490] + else: + var15 = params[491] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[492] + else: + var15 = params[493] + else: + if inputs[0] <= -0.8207887793525789: + var15 = params[494] + else: + var15 = params[495] + else: + if inputs[2] > 2.7958170819201564: + if inputs[2] > 4.13752641008496: + var15 = params[496] + else: + var15 = params[497] + else: + if inputs[0] > 0.784160935237208: + var15 = params[498] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + var15 = params[499] + else: + var15 = params[500] + else: + if inputs[3] <= -5.555: + var15 = params[501] + else: + var15 = params[502] + else: + if inputs[1] <= -0.7454258097376898: + var15 = params[503] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 2.5000000000000004: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[504] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[505] + else: + if inputs[3] <= -2.779999999999999: + var15 = params[506] + else: + if inputs[0] <= -0.9842767567801477: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[507] + else: + var15 = params[508] + else: + var15 = params[509] + else: + var15 = params[510] + else: + var15 = params[511] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 4.13752641008496: + var16 = params[512] + else: + var16 = params[513] + else: + var16 = params[514] + else: + var16 = params[515] + else: + if inputs[1] <= -1.1757520039296843: + var16 = params[516] + else: + if inputs[2] > 1.4541077537553535: + if inputs[0] <= -1.0189372690308816: + var16 = params[517] + else: + if inputs[2] > 2.7958170819201564: + var16 = params[518] + else: + var16 = params[519] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[6] > 2.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0902035263627476: + var16 = params[520] + else: + if inputs[0] <= -1.0189372690308816: + var16 = params[521] + else: + var16 = params[522] + else: + var16 = params[523] + else: + var16 = params[524] + else: + var16 = params[525] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var16 = params[526] + else: + var16 = params[527] + else: + var16 = params[528] + else: + if inputs[6] > 4.500000000000001: + var16 = params[529] + else: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -0.23757260892951562: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var16 = params[530] + else: + var16 = params[531] + else: + var16 = params[532] + else: + var16 = params[533] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.5112757101339717: + var16 = params[534] + else: + var16 = params[535] + else: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -5.549999999999998: + var16 = params[536] + else: + var16 = params[537] + else: + var16 = params[538] + else: + if inputs[3] <= -5.555: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var16 = params[539] + else: + var16 = params[540] + else: + if inputs[0] > 0.33507741043752043: + var16 = params[541] + else: + var16 = params[542] + else: + var16 = params[543] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var17 = params[544] + else: + if inputs[0] <= -0.3335963750119059: + if inputs[6] > 3.5000000000000004: + var17 = params[545] + else: + var17 = params[546] + else: + var17 = params[547] + else: + if inputs[0] > 0.6889771560588532: + var17 = params[548] + else: + var17 = params[549] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[0] > 0.01309716716954198: + var17 = params[550] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + if inputs[3] > 7.22: + var17 = params[551] + else: + var17 = params[552] + else: + var17 = params[553] + else: + var17 = params[554] + else: + if inputs[2] > 1.4541077537553535: + if inputs[0] <= -1.0189372690308816: + var17 = params[555] + else: + if inputs[2] > 2.7958170819201564: + var17 = params[556] + else: + var17 = params[557] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[6] > 2.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0902035263627476: + var17 = params[558] + else: + if inputs[0] <= -1.0298570987833446: + var17 = params[559] + else: + var17 = params[560] + else: + var17 = params[561] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var17 = params[562] + else: + var17 = params[563] + else: + var17 = params[564] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -4.164999999999998: + var17 = params[565] + else: + if inputs[0] > 0.01309716716954198: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var17 = params[566] + else: + var17 = params[567] + else: + var17 = params[568] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] > 1.4046572252719522: + if inputs[3] <= -5.549999999999998: + var17 = params[569] + else: + var17 = params[570] + else: + if inputs[3] > 8.335000000000003: + var17 = params[571] + else: + if inputs[5] > 1.5000000000000002: + var17 = params[572] + else: + var17 = params[573] + else: + var17 = params[574] + else: + var17 = params[575] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 4.13752641008496: + var18 = params[576] + else: + var18 = params[577] + else: + var18 = params[578] + else: + var18 = params[579] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[0] <= -0.16170852854398074: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 5.5550000000000015: + if inputs[3] > 7.22: + var18 = params[580] + else: + var18 = params[581] + else: + var18 = params[582] + else: + var18 = params[583] + else: + var18 = params[584] + else: + if inputs[2] > 1.4541077537553535: + if inputs[1] <= -0.3150996155456951: + var18 = params[585] + else: + var18 = params[586] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.0706185685476008: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var18 = params[587] + else: + var18 = params[588] + else: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -5.835: + var18 = params[589] + else: + var18 = params[590] + else: + var18 = params[591] + else: + if inputs[3] <= -5.555: + var18 = params[592] + else: + if inputs[3] > 12.774999999999997: + var18 = params[593] + else: + var18 = params[594] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var18 = params[595] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -0.6928455109168341: + if inputs[6] > 4.500000000000001: + var18 = params[596] + else: + var18 = params[597] + else: + var18 = params[598] + else: + if inputs[0] <= -1.1469247473036808: + var18 = params[599] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var18 = params[600] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var18 = params[601] + else: + if inputs[0] <= -0.3035336858148408: + var18 = params[602] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var18 = params[603] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var18 = params[604] + else: + var18 = params[605] + else: + var18 = params[606] + else: + var18 = params[607] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var19 = params[608] + else: + if inputs[1] > 0.544004836887963: + var19 = params[609] + else: + if inputs[5] > 1.5000000000000002: + var19 = params[610] + else: + if inputs[0] > 0.18878705962415496: + var19 = params[611] + else: + if inputs[6] > 3.5000000000000004: + if inputs[6] > 5.500000000000001: + var19 = params[612] + else: + var19 = params[613] + else: + var19 = params[614] + else: + var19 = params[615] + else: + if inputs[1] <= -0.7454258097376898: + var19 = params[616] + else: + if inputs[2] > 1.4541077537553535: + if inputs[0] <= -1.0189372690308816: + var19 = params[617] + else: + if inputs[2] > 2.7958170819201564: + var19 = params[618] + else: + var19 = params[619] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[6] > 2.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.0902035263627476: + var19 = params[620] + else: + if inputs[0] <= -1.0298570987833446: + var19 = params[621] + else: + var19 = params[622] + else: + var19 = params[623] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var19 = params[624] + else: + var19 = params[625] + else: + var19 = params[626] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var19 = params[627] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + var19 = params[628] + else: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -0.6870098124256391: + if inputs[6] > 3.5000000000000004: + var19 = params[629] + else: + var19 = params[630] + else: + var19 = params[631] + else: + var19 = params[632] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.3335963750119059: + var19 = params[633] + else: + var19 = params[634] + else: + if inputs[3] <= -2.779999999999999: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + var19 = params[635] + else: + var19 = params[636] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var19 = params[637] + else: + var19 = params[638] + else: + var19 = params[639] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 0.03758941689773911: + if inputs[6] > 3.5000000000000004: + var20 = params[640] + else: + var20 = params[641] + else: + var20 = params[642] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[0] <= -0.8365274813439836: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[643] + else: + if inputs[0] <= -1.013587878747286: + var20 = params[644] + else: + if inputs[3] > 5.5550000000000015: + var20 = params[645] + else: + if inputs[5] > 1.5000000000000002: + var20 = params[646] + else: + var20 = params[647] + else: + if inputs[0] <= -0.51861454308502: + if inputs[0] <= -0.8148646611872749: + var20 = params[648] + else: + var20 = params[649] + else: + var20 = params[650] + else: + if inputs[2] > 1.4541077537553535: + var20 = params[651] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.001120704697915: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.0244634986626948: + if inputs[0] <= -1.0706185685476008: + var20 = params[652] + else: + var20 = params[653] + else: + var20 = params[654] + else: + if inputs[3] <= -5.555: + var20 = params[655] + else: + var20 = params[656] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[657] + else: + if inputs[1] > 2.0493725485847785: + var20 = params[658] + else: + var20 = params[659] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[660] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -0.9842767567801477: + var20 = params[661] + else: + var20 = params[662] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[663] + else: + if inputs[0] <= -1.0806984113960285: + var20 = params[664] + else: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var20 = params[665] + else: + if inputs[0] <= -0.3816082580531011: + var20 = params[666] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[667] + else: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[668] + else: + var20 = params[669] + else: + var20 = params[670] + else: + var20 = params[671] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.3035336858148408: + var21 = params[672] + else: + if inputs[2] > 1.4541077537553535: + var21 = params[673] + else: + var21 = params[674] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[0] <= -0.8365274813439836: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[675] + else: + if inputs[0] <= -1.013587878747286: + var21 = params[676] + else: + var21 = params[677] + else: + if inputs[0] <= -0.3553918246797782: + var21 = params[678] + else: + var21 = params[679] + else: + if inputs[2] > 1.4541077537553535: + var21 = params[680] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -11.384999999999996: + var21 = params[681] + else: + if inputs[1] > 0.544004836887963: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.7289649477903667: + var21 = params[682] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[683] + else: + if inputs[0] > 1.2557472670976397: + var21 = params[684] + else: + var21 = params[685] + else: + var21 = params[686] + else: + if inputs[0] <= -1.0706185685476008: + if inputs[0] <= -1.0806984113960285: + var21 = params[687] + else: + var21 = params[688] + else: + if inputs[0] <= -1.060096627328628: + var21 = params[689] + else: + if inputs[3] <= -5.555: + var21 = params[690] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[691] + else: + if inputs[3] > 7.22: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 0.49078445654349595: + var21 = params[692] + else: + var21 = params[693] + else: + var21 = params[694] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 2.8144092822913573: + var21 = params[695] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[696] + else: + var21 = params[697] + else: + var21 = params[698] + else: + var21 = params[699] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[700] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.060096627328628: + var21 = params[701] + else: + var21 = params[702] + else: + var21 = params[703] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.3335963750119059: + if inputs[3] > 7.22: + if inputs[5] > 1.5000000000000002: + var22 = params[704] + else: + var22 = params[705] + else: + if inputs[1] > 2.0493725485847785: + var22 = params[706] + else: + if inputs[1] <= -1.1757520039296843: + var22 = params[707] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 2.7958170819201564: + var22 = params[708] + else: + var22 = params[709] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var22 = params[710] + else: + if inputs[6] > 4.500000000000001: + var22 = params[711] + else: + var22 = params[712] + else: + if inputs[2] > 4.13752641008496: + var22 = params[713] + else: + if inputs[2] > 2.7958170819201564: + var22 = params[714] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 5.500000000000001: + var22 = params[715] + else: + var22 = params[716] + else: + var22 = params[717] + else: + var22 = params[718] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var22 = params[719] + else: + if inputs[0] <= -0.8480220389781555: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9505446511075585: + var22 = params[720] + else: + var22 = params[721] + else: + if inputs[5] > 1.5000000000000002: + var22 = params[722] + else: + var22 = params[723] + else: + if inputs[0] <= -0.51861454308502: + var22 = params[724] + else: + var22 = params[725] + else: + if inputs[6] > 3.5000000000000004: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var22 = params[726] + else: + var22 = params[727] + else: + if inputs[0] <= -0.9842767567801477: + var22 = params[728] + else: + if inputs[3] <= -2.774999999999998: + var22 = params[729] + else: + var22 = params[730] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var22 = params[731] + else: + var22 = params[732] + else: + if inputs[3] <= -5.549999999999998: + var22 = params[733] + else: + var22 = params[734] + else: + var22 = params[735] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 0.25969963825958503: + var23 = params[736] + else: + if inputs[1] > 2.0493725485847785: + var23 = params[737] + else: + var23 = params[738] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[0] <= -1.013587878747286: + var23 = params[739] + else: + if inputs[0] <= -0.15330865950362435: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.7813093948629036: + var23 = params[740] + else: + var23 = params[741] + else: + if inputs[3] > 5.5550000000000015: + if inputs[0] <= -0.34774352286934845: + var23 = params[742] + else: + var23 = params[743] + else: + var23 = params[744] + else: + var23 = params[745] + else: + if inputs[6] > 3.5000000000000004: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var23 = params[746] + else: + if inputs[3] > 5.55: + var23 = params[747] + else: + var23 = params[748] + else: + if inputs[3] > 2.7749999999999995: + if inputs[0] > 0.5330048509305506: + var23 = params[749] + else: + var23 = params[750] + else: + if inputs[0] <= -0.6036300597408378: + if inputs[1] <= -0.3150996155456951: + var23 = params[751] + else: + if inputs[6] > 4.500000000000001: + var23 = params[752] + else: + if inputs[0] <= -0.9880345929297808: + var23 = params[753] + else: + var23 = params[754] + else: + if inputs[0] > 2.8869134150607496: + var23 = params[755] + else: + var23 = params[756] + else: + if inputs[0] <= -1.0706185685476008: + if inputs[0] <= -1.0806984113960285: + var23 = params[757] + else: + var23 = params[758] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -5.549999999999998: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9447089526163635: + var23 = params[759] + else: + var23 = params[760] + else: + if inputs[0] > 0.348030892694491: + var23 = params[761] + else: + var23 = params[762] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[0] > 0.12556699263620927: + var23 = params[763] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var23 = params[764] + else: + var23 = params[765] + else: + var23 = params[766] + else: + var23 = params[767] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[768] + else: + var24 = params[769] + else: + if inputs[1] <= -0.7454258097376898: + var24 = params[770] + else: + if inputs[6] > 4.500000000000001: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var24 = params[771] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[0] <= -0.2667511013854906: + if inputs[0] <= -0.5986785579907331: + var24 = params[772] + else: + var24 = params[773] + else: + var24 = params[774] + else: + if inputs[0] <= -0.8628323343914156: + var24 = params[775] + else: + var24 = params[776] + else: + if inputs[0] <= -0.7710085028292034: + var24 = params[777] + else: + var24 = params[778] + else: + if inputs[0] <= -1.0706185685476008: + var24 = params[779] + else: + if inputs[3] <= -5.555: + if inputs[1] > 0.544004836887963: + var24 = params[780] + else: + var24 = params[781] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[1] <= -0.3150996155456951: + if inputs[3] > 5.55: + var24 = params[782] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[783] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[784] + else: + if inputs[0] <= -0.938386945917569: + var24 = params[785] + else: + var24 = params[786] + else: + if inputs[0] <= -0.6791404614299368: + if inputs[6] > 3.5000000000000004: + if inputs[5] > 1.5000000000000002: + if inputs[5] > 2.5000000000000004: + var24 = params[787] + else: + var24 = params[788] + else: + if inputs[0] <= -0.7870566736799897: + if inputs[0] <= -0.9673001793512168: + var24 = params[789] + else: + var24 = params[790] + else: + var24 = params[791] + else: + if inputs[0] <= -1.0491767975761646: + var24 = params[792] + else: + var24 = params[793] + else: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[794] + else: + if inputs[0] <= -0.6036300597408378: + var24 = params[795] + else: + if inputs[0] <= -0.524803920272651: + var24 = params[796] + else: + var24 = params[797] + else: + var24 = params[798] + else: + var24 = params[799] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 4.13752641008496: + var25 = params[800] + else: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[801] + else: + var25 = params[802] + else: + if inputs[0] > 2.022478471133964: + var25 = params[803] + else: + var25 = params[804] + else: + if inputs[1] <= -0.7454258097376898: + if inputs[3] > 5.5550000000000015: + if inputs[0] <= -0.34774352286934845: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] > 7.22: + var25 = params[805] + else: + var25 = params[806] + else: + var25 = params[807] + else: + var25 = params[808] + else: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[809] + else: + if inputs[5] > 1.5000000000000002: + var25 = params[810] + else: + var25 = params[811] + else: + if inputs[2] > 1.4541077537553535: + var25 = params[812] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -11.384999999999996: + if inputs[0] > 0.8038343127264639: + var25 = params[813] + else: + var25 = params[814] + else: + if inputs[1] > 1.4046572252719522: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.634223266982557: + var25 = params[815] + else: + if inputs[12] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[816] + else: + var25 = params[817] + else: + var25 = params[818] + else: + if inputs[3] > 12.774999999999997: + var25 = params[819] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[820] + else: + var25 = params[821] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[822] + else: + var25 = params[823] + else: + if inputs[7] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9224714045779462: + var25 = params[824] + else: + if inputs[0] <= -0.6537640149606494: + var25 = params[825] + else: + var25 = params[826] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9163704470644242: + var25 = params[827] + else: + var25 = params[828] + else: + if inputs[0] <= -1.0902035263627476: + var25 = params[829] + else: + var25 = params[830] + else: + var25 = params[831] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 4.13752641008496: + var26 = params[832] + else: + if inputs[1] > 0.544004836887963: + var26 = params[833] + else: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -0.17094838448837282: + var26 = params[834] + else: + var26 = params[835] + else: + if inputs[6] > 4.500000000000001: + if inputs[0] <= -0.6928455109168341: + var26 = params[836] + else: + var26 = params[837] + else: + if inputs[0] > 0.25969963825958503: + var26 = params[838] + else: + if inputs[0] <= -0.8365274813439836: + var26 = params[839] + else: + var26 = params[840] + else: + if inputs[0] > 2.022478471133964: + var26 = params[841] + else: + var26 = params[842] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var26 = params[843] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.524803920272651: + var26 = params[844] + else: + var26 = params[845] + else: + var26 = params[846] + else: + if inputs[2] > 1.4541077537553535: + var26 = params[847] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var26 = params[848] + else: + var26 = params[849] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var26 = params[850] + else: + if inputs[0] <= -1.0341896628146865: + var26 = params[851] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var26 = params[852] + else: + var26 = params[853] + else: + if inputs[6] > 4.500000000000001: + if inputs[0] <= -0.8577039932930927: + var26 = params[854] + else: + if inputs[0] <= -0.3553918246797782: + var26 = params[855] + else: + var26 = params[856] + else: + var26 = params[857] + else: + if inputs[5] > 2.5000000000000004: + var26 = params[858] + else: + if inputs[0] <= -1.1469247473036808: + var26 = params[859] + else: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var26 = params[860] + else: + var26 = params[861] + else: + var26 = params[862] + else: + var26 = params[863] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 2.7958170819201564: + var27 = params[864] + else: + if inputs[0] <= -0.3335963750119059: + var27 = params[865] + else: + var27 = params[866] + else: + var27 = params[867] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var27 = params[868] + else: + var27 = params[869] + else: + if inputs[2] > 2.7958170819201564: + if inputs[0] <= -0.7870566736799897: + var27 = params[870] + else: + var27 = params[871] + else: + if inputs[0] <= -0.9789715763336068: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.0298570987833446: + if inputs[0] <= -1.0706185685476008: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + var27 = params[872] + else: + if inputs[0] <= -1.1261461238880623: + var27 = params[873] + else: + var27 = params[874] + else: + var27 = params[875] + else: + if inputs[0] <= -0.9943123897915209: + var27 = params[876] + else: + var27 = params[877] + else: + if inputs[0] <= -0.9943123897915209: + var27 = params[878] + else: + var27 = params[879] + else: + if inputs[5] > 0.000000000000000000000000000000000010000000180025095: + if inputs[3] <= -5.549999999999998: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + var27 = params[880] + else: + var27 = params[881] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var27 = params[882] + else: + var27 = params[883] + else: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + var27 = params[884] + else: + if inputs[0] > 1.6078786192367922: + if inputs[1] > 1.4046572252719522: + var27 = params[885] + else: + var27 = params[886] + else: + if inputs[3] > 2.7749999999999995: + var27 = params[887] + else: + if inputs[0] <= -0.4675079714500093: + if inputs[0] <= -0.7639349289004822: + var27 = params[888] + else: + var27 = params[889] + else: + if inputs[0] <= -0.13774679686043764: + var27 = params[890] + else: + var27 = params[891] + else: + var27 = params[892] + else: + if inputs[0] > 0.2796824846082225: + var27 = params[893] + else: + var27 = params[894] + else: + var27 = params[895] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[2] > 1.4541077537553535: + if inputs[2] > 4.13752641008496: + var28 = params[896] + else: + if inputs[3] <= -0.000000000000000000000000000000000010000000180025095: + var28 = params[897] + else: + var28 = params[898] + else: + if inputs[0] > 2.276552404686219: + var28 = params[899] + else: + var28 = params[900] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var28 = params[901] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.524803920272651: + var28 = params[902] + else: + var28 = params[903] + else: + if inputs[3] > 7.22: + var28 = params[904] + else: + if inputs[5] > 1.5000000000000002: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9114631551513738: + var28 = params[905] + else: + var28 = params[906] + else: + var28 = params[907] + else: + if inputs[3] > 5.5550000000000015: + var28 = params[908] + else: + var28 = params[909] + else: + if inputs[2] > 2.7958170819201564: + if inputs[0] <= -0.7870566736799897: + var28 = params[910] + else: + var28 = params[911] + else: + if inputs[6] > 4.500000000000001: + if inputs[8] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var28 = params[912] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[0] <= -0.2667511013854906: + if inputs[0] <= -0.5986785579907331: + var28 = params[913] + else: + var28 = params[914] + else: + var28 = params[915] + else: + var28 = params[916] + else: + var28 = params[917] + else: + if inputs[3] <= -5.549999999999998: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + var28 = params[918] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var28 = params[919] + else: + var28 = params[920] + else: + if inputs[1] > 0.544004836887963: + var28 = params[921] + else: + if inputs[0] <= -1.0706185685476008: + if inputs[1] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.101034936441102: + var28 = params[922] + else: + var28 = params[923] + else: + var28 = params[924] + else: + if inputs[0] > 0.12556699263620927: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var28 = params[925] + else: + var28 = params[926] + else: + var28 = params[927] + if inputs[4] <= -0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 0.25969963825958503: + var29 = params[928] + else: + var29 = params[929] + else: + if inputs[1] <= -1.1757520039296843: + if inputs[3] > 5.5550000000000015: + if inputs[0] <= -0.415915091607399: + if inputs[3] > 9.725000000000003: + var29 = params[930] + else: + if inputs[0] <= -0.9842767567801477: + var29 = params[931] + else: + if inputs[0] <= -0.794837605001583: + var29 = params[932] + else: + var29 = params[933] + else: + var29 = params[934] + else: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + var29 = params[935] + else: + if inputs[5] > 1.5000000000000002: + var29 = params[936] + else: + var29 = params[937] + else: + if inputs[2] > 1.4541077537553535: + var29 = params[938] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var29 = params[939] + else: + var29 = params[940] + else: + if inputs[1] <= -0.3150996155456951: + if inputs[9] > 0.000000000000000000000000000000000010000000180025095: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + var29 = params[941] + else: + if inputs[0] <= -1.0244634986626948: + var29 = params[942] + else: + var29 = params[943] + else: + if inputs[3] > 5.55: + if inputs[13] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.8098689496001155: + var29 = params[944] + else: + var29 = params[945] + else: + var29 = params[946] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -0.775075807838218: + var29 = params[947] + else: + var29 = params[948] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.8098689496001155: + if inputs[0] <= -0.9943123897915209: + var29 = params[949] + else: + var29 = params[950] + else: + if inputs[0] <= -0.6288738766989617: + var29 = params[951] + else: + if inputs[0] <= -0.5036274083235419: + var29 = params[952] + else: + if inputs[0] > 0.734513288224996: + var29 = params[953] + else: + if inputs[0] > 0.1583706917306538: + var29 = params[954] + else: + if inputs[0] <= -0.3335963750119059: + var29 = params[955] + else: + var29 = params[956] + else: + var29 = params[957] + else: + var29 = params[958] + else: + var29 = params[959] + return var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20 + var21 + var22 + var23 + var24 + var25 + var26 + var27 + var28 + var29 + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/capacity_right_before_left.py b/matsim/scenariogen/network/ref_model/germany/capacity_right_before_left.py new file mode 100644 index 0000000..0d6a2fa --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/capacity_right_before_left.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +"""PassiveAggressiveRegressor(C=0.015320363769859633, random_state=1373158606) +Error: 161.238227""" +def features(ft, data): + data[0] = (ft.get("length") - 126.5781093424676) / 82.93604475431307 + data[1] = (ft.get("speed") - 8.347924642353416) / 0.2530674029724574 + data[2] = (ft.get("num_lanes") - 1.0161192826919203) / 0.1410293306032409 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [] +def score(params, inputs): + return 820.7862981813687 + inputs[0] * -2.2407160935169324 + inputs[1] * -1.0312478382897772 + inputs[2] * -65.10322048874464 + inputs[3] * -3.7672954706609025 + inputs[4] * 91.56185003046016 + inputs[5] * 8.354883935056996 + inputs[6] * -16.573320689701585 + inputs[7] * 1.3872614339054785 + inputs[8] * 798.9462847274731 + inputs[9] * 20.45275201994965 + inputs[10] * 12.054157458777055 + inputs[11] * -11.583879746981143 + inputs[12] * -1.4911083760151145 + inputs[13] * 15.111478746337356 + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/capacity_traffic_light.py b/matsim/scenariogen/network/ref_model/germany/capacity_traffic_light.py new file mode 100644 index 0000000..e72ff12 --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/capacity_traffic_light.py @@ -0,0 +1,1296 @@ +# -*- coding: utf-8 -*- +"""XGBRegressor(alpha=0.08611386023702905, base_score=0.5, booster='gbtree', + callbacks=None, colsample_bylevel=1, colsample_bynode=0.9, + colsample_bytree=0.9, early_stopping_rounds=None, + enable_categorical=False, eta=0.5221569428936291, + eval_metric='mae', feature_types=None, gamma=0.04039757753888484, + gpu_id=-1, grow_policy='depthwise', importance_type=None, + interaction_constraints='', lambda=0.10033750030576022, + learning_rate=0.522156954, max_bin=256, max_cat_threshold=64, + max_cat_to_onehot=4, max_delta_step=0, max_depth=4, max_leaves=0, + min_child_weight=7, missing=nan, monotone_constraints='()', + n_estimators=30, n_jobs=0, ...) +Error: 173.054843""" +def features(ft, data): + data[0] = (ft.get("length") - 107.8300974851653) / 88.3127424806261 + data[1] = (ft.get("speed") - 14.238025572195534) / 3.7074142979554225 + data[2] = (ft.get("num_lanes") - 1.8936140152585477) / 0.8774023537080416 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [615.49475, 555.2296, 403.64377, 512.5417, 661.32526, 776.8592, 307.94974, 579.0987, 351.24344, 422.79248, 382.6958, 493.21002, 604.71576, 711.4676, 432.66574, 576.4394, 65.18873, -47.093124, 168.29794, 107.08128, 243.5391, 348.37152, 63.15197, 157.08269, 316.79657, 387.24396, 182.98808, 319.41205, 270.38162, 357.83185, 267.3479, 333.61728, 148.07251, 177.21588, 249.219, 155.23297, 118.858284, 173.88063, 126.52623, -24.637136, 16.66276, 56.981136, -81.52849, -7.1707215, 9.567015, -21.692072, -63.04734, -129.19891, 79.595566, 134.95496, 86.61436, 45.112183, -86.80803, 116.523636, 176.37932, 92.327934, 72.63386, 159.7371, 21.352165, -28.561874, -63.79159, 16.319218, -56.681995, -18.979984, 52.656525, 101.28996, -0.20502506, 69.61571, 33.462482, -65.63418, -68.76875, 48.720375, 23.87262, -17.97695, 62.186214, -9.389751, -5.4268684, -112.2844, 31.694218, 9.407171, -22.371742, 12.499399, 45.16506, 6.938427, -173.38019, 43.91622, 17.05614, -51.214798, -26.926168, -73.75736, -65.82583, 44.535336, 67.0273, 22.328768, 20.755566, -34.31819, 24.89524, -120.450294, -16.83533, 9.439478, -3.2446234, -139.10558, -4.885112, -73.83486, -105.620186, -33.20488, 28.100395, 7.387344, 34.008724, -37.129234, 1.1639067, -48.699387, -144.18034, -10.493104, 14.687679, -12.55395, -150.10774, 73.44105, -79.41268, 17.903439, -62.17122, 21.784134, 6.881216, -36.80274, 24.643566, -165.61743, 31.753023, 5.519214, 31.839605, -2.267683, -307.40558, -17.42233, -21.832182, 0.88072836, 29.75676, 1.7219872, 13.106872, -40.675232, -16.166363, 13.627753, 6.6565485, -103.0756, -28.808006, 110.27433, -35.767406, 2.9878566, -14.317886, -116.920265, 3.4358, -91.6584, 143.51192, 44.472115, -154.778, -81.63228, 57.86223, -52.41524, -62.078373, 17.617413, 127.360306, 21.375433, -8.385985, -22.935337, 48.906567, -34.74683, 3.9749646, -55.860897, 1.2457579, -30.196217, -1.5732583, -26.041641, -58.08545, 17.769197, -4.349664, -13.307687, 3.280725, -181.25356, -132.75182, 151.12465, -1.5777951, -16.651737, 90.23882, -15.37349, 13.606266, -91.40819, -41.258648, -180.38171, -19.271168, 1.0529263, -4.048095, 23.175564, -156.65048, -16.262281, 0.9099455, -44.414482, -99.75218, 99.07861, -6.1669326, 23.30339, -8.069562, 3.1905315, 105.503, 10.885436, 0.2122908, -3.832464, -28.705606, -104.79665, -15.315421, -138.83813, -0.05046561, 22.144823, -96.42455, -0.55342764, -51.706005, -133.55592, -45.583202, -2.5133393, 22.807049, -43.28402, 75.72772, 17.254173, -20.209124, 74.24624, 5.440937, 13.741028, -33.902576, 18.58394, -9.959772, 0.1041136, 11.82333, -55.533398, -5.4675765, -15.161497, -1.0267476, 32.695103, -24.99268, 11.922537, 168.70767, -130.78442, 142.66498, 73.242714, 22.27427, 63.905235, -1.3671306, 144.34485, -183.73148, -46.954998, 3.1506326, -66.14528, -76.67139, 101.13374, 4.0305805, 29.317297, 1.181701, -28.506397, -1.6518514, -31.184534, 111.60579, 24.28994, -79.61493, -116.00568, -32.023697, -5.7514906, 101.93708, 0.98392236, 31.337439, -75.310326, -4.5046306, -3.711782, -22.309193, -126.83017, -3.6419837, -0.33691192, 31.669813, -115.76439, -10.27076, 4.059611, -198.88503, -20.161263, -29.47476, 57.17951, -21.95527, 8.026982, 16.390108, -1.1080929, 7.407652, 64.743996, -120.04329, -17.445286, 75.8192, 20.360197, 53.785393, 10.200187, -30.04236, 6.437817, 0.3975224, -67.91621, 1.6522281, -7.837328, -29.006836, 201.19627, -7.32522, -105.99434, -2.4548867, 4.179684, 0.25429633, 15.097081, 7.4597287, -7.0939264, 28.318413, 2.313068, -3.7515059, -62.431297, 38.725285, -107.10958, 13.348956, -49.943775, -29.762196, 17.032738, -115.64885, -35.744957, -54.889526, 10.712898, -2.0292566, 6.2752585, 2.239138, -3.306334, -22.934214, 9.933622, 45.308083, 70.00484, 112.36703, -32.074837, -162.80998, -79.04883, 11.676644, 96.72633, -20.760891, 30.646982, -11.06929, -137.50465, -187.47688, 9.259439, -74.744194, 15.253941, 77.878845, 43.031143, -74.70491, 0.8596837, -3.5045547, 7.4930143, -62.12004, -201.92722, -14.383545, 188.42667, 52.05429, 25.04509, -25.63214, -74.18135, 46.912468, 99.37713, 17.79873, -2.1403294, 72.36021, 15.878182, -10.988122, -0.4876936, -98.321266, -15.296746, 78.528404, 1.3916807, -197.96143, 48.620667, -55.48649, 90.06772, -1.8789421, 148.41797, -79.165825, 44.078205, 5.211938, 104.9392, -3.1070962, -12.826189, -42.78979, 66.79847, -3.7024772, -4.8472857, 15.723977, 1.2936529, -8.688843, 21.240936, 1.3776098, -15.6449795, -154.3604, 23.49148, -7.519365, -1.6222787, 10.925819, -4.189361, -91.339485, 5.8957524, -4.6089797, -31.249628, 16.335638, -29.451998, 13.344731, -24.234076, 39.230362, -11.508264, -56.050926, -11.093029, 2.6919734, -78.32911, 71.32819, 22.187014, -229.40271, -165.41776, 3.8701072, 17.674295, -7.9431186, 3.8358455, -10.224057, 12.491475, 109.73238, -25.23852, 5.5010023, 0.013512374, -28.22281, -1.2147744, 14.7177105, 1.5710909, -47.821503, -14.950896, -126.36881, 37.637623, 146.43083, -128.48166, 11.404479, 29.001417, -16.301233] +def score(params, inputs): + if inputs[0] >= 0.09302058: + if inputs[6] >= 5.5: + if inputs[0] >= 0.70052063: + if inputs[1] >= -1.218646: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[6] >= 10.5: + var0 = params[2] + else: + var0 = params[3] + else: + if inputs[1] >= -1.218646: + if inputs[6] >= 3.5: + var0 = params[4] + else: + var0 = params[5] + else: + if inputs[3] >= 6.9449997: + var0 = params[6] + else: + var0 = params[7] + else: + if inputs[6] >= 4.5: + if inputs[5] >= 2.5: + if inputs[10] >= 0.5: + var0 = params[8] + else: + var0 = params[9] + else: + if inputs[1] >= 0.28105152: + var0 = params[10] + else: + var0 = params[11] + else: + if inputs[0] >= -0.68410397: + if inputs[6] >= 3.5: + var0 = params[12] + else: + var0 = params[13] + else: + if inputs[0] >= -0.88130087: + var0 = params[14] + else: + var0 = params[15] + if inputs[2] >= -0.44861287: + if inputs[5] >= 2.5: + if inputs[1] >= 1.0295516: + if inputs[3] >= -10.0: + var1 = params[16] + else: + var1 = params[17] + else: + if inputs[10] >= 0.5: + var1 = params[18] + else: + var1 = params[19] + else: + if inputs[0] >= -0.66694903: + if inputs[5] >= 1.5: + var1 = params[20] + else: + var1 = params[21] + else: + if inputs[3] >= 6.9449997: + var1 = params[22] + else: + var1 = params[23] + else: + if inputs[1] >= 0.28105152: + if inputs[0] >= -0.62159884: + if inputs[3] >= 1.385: + var1 = params[24] + else: + var1 = params[25] + else: + if inputs[6] >= 3.5: + var1 = params[26] + else: + var1 = params[27] + else: + if inputs[1] >= -0.46879724: + if inputs[13] >= 0.5: + var1 = params[28] + else: + var1 = params[29] + else: + if inputs[5] >= 2.5: + var1 = params[30] + else: + var1 = params[31] + if inputs[4] >= -0.5: + if inputs[10] >= 0.5: + if inputs[5] >= 2.5: + if inputs[9] >= 0.5: + var2 = params[32] + else: + var2 = params[33] + else: + if inputs[5] >= 1.5: + var2 = params[34] + else: + var2 = params[35] + else: + if inputs[4] >= 0.5: + if inputs[9] >= 0.5: + var2 = params[36] + else: + var2 = params[37] + else: + if inputs[3] >= -6.9449997: + var2 = params[38] + else: + var2 = params[39] + else: + if inputs[4] >= -1.5: + if inputs[10] >= 0.5: + if inputs[3] >= 4.165: + var2 = params[40] + else: + var2 = params[41] + else: + if inputs[1] >= 2.5279005: + var2 = params[42] + else: + var2 = params[43] + else: + if inputs[6] >= 8.5: + if inputs[8] >= 0.5: + var2 = params[44] + else: + var2 = params[45] + else: + if inputs[1] >= -0.46879724: + var2 = params[46] + else: + var2 = params[47] + if inputs[4] >= -0.5: + if inputs[0] >= -0.7546487: + if inputs[1] >= -0.46879724: + if inputs[5] >= 2.5: + var3 = params[48] + else: + var3 = params[49] + else: + if inputs[4] >= 0.5: + var3 = params[50] + else: + var3 = params[51] + else: + if inputs[0] >= -0.88130087: + if inputs[1] >= -1.218646: + var3 = params[52] + else: + var3 = params[53] + else: + if inputs[1] >= 0.28105152: + var3 = params[54] + else: + var3 = params[55] + else: + if inputs[2] >= 0.6911151: + if inputs[4] >= -1.5: + if inputs[6] >= 6.5: + var3 = params[56] + else: + var3 = params[57] + else: + if inputs[6] >= 11.5: + var3 = params[58] + else: + var3 = params[59] + else: + if inputs[1] >= 1.0295516: + if inputs[1] >= 2.9028249: + var3 = params[60] + else: + var3 = params[61] + else: + if inputs[0] >= 0.099814616: + var3 = params[62] + else: + var3 = params[63] + if inputs[4] >= -0.5: + if inputs[2] >= -0.44861287: + if inputs[0] >= -0.590233: + if inputs[5] >= 2.5: + var4 = params[64] + else: + var4 = params[65] + else: + if inputs[6] >= 5.5: + var4 = params[66] + else: + var4 = params[67] + else: + if inputs[0] >= -0.7723698: + if inputs[3] >= -1.385: + var4 = params[68] + else: + var4 = params[69] + else: + if inputs[0] >= -0.88130087: + var4 = params[70] + else: + var4 = params[71] + else: + if inputs[2] >= 0.6911151: + if inputs[5] >= 2.5: + if inputs[11] >= 0.5: + var4 = params[72] + else: + var4 = params[73] + else: + if inputs[4] >= -1.5: + var4 = params[74] + else: + var4 = params[75] + else: + if inputs[0] >= -0.88452804: + if inputs[0] >= -0.81109583: + var4 = params[76] + else: + var4 = params[77] + else: + if inputs[1] >= 0.28105152: + var4 = params[78] + else: + var4 = params[79] + if inputs[0] >= -0.6641182: + if inputs[0] >= 0.15620512: + if inputs[5] >= 2.5: + if inputs[6] >= 4.5: + var5 = params[80] + else: + var5 = params[81] + else: + if inputs[9] >= 0.5: + var5 = params[82] + else: + var5 = params[83] + else: + if inputs[4] >= -0.5: + if inputs[1] >= 2.5279005: + var5 = params[84] + else: + var5 = params[85] + else: + if inputs[6] >= 4.5: + var5 = params[86] + else: + var5 = params[87] + else: + if inputs[0] >= -0.88130087: + if inputs[6] >= 4.5: + if inputs[0] >= -0.80135775: + var5 = params[88] + else: + var5 = params[89] + else: + if inputs[1] >= 1.0295516: + var5 = params[90] + else: + var5 = params[91] + else: + if inputs[6] >= 4.5: + if inputs[4] >= -0.5: + var5 = params[92] + else: + var5 = params[93] + else: + if inputs[10] >= 0.5: + var5 = params[94] + else: + var5 = params[95] + if inputs[3] >= 4.165: + if inputs[3] >= 5.5550003: + if inputs[4] >= 0.5: + if inputs[0] >= -0.9836644: + var6 = params[96] + else: + var6 = params[97] + else: + if inputs[0] >= -0.68772745: + var6 = params[98] + else: + var6 = params[99] + else: + if inputs[4] >= -0.5: + if inputs[13] >= 0.5: + var6 = params[100] + else: + var6 = params[101] + else: + if inputs[0] >= -0.8086613: + var6 = params[102] + else: + var6 = params[103] + else: + if inputs[4] >= -0.5: + if inputs[2] >= 1.830843: + if inputs[8] >= 0.5: + var6 = params[104] + else: + var6 = params[105] + else: + if inputs[2] >= -0.44861287: + var6 = params[106] + else: + var6 = params[107] + else: + if inputs[2] >= 1.830843: + if inputs[4] >= -2.5: + var6 = params[108] + else: + var6 = params[109] + else: + if inputs[4] >= -1.5: + var6 = params[110] + else: + var6 = params[111] + if inputs[0] >= -0.456617: + if inputs[5] >= 1.5: + if inputs[0] >= 0.9316878: + if inputs[5] >= 3.5: + var7 = params[112] + else: + var7 = params[113] + else: + if inputs[1] >= -1.218646: + var7 = params[114] + else: + var7 = params[115] + else: + if inputs[4] >= -0.5: + if inputs[2] >= 1.830843: + var7 = params[116] + else: + var7 = params[117] + else: + if inputs[0] >= -0.026384613: + var7 = params[118] + else: + var7 = params[119] + else: + if inputs[0] >= -0.8788663: + if inputs[1] >= 1.0295516: + if inputs[11] >= 0.5: + var7 = params[120] + else: + var7 = params[121] + else: + if inputs[0] >= -0.78997767: + var7 = params[122] + else: + var7 = params[123] + else: + if inputs[1] >= 2.5279005: + if inputs[0] >= -0.9264246: + var7 = params[124] + else: + var7 = params[125] + else: + if inputs[1] >= 0.28105152: + var7 = params[126] + else: + var7 = params[127] + if inputs[10] >= 0.5: + if inputs[8] >= 0.5: + if inputs[0] >= -1.0257874: + if inputs[4] >= 0.5: + var8 = params[128] + else: + var8 = params[129] + else: + if inputs[4] >= 0.5: + var8 = params[130] + else: + var8 = params[131] + else: + if inputs[5] >= 2.5: + if inputs[0] >= 0.10587263: + var8 = params[132] + else: + var8 = params[133] + else: + if inputs[2] >= -0.44861287: + var8 = params[134] + else: + var8 = params[135] + else: + if inputs[2] >= -0.44861287: + if inputs[4] >= -0.5: + if inputs[0] >= 0.11057184: + var8 = params[136] + else: + var8 = params[137] + else: + if inputs[0] >= -0.6677983: + var8 = params[138] + else: + var8 = params[139] + else: + if inputs[0] >= -0.9973091: + if inputs[0] >= -0.95756394: + var8 = params[140] + else: + var8 = params[141] + else: + if inputs[7] >= 0.5: + var8 = params[142] + else: + var8 = params[143] + if inputs[3] >= -5.5550003: + if inputs[3] >= 1.385: + if inputs[6] >= 4.5: + if inputs[6] >= 10.5: + var9 = params[144] + else: + var9 = params[145] + else: + if inputs[0] >= -0.9889864: + var9 = params[146] + else: + var9 = params[147] + else: + if inputs[0] >= -1.1094673: + if inputs[0] >= -1.0898212: + var9 = params[148] + else: + var9 = params[149] + else: + if inputs[6] >= 4.5: + var9 = params[150] + else: + var9 = params[151] + else: + if inputs[0] >= -0.77072793: + if inputs[3] >= -6.9449997: + if inputs[6] >= 7.5: + var9 = params[152] + else: + var9 = params[153] + else: + if inputs[5] >= 2.5: + var9 = params[154] + else: + var9 = params[155] + else: + if inputs[6] >= 4.5: + if inputs[2] >= -0.44861287: + var9 = params[156] + else: + var9 = params[157] + else: + var9 = params[158] + if inputs[4] >= -0.5: + if inputs[9] >= 0.5: + if inputs[6] >= 3.5: + if inputs[2] >= -0.44861287: + var10 = params[159] + else: + var10 = params[160] + else: + if inputs[13] >= 0.5: + var10 = params[161] + else: + var10 = params[162] + else: + if inputs[6] >= 3.5: + if inputs[3] >= 6.9449997: + var10 = params[163] + else: + var10 = params[164] + else: + if inputs[7] >= 0.5: + var10 = params[165] + else: + var10 = params[166] + else: + if inputs[0] >= 0.10360795: + if inputs[6] >= 5.5: + if inputs[5] >= 2.5: + var10 = params[167] + else: + var10 = params[168] + else: + if inputs[8] >= 0.5: + var10 = params[169] + else: + var10 = params[170] + else: + if inputs[0] >= -0.287219: + if inputs[11] >= 0.5: + var10 = params[171] + else: + var10 = params[172] + else: + if inputs[6] >= 5.5: + var10 = params[173] + else: + var10 = params[174] + if inputs[4] >= 0.5: + if inputs[11] >= 0.5: + if inputs[4] >= 1.5: + if inputs[4] >= 2.5: + var11 = params[175] + else: + var11 = params[176] + else: + if inputs[1] >= 2.5279005: + var11 = params[177] + else: + var11 = params[178] + else: + if inputs[1] >= 0.28105152: + if inputs[1] >= 1.0295516: + var11 = params[179] + else: + var11 = params[180] + else: + if inputs[6] >= 9.5: + var11 = params[181] + else: + var11 = params[182] + else: + if inputs[3] >= 24.16: + if inputs[6] >= 7.5: + var11 = params[183] + else: + var11 = params[184] + else: + if inputs[1] >= 1.7780516: + if inputs[6] >= 9.5: + var11 = params[185] + else: + var11 = params[186] + else: + if inputs[11] >= 0.5: + var11 = params[187] + else: + var11 = params[188] + if inputs[6] >= 7.5: + if inputs[0] >= -0.73941875: + if inputs[4] >= 0.5: + if inputs[5] >= 1.5: + var12 = params[189] + else: + var12 = params[190] + else: + if inputs[4] >= -0.5: + var12 = params[191] + else: + var12 = params[192] + else: + if inputs[0] >= -0.97488874: + if inputs[5] >= 1.5: + var12 = params[193] + else: + var12 = params[194] + else: + if inputs[10] >= 0.5: + var12 = params[195] + else: + var12 = params[196] + else: + if inputs[2] >= 0.6911151: + if inputs[0] >= -0.9565449: + if inputs[4] >= -1.5: + var12 = params[197] + else: + var12 = params[198] + else: + if inputs[6] >= 6.5: + var12 = params[199] + else: + var12 = params[200] + else: + if inputs[4] >= -0.5: + if inputs[2] >= -0.44861287: + var12 = params[201] + else: + var12 = params[202] + else: + if inputs[5] >= 1.5: + var12 = params[203] + else: + var12 = params[204] + if inputs[3] >= -5.5550003: + if inputs[0] >= 4.074496: + if inputs[5] >= 1.5: + if inputs[0] >= 4.3374815: + var13 = params[205] + else: + var13 = params[206] + else: + var13 = params[207] + else: + if inputs[0] >= -1.033091: + if inputs[0] >= -0.92800987: + var13 = params[208] + else: + var13 = params[209] + else: + if inputs[0] >= -1.0600407: + var13 = params[210] + else: + var13 = params[211] + else: + if inputs[5] >= 1.5: + if inputs[11] >= 0.5: + if inputs[0] >= -0.60495347: + var13 = params[212] + else: + var13 = params[213] + else: + if inputs[10] >= 0.5: + var13 = params[214] + else: + var13 = params[215] + else: + if inputs[0] >= -0.9573375: + if inputs[0] >= -0.8931339: + var13 = params[216] + else: + var13 = params[217] + else: + var13 = params[218] + if inputs[0] >= 0.8187369: + if inputs[0] >= 1.7982671: + if inputs[0] >= 2.2454846: + if inputs[9] >= 0.5: + var14 = params[219] + else: + var14 = params[220] + else: + if inputs[8] >= 0.5: + var14 = params[221] + else: + var14 = params[222] + else: + if inputs[6] >= 4.5: + if inputs[1] >= 0.28105152: + var14 = params[223] + else: + var14 = params[224] + else: + if inputs[8] >= 0.5: + var14 = params[225] + else: + var14 = params[226] + else: + if inputs[0] >= -0.38686487: + if inputs[1] >= -1.218646: + if inputs[0] >= 0.10847701: + var14 = params[227] + else: + var14 = params[228] + else: + if inputs[2] >= 0.6911151: + var14 = params[229] + else: + var14 = params[230] + else: + if inputs[1] >= -1.218646: + if inputs[1] >= 1.0295516: + var14 = params[231] + else: + var14 = params[232] + else: + if inputs[3] >= 5.5550003: + var14 = params[233] + else: + var14 = params[234] + if inputs[4] >= 1.5: + if inputs[0] >= -0.92030996: + if inputs[0] >= -0.8825464: + if inputs[0] >= -0.84784025: + var15 = params[235] + else: + var15 = params[236] + else: + var15 = params[237] + else: + if inputs[0] >= -1.0717604: + if inputs[3] >= 1.39: + var15 = params[238] + else: + var15 = params[239] + else: + var15 = params[240] + else: + if inputs[0] >= -1.0984836: + if inputs[0] >= -1.0955961: + if inputs[0] >= 4.2805815: + var15 = params[241] + else: + var15 = params[242] + else: + var15 = params[243] + else: + if inputs[6] >= 5.5: + if inputs[0] >= -1.1162047: + var15 = params[244] + else: + var15 = params[245] + else: + if inputs[4] >= -0.5: + var15 = params[246] + else: + var15 = params[247] + if inputs[0] >= 4.316533: + var16 = params[248] + else: + if inputs[0] >= 4.282507: + var16 = params[249] + else: + if inputs[2] >= 1.830843: + if inputs[6] >= 9.5: + var16 = params[250] + else: + var16 = params[251] + else: + if inputs[4] >= -1.5: + var16 = params[252] + else: + var16 = params[253] + if inputs[0] >= 1.0731735: + if inputs[0] >= 1.4191599: + if inputs[0] >= 1.4496765: + if inputs[0] >= 1.5391879: + var17 = params[254] + else: + var17 = params[255] + else: + if inputs[0] >= 1.4420332: + var17 = params[256] + else: + var17 = params[257] + else: + if inputs[13] >= 0.5: + if inputs[0] >= 1.2611985: + var17 = params[258] + else: + var17 = params[259] + else: + if inputs[0] >= 1.248573: + var17 = params[260] + else: + var17 = params[261] + else: + if inputs[0] >= 1.0697765: + var17 = params[262] + else: + if inputs[3] >= -12.775: + if inputs[3] >= -8.335: + var17 = params[263] + else: + var17 = params[264] + else: + if inputs[4] >= -0.5: + var17 = params[265] + else: + var17 = params[266] + if inputs[6] >= 5.5: + if inputs[8] >= 0.5: + if inputs[1] >= -0.46879724: + if inputs[0] >= -0.59045947: + var18 = params[267] + else: + var18 = params[268] + else: + if inputs[11] >= 0.5: + var18 = params[269] + else: + var18 = params[270] + else: + if inputs[0] >= -1.0908968: + if inputs[0] >= -0.9190078: + var18 = params[271] + else: + var18 = params[272] + else: + var18 = params[273] + else: + if inputs[0] >= -0.69622004: + if inputs[0] >= -0.6800841: + if inputs[7] >= 0.5: + var18 = params[274] + else: + var18 = params[275] + else: + if inputs[1] >= 1.0295516: + var18 = params[276] + else: + var18 = params[277] + else: + if inputs[0] >= -0.7900909: + if inputs[7] >= 0.5: + var18 = params[278] + else: + var18 = params[279] + else: + if inputs[0] >= -0.83668673: + var18 = params[280] + else: + var18 = params[281] + if inputs[3] >= 5.5550003: + if inputs[5] >= 1.5: + if inputs[6] >= 3.5: + if inputs[1] >= 1.0295516: + var19 = params[282] + else: + var19 = params[283] + else: + if inputs[7] >= 0.5: + var19 = params[284] + else: + var19 = params[285] + else: + if inputs[9] >= 0.5: + var19 = params[286] + else: + if inputs[6] >= 5.5: + var19 = params[287] + else: + var19 = params[288] + else: + if inputs[3] >= 1.385: + if inputs[2] >= 0.6911151: + if inputs[10] >= 0.5: + var19 = params[289] + else: + var19 = params[290] + else: + if inputs[7] >= 0.5: + var19 = params[291] + else: + var19 = params[292] + else: + if inputs[6] >= 3.5: + if inputs[1] >= 0.28105152: + var19 = params[293] + else: + var19 = params[294] + else: + if inputs[7] >= 0.5: + var19 = params[295] + else: + var19 = params[296] + if inputs[3] >= 21.385: + if inputs[2] >= -0.44861287: + if inputs[2] >= 0.6911151: + var20 = params[297] + else: + var20 = params[298] + else: + var20 = params[299] + else: + if inputs[4] >= -0.5: + if inputs[3] >= 9.725: + if inputs[1] >= -1.218646: + var20 = params[300] + else: + var20 = params[301] + else: + if inputs[8] >= 0.5: + var20 = params[302] + else: + var20 = params[303] + else: + if inputs[1] >= 0.28105152: + if inputs[1] >= 1.0295516: + var20 = params[304] + else: + var20 = params[305] + else: + if inputs[6] >= 10.5: + var20 = params[306] + else: + var20 = params[307] + if inputs[6] >= 9.5: + if inputs[5] >= 2.5: + if inputs[6] >= 11.5: + if inputs[8] >= 0.5: + var21 = params[308] + else: + var21 = params[309] + else: + if inputs[0] >= -0.655569: + var21 = params[310] + else: + var21 = params[311] + else: + if inputs[4] >= -0.5: + if inputs[0] >= 0.16022491: + var21 = params[312] + else: + var21 = params[313] + else: + if inputs[0] >= -0.35748065: + var21 = params[314] + else: + var21 = params[315] + else: + if inputs[5] >= 3.5: + if inputs[2] >= -0.44861287: + if inputs[6] >= 7.5: + var21 = params[316] + else: + var21 = params[317] + else: + if inputs[0] >= 0.22833514: + var21 = params[318] + else: + var21 = params[319] + else: + if inputs[2] >= 0.6911151: + if inputs[0] >= 1.5724787: + var21 = params[320] + else: + var21 = params[321] + else: + if inputs[0] >= -0.7248682: + var21 = params[322] + else: + var21 = params[323] + if inputs[0] >= -0.9995737: + if inputs[0] >= -0.99679947: + if inputs[4] >= -1.5: + if inputs[0] >= -0.70408976: + var22 = params[324] + else: + var22 = params[325] + else: + if inputs[0] >= -0.4400282: + var22 = params[326] + else: + var22 = params[327] + else: + if inputs[3] >= 4.165: + var22 = params[328] + else: + if inputs[11] >= 0.5: + var22 = params[329] + else: + var22 = params[330] + else: + if inputs[6] >= 2.5: + if inputs[0] >= -1.0424328: + if inputs[0] >= -1.0356953: + var22 = params[331] + else: + var22 = params[332] + else: + if inputs[3] >= 4.165: + var22 = params[333] + else: + var22 = params[334] + else: + var22 = params[335] + if inputs[0] >= 3.4627495: + if inputs[0] >= 3.604858: + if inputs[6] >= 3.5: + if inputs[0] >= 4.105069: + var23 = params[336] + else: + var23 = params[337] + else: + if inputs[0] >= 3.9084382: + var23 = params[338] + else: + var23 = params[339] + else: + if inputs[8] >= 0.5: + var23 = params[340] + else: + if inputs[0] >= 3.5178943: + var23 = params[341] + else: + var23 = params[342] + else: + if inputs[0] >= 3.2692895: + if inputs[0] >= 3.395262: + var23 = params[343] + else: + if inputs[0] >= 3.3073926: + var23 = params[344] + else: + var23 = params[345] + else: + if inputs[0] >= 3.182835: + var23 = params[346] + else: + if inputs[0] >= -0.70969486: + var23 = params[347] + else: + var23 = params[348] + if inputs[4] >= 0.5: + if inputs[0] >= -0.8515203: + if inputs[3] >= -1.39: + if inputs[0] >= -0.80883116: + var24 = params[349] + else: + var24 = params[350] + else: + if inputs[3] >= -5.5550003: + var24 = params[351] + else: + var24 = params[352] + else: + if inputs[1] >= 0.28105152: + if inputs[6] >= 6.5: + var24 = params[353] + else: + var24 = params[354] + else: + if inputs[0] >= -0.97336006: + var24 = params[355] + else: + var24 = params[356] + else: + if inputs[0] >= 3.9279711: + if inputs[9] >= 0.5: + if inputs[0] >= 4.2983027: + var24 = params[357] + else: + var24 = params[358] + else: + if inputs[0] >= 4.2805815: + var24 = params[359] + else: + var24 = params[360] + else: + if inputs[5] >= 1.5: + if inputs[6] >= 2.5: + var24 = params[361] + else: + var24 = params[362] + else: + if inputs[6] >= 4.5: + var24 = params[363] + else: + var24 = params[364] + if inputs[0] >= -0.96871746: + if inputs[0] >= -0.95756394: + if inputs[0] >= -0.9499773: + if inputs[0] >= -0.9480523: + var25 = params[365] + else: + var25 = params[366] + else: + if inputs[9] >= 0.5: + var25 = params[367] + else: + var25 = params[368] + else: + if inputs[13] >= 0.5: + if inputs[3] >= 1.385: + var25 = params[369] + else: + var25 = params[370] + else: + if inputs[0] >= -0.9611874: + var25 = params[371] + else: + var25 = params[372] + else: + if inputs[0] >= -0.97296375: + if inputs[2] >= -0.44861287: + if inputs[0] >= -0.97086895: + var25 = params[373] + else: + var25 = params[374] + else: + var25 = params[375] + else: + if inputs[0] >= -0.9747189: + var25 = params[376] + else: + if inputs[6] >= 7.5: + var25 = params[377] + else: + var25 = params[378] + if inputs[0] >= 0.10360795: + if inputs[6] >= 4.5: + if inputs[6] >= 5.5: + if inputs[1] >= 1.7780516: + var26 = params[379] + else: + var26 = params[380] + else: + if inputs[0] >= 0.38210684: + var26 = params[381] + else: + var26 = params[382] + else: + if inputs[1] >= 1.0295516: + if inputs[4] >= -0.5: + var26 = params[383] + else: + var26 = params[384] + else: + if inputs[1] >= -0.46879724: + var26 = params[385] + else: + var26 = params[386] + else: + if inputs[6] >= 4.5: + if inputs[6] >= 5.5: + if inputs[0] >= -0.7606501: + var26 = params[387] + else: + var26 = params[388] + else: + if inputs[0] >= -0.6874443: + var26 = params[389] + else: + var26 = params[390] + else: + if inputs[0] >= -0.22697854: + if inputs[0] >= -0.2162213: + var26 = params[391] + else: + var26 = params[392] + else: + if inputs[9] >= 0.5: + var26 = params[393] + else: + var26 = params[394] + if inputs[3] >= -4.165: + if inputs[11] >= 0.5: + if inputs[5] >= 1.5: + if inputs[8] >= 0.5: + var27 = params[395] + else: + var27 = params[396] + else: + if inputs[3] >= -1.385: + var27 = params[397] + else: + var27 = params[398] + else: + if inputs[5] >= 1.5: + if inputs[8] >= 0.5: + var27 = params[399] + else: + var27 = params[400] + else: + if inputs[2] >= 0.6911151: + var27 = params[401] + else: + var27 = params[402] + else: + if inputs[8] >= 0.5: + if inputs[2] >= 1.830843: + var27 = params[403] + else: + if inputs[3] >= -11.115: + var27 = params[404] + else: + var27 = params[405] + else: + if inputs[5] >= 2.5: + if inputs[1] >= 0.6546272: + var27 = params[406] + else: + var27 = params[407] + else: + if inputs[4] >= -0.5: + var27 = params[408] + else: + var27 = params[409] + if inputs[4] >= -0.5: + if inputs[0] >= -1.0262969: + if inputs[0] >= -0.9953841: + if inputs[0] >= -0.98751426: + var28 = params[410] + else: + var28 = params[411] + else: + if inputs[0] >= -0.99696934: + var28 = params[412] + else: + var28 = params[413] + else: + if inputs[0] >= -1.0285616: + var28 = params[414] + else: + if inputs[1] >= 1.0295516: + var28 = params[415] + else: + var28 = params[416] + else: + if inputs[0] >= -0.5803817: + if inputs[6] >= 10.5: + if inputs[4] >= -1.5: + var28 = params[417] + else: + var28 = params[418] + else: + if inputs[1] >= 0.28105152: + var28 = params[419] + else: + var28 = params[420] + else: + if inputs[0] >= -0.734946: + if inputs[0] >= -0.73285115: + var28 = params[421] + else: + var28 = params[422] + else: + if inputs[0] >= -0.794507: + var28 = params[423] + else: + var28 = params[424] + if inputs[0] >= -0.875073: + if inputs[0] >= -0.8619379: + if inputs[1] >= 0.28105152: + if inputs[5] >= 1.5: + var29 = params[425] + else: + var29 = params[426] + else: + if inputs[0] >= -0.6480956: + var29 = params[427] + else: + var29 = params[428] + else: + if inputs[1] >= 0.28105152: + if inputs[1] >= 1.0295516: + var29 = params[429] + else: + var29 = params[430] + else: + if inputs[3] >= 5.5550003: + var29 = params[431] + else: + var29 = params[432] + else: + if inputs[0] >= -0.8769413: + if inputs[6] >= 3.5: + var29 = params[433] + else: + var29 = params[434] + else: + if inputs[6] >= 4.5: + if inputs[0] >= -0.8780737: + var29 = params[435] + else: + var29 = params[436] + else: + if inputs[0] >= -0.9050234: + var29 = params[437] + else: + var29 = params[438] + return 0.5 + (var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20 + var21 + var22 + var23 + var24 + var25 + var26 + var27 + var28 + var29) + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/speedRelative_priority.py b/matsim/scenariogen/network/ref_model/germany/speedRelative_priority.py new file mode 100644 index 0000000..a69e500 --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/speedRelative_priority.py @@ -0,0 +1,1197 @@ +# -*- coding: utf-8 -*- +"""XGBRegressor(alpha=0.3391108329877409, base_score=0.5, booster='gbtree', + callbacks=None, colsample_bylevel=1, colsample_bynode=0.9, + colsample_bytree=0.9, early_stopping_rounds=None, + enable_categorical=False, eta=0.9452722646544713, + eval_metric='mae', feature_types=None, gamma=0.011255353367418076, + gpu_id=-1, grow_policy='depthwise', importance_type=None, + interaction_constraints='', lambda=0.19373723699071155, + learning_rate=0.945272267, max_bin=256, max_cat_threshold=64, + max_cat_to_onehot=4, max_delta_step=0, max_depth=4, max_leaves=0, + min_child_weight=7, missing=nan, monotone_constraints='()', + n_estimators=30, n_jobs=0, ...) +Error: 0.047661""" +def features(ft, data): + data[0] = (ft.get("length") - 136.6196185884635) / 100.86082059541495 + data[1] = (ft.get("speed") - 13.986934871911906) / 4.71750654884318 + data[2] = (ft.get("num_lanes") - 1.2681719632566897) / 0.6868784909822384 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [0.3608418, 0.34890103, 0.3805294, 0.367862, 0.3214511, 0.25815126, 0.3545712, 0.32907134, 0.3583316, 0.37464577, 0.2698579, 0.22336875, 0.07104687, 0.053362835, 0.041006442, 0.025985682, 0.016914705, 0.030068675, 0.02692251, 0.007944532, -0.057301573, -0.01079493, 0.024668941, 0.065943725, 0.0073271547, -0.010634697, -0.042568587, -0.005014392, 0.0064422577, -0.008124101, -0.0009762109, -0.021804716, -0.041783743, -0.019399365, -0.013127809, 0.010771646, -0.02702811, -0.0071091, -0.019728376, -8.590933e-06, 0.0075863185, -0.000997167, 0.005540737, -0.020661844, 0.070752524, -0.010993776, 0.0061843814, 0.04742048, 0.0, -0.04123083, 0.0020972916, 0.01982593, -0.016842471, 0.002185143, -0.010056106, 0.005740708, -0.0010336025, -0.008926538, 0.0066137724, -0.055676598, -0.04465999, 0.011639535, 0.023085762, 0.0429667, -0.0047127116, 0.0066190767, -0.01991489, 0.012343046, -0.00030098224, 0.03327441, -0.02933379, 0.00227875, 0.013856811, -0.002690753, 0.0011580876, 0.009282305, -0.0032510154, 0.0037855355, 0.016429743, -0.0069674533, -0.0029329038, -0.016298464, -0.0022534884, 0.012884261, 0.0053116493, 0.021705957, -0.0211505, -0.0044319867, 0.005657457, -0.012777755, 0.0024879414, -0.016855681, -0.0006641551, -0.03385302, -0.039455965, -0.008037433, 0.054003634, 0.0, 0.00022664567, -0.007361894, -0.00042022497, 0.002072075, -0.02629097, -0.0057141623, 0.0, 0.02430369, 0.008704219, 0.00015066605, 0.029546643, 0.00025354454, -0.001516591, -0.031973023, -0.011100723, -0.0027563435, 0.009762235, 0.05289628, -0.038872607, 0.0, 0.011091023, -0.0006365045, -0.00012944487, 0.026204467, 0.0, 0.016556863, 0.0, -0.018513616, 0.019378055, 0.021001568, -0.021603102, 0.00015185689, -0.003958503, 0.013025162, -0.029794283, -0.02102098, -0.0009905503, 0.0024388963, -0.018523036, -0.0026774986, 0.02191896, 0.040357094, 0.0007669913, 0.0, 0.030865172, 0.012599033, 0.001843638, 0.00020173307, -0.006769137, -0.00031856322, 0.021274647, -0.024304036, -0.0033816784, 0.057870377, 0.0, -0.025712753, 0.012415222, 2.5677633e-05, -0.003756883, 0.006571175, 0.0011496701, 0.000138112, -0.0034407757, -0.0058021317, -0.056079507, -0.00035336296, 0.017468143, 0.012312527, -0.0016519147, -0.047752056, -0.035473906, 0.0, -0.0015261818, 0.015923837, 0.015606506, 0.0, -0.054741237, 0.0, -0.0025508015, 0.0022049379, -0.058122016, -0.0013978699, -0.026567709, -0.00024357338, 0.013887028, -0.00023815365, -0.0035327831, 0.015097718, -0.008128642, 8.880287e-05, 0.0067553106, -0.039901286, -0.0010965111, -0.012228503, 0.0025326295, 0.009830933, -0.004871507, 0.0007961357, -0.001985299, -0.00078088214, -0.015130762, 0.026426077, -0.011166116, 0.0047168666, -0.027053688, 0.0, 0.02502007, 0.0014169022, 0.027513124, 0.0, -0.006609659, 0.0067208144, 0.0007307121, -0.0007767367, -0.008880603, -0.0024207279, 0.0018657955, 0.007664186, -0.009534747, 0.00017667886, 0.0024938702, 0.000160656, -0.016127694, 0.031065073, -0.04356924, 0.0, 0.012454214, 9.2470545e-05, 0.013130494, -0.008663621, 0.020356651, 0.007865714, -0.0008692618, 0.004226911, -0.04767229, -0.00800842, 0.022846434, -0.0005788225, 0.009330586, -0.0019520844, 0.014785738, -0.041578304, 0.005497856, -0.032945607, 0.0, 0.0, -0.0013004113, 0.014651219, 0.0021028256, -0.008371005, -0.025870936, 0.0024653892, -7.002424e-05, 0.005613593, -0.0016404922, 0.008008113, -0.07883139, -0.008216268, 3.8600334e-05, -0.017916556, 0.0024656826, -0.060181007, 0.00026912204, 0.031037448, -0.009628712, -0.0120592415, 0.012064624, 0.0031491993, 0.013506664, 0.07318686, 0.00520229, -0.015804362, 0.011408404, 0.011172467, -0.001980757, -0.0025338277, 0.04618932, 0.0, -0.036171604, -0.0072938483, -0.0045603677, 8.558682e-05, -0.0021300775, 0.0059226053, 0.0015338295, -0.008351804, -0.0120370975, 0.0016534014, -0.009641722, 0.0024682067, -0.005995545, 0.0012730533, 0.0062334156, -0.0021061848, 0.0030723317, -0.00076261914, -0.000409436, 0.0007906831, 0.0, -0.061738558, -0.003120113, 0.028220955, 0.0022685728, -0.078828804, -0.0061356295, 8.381979e-05, 0.009887914, -0.00015392517, 0.008531038, 0.014667562, -0.01351278, 0.032202978, -0.02082266, 0.010006648, -0.03738514, 0.018855287, -0.058886614, -0.002497527, 0.0, 0.0059951753, 0.004368303, -0.0039021652, 0.0, -0.024193443, 0.0037743084, -0.0009127918, 0.0060951156, -0.0035422945, -0.00077070843, 0.001098186, 0.045046873, 0.0, 0.018084358, 0.0, 0.0, 0.011261725, -0.01039281, -0.0030560154, 0.016621474, 0.0, 0.007005952, 0.00014934929, -0.0041960427, -0.04577778, -0.001939774, 0.0002733276, 0.00912787, 0.004038844, -0.004946535, -0.026469113, 0.0, -0.0036243391, -3.5375142e-05, -0.0047778115, 0.014300297, 0.0039307415, 0.0, 0.0023882187, 0.00014195738, 0.011001494, 0.0011960509, 4.1772782e-05, -0.059463408, 0.0, 0.025786124, 0.0, -0.03289172, 0.003945976, -0.020250496, -6.1883075e-05, 0.009469738, -0.0036501247, 0.019228429, -0.005557274, 9.671706e-05, -0.0074998294, 0.02349894, 0.0018955221, 0.00071145897, -0.02839732, 0.0, -5.2149077e-05, -0.04872126, 0.022880139, 0.0, -0.017270446, 0.010601865, -0.00931396, 0.037245013, 0.0, 0.01629717, 0.0, -0.019269185, 0.014912463, 0.00050286605, -0.00011430594, 0.0055607953, -0.0004733346, 0.0, -0.018639635, 0.0, -0.013346717, 0.028006427, 0.004957935, 0.0, -0.018996669, -0.0012800392, 0.019457394] +def score(params, inputs): + if inputs[0] >= -0.18931651: + if inputs[3] >= -5.5550003: + if inputs[5] >= 1.5: + if inputs[9] >= 0.5: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[11] >= 0.5: + var0 = params[2] + else: + var0 = params[3] + else: + if inputs[3] >= -12.775: + var0 = params[4] + else: + var0 = params[5] + else: + if inputs[3] >= -4.165: + if inputs[1] >= -0.31519508: + if inputs[11] >= 0.5: + var0 = params[6] + else: + var0 = params[7] + else: + if inputs[6] >= 2.5: + var0 = params[8] + else: + var0 = params[9] + else: + if inputs[0] >= -0.72341883: + var0 = params[10] + else: + var0 = params[11] + if inputs[0] >= -1.1267469: + if inputs[2] >= 0.3375095: + if inputs[0] >= 1.1064789: + if inputs[12] >= 0.5: + var1 = params[12] + else: + var1 = params[13] + else: + if inputs[4] >= -0.5: + var1 = params[14] + else: + var1 = params[15] + else: + if inputs[9] >= 0.5: + if inputs[0] >= -0.18297113: + var1 = params[16] + else: + var1 = params[17] + else: + if inputs[3] >= 1.385: + var1 = params[18] + else: + var1 = params[19] + else: + if inputs[2] >= 0.3375095: + if inputs[0] >= -1.1286306: + var1 = params[20] + else: + if inputs[5] >= 1.5: + var1 = params[21] + else: + var1 = params[22] + else: + if inputs[3] >= 12.5: + var1 = params[23] + else: + if inputs[9] >= 0.5: + var1 = params[24] + else: + var1 = params[25] + if inputs[5] >= 2.5: + if inputs[0] >= -0.6054345: + if inputs[1] >= -0.60984224: + if inputs[7] >= 0.5: + var2 = params[26] + else: + var2 = params[27] + else: + if inputs[0] >= -0.37278715: + var2 = params[28] + else: + var2 = params[29] + else: + if inputs[9] >= 0.5: + if inputs[0] >= -0.7754212: + var2 = params[30] + else: + var2 = params[31] + else: + if inputs[1] >= -0.60984224: + var2 = params[32] + else: + var2 = params[33] + else: + if inputs[1] >= 0.8623338: + if inputs[4] >= 0.5: + if inputs[4] >= 1.5: + var2 = params[34] + else: + var2 = params[35] + else: + if inputs[1] >= 3.5120387: + var2 = params[36] + else: + var2 = params[37] + else: + if inputs[7] >= 0.5: + if inputs[1] >= -0.9044894: + var2 = params[38] + else: + var2 = params[39] + else: + if inputs[0] >= -0.82038414: + var2 = params[40] + else: + var2 = params[41] + if inputs[12] >= 0.5: + if inputs[1] >= 3.5120387: + if inputs[0] >= -0.58545643: + if inputs[0] >= 0.43689296: + var3 = params[42] + else: + var3 = params[43] + else: + if inputs[0] >= -1.1621423: + var3 = params[44] + else: + var3 = params[45] + else: + if inputs[0] >= 1.1714696: + var3 = params[46] + else: + if inputs[2] >= 0.3375095: + var3 = params[47] + else: + var3 = params[48] + else: + if inputs[13] >= 0.5: + if inputs[6] >= 2.5: + if inputs[9] >= 0.5: + var3 = params[49] + else: + var3 = params[50] + else: + if inputs[0] >= -1.049363: + var3 = params[51] + else: + var3 = params[52] + else: + if inputs[11] >= 0.5: + if inputs[2] >= 1.7933712: + var3 = params[53] + else: + var3 = params[54] + else: + if inputs[0] >= 0.7997692: + var3 = params[55] + else: + var3 = params[56] + if inputs[3] >= 5.835: + if inputs[0] >= -0.21107918: + if inputs[0] >= 0.64663744: + var4 = params[57] + else: + if inputs[0] >= -0.20285001: + var4 = params[58] + else: + var4 = params[59] + else: + if inputs[5] >= 1.5: + if inputs[1] >= -0.60984224: + var4 = params[60] + else: + var4 = params[61] + else: + if inputs[0] >= -0.68727994: + var4 = params[62] + else: + var4 = params[63] + else: + if inputs[4] >= 0.5: + if inputs[0] >= -0.15991956: + if inputs[8] >= 0.5: + var4 = params[64] + else: + var4 = params[65] + else: + if inputs[7] >= 0.5: + var4 = params[66] + else: + var4 = params[67] + else: + if inputs[6] >= 1.5: + if inputs[0] >= -1.2913301: + var4 = params[68] + else: + var4 = params[69] + else: + if inputs[1] >= -0.31519508: + var4 = params[70] + else: + var4 = params[71] + if inputs[5] >= 1.5: + if inputs[0] >= 0.17985559: + if inputs[9] >= 0.5: + if inputs[2] >= 0.3375095: + var5 = params[72] + else: + var5 = params[73] + else: + if inputs[3] >= 2.775: + var5 = params[74] + else: + var5 = params[75] + else: + if inputs[9] >= 0.5: + if inputs[10] >= 0.5: + var5 = params[76] + else: + var5 = params[77] + else: + if inputs[1] >= 1.4505682: + var5 = params[78] + else: + var5 = params[79] + else: + if inputs[0] >= -0.1899114: + if inputs[6] >= 1.5: + if inputs[4] >= -0.5: + var5 = params[80] + else: + var5 = params[81] + else: + if inputs[1] >= 2.3345098: + var5 = params[82] + else: + var5 = params[83] + else: + if inputs[5] >= 0.5: + if inputs[6] >= 1.5: + var5 = params[84] + else: + var5 = params[85] + else: + if inputs[1] >= -0.60984224: + var5 = params[86] + else: + var5 = params[87] + if inputs[1] >= 0.8623338: + if inputs[0] >= -0.49880242: + if inputs[10] >= 0.5: + if inputs[11] >= 0.5: + var6 = params[88] + else: + var6 = params[89] + else: + if inputs[0] >= 1.5952713: + var6 = params[90] + else: + var6 = params[91] + else: + if inputs[5] >= 1.5: + if inputs[0] >= -0.6634352: + var6 = params[92] + else: + var6 = params[93] + else: + if inputs[0] >= -0.5407909: + var6 = params[94] + else: + var6 = params[95] + else: + if inputs[11] >= 0.5: + if inputs[7] >= 0.5: + if inputs[0] >= -1.1048355: + var6 = params[96] + else: + var6 = params[97] + else: + if inputs[0] >= -0.45141035: + var6 = params[98] + else: + var6 = params[99] + else: + if inputs[0] >= -1.249639: + if inputs[0] >= -0.18971309: + var6 = params[100] + else: + var6 = params[101] + else: + if inputs[0] >= -1.2646598: + var6 = params[102] + else: + var6 = params[103] + if inputs[0] >= 2.4748993: + if inputs[3] >= -5.5550003: + if inputs[7] >= 0.5: + if inputs[3] >= 1.39: + var7 = params[104] + else: + var7 = params[105] + else: + if inputs[1] >= 1.4505682: + var7 = params[106] + else: + var7 = params[107] + else: + var7 = params[108] + else: + if inputs[0] >= -1.1069176: + if inputs[0] >= -1.0723155: + if inputs[0] >= -0.58317614: + var7 = params[109] + else: + var7 = params[110] + else: + if inputs[7] >= 0.5: + var7 = params[111] + else: + var7 = params[112] + else: + if inputs[5] >= 0.5: + if inputs[10] >= 0.5: + var7 = params[113] + else: + var7 = params[114] + else: + var7 = params[115] + if inputs[6] >= 5.5: + if inputs[4] >= -0.5: + if inputs[8] >= 0.5: + if inputs[6] >= 6.5: + var8 = params[116] + else: + var8 = params[117] + else: + if inputs[10] >= 0.5: + var8 = params[118] + else: + var8 = params[119] + else: + if inputs[10] >= 0.5: + if inputs[1] >= 0.8623338: + var8 = params[120] + else: + var8 = params[121] + else: + var8 = params[122] + else: + if inputs[1] >= 3.5120387: + if inputs[2] >= 3.2492328: + if inputs[1] >= 4.747861: + var8 = params[123] + else: + var8 = params[124] + else: + if inputs[3] >= -1.39: + var8 = params[125] + else: + var8 = params[126] + else: + if inputs[4] >= 2.5: + if inputs[8] >= 0.5: + var8 = params[127] + else: + var8 = params[128] + else: + if inputs[3] >= -1.385: + var8 = params[129] + else: + var8 = params[130] + if inputs[5] >= 1.5: + if inputs[1] >= -0.9044894: + if inputs[3] >= 1.385: + if inputs[2] >= 0.3375095: + var9 = params[131] + else: + var9 = params[132] + else: + if inputs[4] >= 0.5: + var9 = params[133] + else: + var9 = params[134] + else: + if inputs[3] >= 5.5550003: + if inputs[0] >= -0.824697: + var9 = params[135] + else: + var9 = params[136] + else: + if inputs[9] >= 0.5: + var9 = params[137] + else: + var9 = params[138] + else: + if inputs[3] >= 1.385: + if inputs[0] >= -0.8564735: + if inputs[9] >= 0.5: + var9 = params[139] + else: + var9 = params[140] + else: + if inputs[3] >= 8.335: + var9 = params[141] + else: + var9 = params[142] + else: + if inputs[1] >= 1.4505682: + if inputs[0] >= 2.2239594: + var9 = params[143] + else: + var9 = params[144] + else: + if inputs[3] >= -1.385: + var9 = params[145] + else: + var9 = params[146] + if inputs[7] >= 0.5: + if inputs[0] >= -0.90738523: + if inputs[0] >= -0.103158176: + if inputs[6] >= 2.5: + var10 = params[147] + else: + var10 = params[148] + else: + if inputs[1] >= -0.9044894: + var10 = params[149] + else: + var10 = params[150] + else: + if inputs[1] >= -0.60984224: + if inputs[6] >= 2.5: + var10 = params[151] + else: + var10 = params[152] + else: + if inputs[3] >= 5.5550003: + var10 = params[153] + else: + var10 = params[154] + else: + if inputs[6] >= 2.5: + if inputs[0] >= -0.19030797: + if inputs[0] >= -0.02612133: + var10 = params[155] + else: + var10 = params[156] + else: + if inputs[0] >= -0.41636205: + var10 = params[157] + else: + var10 = params[158] + else: + if inputs[8] >= 0.5: + if inputs[0] >= -0.8501281: + var10 = params[159] + else: + var10 = params[160] + else: + if inputs[0] >= -1.0568982: + var10 = params[161] + else: + var10 = params[162] + if inputs[0] >= -0.8138405: + if inputs[0] >= -0.8104695: + if inputs[3] >= -5.5550003: + if inputs[0] >= -0.80809: + var11 = params[163] + else: + var11 = params[164] + else: + if inputs[0] >= 0.62140465: + var11 = params[165] + else: + var11 = params[166] + else: + if inputs[2] >= 0.3375095: + var11 = params[167] + else: + if inputs[0] >= -0.81126267: + var11 = params[168] + else: + var11 = params[169] + else: + if inputs[5] >= 2.5: + if inputs[9] >= 0.5: + if inputs[1] >= -0.60984224: + var11 = params[170] + else: + var11 = params[171] + else: + if inputs[0] >= -1.164026: + var11 = params[172] + else: + var11 = params[173] + else: + if inputs[13] >= 0.5: + if inputs[3] >= 2.775: + var11 = params[174] + else: + var11 = params[175] + else: + if inputs[2] >= 0.3375095: + var11 = params[176] + else: + var11 = params[177] + if inputs[1] >= 5.042508: + if inputs[5] >= 1.5: + if inputs[0] >= 0.9575609: + var12 = params[178] + else: + var12 = params[179] + else: + if inputs[0] >= 0.47868323: + if inputs[4] >= -0.5: + var12 = params[180] + else: + var12 = params[181] + else: + var12 = params[182] + else: + if inputs[6] >= 3.5: + if inputs[0] >= -1.1479642: + if inputs[5] >= 2.5: + var12 = params[183] + else: + var12 = params[184] + else: + if inputs[4] >= -0.5: + var12 = params[185] + else: + var12 = params[186] + else: + if inputs[0] >= -1.2884054: + if inputs[4] >= -0.5: + var12 = params[187] + else: + var12 = params[188] + else: + if inputs[5] >= 1.5: + var12 = params[189] + else: + var12 = params[190] + if inputs[3] >= -5.835: + if inputs[6] >= 4.5: + if inputs[0] >= -0.2966922: + if inputs[8] >= 0.5: + var13 = params[191] + else: + var13 = params[192] + else: + if inputs[10] >= 0.5: + var13 = params[193] + else: + var13 = params[194] + else: + if inputs[0] >= -0.5833248: + if inputs[1] >= -0.9044894: + var13 = params[195] + else: + var13 = params[196] + else: + if inputs[5] >= 0.5: + var13 = params[197] + else: + var13 = params[198] + else: + if inputs[7] >= 0.5: + var13 = params[199] + else: + if inputs[0] >= 0.71465194: + if inputs[0] >= 2.5458884: + var13 = params[200] + else: + var13 = params[201] + else: + if inputs[0] >= -0.6475718: + var13 = params[202] + else: + var13 = params[203] + if inputs[3] >= 2.775: + if inputs[9] >= 0.5: + if inputs[0] >= -0.8122046: + if inputs[3] >= 6.9449997: + var14 = params[204] + else: + var14 = params[205] + else: + var14 = params[206] + else: + if inputs[0] >= 1.137264: + if inputs[0] >= 2.1696272: + var14 = params[207] + else: + var14 = params[208] + else: + if inputs[10] >= 0.5: + var14 = params[209] + else: + var14 = params[210] + else: + if inputs[10] >= 0.5: + if inputs[5] >= 1.5: + if inputs[0] >= -0.79936504: + var14 = params[211] + else: + var14 = params[212] + else: + if inputs[0] >= -0.27433467: + var14 = params[213] + else: + var14 = params[214] + else: + if inputs[2] >= 0.3375095: + if inputs[2] >= 1.7933712: + var14 = params[215] + else: + var14 = params[216] + else: + if inputs[0] >= -0.8309928: + var14 = params[217] + else: + var14 = params[218] + if inputs[0] >= -1.2908344: + if inputs[0] >= -1.2877609: + if inputs[0] >= -1.2833984: + if inputs[0] >= -1.2753179: + var15 = params[219] + else: + var15 = params[220] + else: + var15 = params[221] + else: + if inputs[0] >= -1.2893472: + var15 = params[222] + else: + var15 = params[223] + else: + var15 = params[224] + if inputs[0] >= -0.943425: + if inputs[0] >= -0.89028245: + if inputs[4] >= -1.5: + var16 = params[225] + else: + if inputs[2] >= 3.2492328: + var16 = params[226] + else: + var16 = params[227] + else: + if inputs[3] >= 6.9449997: + var16 = params[228] + else: + if inputs[0] >= -0.92052215: + var16 = params[229] + else: + var16 = params[230] + else: + if inputs[0] >= -0.9524473: + if inputs[1] >= 0.27409926: + var16 = params[231] + else: + if inputs[2] >= 0.3375095: + var16 = params[232] + else: + var16 = params[233] + else: + if inputs[4] >= 0.5: + if inputs[1] >= 0.27409926: + var16 = params[234] + else: + var16 = params[235] + else: + if inputs[0] >= -0.9611722: + var16 = params[236] + else: + var16 = params[237] + if inputs[6] >= 7.5: + if inputs[2] >= 3.2492328: + if inputs[0] >= -0.7591116: + var17 = params[238] + else: + if inputs[0] >= -0.8616787: + var17 = params[239] + else: + var17 = params[240] + else: + if inputs[1] >= -0.60984224: + if inputs[0] >= -0.79941463: + var17 = params[241] + else: + var17 = params[242] + else: + var17 = params[243] + else: + if inputs[4] >= 1.5: + if inputs[13] >= 0.5: + if inputs[6] >= 3.5: + var17 = params[244] + else: + var17 = params[245] + else: + if inputs[11] >= 0.5: + var17 = params[246] + else: + var17 = params[247] + else: + if inputs[13] >= 0.5: + if inputs[6] >= 2.5: + var17 = params[248] + else: + var17 = params[249] + else: + if inputs[5] >= 0.5: + var17 = params[250] + else: + var17 = params[251] + if inputs[6] >= 1.5: + if inputs[1] >= 0.8623338: + if inputs[0] >= -0.96910393: + if inputs[0] >= -0.7581202: + var18 = params[252] + else: + var18 = params[253] + else: + if inputs[0] >= -0.97832453: + var18 = params[254] + else: + var18 = params[255] + else: + if inputs[0] >= -1.0342927: + if inputs[0] >= -1.030773: + var18 = params[256] + else: + var18 = params[257] + else: + if inputs[4] >= -1.5: + var18 = params[258] + else: + var18 = params[259] + else: + if inputs[0] >= -0.58600175: + var18 = params[260] + else: + if inputs[13] >= 0.5: + if inputs[4] >= 0.5: + var18 = params[261] + else: + var18 = params[262] + else: + if inputs[0] >= -1.2735829: + var18 = params[263] + else: + var18 = params[264] + if inputs[1] >= 1.4505682: + if inputs[2] >= 0.3375095: + if inputs[10] >= 0.5: + if inputs[6] >= 2.5: + var19 = params[265] + else: + var19 = params[266] + else: + if inputs[2] >= 1.7933712: + var19 = params[267] + else: + var19 = params[268] + else: + if inputs[5] >= 1.5: + if inputs[6] >= 2.5: + var19 = params[269] + else: + var19 = params[270] + else: + if inputs[6] >= 2.5: + var19 = params[271] + else: + var19 = params[272] + else: + if inputs[1] >= 0.8623338: + if inputs[0] >= -1.1637781: + if inputs[0] >= -1.1464274: + var19 = params[273] + else: + var19 = params[274] + else: + if inputs[2] >= 0.3375095: + var19 = params[275] + else: + var19 = params[276] + else: + if inputs[3] >= 15.275: + var19 = params[277] + else: + if inputs[2] >= 3.2492328: + var19 = params[278] + else: + var19 = params[279] + if inputs[2] >= 0.3375095: + if inputs[0] >= -0.38770872: + if inputs[4] >= -0.5: + if inputs[2] >= 1.7933712: + var20 = params[280] + else: + var20 = params[281] + else: + if inputs[2] >= 1.7933712: + var20 = params[282] + else: + var20 = params[283] + else: + if inputs[4] >= 0.5: + if inputs[0] >= -1.1215913: + var20 = params[284] + else: + var20 = params[285] + else: + if inputs[7] >= 0.5: + var20 = params[286] + else: + var20 = params[287] + else: + if inputs[11] >= 0.5: + if inputs[8] >= 0.5: + if inputs[0] >= -0.97723395: + var20 = params[288] + else: + var20 = params[289] + else: + if inputs[0] >= -0.17330435: + var20 = params[290] + else: + var20 = params[291] + else: + if inputs[0] >= 1.774677: + if inputs[6] >= 2.5: + var20 = params[292] + else: + var20 = params[293] + else: + if inputs[6] >= 2.5: + var20 = params[294] + else: + var20 = params[295] + if inputs[3] >= -11.385: + if inputs[1] >= 2.3345098: + if inputs[4] >= 2.5: + if inputs[6] >= 4.5: + var21 = params[296] + else: + var21 = params[297] + else: + if inputs[0] >= -1.0748932: + var21 = params[298] + else: + var21 = params[299] + else: + if inputs[1] >= 0.27409926: + if inputs[5] >= 0.5: + var21 = params[300] + else: + var21 = params[301] + else: + if inputs[13] >= 0.5: + var21 = params[302] + else: + var21 = params[303] + else: + var21 = params[304] + if inputs[0] >= -1.2305534: + if inputs[0] >= -1.2270832: + if inputs[0] >= -1.2170694: + if inputs[0] >= -1.2048744: + var22 = params[305] + else: + var22 = params[306] + else: + if inputs[4] >= 0.5: + var22 = params[307] + else: + var22 = params[308] + else: + var22 = params[309] + else: + if inputs[0] >= -1.2419057: + if inputs[0] >= -1.2383859: + if inputs[0] >= -1.2345688: + var22 = params[310] + else: + var22 = params[311] + else: + var22 = params[312] + else: + if inputs[0] >= -1.2443843: + var22 = params[313] + else: + if inputs[0] >= -1.2451775: + var22 = params[314] + else: + var22 = params[315] + if inputs[0] >= -0.23313928: + if inputs[3] >= 5.5550003: + if inputs[5] >= 1.5: + if inputs[5] >= 2.5: + var23 = params[316] + else: + var23 = params[317] + else: + if inputs[1] >= 0.8623338: + var23 = params[318] + else: + var23 = params[319] + else: + if inputs[3] >= 4.165: + if inputs[1] >= -0.60984224: + var23 = params[320] + else: + var23 = params[321] + else: + if inputs[13] >= 0.5: + var23 = params[322] + else: + var23 = params[323] + else: + if inputs[3] >= -4.165: + if inputs[0] >= -0.29907173: + if inputs[1] >= -0.9044894: + var23 = params[324] + else: + var23 = params[325] + else: + if inputs[5] >= 1.5: + var23 = params[326] + else: + var23 = params[327] + else: + if inputs[11] >= 0.5: + if inputs[3] >= -5.835: + var23 = params[328] + else: + var23 = params[329] + else: + if inputs[3] >= -5.5550003: + var23 = params[330] + else: + var23 = params[331] + if inputs[4] >= 1.5: + if inputs[6] >= 2.5: + if inputs[3] >= 8.335: + var24 = params[332] + else: + if inputs[3] >= -4.165: + var24 = params[333] + else: + var24 = params[334] + else: + var24 = params[335] + else: + if inputs[5] >= 1.5: + if inputs[13] >= 0.5: + if inputs[8] >= 0.5: + var24 = params[336] + else: + var24 = params[337] + else: + if inputs[3] >= 6.8: + var24 = params[338] + else: + var24 = params[339] + else: + if inputs[13] >= 0.5: + if inputs[5] >= 0.5: + var24 = params[340] + else: + var24 = params[341] + else: + if inputs[11] >= 0.5: + var24 = params[342] + else: + var24 = params[343] + if inputs[3] >= 5.5550003: + if inputs[4] >= 0.5: + if inputs[5] >= 1.5: + var25 = params[344] + else: + if inputs[3] >= 16.945: + var25 = params[345] + else: + var25 = params[346] + else: + if inputs[13] >= 0.5: + if inputs[1] >= -0.9044894: + var25 = params[347] + else: + var25 = params[348] + else: + if inputs[7] >= 0.5: + var25 = params[349] + else: + var25 = params[350] + else: + if inputs[8] >= 0.5: + if inputs[5] >= 2.5: + if inputs[3] >= -1.39: + var25 = params[351] + else: + var25 = params[352] + else: + if inputs[3] >= 1.385: + var25 = params[353] + else: + var25 = params[354] + else: + if inputs[5] >= 1.5: + if inputs[5] >= 2.5: + var25 = params[355] + else: + var25 = params[356] + else: + if inputs[7] >= 0.5: + var25 = params[357] + else: + var25 = params[358] + if inputs[0] >= -1.0577409: + if inputs[0] >= -1.0321611: + if inputs[0] >= -1.031368: + var26 = params[359] + else: + if inputs[10] >= 0.5: + var26 = params[360] + else: + var26 = params[361] + else: + if inputs[0] >= -1.0363252: + if inputs[10] >= 0.5: + var26 = params[362] + else: + var26 = params[363] + else: + if inputs[0] >= -1.0379117: + var26 = params[364] + else: + var26 = params[365] + else: + if inputs[0] >= -1.0630949: + var26 = params[366] + else: + if inputs[9] >= 0.5: + if inputs[0] >= -1.1243675: + var26 = params[367] + else: + var26 = params[368] + else: + if inputs[5] >= 0.5: + var26 = params[369] + else: + var26 = params[370] + if inputs[0] >= 3.4985871: + var27 = params[371] + else: + if inputs[0] >= -1.2877609: + if inputs[0] >= -1.2194489: + if inputs[0] >= -1.1886144: + var27 = params[372] + else: + var27 = params[373] + else: + if inputs[0] >= -1.2219276: + var27 = params[374] + else: + var27 = params[375] + else: + if inputs[10] >= 0.5: + var27 = params[376] + else: + if inputs[6] >= 1.5: + var27 = params[377] + else: + var27 = params[378] + if inputs[0] >= -0.98506653: + if inputs[0] >= -0.97316897: + if inputs[0] >= -0.9722271: + if inputs[0] >= -0.9719792: + var28 = params[379] + else: + var28 = params[380] + else: + var28 = params[381] + else: + if inputs[0] >= -0.9796135: + if inputs[4] >= 0.5: + var28 = params[382] + else: + var28 = params[383] + else: + if inputs[0] >= -0.9821913: + var28 = params[384] + else: + var28 = params[385] + else: + if inputs[0] >= -0.9951795: + if inputs[0] >= -0.9861572: + var28 = params[386] + else: + if inputs[0] >= -0.9890324: + var28 = params[387] + else: + var28 = params[388] + else: + if inputs[0] >= -1.0013762: + if inputs[3] >= 1.39: + var28 = params[389] + else: + var28 = params[390] + else: + if inputs[6] >= 5.5: + var28 = params[391] + else: + var28 = params[392] + if inputs[0] >= -1.1534669: + if inputs[0] >= -1.1388428: + if inputs[0] >= -1.0633923: + var29 = params[393] + else: + if inputs[0] >= -1.0981431: + var29 = params[394] + else: + var29 = params[395] + else: + if inputs[1] >= 0.27409926: + var29 = params[396] + else: + if inputs[1] >= -0.60984224: + var29 = params[397] + else: + var29 = params[398] + else: + if inputs[0] >= -1.1652157: + if inputs[1] >= 0.8623338: + var29 = params[399] + else: + if inputs[6] >= 2.5: + var29 = params[400] + else: + var29 = params[401] + else: + if inputs[6] >= 2.5: + if inputs[1] >= -0.60984224: + var29 = params[402] + else: + var29 = params[403] + else: + if inputs[1] >= -0.9044894: + var29 = params[404] + else: + var29 = params[405] + return 0.5 + (var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20 + var21 + var22 + var23 + var24 + var25 + var26 + var27 + var28 + var29) + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/speedRelative_right_before_left.py b/matsim/scenariogen/network/ref_model/germany/speedRelative_right_before_left.py new file mode 100644 index 0000000..b2f33d3 --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/speedRelative_right_before_left.py @@ -0,0 +1,1142 @@ +# -*- coding: utf-8 -*- +"""LGBMRegressor(colsample_bytree=0.9, n_estimators=30, num_leaves=13, + objective='regression', random_state=1373158606, + reg_alpha=3.7455741377665617e-06, subsample=0.9, + subsample_freq=10) +Error: 0.036652""" +def features(ft, data): + data[0] = (ft.get("length") - 129.1767954600338) / 78.97322235207317 + data[1] = (ft.get("speed") - 8.33391612331965) / 0.1443092283706778 + data[2] = (ft.get("num_lanes") - 1.0065201642115431) / 0.08720432118127261 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [0.8864659570912161, 0.8886346793780135, 0.8944630181269778, 0.8890309067205917, 0.8874735506939693, 0.8925656080477194, 0.8900701782397851, 0.8894620722828522, 0.8898128000382747, 0.8925038418807839, 0.8875414379529868, 0.8898447138527441, 0.8902057455627282, -0.003176603722093758, -0.001142805215351266, 0.00412489086786223, -0.0012963500676911712, 0.0007960975779070306, 0.0024172217019919357, -0.0002495590165750649, 0.00014141088753057422, -0.00018514909817908589, 0.0023616320968923203, -0.002104531378895777, -3.158317381347117e-05, 0.00029334545027468644, 0.00415646261684678, 0.002181702693556677, -0.0006662572291531742, -0.0001694584944588256, -0.00045515139388111776, -0.001921888512782723, -0.0013498421180199401, -0.0002694025127131656, 0.0011152634970545562, -0.00031927125792327815, 6.674567468923436e-05, -0.0006583757585729707, 0.00043179169808927015, 0.0035010822469440485, -0.0026241462975569777, -0.000915286037568795, -0.0011801103769971744, 0.000578020892177729, 0.00017371330623629233, -0.00035452862100137636, -0.0006206201389712915, 0.00258180114370854, 0.000164579538912845, -0.00013664817983827658, -0.00174761850133731, 0.00022106572125606312, -0.002531417289939238, -0.000868901169125505, 0.003229993570341847, 7.196588628168523e-05, -0.0010266638819524773, 0.0006611159842176571, 0.002415295053259264, -0.00021382686306017714, -0.0005585581629696847, 0.00017250108880099415, -0.00012573515756959043, 0.0004981163773005874, 0.0001578085551109841, 0.0032554646389360096, 0.0017405310212822538, -0.0006125193802845163, -0.0006043757873027607, -0.00011962111858832767, -0.00037845136283079484, -0.0016478226042059623, -0.0012499212802444194, -0.00015353843136334301, 0.001000228696410834, 4.4218913934509834e-05, -0.0006112684929534735, 0.00037460917435611557, 0.002929918166033496, 0.0015664779227883903, -0.0005512674233792459, -0.00011202572705123527, -0.00034060626394108543, -0.0014830403505354116, -0.0011249290838772567, -0.0001381845387439319, 0.0009002057671559148, -0.0002753731141877458, 4.3265232424404206e-05, -0.0005501416776978569, 0.0003371482918267413, -0.0024341731574487185, -0.0007882900309776836, 0.0024384285684096417, -0.0009628093822300816, 0.0005695763351218445, 0.0021598580175563385, 0.00018976996876801506, -0.0002908368328680208, -0.0005017097431810812, 0.00028243559380667195, 0.00010104634539219307, 0.00042498787229237623, -5.910488118281136e-05, -0.002262718385366335, -0.0007555855052933021, 0.0024053076093487487, -0.0015577437811436145, 0.0009044248077237596, 0.0017724917829290206, -0.0002302279758787586, -0.0005256924781816423, 0.00016811389027082818, 0.0014739210250930954, 0.0001086636759519763, -0.00022162333454851582, 0.00015580495367835458, -0.0018537699881818017, -0.0006116234770305915, 0.0019954931143386814, -0.0008155873846391452, 0.0005125078210623162, 0.001963034673688902, 0.00019171873339851172, -0.00024452468627907375, 0.00023952374538370794, -0.0010300574562693485, -0.00023841049735053482, 0.0012905177760946256, 7.283043699322369e-05, 0.0027547843506953995, 0.00040524129234728617, -0.0032227319315022438, -0.0006032063330446828, -0.0018032323385464505, -0.001014003835700352, -0.00023856649028962358, 0.00024105225119193374, 0.00020794903118540682, 0.002324677131132611, -0.00022311769770673028, -0.0014680525825924392, 3.897921759361141e-05, -7.842079130500989e-06, 0.0019670423726061608, -0.0027979214020439312, -0.0005319294929031897, 0.0014663048203905377, -0.000226759642195669, 0.00021707271133928146, 0.0020922093764104456, -0.00020080583865113587, -0.0001412682134293592, -0.0012358455829109916, 0.0006143430876230161, 3.270946191822671e-05, 0.0015965409683157809, -0.00022553424822164753, -0.0006413953492980231, -7.144036390218956e-05, -0.00048630877755874636, 0.0007107239346671657, -0.0010826120880711638, 1.6917662644080612e-05, 0.000877544386585528, -0.00021414852868415765, -0.0004265764506149945, 0.00017866178427496034, 0.0005059422478083335, -0.0025873208570081916, -0.0008828893053730443, -0.001252974726427497, -0.0003878024436704962, -2.6796210698768737e-06, -0.0007635299571654938, -0.00015465889878454173, 0.0019424439617328013, -0.00099052699263255, 0.0003675364887835544, 0.0001959593817436879, 0.0017518043102475159, 7.903579227781201e-06, -0.001093298750038071, -0.0003217221069558118, -0.0016202683914670005, 0.00027136707339609905, 0.0021546190795963477, -0.0018552477887536453, 0.0003042154910858605, 0.0030166860086521365, 0.0018733519826634006, 0.00019605783466408115, -0.00024626246113437664, 0.00018182638530584558, 7.113232121862726e-06, -0.0006536262604728139, 0.0002442303814402535, 0.0019391571944326709, -0.0016697229496218627, 0.00027379394118804215, 0.00271501735115421, 0.0016860167926993103, 0.00017645198289750427, -0.00022163621235947028, -5.616658064435556e-05, 0.0003133867724116204, -0.0013510907566081562, 1.8871248848537682e-05, -0.001388247104900158, -0.00028927865709739913, 0.0022290177725907126, -0.0015027506479543067, 0.00024641454761046644, 0.002443515662698217, 0.00033399180265999886, -0.0001890982155879508, 0.0001505710513807078, -8.761858008071125e-05, 3.719599014012271e-05, -0.0011379665186890462, 0.0005790831516880352, -0.0012494224581897399, -0.0002603507636414558, 0.0020061160091382644, -0.0013524756654142145, 0.001233470237879718, 0.00030059268042121576, -0.00018601450047873403, -0.00013152387780429877, -0.0011162957179690941, 0.0005481689391658953, 4.557947425653169e-06, -0.0005588598179344392, 5.7216930504702704e-05, -0.001905732774401769, -0.0005927060006382877, -0.0002781906525975384, 0.00018220467708174467, -0.0005791373609531658, 0.0006762174857421165, 2.5605032649551712e-05, -0.0005589343962427543, 0.00020645707490087755, -0.0013869567302029978, 0.0009112524649122181, -0.0007500731191835799, 2.9971706583885123e-05, -0.0017608210634719361, -0.0005328451030401521, -0.00025037152448979837, 0.00016398420647343654, -0.0005212235550313587, 0.0005008502035558727, -4.712902624631737e-05, -0.0005030409085862379, 0.00029047561605323924, -0.0008798141826816298, 0.0008201272147962652, -0.0006750658441909193, 2.697454052577612e-05, -0.0011416106534911806, -0.00042456737824054917, 0.0006147829729002798, -0.0007263946661497118, 0.0013693809316736077, -0.001671706759527441, -0.0003359029351837641, 0.0001038820682607435, -0.0006341440549551684, -5.989533658305727e-05, 0.0007200948128212044, -0.0008397914224897388, 6.594427803346967e-07, -0.0012249452875894582, -0.0003934365988588341, 0.0007038847536815144, -0.0009307326374548902, 0.0012324428194298792, -0.00033031325712584643, 0.0006052522542412889, -9.362824417560856e-05, -0.0009772675149914024, 0.0008234298605953338, -0.000575184741163782, 6.854940438801642e-05, 5.7612831764208734e-05, -0.0011024507132488537, -0.0007591088924189504, -0.0002223942027470075, 0.0006334962670873447, -0.0008376593817037636, 0.0011091985199672403, -0.0002972819401917507, 0.0005447269637620798, -0.00015388310040016795, 0.0007410869064472723, -0.0005176662598875561, 6.169447917169525e-05, 5.1851566344499566e-05, 0.0011955307352454034, -5.3587922400749816e-05, -0.00017867886005436015, -0.0004299945157841578, 3.9526685806231094e-05, 0.0006293559108061457, -0.00019603885396834186, 0.0016042256546111436, 0.0007409146422153379, -0.001203188821368948, -0.0006391839970904921, 9.01406173033508e-05, 0.000521916257347054, -0.0007275458466557566, 0.001493147182660996, -0.0006136879936117759, -0.0019991976508522027, -0.0002336849141998398, -2.1038471057114215e-05, -0.0005336056837318445, 0.0007318848011632377, 0.0007384824257281452, -0.0005080455602217431, 0.000788096804452975, -0.0005522952143599204, 3.104615089594614e-05, -0.001288536567056777, -0.00039529214602657917, 6.609890330985567e-05, -0.0011706252254767124, 0.00041864387025067925, -0.0001087738581359102, 0.0009528311438934281, -0.0010221127047840852, 0.0008388555258446368, 2.422488328059628e-05, 0.0003302593266375178, -0.0007706780147580264, -2.1631377795139428e-06, -0.0006240562267718821, -0.00010589333422622578, -0.0010535626547083705, 0.00037677953557528144, -8.49861099164895e-05, 0.0012426791052188968, -0.0009199014002386701, 0.00017142981693589931, -0.00035721239260736294, 0.0005322322477329898, 0.0006577525817968295, -0.0002313311611745716, 2.7801418080306334e-05, -0.0004614772225488373, 0.0006676321629508337, -0.0002660460465501348, -0.0018519780999294588, 0.0001783266685922422, 0.0001428398502472288, -0.0011894853899962572, -0.00011766004488704949, 0.00023516960689187665, -0.0008831127208618997, -0.00022524270334292704, 0.0005643404857937848, 1.7740083381208228e-05, -0.0005155028354136666, 0.000600868917042756, -0.0003180040862960638, -0.0016667803694195842, 0.00016049401128349132, 8.710473256555799e-05, -0.0010705367705479607, 0.0003616444609119379, -0.0005664599940825662, 0.0002116526993298608, -0.00026682417786230955, 0.0005079064806921763, 1.5966080575336485e-05, -0.00038165491943539434, 0.000540782030760677, -0.0010471447682704027, 4.46199953517593e-05, -0.00023456581533165012, 0.0005978389526233623, -0.0008504256292103089, 0.0007025405432199506, -0.0014946645459751446, -2.4103112570408605e-05, 0.0005924267201256374, -0.0006997610118106629, -1.2241829991080822e-05] +def score(params, inputs): + if inputs[0] <= -0.8087145687851901: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.203215376427391: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[2] + else: + if inputs[0] <= -1.265641599559346: + if inputs[0] <= -1.2806466856468441: + var0 = params[3] + else: + var0 = params[4] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[5] + else: + if inputs[0] <= -1.1611124977430605: + var0 = params[6] + else: + var0 = params[7] + else: + if inputs[5] > 2.5000000000000004: + var0 = params[8] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[9] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var0 = params[10] + else: + if inputs[0] > 0.9463740026559045: + var0 = params[11] + else: + var0 = params[12] + if inputs[0] <= -0.8087145687851901: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.2147382695409974: + var1 = params[13] + else: + var1 = params[14] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[15] + else: + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var1 = params[16] + else: + var1 = params[17] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[18] + else: + var1 = params[19] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] > 0.2844407746187974: + var1 = params[20] + else: + var1 = params[21] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[22] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var1 = params[23] + else: + if inputs[0] > 0.9463740026559045: + var1 = params[24] + else: + var1 = params[25] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[26] + else: + var2 = params[27] + else: + var2 = params[28] + else: + if inputs[5] > 2.5000000000000004: + if inputs[6] > 3.5000000000000004: + var2 = params[29] + else: + var2 = params[30] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var2 = params[31] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[32] + else: + var2 = params[33] + else: + if inputs[5] > 1.5000000000000002: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[34] + else: + if inputs[6] > 3.5000000000000004: + var2 = params[35] + else: + var2 = params[36] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var2 = params[37] + else: + var2 = params[38] + if inputs[0] <= -0.8087145687851901: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[39] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.2147382695409974: + var3 = params[40] + else: + var3 = params[41] + else: + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var3 = params[42] + else: + var3 = params[43] + else: + if inputs[0] <= -1.1611124977430605: + var3 = params[44] + else: + var3 = params[45] + else: + if inputs[0] > 2.8196671974107512: + var3 = params[46] + else: + if inputs[6] > 3.5000000000000004: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[47] + else: + if inputs[0] > 0.2844407746187974: + var3 = params[48] + else: + var3 = params[49] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var3 = params[50] + else: + var3 = params[51] + if inputs[0] <= -0.7717400106624095: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.203215376427391: + var4 = params[52] + else: + var4 = params[53] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + var4 = params[54] + else: + var4 = params[55] + else: + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var4 = params[56] + else: + var4 = params[57] + else: + if inputs[3] > 2.775000000000001: + var4 = params[58] + else: + var4 = params[59] + else: + if inputs[0] > 2.8196671974107512: + var4 = params[60] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] > 0.2844407746187974: + var4 = params[61] + else: + var4 = params[62] + else: + if inputs[0] <= -0.5611623046412313: + var4 = params[63] + else: + var4 = params[64] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[65] + else: + var5 = params[66] + else: + var5 = params[67] + else: + if inputs[5] > 2.5000000000000004: + if inputs[6] > 3.5000000000000004: + if inputs[5] > 3.5000000000000004: + var5 = params[68] + else: + var5 = params[69] + else: + var5 = params[70] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var5 = params[71] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[72] + else: + var5 = params[73] + else: + if inputs[5] > 1.5000000000000002: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[74] + else: + var5 = params[75] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var5 = params[76] + else: + var5 = params[77] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[78] + else: + var6 = params[79] + else: + var6 = params[80] + else: + if inputs[5] > 2.5000000000000004: + if inputs[6] > 3.5000000000000004: + var6 = params[81] + else: + var6 = params[82] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[5] > 1.5000000000000002: + var6 = params[83] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[84] + else: + var6 = params[85] + else: + if inputs[5] > 1.5000000000000002: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[86] + else: + if inputs[6] > 3.5000000000000004: + var6 = params[87] + else: + var6 = params[88] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var6 = params[89] + else: + var6 = params[90] + if inputs[0] <= -0.7717400106624095: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.2274007894460592: + var7 = params[91] + else: + var7 = params[92] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var7 = params[93] + else: + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var7 = params[94] + else: + var7 = params[95] + else: + if inputs[3] > 2.775000000000001: + var7 = params[96] + else: + if inputs[0] <= -1.1611124977430605: + var7 = params[97] + else: + var7 = params[98] + else: + if inputs[0] > 2.8196671974107512: + var7 = params[99] + else: + if inputs[0] <= -0.42282427467843087: + var7 = params[100] + else: + if inputs[0] > 0.0546793509414504: + if inputs[0] > 0.23049843982323412: + var7 = params[101] + else: + var7 = params[102] + else: + var7 = params[103] + if inputs[0] <= -0.8087145687851901: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.2399366841520705: + var8 = params[104] + else: + var8 = params[105] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[106] + else: + if inputs[0] <= -1.4358258670833768: + if inputs[6] > 2.5000000000000004: + var8 = params[107] + else: + var8 = params[108] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var8 = params[109] + else: + var8 = params[110] + else: + if inputs[0] > 3.0312579050243342: + var8 = params[111] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] > 0.2844407746187974: + var8 = params[112] + else: + if inputs[6] > 4.500000000000001: + var8 = params[113] + else: + if inputs[0] <= -0.42282427467843087: + var8 = params[114] + else: + var8 = params[115] + else: + var8 = params[116] + if inputs[0] <= -0.7717400106624095: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.203215376427391: + var9 = params[117] + else: + var9 = params[118] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var9 = params[119] + else: + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var9 = params[120] + else: + var9 = params[121] + else: + if inputs[3] > 2.775000000000001: + var9 = params[122] + else: + if inputs[0] <= -1.1611124977430605: + var9 = params[123] + else: + var9 = params[124] + else: + if inputs[0] <= -0.42282427467843087: + var9 = params[125] + else: + if inputs[0] > 4.052173572369945: + var9 = params[126] + else: + if inputs[0] <= -0.3016439591869893: + if inputs[5] > 1.5000000000000002: + var9 = params[127] + else: + var9 = params[128] + else: + var9 = params[129] + if inputs[0] <= -0.8087145687851901: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + var10 = params[130] + else: + var10 = params[131] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.3880881670412937: + var10 = params[132] + else: + if inputs[0] <= -0.8391679291568637: + var10 = params[133] + else: + var10 = params[134] + else: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -1.3880881670412937: + var10 = params[135] + else: + var10 = params[136] + else: + var10 = params[137] + else: + if inputs[0] <= -0.42282427467843087: + var10 = params[138] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var10 = params[139] + else: + if inputs[0] <= -0.3016439591869893: + var10 = params[140] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var10 = params[141] + else: + var10 = params[142] + if inputs[0] <= -0.7717400106624095: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -1.192768797505715: + var11 = params[143] + else: + var11 = params[144] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.3880881670412937: + var11 = params[145] + else: + var11 = params[146] + else: + if inputs[3] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[147] + else: + var11 = params[148] + else: + if inputs[0] <= -0.42282427467843087: + var11 = params[149] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var11 = params[150] + else: + if inputs[0] <= -0.3016439591869893: + var11 = params[151] + else: + if inputs[0] > 2.430864523725828: + if inputs[0] > 2.5447005776723337: + var11 = params[152] + else: + var11 = params[153] + else: + if inputs[0] > 2.0490262359886886: + var11 = params[154] + else: + var11 = params[155] + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[6] > 3.5000000000000004: + var12 = params[156] + else: + var12 = params[157] + else: + if inputs[5] > 2.5000000000000004: + if inputs[5] > 3.5000000000000004: + var12 = params[158] + else: + var12 = params[159] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[160] + else: + if inputs[5] > 1.5000000000000002: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[161] + else: + if inputs[6] > 2.5000000000000004: + if inputs[3] > 2.775000000000001: + var12 = params[162] + else: + var12 = params[163] + else: + if inputs[3] > 2.775000000000001: + var12 = params[164] + else: + var12 = params[165] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var12 = params[166] + else: + if inputs[6] > 2.5000000000000004: + var12 = params[167] + else: + var12 = params[168] + if inputs[0] <= -0.7717400106624095: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -1.3880881670412937: + if inputs[5] > 2.5000000000000004: + var13 = params[169] + else: + var13 = params[170] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -1.2147382695409974: + var13 = params[171] + else: + var13 = params[172] + else: + if inputs[0] <= -1.1368637721248671: + var13 = params[173] + else: + if inputs[0] <= -1.0560135825310473: + var13 = params[174] + else: + var13 = params[175] + else: + if inputs[6] > 3.5000000000000004: + var13 = params[176] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[177] + else: + var13 = params[178] + else: + if inputs[0] <= -0.42282427467843087: + var13 = params[179] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var13 = params[180] + else: + var13 = params[181] + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -1.2806466856468441: + if inputs[0] <= -1.3880881670412937: + var14 = params[182] + else: + var14 = params[183] + else: + var14 = params[184] + else: + var14 = params[185] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9405947135964089: + var14 = params[186] + else: + if inputs[0] <= -0.6992470842059305: + var14 = params[187] + else: + if inputs[0] > 0.000000000000000000000000000000000010000000180025095: + var14 = params[188] + else: + var14 = params[189] + else: + if inputs[0] <= -0.7717400106624095: + if inputs[3] > 2.775000000000001: + var14 = params[190] + else: + if inputs[0] <= -1.182702094181191: + var14 = params[191] + else: + var14 = params[192] + else: + if inputs[0] <= -0.42282427467843087: + var14 = params[193] + else: + var14 = params[194] + if inputs[0] <= -1.265641599559346: + if inputs[6] > 2.5000000000000004: + var15 = params[195] + else: + var15 = params[196] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9405947135964089: + var15 = params[197] + else: + if inputs[0] <= -0.6992470842059305: + var15 = params[198] + else: + if inputs[0] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[199] + else: + var15 = params[200] + else: + if inputs[0] <= -0.7717400106624095: + if inputs[3] > 2.775000000000001: + var15 = params[201] + else: + if inputs[0] <= -1.182702094181191: + var15 = params[202] + else: + var15 = params[203] + else: + if inputs[0] <= -0.5446377161651256: + if inputs[5] > 2.5000000000000004: + var15 = params[204] + else: + var15 = params[205] + else: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var15 = params[206] + else: + var15 = params[207] + if inputs[0] <= -1.2399366841520705: + if inputs[5] > 2.5000000000000004: + var16 = params[208] + else: + var16 = params[209] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9405947135964089: + var16 = params[210] + else: + if inputs[0] <= -0.6992470842059305: + var16 = params[211] + else: + if inputs[0] > 0.000000000000000000000000000000000010000000180025095: + var16 = params[212] + else: + var16 = params[213] + else: + if inputs[0] <= -0.7717400106624095: + if inputs[0] <= -1.182702094181191: + var16 = params[214] + else: + var16 = params[215] + else: + if inputs[0] <= -0.42282427467843087: + var16 = params[216] + else: + if inputs[0] <= -0.038010294763601994: + var16 = params[217] + else: + if inputs[0] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] > 0.007701402093671097: + var16 = params[218] + else: + var16 = params[219] + else: + var16 = params[220] + if inputs[0] <= -1.2399366841520705: + if inputs[5] > 2.5000000000000004: + var17 = params[221] + else: + var17 = params[222] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + if inputs[0] <= -0.9405947135964089: + var17 = params[223] + else: + if inputs[0] <= -0.6992470842059305: + var17 = params[224] + else: + var17 = params[225] + else: + if inputs[0] <= -0.8087145687851901: + if inputs[0] <= -1.182702094181191: + var17 = params[226] + else: + var17 = params[227] + else: + if inputs[0] > 2.430864523725828: + if inputs[0] > 2.5447005776723337: + var17 = params[228] + else: + var17 = params[229] + else: + if inputs[0] > 2.0490262359886886: + var17 = params[230] + else: + if inputs[0] > 0.972901981857009: + if inputs[0] > 1.1375780532223383: + var17 = params[231] + else: + var17 = params[232] + else: + var17 = params[233] + if inputs[0] <= -0.899251586106382: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -1.3880881670412937: + if inputs[5] > 2.5000000000000004: + var18 = params[234] + else: + var18 = params[235] + else: + if inputs[0] <= -0.9633239368259949: + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.1368637721248671: + if inputs[0] <= -1.2399366841520705: + var18 = params[236] + else: + var18 = params[237] + else: + var18 = params[238] + else: + if inputs[0] <= -1.026446598552728: + var18 = params[239] + else: + var18 = params[240] + else: + var18 = params[241] + else: + if inputs[0] <= -1.1368637721248671: + if inputs[0] <= -1.182702094181191: + var18 = params[242] + else: + var18 = params[243] + else: + var18 = params[244] + else: + if inputs[0] > 4.052173572369945: + var18 = params[245] + else: + var18 = params[246] + if inputs[0] <= -0.899251586106382: + if inputs[5] > 1.5000000000000002: + if inputs[0] <= -1.3880881670412937: + if inputs[6] > 3.5000000000000004: + var19 = params[247] + else: + var19 = params[248] + else: + if inputs[0] <= -0.9633239368259949: + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.1368637721248671: + if inputs[0] <= -1.2399366841520705: + var19 = params[249] + else: + var19 = params[250] + else: + var19 = params[251] + else: + if inputs[0] <= -1.0146704550410206: + var19 = params[252] + else: + var19 = params[253] + else: + var19 = params[254] + else: + if inputs[0] <= -1.1368637721248671: + if inputs[0] <= -1.203215376427391: + var19 = params[255] + else: + var19 = params[256] + else: + var19 = params[257] + else: + if inputs[0] > 4.052173572369945: + var19 = params[258] + else: + var19 = params[259] + if inputs[0] <= -1.2399366841520705: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -1.4358258670833768: + var20 = params[260] + else: + var20 = params[261] + else: + if inputs[0] <= -1.2966647733267473: + var20 = params[262] + else: + var20 = params[263] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var20 = params[264] + else: + if inputs[0] > 0.0546793509414504: + if inputs[0] > 0.20821240479032524: + if inputs[6] > 2.5000000000000004: + if inputs[6] > 4.500000000000001: + var20 = params[265] + else: + if inputs[0] > 2.8196671974107512: + var20 = params[266] + else: + var20 = params[267] + else: + var20 = params[268] + else: + if inputs[5] > 2.5000000000000004: + var20 = params[269] + else: + var20 = params[270] + else: + if inputs[0] > 0.03638200967863615: + var20 = params[271] + else: + var20 = params[272] + if inputs[0] <= -1.2399366841520705: + if inputs[5] > 2.5000000000000004: + var21 = params[273] + else: + if inputs[6] > 2.5000000000000004: + var21 = params[274] + else: + if inputs[0] <= -1.2966647733267473: + var21 = params[275] + else: + var21 = params[276] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var21 = params[277] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -0.5849045294632221: + var21 = params[278] + else: + if inputs[0] <= -0.5014585232888648: + var21 = params[279] + else: + if inputs[0] <= -0.1195569229522002: + if inputs[0] <= -0.20129348893937427: + if inputs[0] <= -0.2256688397566183: + if inputs[0] <= -0.2468152479980715: + var21 = params[280] + else: + var21 = params[281] + else: + var21 = params[282] + else: + var21 = params[283] + else: + var21 = params[284] + else: + var21 = params[285] + if inputs[0] <= -1.2399366841520705: + if inputs[5] > 2.5000000000000004: + var22 = params[286] + else: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -1.3880881670412937: + var22 = params[287] + else: + var22 = params[288] + else: + if inputs[0] <= -1.2966647733267473: + var22 = params[289] + else: + var22 = params[290] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var22 = params[291] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] <= -0.5849045294632221: + var22 = params[292] + else: + if inputs[0] <= -0.5014585232888648: + var22 = params[293] + else: + if inputs[0] <= -0.1195569229522002: + if inputs[0] <= -0.20129348893937427: + if inputs[0] <= -0.2256688397566183: + var22 = params[294] + else: + var22 = params[295] + else: + var22 = params[296] + else: + var22 = params[297] + else: + var22 = params[298] + if inputs[5] > 1.5000000000000002: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var23 = params[299] + else: + if inputs[6] > 3.5000000000000004: + var23 = params[300] + else: + if inputs[6] > 2.5000000000000004: + if inputs[5] > 2.5000000000000004: + var23 = params[301] + else: + if inputs[3] > 2.775000000000001: + var23 = params[302] + else: + var23 = params[303] + else: + if inputs[3] > 2.775000000000001: + var23 = params[304] + else: + var23 = params[305] + else: + if inputs[6] > 3.5000000000000004: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var23 = params[306] + else: + var23 = params[307] + else: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + if inputs[10] > 0.000000000000000000000000000000000010000000180025095: + var23 = params[308] + else: + var23 = params[309] + else: + if inputs[6] > 2.5000000000000004: + var23 = params[310] + else: + var23 = params[311] + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.4358258670833768: + var24 = params[312] + else: + if inputs[11] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[313] + else: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.2147382695409974: + if inputs[0] <= -1.251332952066626: + var24 = params[314] + else: + var24 = params[315] + else: + var24 = params[316] + else: + if inputs[0] <= -1.1039412203717063: + var24 = params[317] + else: + var24 = params[318] + else: + if inputs[0] <= -1.026446598552728: + var24 = params[319] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var24 = params[320] + else: + if inputs[0] > 2.8196671974107512: + if inputs[0] > 3.6239271491807528: + if inputs[0] > 4.052173572369945: + var24 = params[321] + else: + var24 = params[322] + else: + var24 = params[323] + else: + var24 = params[324] + if inputs[0] <= -1.2399366841520705: + if inputs[0] <= -1.251332952066626: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -1.265641599559346: + if inputs[0] <= -1.2806466856468441: + if inputs[0] <= -1.3333860810514266: + if inputs[6] > 3.5000000000000004: + var25 = params[325] + else: + var25 = params[326] + else: + var25 = params[327] + else: + var25 = params[328] + else: + var25 = params[329] + else: + if inputs[5] > 1.5000000000000002: + var25 = params[330] + else: + var25 = params[331] + else: + var25 = params[332] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var25 = params[333] + else: + if inputs[0] > 0.0546793509414504: + if inputs[0] > 0.20821240479032524: + var25 = params[334] + else: + var25 = params[335] + else: + if inputs[0] > 0.03638200967863615: + var25 = params[336] + else: + var25 = params[337] + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.4358258670833768: + var26 = params[338] + else: + if inputs[0] <= -1.1611124977430605: + if inputs[0] <= -1.2399366841520705: + if inputs[0] <= -1.251332952066626: + if inputs[6] > 2.5000000000000004: + if inputs[0] <= -1.265641599559346: + if inputs[0] <= -1.2806466856468441: + var26 = params[339] + else: + var26 = params[340] + else: + var26 = params[341] + else: + if inputs[5] > 1.5000000000000002: + var26 = params[342] + else: + var26 = params[343] + else: + var26 = params[344] + else: + var26 = params[345] + else: + if inputs[5] > 1.5000000000000002: + var26 = params[346] + else: + var26 = params[347] + else: + if inputs[0] <= -1.026446598552728: + var26 = params[348] + else: + if inputs[0] > 2.8196671974107512: + var26 = params[349] + else: + var26 = params[350] + if inputs[0] <= -1.3880881670412937: + var27 = params[351] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var27 = params[352] + else: + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.1611124977430605: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.2147382695409974: + if inputs[0] <= -1.251332952066626: + var27 = params[353] + else: + var27 = params[354] + else: + var27 = params[355] + else: + if inputs[0] <= -1.2399366841520705: + if inputs[0] <= -1.2806466856468441: + var27 = params[356] + else: + if inputs[0] <= -1.265641599559346: + var27 = params[357] + else: + var27 = params[358] + else: + var27 = params[359] + else: + if inputs[0] <= -1.1498428550275557: + var27 = params[360] + else: + var27 = params[361] + else: + if inputs[0] <= -1.026446598552728: + var27 = params[362] + else: + var27 = params[363] + if inputs[0] <= -1.4358258670833768: + var28 = params[364] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var28 = params[365] + else: + if inputs[0] <= -1.0560135825310473: + if inputs[0] <= -1.1611124977430605: + if inputs[6] > 3.5000000000000004: + if inputs[0] <= -1.2147382695409974: + if inputs[0] <= -1.251332952066626: + var28 = params[366] + else: + var28 = params[367] + else: + var28 = params[368] + else: + if inputs[0] <= -1.2399366841520705: + if inputs[0] <= -1.2806466856468441: + var28 = params[369] + else: + if inputs[0] <= -1.265641599559346: + var28 = params[370] + else: + if inputs[0] <= -1.251332952066626: + var28 = params[371] + else: + var28 = params[372] + else: + var28 = params[373] + else: + var28 = params[374] + else: + if inputs[0] <= -1.026446598552728: + var28 = params[375] + else: + var28 = params[376] + if inputs[0] <= -1.3880881670412937: + var29 = params[377] + else: + if inputs[2] > 0.000000000000000000000000000000000010000000180025095: + var29 = params[378] + else: + if inputs[0] > 0.0546793509414504: + if inputs[0] > 0.20821240479032524: + if inputs[4] > 0.000000000000000000000000000000000010000000180025095: + var29 = params[379] + else: + if inputs[0] > 0.2844407746187974: + var29 = params[380] + else: + var29 = params[381] + else: + if inputs[5] > 2.5000000000000004: + if inputs[0] > 0.18219092638542328: + var29 = params[382] + else: + if inputs[0] > 0.14439330446881357: + var29 = params[383] + else: + if inputs[0] > 0.1064690573531535: + var29 = params[384] + else: + if inputs[0] > 0.09608579103100272: + var29 = params[385] + else: + var29 = params[386] + else: + var29 = params[387] + else: + if inputs[0] > 0.03638200967863615: + var29 = params[388] + else: + var29 = params[389] + return var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20 + var21 + var22 + var23 + var24 + var25 + var26 + var27 + var28 + var29 + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/germany/speedRelative_traffic_light.py b/matsim/scenariogen/network/ref_model/germany/speedRelative_traffic_light.py new file mode 100644 index 0000000..16466a2 --- /dev/null +++ b/matsim/scenariogen/network/ref_model/germany/speedRelative_traffic_light.py @@ -0,0 +1,1221 @@ +# -*- coding: utf-8 -*- +"""XGBRegressor(alpha=0.047001391102599516, base_score=0.5, booster='gbtree', + callbacks=None, colsample_bylevel=1, colsample_bynode=0.9, + colsample_bytree=0.9, early_stopping_rounds=None, + enable_categorical=False, eta=0.3941368339308491, + eval_metric='mae', feature_types=None, gamma=0.015204717741625653, + gpu_id=-1, grow_policy='depthwise', importance_type=None, + interaction_constraints='', lambda=0.06265617744974636, + learning_rate=0.394136846, max_bin=256, max_cat_threshold=64, + max_cat_to_onehot=4, max_delta_step=0, max_depth=4, max_leaves=0, + min_child_weight=1, missing=nan, monotone_constraints='()', + n_estimators=30, n_jobs=0, ...) +Error: 0.065839""" +def features(ft, data): + data[0] = (ft.get("length") - 118.1870083102493) / 85.53737656584288 + data[1] = (ft.get("speed") - 13.07573990377606) / 2.714858934612079 + data[2] = (ft.get("num_lanes") - 1.898819069835253) / 0.9764526365080834 + data[3] = ft.get("change_speed") + data[4] = ft.get("change_num_lanes") + data[5] = ft.get("num_to_links") + data[6] = ft.get("junction_inc_lanes") + data[7] = ft.get("priority_lower") + data[8] = ft.get("priority_equal") + data[9] = ft.get("priority_higher") + data[10] = ft.get("is_secondary_or_higher") + data[11] = ft.get("is_primary_or_higher") + data[12] = ft.get("is_motorway") + data[13] = ft.get("is_link") + +params = [0.06790623, 0.034632765, -0.011209435, 0.04577619, 0.0880185, 0.047057196, 0.10822878, 0.08355451, -0.0819455, -0.034643985, -0.027316023, -0.07005219, -0.007893718, 0.050933607, -0.050275955, -0.0057284646, 0.017012136, 0.043477625, -0.01993124, 0.011612414, -0.033527438, -0.062167246, -0.0042647053, -0.036844037, 0.010196017, 0.056714352, -0.025823936, 0.034707848, 0.0015412709, 0.01949823, 0.027255317, -0.03200495, -0.05468421, 0.0, 0.019082194, -0.010470612, -0.026849343, -0.13238138, 0.035029292, 0.01832633, -0.020596212, -0.04140348, -0.0043531493, 0.03936372, -0.06849704, -0.0009418421, 0.009460706, -0.008723757, 0.036718156, -0.044914506, 0.035381146, 0.02266762, -0.014656713, 0.027509872, -0.022450017, 0.009973883, 0.021223705, -0.013778199, -0.016864818, -0.03560116, -0.013142123, 0.01078481, 0.0034205264, -0.019221146, -0.053455953, -0.086902104, -0.0545471, -0.027562099, -0.014050962, 0.0066683814, -0.0009228036, 0.01587043, -0.023853047, -0.0002186747, 0.015491075, -0.01240522, -0.047347978, 0.031765904, -0.039147522, 0.008001228, -0.066487804, -0.031976275, -0.04089825, 0.0053946464, 0.01517929, -0.019650074, 0.0370233, -0.038363665, -0.06605387, -0.02930215, -0.0087859705, -0.024408419, -0.004786583, 0.016753469, 0.026538929, 0.0021821405, 0.017158577, 0.0077318633, 0.013361957, 0.002492773, 0.016783584, -0.008524774, -0.0071881786, -0.017453086, 0.03549861, -0.04956106, 0.00886389, -0.008774117, 0.0025088205, -0.002580323, -0.010493644, -0.04805658, -0.066898845, -0.015498039, 0.010330905, 0.0029518704, -0.043891404, -0.009994398, 0.036285102, 0.004521423, -0.0066570383, -0.01676263, 0.010302288, -0.060991153, -0.011717055, -0.050649498, 0.0, -0.01821129, 0.023557747, 0.007826897, -0.015035515, -0.006106305, -0.03755243, 0.0023724097, -0.005185496, 0.005094755, 0.065492965, 0.0019828319, 0.02029748, 0.014927406, -0.00010956537, 0.013305125, -0.009676593, -0.03953449, 0.012009435, 0.0, 0.052751556, -0.008745545, -0.034963988, 0.044285417, -0.012566226, 0.008154273, -0.0033447242, 0.006168181, -0.0029966286, 0.0060548233, 0.00039674135, -0.021450378, 0.039186753, -0.003896553, -0.018237207, 0.0052921646, 0.0022821582, 0.051311508, 0.08115114, 0.0138180675, 0.0, 0.053865634, -0.038993374, -0.009050318, 0.013135795, 0.0066654873, 0.0007622345, 0.047147546, 0.009399889, -0.02897284, -0.006884936, 0.00662854, -0.010828887, -0.0013556709, 0.009268267, -0.0024131185, 0.005239874, -0.0051272567, 0.08559939, -0.01375245, 0.040658217, 0.0140133, 0.047104117, -0.018700076, -0.06612628, 0.012063506, 0.0017672975, -0.0007462956, -0.014046012, -0.0072673075, -0.02431682, 0.0023534077, -0.008500829, 0.10719526, 0.004079055, -0.0053740633, -0.09862536, 0.0040577766, -0.049893934, 0.011684913, 0.01898168, -0.034786213, -0.0014466611, 0.0, 0.07370232, 0.04828216, 0.015566578, -0.010944348, 0.0013533304, -0.0031485711, 0.00040815855, 0.077660136, 0.0, 0.008733414, -0.03529251, -0.022965346, -0.0037971581, -0.00070111395, 0.003429289, 0.00087198295, -0.027258886, 0.036887784, -0.014568294, 0.05453901, 0.014291372, -0.025041157, -0.060959555, 0.0068763434, 0.09121028, 0.0006954265, 0.00038299375, -0.020050624, -0.0014860297, -0.018464416, 0.017304298, 0.0056287106, 0.00079059287, -0.0026184975, 0.02052197, 0.0027167753, 0.14830045, 0.05380311, 0.06719894, 0.011664438, 0.058087803, -0.042504944, 0.020543959, -0.0017126647, -0.021107348, -0.024503708, -0.0010299521, 0.00022382621, 0.09911475, 0.008810727, -0.030270861, -0.0036977471, 0.034903526, 0.04277103, -0.0016510044, 0.04814092, 0.0, -0.099094965, -0.008851885, -0.008267712, 0.0050739637, 0.018586261, -0.042596452, -0.0028918746, 0.020863501, -0.0314092, 0.0, -0.0016262544, 0.0062467703, -0.002645085, 0.0009108173, 0.00846314, 0.025383726, -0.013415105, 0.0023971228, -0.072558574, -0.0014006126, -0.0026091759, -0.00025234264, -0.008309074, -0.0022059528, 0.014517953, -0.006325167, 0.0023618157, -0.0007848198, 0.001425744, 0.04030019, -6.477191e-05, 0.11148067, 0.0016294338, -0.021962913, -0.036813963, 0.03363942, -0.0062452178, 0.012401687, -8.250797e-05, -0.0032123856, -0.05763109, -0.0036932572, -0.021652194, 0.03144192, 0.020936608, -0.013293991, 0.003570338, 0.004783369, -0.0015694727, -0.013244351, -0.027097417, 0.014033851, 0.05943601, 0.001303502, 0.0007681418, -0.013094218, 6.0819482e-05, -0.003216767, -0.03489369, -0.004310269, 0.078428924, -0.020854548, -0.040383656, -8.884911e-05, -0.010848852, -0.0033101991, 0.02270593, -0.0034757163, 0.02270174, -0.05760729, 0.012181459, -0.0073860073, 0.0014437418, 0.0016960505, 0.030603828, -0.0483842, 0.015619719, -0.0063001984, -0.0024699746, 0.035763524, -0.019962663, 0.0017212804, 0.029769387, 0.00061234157, 0.039824042, -0.0010563757, 0.08099293, 0.00394579, 0.012517526, -0.0005035828, 0.0047116997, 0.0005257211, -0.0033985288, -0.024204433, 0.026075657, -0.012003716, -0.0006758022, -0.0016981185, 0.00068652624, 0.043410677, -0.02996935, 0.004826302, -0.011975468, 0.0042384565, 0.0061476687, -0.024505187, 0.025222618, 0.013374519, -0.05868894, 0.0024167027, -7.5827935e-05, 0.013496813, 0.0, -0.043456644, -0.004089359, -0.017123394, 0.0029439353, -0.0055463156, -0.012465894, 2.672521e-05, 0.001222799, -0.016599808, -0.0024725378, -0.030502506, -0.00064433145, -0.0047695637, 0.0007970989, -0.05864099, -0.021104973, 0.0, 0.024772102, 0.0079932045, -0.008547953, 0.00088216783, -0.035597026, 0.09471237, 0.010676396, -0.034800455, 0.0108672995, -0.003780443, 0.0015160043, -0.0021869375, -0.02006114, -0.061431926, 0.07598046, 0.028308306, 0.002596565] +def score(params, inputs): + if inputs[0] >= -0.1273947: + if inputs[6] >= 6.5: + if inputs[0] >= 0.6765813: + if inputs[0] >= 1.1753106: + var0 = params[0] + else: + var0 = params[1] + else: + if inputs[1] >= -1.2360642: + var0 = params[2] + else: + var0 = params[3] + else: + if inputs[1] >= -1.2360642: + if inputs[0] >= 1.2711751: + var0 = params[4] + else: + var0 = params[5] + else: + if inputs[0] >= 0.64478236: + var0 = params[6] + else: + var0 = params[7] + else: + if inputs[6] >= 6.5: + if inputs[5] >= 2.5: + if inputs[1] >= -0.72406703: + var0 = params[8] + else: + var0 = params[9] + else: + if inputs[0] >= -0.7543136: + var0 = params[10] + else: + var0 = params[11] + else: + if inputs[0] >= -0.6443032: + if inputs[1] >= -1.2360642: + var0 = params[12] + else: + var0 = params[13] + else: + if inputs[1] >= -0.72406703: + var0 = params[14] + else: + var0 = params[15] + if inputs[6] >= 4.5: + if inputs[0] >= -0.24336739: + if inputs[0] >= 0.5039667: + if inputs[6] >= 8.5: + var1 = params[16] + else: + var1 = params[17] + else: + if inputs[6] >= 8.5: + var1 = params[18] + else: + var1 = params[19] + else: + if inputs[6] >= 8.5: + if inputs[0] >= -0.49056926: + var1 = params[20] + else: + var1 = params[21] + else: + if inputs[2] >= 0.6156785: + var1 = params[22] + else: + var1 = params[23] + else: + if inputs[0] >= -0.4307124: + if inputs[0] >= 0.2598629: + if inputs[13] >= 0.5: + var1 = params[24] + else: + var1 = params[25] + else: + if inputs[13] >= 0.5: + var1 = params[26] + else: + var1 = params[27] + else: + if inputs[0] >= -0.8881732: + if inputs[0] >= -0.83574: + var1 = params[28] + else: + var1 = params[29] + else: + if inputs[2] >= 0.6156785: + var1 = params[30] + else: + var1 = params[31] + if inputs[0] >= -0.34355754: + if inputs[6] >= 8.5: + if inputs[1] >= 0.81192434: + if inputs[0] >= -0.27352965: + var2 = params[32] + else: + var2 = params[33] + else: + if inputs[0] >= 0.2842967: + var2 = params[34] + else: + var2 = params[35] + else: + if inputs[1] >= 0.81192434: + if inputs[3] >= -5.5550003: + var2 = params[36] + else: + var2 = params[37] + else: + if inputs[0] >= 0.7530391: + var2 = params[38] + else: + var2 = params[39] + else: + if inputs[6] >= 5.5: + if inputs[1] >= -0.72406703: + if inputs[0] >= -0.648395: + var2 = params[40] + else: + var2 = params[41] + else: + if inputs[3] >= 2.78: + var2 = params[42] + else: + var2 = params[43] + else: + if inputs[1] >= 0.81192434: + if inputs[6] >= 2.5: + var2 = params[44] + else: + var2 = params[45] + else: + if inputs[0] >= -0.723333: + var2 = params[46] + else: + var2 = params[47] + if inputs[0] >= 0.011608863: + if inputs[0] >= 1.6133647: + if inputs[3] >= 6.95: + if inputs[0] >= 3.2881882: + var3 = params[48] + else: + var3 = params[49] + else: + if inputs[0] >= 2.6381216: + var3 = params[50] + else: + var3 = params[51] + else: + if inputs[3] >= 5.5550003: + if inputs[3] >= 6.9449997: + var3 = params[52] + else: + var3 = params[53] + else: + if inputs[3] >= 1.385: + var3 = params[54] + else: + var3 = params[55] + else: + if inputs[5] >= 2.5: + if inputs[3] >= 5.5550003: + if inputs[0] >= -0.5320132: + var3 = params[56] + else: + var3 = params[57] + else: + if inputs[0] >= -0.7692194: + var3 = params[58] + else: + var3 = params[59] + else: + if inputs[0] >= -0.89366794: + if inputs[7] >= 0.5: + var3 = params[60] + else: + var3 = params[61] + else: + if inputs[4] >= 0.5: + var3 = params[62] + else: + var3 = params[63] + if inputs[1] >= -1.2360642: + if inputs[1] >= 1.8340769: + if inputs[5] >= 2.5: + if inputs[11] >= 0.5: + var4 = params[64] + else: + var4 = params[65] + else: + if inputs[8] >= 0.5: + var4 = params[66] + else: + var4 = params[67] + else: + if inputs[5] >= 2.5: + if inputs[6] >= 4.5: + var4 = params[68] + else: + var4 = params[69] + else: + if inputs[4] >= -0.5: + var4 = params[70] + else: + var4 = params[71] + else: + if inputs[6] >= 10.5: + if inputs[7] >= 0.5: + var4 = params[72] + else: + var4 = params[73] + else: + if inputs[3] >= 5.5550003: + if inputs[5] >= 1.5: + var4 = params[74] + else: + var4 = params[75] + else: + if inputs[5] >= 3.5: + var4 = params[76] + else: + var4 = params[77] + if inputs[0] >= -0.4926736: + if inputs[1] >= 1.8340769: + if inputs[0] >= 0.008861526: + if inputs[5] >= 2.5: + var5 = params[78] + else: + var5 = params[79] + else: + if inputs[1] >= 2.8562293: + var5 = params[80] + else: + var5 = params[81] + else: + if inputs[1] >= -1.2360642: + if inputs[3] >= 4.165: + var5 = params[82] + else: + var5 = params[83] + else: + if inputs[5] >= 1.5: + var5 = params[84] + else: + var5 = params[85] + else: + if inputs[1] >= 0.81192434: + if inputs[4] >= 0.5: + if inputs[0] >= -0.90757996: + var5 = params[86] + else: + var5 = params[87] + else: + if inputs[3] >= 1.385: + var5 = params[88] + else: + var5 = params[89] + else: + if inputs[5] >= 2.5: + if inputs[0] >= -0.8758979: + var5 = params[90] + else: + var5 = params[91] + else: + if inputs[1] >= -1.2360642: + var5 = params[92] + else: + var5 = params[93] + if inputs[0] >= 0.20041522: + if inputs[0] >= 2.0295572: + if inputs[2] >= -0.40843666: + if inputs[4] >= -0.5: + var6 = params[94] + else: + var6 = params[95] + else: + if inputs[0] >= 2.772975: + var6 = params[96] + else: + var6 = params[97] + else: + if inputs[6] >= 3.5: + if inputs[11] >= 0.5: + var6 = params[98] + else: + var6 = params[99] + else: + if inputs[0] >= 0.2598629: + var6 = params[100] + else: + var6 = params[101] + else: + if inputs[6] >= 10.5: + if inputs[0] >= -1.1355505: + if inputs[0] >= -0.25447363: + var6 = params[102] + else: + var6 = params[103] + else: + var6 = params[104] + else: + if inputs[2] >= 0.6156785: + if inputs[3] >= 9.725: + var6 = params[105] + else: + var6 = params[106] + else: + if inputs[6] >= 4.5: + var6 = params[107] + else: + var6 = params[108] + if inputs[0] >= -0.53101945: + if inputs[6] >= 10.5: + if inputs[3] >= -5.5550003: + if inputs[11] >= 0.5: + var7 = params[109] + else: + var7 = params[110] + else: + var7 = params[111] + else: + if inputs[3] >= 8.335: + if inputs[3] >= 16.945: + var7 = params[112] + else: + var7 = params[113] + else: + if inputs[11] >= 0.5: + var7 = params[114] + else: + var7 = params[115] + else: + if inputs[6] >= 7.5: + if inputs[0] >= -1.1889775: + if inputs[3] >= 9.725: + var7 = params[116] + else: + var7 = params[117] + else: + var7 = params[118] + else: + if inputs[0] >= -1.0966785: + if inputs[10] >= 0.5: + var7 = params[119] + else: + var7 = params[120] + else: + if inputs[4] >= -0.5: + var7 = params[121] + else: + var7 = params[122] + if inputs[1] >= 0.81192434: + if inputs[3] >= 1.385: + if inputs[3] >= 2.775: + if inputs[0] >= 0.6119897: + var8 = params[123] + else: + var8 = params[124] + else: + if inputs[0] >= -1.1440263: + var8 = params[125] + else: + var8 = params[126] + else: + if inputs[1] >= 1.8340769: + if inputs[0] >= -1.167934: + var8 = params[127] + else: + var8 = params[128] + else: + if inputs[0] >= -0.52914894: + var8 = params[129] + else: + var8 = params[130] + else: + if inputs[1] >= -1.2360642: + if inputs[3] >= 4.165: + if inputs[0] >= 0.32328546: + var8 = params[131] + else: + var8 = params[132] + else: + if inputs[10] >= 0.5: + var8 = params[133] + else: + var8 = params[134] + else: + if inputs[3] >= 5.5550003: + if inputs[0] >= -1.2164508: + var8 = params[135] + else: + var8 = params[136] + else: + if inputs[0] >= 0.29347396: + var8 = params[137] + else: + var8 = params[138] + if inputs[6] >= 6.5: + if inputs[0] >= -1.1738379: + if inputs[2] >= 0.6156785: + if inputs[0] >= 0.45930788: + var9 = params[139] + else: + var9 = params[140] + else: + if inputs[0] >= 2.6381216: + var9 = params[141] + else: + var9 = params[142] + else: + if inputs[2] >= 0.6156785: + if inputs[0] >= -1.1889775: + var9 = params[143] + else: + var9 = params[144] + else: + if inputs[9] >= 0.5: + var9 = params[145] + else: + var9 = params[146] + else: + if inputs[5] >= 3.5: + if inputs[0] >= -1.1991484: + if inputs[0] >= 0.5094614: + var9 = params[147] + else: + var9 = params[148] + else: + var9 = params[149] + else: + if inputs[2] >= -0.40843666: + if inputs[13] >= 0.5: + var9 = params[150] + else: + var9 = params[151] + else: + if inputs[1] >= -0.2120699: + var9 = params[152] + else: + var9 = params[153] + if inputs[6] >= 4.5: + if inputs[0] >= -0.88887465: + if inputs[2] >= -0.40843666: + if inputs[6] >= 7.5: + var10 = params[154] + else: + var10 = params[155] + else: + if inputs[4] >= 0.5: + var10 = params[156] + else: + var10 = params[157] + else: + if inputs[4] >= 0.5: + if inputs[3] >= 4.165: + var10 = params[158] + else: + var10 = params[159] + else: + if inputs[0] >= -1.1740131: + var10 = params[160] + else: + var10 = params[161] + else: + if inputs[0] >= -1.0966785: + if inputs[6] >= 2.5: + if inputs[0] >= -1.0678023: + var10 = params[162] + else: + var10 = params[163] + else: + if inputs[4] >= 0.5: + var10 = params[164] + else: + var10 = params[165] + else: + if inputs[2] >= 0.6156785: + if inputs[0] >= -1.1775205: + var10 = params[166] + else: + var10 = params[167] + else: + if inputs[0] >= -1.1268408: + var10 = params[168] + else: + var10 = params[169] + if inputs[0] >= 1.1105437: + if inputs[0] >= 2.9452972: + var11 = params[170] + else: + if inputs[6] >= 3.5: + if inputs[2] >= -0.40843666: + var11 = params[171] + else: + var11 = params[172] + else: + if inputs[3] >= 6.9449997: + var11 = params[173] + else: + var11 = params[174] + else: + if inputs[1] >= 0.81192434: + if inputs[5] >= 2.5: + if inputs[0] >= -0.13610435: + var11 = params[175] + else: + var11 = params[176] + else: + if inputs[0] >= -0.102727115: + var11 = params[177] + else: + var11 = params[178] + else: + if inputs[2] >= 0.6156785: + if inputs[6] >= 9.5: + var11 = params[179] + else: + var11 = params[180] + else: + if inputs[6] >= 3.5: + var11 = params[181] + else: + var11 = params[182] + if inputs[6] >= 11.5: + if inputs[0] >= -1.0830588: + if inputs[0] >= -0.7648938: + if inputs[0] >= -0.7618542: + var12 = params[183] + else: + var12 = params[184] + else: + var12 = params[185] + else: + var12 = params[186] + else: + if inputs[2] >= 1.6397938: + if inputs[0] >= -1.0583327: + if inputs[0] >= -0.88460755: + var12 = params[187] + else: + var12 = params[188] + else: + if inputs[0] >= -1.1504562: + var12 = params[189] + else: + var12 = params[190] + else: + if inputs[0] >= 0.30399567: + if inputs[2] >= 0.6156785: + var12 = params[191] + else: + var12 = params[192] + else: + if inputs[4] >= -1.5: + var12 = params[193] + else: + var12 = params[194] + if inputs[0] >= -0.6066004: + if inputs[0] >= -0.6060159: + if inputs[1] >= 1.8340769: + if inputs[2] >= -0.40843666: + var13 = params[195] + else: + var13 = params[196] + else: + if inputs[5] >= 1.5: + var13 = params[197] + else: + var13 = params[198] + else: + var13 = params[199] + else: + if inputs[0] >= -1.241469: + if inputs[1] >= -0.72406703: + if inputs[4] >= 0.5: + var13 = params[200] + else: + var13 = params[201] + else: + if inputs[13] >= 0.5: + var13 = params[202] + else: + var13 = params[203] + else: + if inputs[4] >= 0.5: + if inputs[0] >= -1.2780613: + var13 = params[204] + else: + var13 = params[205] + else: + var13 = params[206] + if inputs[4] >= 1.5: + if inputs[1] >= -0.72406703: + if inputs[6] >= 3.5: + if inputs[11] >= 0.5: + var14 = params[207] + else: + var14 = params[208] + else: + if inputs[7] >= 0.5: + var14 = params[209] + else: + var14 = params[210] + else: + if inputs[4] >= 2.5: + var14 = params[211] + else: + var14 = params[212] + else: + if inputs[6] >= 2.5: + if inputs[9] >= 0.5: + if inputs[4] >= 0.5: + var14 = params[213] + else: + var14 = params[214] + else: + if inputs[1] >= -0.72406703: + var14 = params[215] + else: + var14 = params[216] + else: + if inputs[4] >= 0.5: + if inputs[8] >= 0.5: + var14 = params[217] + else: + var14 = params[218] + else: + if inputs[3] >= -1.39: + var14 = params[219] + else: + var14 = params[220] + if inputs[6] >= 4.5: + if inputs[2] >= -0.40843666: + if inputs[3] >= 1.385: + if inputs[13] >= 0.5: + var15 = params[221] + else: + var15 = params[222] + else: + if inputs[5] >= 2.5: + var15 = params[223] + else: + var15 = params[224] + else: + if inputs[4] >= 0.5: + if inputs[5] >= 1.5: + var15 = params[225] + else: + var15 = params[226] + else: + if inputs[3] >= 8.335: + var15 = params[227] + else: + var15 = params[228] + else: + if inputs[4] >= 1.5: + if inputs[0] >= -1.2207179: + if inputs[13] >= 0.5: + var15 = params[229] + else: + var15 = params[230] + else: + var15 = params[231] + else: + if inputs[2] >= -0.40843666: + if inputs[5] >= 3.5: + var15 = params[232] + else: + var15 = params[233] + else: + if inputs[3] >= 16.94: + var15 = params[234] + else: + var15 = params[235] + if inputs[1] >= -1.2360642: + if inputs[3] >= 1.385: + if inputs[0] >= -0.28451902: + if inputs[3] >= 2.775: + var16 = params[236] + else: + var16 = params[237] + else: + if inputs[8] >= 0.5: + var16 = params[238] + else: + var16 = params[239] + else: + if inputs[0] >= 2.6961663: + if inputs[8] >= 0.5: + var16 = params[240] + else: + var16 = params[241] + else: + if inputs[2] >= -0.40843666: + var16 = params[242] + else: + var16 = params[243] + else: + if inputs[0] >= -1.0745245: + if inputs[0] >= -1.0508506: + if inputs[3] >= 9.725: + var16 = params[244] + else: + var16 = params[245] + else: + if inputs[9] >= 0.5: + var16 = params[246] + else: + var16 = params[247] + else: + if inputs[8] >= 0.5: + if inputs[4] >= 0.5: + var16 = params[248] + else: + var16 = params[249] + else: + if inputs[4] >= 1.5: + var16 = params[250] + else: + var16 = params[251] + if inputs[1] >= 1.8340769: + if inputs[0] >= 3.0555997: + var17 = params[252] + else: + if inputs[2] >= -0.40843666: + if inputs[4] >= -1.5: + var17 = params[253] + else: + var17 = params[254] + else: + if inputs[6] >= 3.5: + var17 = params[255] + else: + var17 = params[256] + else: + if inputs[0] >= -1.2234068: + if inputs[0] >= -1.1792741: + if inputs[0] >= -1.1776373: + var17 = params[257] + else: + var17 = params[258] + else: + if inputs[6] >= 6.5: + var17 = params[259] + else: + var17 = params[260] + else: + if inputs[5] >= 2.5: + if inputs[0] >= -1.2355652: + var17 = params[261] + else: + var17 = params[262] + else: + if inputs[0] >= -1.2304213: + var17 = params[263] + else: + var17 = params[264] + if inputs[2] >= 1.6397938: + if inputs[8] >= 0.5: + if inputs[5] >= 2.5: + if inputs[0] >= 0.25588804: + var18 = params[265] + else: + var18 = params[266] + else: + if inputs[0] >= -0.043630145: + var18 = params[267] + else: + var18 = params[268] + else: + if inputs[6] >= 10.5: + if inputs[0] >= 0.039666772: + var18 = params[269] + else: + var18 = params[270] + else: + if inputs[0] >= -1.0241957: + var18 = params[271] + else: + var18 = params[272] + else: + if inputs[6] >= 9.5: + if inputs[5] >= 2.5: + if inputs[0] >= -1.0833511: + var18 = params[273] + else: + var18 = params[274] + else: + if inputs[1] >= -0.72406703: + var18 = params[275] + else: + var18 = params[276] + else: + if inputs[2] >= 0.6156785: + if inputs[5] >= 2.5: + var18 = params[277] + else: + var18 = params[278] + else: + if inputs[6] >= 5.5: + var18 = params[279] + else: + var18 = params[280] + if inputs[0] >= 1.562393: + if inputs[0] >= 3.5200167: + var19 = params[281] + else: + if inputs[2] >= 1.6397938: + var19 = params[282] + else: + if inputs[6] >= 9.5: + var19 = params[283] + else: + var19 = params[284] + else: + if inputs[0] >= 1.4279487: + if inputs[7] >= 0.5: + if inputs[4] >= 0.5: + var19 = params[285] + else: + var19 = params[286] + else: + var19 = params[287] + else: + if inputs[0] >= -1.2381372: + if inputs[0] >= -1.1435586: + var19 = params[288] + else: + var19 = params[289] + else: + if inputs[2] >= 0.6156785: + var19 = params[290] + else: + var19 = params[291] + if inputs[3] >= -2.775: + if inputs[6] >= 2.5: + if inputs[11] >= 0.5: + if inputs[3] >= 4.165: + var20 = params[292] + else: + var20 = params[293] + else: + if inputs[1] >= -0.2120699: + var20 = params[294] + else: + var20 = params[295] + else: + if inputs[4] >= -0.5: + if inputs[4] >= 0.5: + var20 = params[296] + else: + var20 = params[297] + else: + if inputs[1] >= 0.81192434: + var20 = params[298] + else: + var20 = params[299] + else: + if inputs[7] >= 0.5: + var20 = params[300] + else: + if inputs[6] >= 11.5: + var20 = params[301] + else: + if inputs[6] >= 7.5: + var20 = params[302] + else: + var20 = params[303] + if inputs[0] >= -0.18257526: + if inputs[4] >= -1.5: + if inputs[0] >= -0.07835181: + if inputs[2] >= 1.6397938: + var21 = params[304] + else: + var21 = params[305] + else: + if inputs[5] >= 1.5: + var21 = params[306] + else: + var21 = params[307] + else: + if inputs[6] >= 5.5: + if inputs[11] >= 0.5: + var21 = params[308] + else: + var21 = params[309] + else: + var21 = params[310] + else: + if inputs[0] >= -0.19888392: + var21 = params[311] + else: + if inputs[0] >= -0.53101945: + if inputs[13] >= 0.5: + var21 = params[312] + else: + var21 = params[313] + else: + if inputs[4] >= 0.5: + var21 = params[314] + else: + var21 = params[315] + if inputs[5] >= 3.5: + if inputs[0] >= -0.8305961: + if inputs[6] >= 4.5: + var22 = params[316] + else: + if inputs[8] >= 0.5: + var22 = params[317] + else: + var22 = params[318] + else: + if inputs[6] >= 10.5: + var22 = params[319] + else: + var22 = params[320] + else: + if inputs[5] >= 1.5: + if inputs[2] >= -0.40843666: + if inputs[3] >= -5.5550003: + var22 = params[321] + else: + var22 = params[322] + else: + if inputs[5] >= 2.5: + var22 = params[323] + else: + var22 = params[324] + else: + if inputs[3] >= -5.5550003: + if inputs[2] >= 2.663909: + var22 = params[325] + else: + var22 = params[326] + else: + if inputs[8] >= 0.5: + var22 = params[327] + else: + var22 = params[328] + if inputs[6] >= 3.5: + if inputs[3] >= 16.665: + var23 = params[329] + else: + if inputs[0] >= -0.8443327: + if inputs[3] >= -5.5550003: + var23 = params[330] + else: + var23 = params[331] + else: + if inputs[3] >= -4.17: + var23 = params[332] + else: + var23 = params[333] + else: + if inputs[7] >= 0.5: + if inputs[0] >= -1.0372308: + var23 = params[334] + else: + if inputs[1] >= 0.81192434: + var23 = params[335] + else: + var23 = params[336] + else: + if inputs[0] >= 0.5085846: + if inputs[1] >= -0.2120699: + var23 = params[337] + else: + var23 = params[338] + else: + var23 = params[339] + if inputs[6] >= 7.5: + if inputs[2] >= 1.6397938: + if inputs[0] >= -1.1504562: + if inputs[0] >= -0.96270204: + var24 = params[340] + else: + var24 = params[341] + else: + var24 = params[342] + else: + if inputs[4] >= 1.5: + if inputs[0] >= -0.22103798: + var24 = params[343] + else: + var24 = params[344] + else: + if inputs[3] >= -5.5550003: + var24 = params[345] + else: + var24 = params[346] + else: + if inputs[2] >= -0.40843666: + if inputs[5] >= 1.5: + if inputs[3] >= 9.725: + var24 = params[347] + else: + var24 = params[348] + else: + if inputs[7] >= 0.5: + var24 = params[349] + else: + var24 = params[350] + else: + if inputs[0] >= -1.0936389: + if inputs[3] >= 9.725: + var24 = params[351] + else: + var24 = params[352] + else: + if inputs[0] >= -1.095568: + var24 = params[353] + else: + var24 = params[354] + if inputs[4] >= 2.5: + var25 = params[355] + else: + if inputs[5] >= 1.5: + if inputs[2] >= 0.6156785: + if inputs[5] >= 2.5: + var25 = params[356] + else: + var25 = params[357] + else: + if inputs[4] >= -0.5: + var25 = params[358] + else: + var25 = params[359] + else: + if inputs[2] >= 1.6397938: + if inputs[4] >= -0.5: + var25 = params[360] + else: + var25 = params[361] + else: + if inputs[3] >= 2.775: + var25 = params[362] + else: + var25 = params[363] + if inputs[0] >= -0.12295219: + if inputs[0] >= -0.09384212: + if inputs[0] >= -0.09273149: + if inputs[6] >= 4.5: + var26 = params[364] + else: + var26 = params[365] + else: + var26 = params[366] + else: + if inputs[3] >= 2.775: + if inputs[6] >= 3.5: + var26 = params[367] + else: + var26 = params[368] + else: + if inputs[0] >= -0.10927397: + var26 = params[369] + else: + var26 = params[370] + else: + if inputs[0] >= -0.15434198: + if inputs[0] >= -0.14627534: + if inputs[0] >= -0.14352798: + var26 = params[371] + else: + var26 = params[372] + else: + var26 = params[373] + else: + if inputs[0] >= -0.15632942: + if inputs[5] >= 2.5: + var26 = params[374] + else: + var26 = params[375] + else: + if inputs[0] >= -0.53101945: + var26 = params[376] + else: + var26 = params[377] + if inputs[1] >= 0.81192434: + if inputs[7] >= 0.5: + if inputs[4] >= -1.5: + if inputs[2] >= 0.6156785: + var27 = params[378] + else: + var27 = params[379] + else: + var27 = params[380] + else: + var27 = params[381] + else: + if inputs[11] >= 0.5: + if inputs[4] >= 1.5: + var27 = params[382] + else: + if inputs[2] >= -0.40843666: + var27 = params[383] + else: + var27 = params[384] + else: + if inputs[1] >= -0.2120699: + if inputs[3] >= 4.165: + var27 = params[385] + else: + var27 = params[386] + else: + var27 = params[387] + if inputs[0] >= -1.200376: + if inputs[6] >= 6.5: + if inputs[4] >= 0.5: + if inputs[2] >= 0.6156785: + var28 = params[388] + else: + var28 = params[389] + else: + if inputs[1] >= 2.8562293: + var28 = params[390] + else: + var28 = params[391] + else: + if inputs[0] >= -1.1789818: + if inputs[1] >= 0.81192434: + var28 = params[392] + else: + var28 = params[393] + else: + if inputs[4] >= 0.5: + var28 = params[394] + else: + var28 = params[395] + else: + if inputs[2] >= 0.6156785: + var28 = params[396] + else: + if inputs[6] >= 3.5: + if inputs[10] >= 0.5: + var28 = params[397] + else: + var28 = params[398] + else: + var28 = params[399] + if inputs[2] >= -0.40843666: + if inputs[0] >= -1.0989583: + if inputs[0] >= -1.0953926: + if inputs[0] >= -1.0896641: + var29 = params[400] + else: + var29 = params[401] + else: + var29 = params[402] + else: + if inputs[0] >= -1.1170206: + if inputs[6] >= 9.0: + var29 = params[403] + else: + var29 = params[404] + else: + if inputs[7] >= 0.5: + var29 = params[405] + else: + var29 = params[406] + else: + if inputs[0] >= -1.0439532: + if inputs[0] >= -1.0098159: + if inputs[0] >= 0.7677696: + var29 = params[407] + else: + var29 = params[408] + else: + if inputs[6] >= 3.5: + var29 = params[409] + else: + var29 = params[410] + else: + if inputs[0] >= -1.0448884: + var29 = params[411] + else: + if inputs[6] >= 6.5: + var29 = params[412] + else: + var29 = params[413] + return 0.5 + (var0 + var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20 + var21 + var22 + var23 + var24 + var25 + var26 + var27 + var28 + var29) + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/ref_model/tree.py b/matsim/scenariogen/network/ref_model/tree.py new file mode 100644 index 0000000..1ac839f --- /dev/null +++ b/matsim/scenariogen/network/ref_model/tree.py @@ -0,0 +1,109 @@ +""" Custom defined reference model for speed relative target """ + +# simple decision tree + +# Inputs: length, (0) +# priority_lower, priority_equal, priority_higher, (1,2,3) +# is_secondary_or_higher, is_primary_or_higher, is_motorway (4,5,6) +# speed (7) + +params = [0.9, 0.8, 0.9, 0.8, 0.7, 0.7, 0.7, 0.7] * 3 + +def score(params, inputs): + # lower prio + if inputs[1] == 1: + # highway + if inputs[6] == 1: + # >= 100kmh + if inputs[7] >= 27.5: + return params[0] + else: + return params[1] + # primary + elif inputs[5] == 1: + # >= 80khm + if inputs[7] >= 22: + return params[2] + else: + return params[3] + # secondary + elif inputs[4] == 1: + # 30kmh or lower + if inputs[7] <= 10: + return params[4] + else: + return params[5] + else: + # 30kmh or lower + if inputs[7] <= 10: + return params[6] + else: + return params[7] + + # equal prio + elif inputs[2] == 1: + # highway + if inputs[6] == 1: + # >= 100kmh + if inputs[7] >= 27.5: + return params[8] + else: + return params[9] + # primary + elif inputs[5] == 1: + # >= 80khm + if inputs[7] >= 22: + return params[10] + else: + return params[11] + # secondary + elif inputs[4] == 1: + # 30kmh or lower + if inputs[7] <= 10: + return params[12] + else: + return params[13] + else: + # 30kmh or lower + if inputs[7] <= 10: + return params[14] + else: + return params[15] + + # higher prio + else: + # highway + if inputs[6] == 1: + # >= 100kmh + if inputs[7] >= 27.5: + return params[16] + else: + return params[17] + # primary + elif inputs[5] == 1: + # >= 80khm + if inputs[7] >= 22: + return params[18] + else: + return params[19] + # secondary + elif inputs[4] == 1: + # 30kmh or lower + if inputs[7] <= 10: + return params[20] + else: + return params[21] + else: + # 30kmh or lower + if inputs[7] <= 10: + return params[22] + else: + return params[23] + + +def batch_loss(params, inputs, targets): + error = 0 + for x, y in zip(inputs, targets): + preds = score(params, x) + error += (preds - y) ** 2 + return error diff --git a/matsim/scenariogen/network/runOPT.sh b/matsim/scenariogen/network/runOPT.sh new file mode 100755 index 0000000..3a70a2e --- /dev/null +++ b/matsim/scenariogen/network/runOPT.sh @@ -0,0 +1,49 @@ +#!/bin/bash --login +#$ -l h_rt=700000 +#$ -j y +#$ -m a +#$ -o ./logfile/logfile_$JOB_NAME.log +#$ -cwd +#$ -pe mp 6 +#$ -l mem_free=4G +#$ -l cpuflag_avx2=1 +#$ -N network-opt + +date +hostname + +source venv/bin/activate +module add java/17 + +jar="matsim-[name]-SNAPSHOT.jar" +input="input/*" +model="org.matsim.prepare.network.Model" +network="network.xml.gz" +ft="network-ft.csv.gz" + +# Find a free port +while + port=$(shuf -n 1 -i 49152-65535) + netstat -atun | grep -q "$port" +do + continue +done + +command="java -cp ${jar} org.matsim.application.prepare.network.opt.FreespeedOptServer ${input} + --network ${network} --input-features ${ft} --model ${model} --port ${port}" + +echo "" +echo "command is $command" +echo "" + +$command & + +echo "Waiting to launch on ${port}..." + +while ! nc -z localhost "${port}"; do + sleep 0.5 +done + +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +python -u -m matsim.scenariogen network-opt-freespeed --port "${port}" \ No newline at end of file diff --git a/matsim/scenariogen/network/runSUMO.sh b/matsim/scenariogen/network/runSUMO.sh new file mode 100755 index 0000000..6d8e018 --- /dev/null +++ b/matsim/scenariogen/network/runSUMO.sh @@ -0,0 +1,39 @@ +#!/bin/bash --login +#$ -l h_rt=700000 +#$ -j y +#$ -m a +#$ -o ./logfile/logfile_$JOB_NAME.log +#$ -cwd +#$ -pe mp 3 +#$ -l mem_free=3G +#$ -N sumo + +date +hostname + +source venv/bin/activate + +#ENV=$(realpath "env") +#export LD_LIBRARY_PATH="$ENV/lib64:$ENV/lib:$LD_LIBRARY_PATH" +#export SUMO_HOME="$ENV/share/sumo/" + +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +# use with -t 1-10 +idx=$((SGE_TASK_ID - 1)) +total=$SGE_TASK_LAST + +mode="routes" +scenario="base" +network="sumo.net.xml" + +f="output-${mode}/scenario-$scenario" + +command="python -u -m matsim.scenariogen sumo-${mode} ${mode}.txt --scenario $scenario --network $network --output $f --runner runner/${JOB_ID}${SGE_TASK_ID} --runner-index $idx --runner-total $total" + +echo "" +echo "command is $command" +echo "" + +$command +python -u -m matsim.scenariogen sumo-collect-results $mode --input $f \ No newline at end of file diff --git a/matsim/scenariogen/network/runTrainModel.sh b/matsim/scenariogen/network/runTrainModel.sh new file mode 100755 index 0000000..c3c7884 --- /dev/null +++ b/matsim/scenariogen/network/runTrainModel.sh @@ -0,0 +1,35 @@ +#!/bin/bash --login +#$ -l h_rt=700000 +#$ -j y +#$ -m a +#$ -o ./logfile/logfile_$JOB_NAME.log +#$ -cwd +#$ -pe mp 6 +#$ -l mem_free=4G +#$ -N network-train + +date +hostname + +source venv/bin/activate +module add java/17 + +ft="network-ft.csv.gz" +intersections="result_intersections_scenario-base.csv" +routes="result_routes_scenario-base.csv" +name="Scenario" +package="org.matsim.prepare.network" +output="gen_code" +type="default" + +command="python -u -m matsim.scenariogen network-train-model + --name ${name} --package ${package} --model-type ${type} --output ${output} + --network-features ${ft} --input-intersections ${intersections} --input-routes ${routes}" + +echo "" +echo "command is $command" +echo "" + +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + +$command \ No newline at end of file diff --git a/matsim/scenariogen/network/run_collect_results.py b/matsim/scenariogen/network/run_collect_results.py new file mode 100644 index 0000000..8cf96ec --- /dev/null +++ b/matsim/scenariogen/network/run_collect_results.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import os + +from argparse import ArgumentParser + +from .features import read_edges, read_intersections, read_routes + +METADATA = "sumo-collect-results", "Aggregate results from sumo runs" + + +def setup(parser: ArgumentParser): + + parser.add_argument("mode", nargs='?', help="Convert result file that create with one of the run scripts", + choices=["edges", "intersections", "routes"]) + parser.add_argument("--input", help="Path to input file for conversion", required=True) + +def main(args): + + df = None + + if args.mode == "edges": + df = read_edges(args.input) + + elif args.mode == "intersections": + df = read_intersections(args.input) + + elif args.mode == "routes": + df = read_routes(args.input) + + if df is not None: + base = os.path.basename(args.input.rstrip("/")) + df.to_csv(f"result_{args.mode}_{base}.csv", index=False) diff --git a/matsim/scenariogen/network/run_edges.py b/matsim/scenariogen/network/run_edges.py new file mode 100644 index 0000000..ae50f7a --- /dev/null +++ b/matsim/scenariogen/network/run_edges.py @@ -0,0 +1,225 @@ +#!/usr/bin/env python +# @author Angelo Banse, Ronald Nippold, Christian Rakow + +import os +import shutil +import sys +from argparse import ArgumentParser +from os.path import join, basename + +from .utils import init_workload, setup_parser, create_args, write_scenario, filter_network, vehicle_parameter + +import sumolib.net +import traci # noqa +from sumolib import checkBinary # noqa +import lxml.etree as ET + +import pandas as pd +import numpy as np + +sumoBinary = checkBinary('sumo') +netconvert = checkBinary('netconvert') + +METADATA = "sumo-edges", "Determine edge volumes with SUMO." + + +def capacity_estimate(v): + tT = 1.2 + lL = 7.0 + Qc = v / (v * tT + lL) + + return 3600 * Qc + + +def writeRouteFile(f_name, departLane, arrivalLane, edges, veh, scenario): + text = """ + + +""" + text += """ + %s + + """ % vehicle_parameter(scenario) + + text += """ + + + + +""" + + # departSpeed="speedLimit" ? + context = { + "departLane": departLane, + "arrivalLane": arrivalLane, + "edges": edges, + "veh": veh + } + + with open(f_name, "w") as f: + f.write(text.format(**context)) + + +def writeDetectorFile(f_name, output, lane, laneNr, scale): + text = """ + + + %s + + + """ % "\n".join( + """""" % ( + i, i, i) + for i in + range(laneNr)) + + context = { + "lane": lane, + "laneNr": laneNr, + "output_file": join(output, scale, "lane") + } + + with open(f_name, 'w') as f: + f.write(text.format(**context)) + + +def read_result(folder, edge, scale): + data = [] + + for f in os.listdir(folder): + if not f.endswith(".xml"): + continue + + total = 0 + end = 0 + + for _, elem in ET.iterparse(join(folder, f), events=("end",), + tag=('interval',), + remove_blank_text=True): + + begin = float(elem.attrib["begin"]) + end = float(elem.attrib["end"]) + if begin < 60: + continue + + total += float(elem.attrib["nVehContrib"]) + + data.append({ + "edgeId": edge, + "laneId": f.replace(".xml", ""), + "flow": total * (3600 / (end - 60)), + "scale": float(scale), + "count": total + }) + + return data + + +def run(args, edges): + # saveToFile(edges_ids,"junctions.json") + i = 0 + + if args.to_index <= 0: + args.to_index = len(edges) + + for x in range(args.from_index, args.to_index): + edge = edges[x] + i += 1 + print("Edge id: ", edge._id) + print("Number of lanes: ", edge.getLaneNumber(), "speed:", edge.getSpeed()) + + laneNr = edge.getLaneNumber() # nr of lanes + + cap = capacity_estimate(edge.getSpeed()) * 0.9 * laneNr + + print("Capacity estimate:", cap) + + p_network = join(args.runner, "filtered.net.xml") + p_routes = join(args.runner, "route.rou.xml") + p_detector = join(args.runner, "detector.add.xml") + + filter_network(netconvert, args.network, edge, p_network) + writeRouteFile(p_routes, "best", "current", edge._id, cap, args.scenario) + p_scenario = join(args.runner, "scenario.sumocfg") + + write_scenario(p_scenario, basename(p_network), basename(p_routes), basename(p_detector), args.step_length) + + go(p_scenario, p_network, edge, p_detector, args) + print("####################################################################") + print("[" + str(i) + " / " + str(args.to_index - args.from_index) + "]") + + +def go(scenario, network, edge, p_detector, args): + # while traci.simulation.getMinExpectedNumber() > 0: + + end = int(600 * (1 / args.step_length)) + + res = [] + + folder = join(args.runner, "detector") + + # Clean old data + shutil.rmtree(folder, ignore_errors=True) + os.makedirs(folder, exist_ok=True) + + traci.start([sumoBinary, "-n", network], port=args.port) + + xr = ["%.2f" % s for s in np.arange(1, 2.1, 0.05)] + + # Simulate different scales + for scale in xr: + + # print("Running scale", scale) + + os.makedirs(join(folder, scale), exist_ok=True) + writeDetectorFile(p_detector, "detector", edge._id, edge.getLaneNumber(), scale) + + # Load scenario with desired traffic scaling + traci.load(["-c", scenario, "--scale", scale]) + + try: + for step in range(0, end): + traci.simulationStep() + except Exception as e: + print(e) + + traci.close() + + for scale in xr: + res.extend(read_result(join(folder, scale), edge._id, scale)) + + df = pd.DataFrame(res) + df.to_csv(join(args.output, "%s.csv" % edge._id), index=False) + + sys.stdout.flush() + + +def setup(parser: ArgumentParser): + setup_parser(parser) + + +def main(args): + args = create_args(args) + + net = sumolib.net.readNet(args.network, withConnections=False, withInternal=False, withFoes=False) + + allEdges = net.getEdges() # all type of edges + + with open(args.input[0]) as f: + selection = set(f.read().splitlines()) + + # select if edges in net file + edges = [edge for edge in allEdges if edge._id in selection] + + init_workload(args, edges) + + print("Total number of edges:", len(edges)) + print("Processing: ", args.from_index, ' to ', args.to_index) + + run(args, edges) + + +if __name__ == "__main__": + parser = ArgumentParser(prog=METADATA[0], description=METADATA[1]) + setup(parser) + main(parser.parse_args()) diff --git a/matsim/scenariogen/network/run_intersections.py b/matsim/scenariogen/network/run_intersections.py new file mode 100644 index 0000000..a688229 --- /dev/null +++ b/matsim/scenariogen/network/run_intersections.py @@ -0,0 +1,232 @@ +#!/usr/bin/env python +# @author Angelo Banse, Ronald Nippold, Christian Rakow + +import os +import shutil +import sys +from argparse import ArgumentParser +from os.path import join, basename + +from .utils import setup_parser, create_args, init_workload, write_scenario, filter_network, vehicle_parameter + +import traci # noqa +import sumolib.net +from sumolib import checkBinary # noqa +import lxml.etree as ET + +import pandas as pd + +sumoBinary = checkBinary('sumo') +netconvert = checkBinary('netconvert') + +METADATA = "sumo-intersections", "Determine intersection volumes with SUMO." + + +def writeRouteFile(f_name, routes, extra_routes, scenario): + """ Write route file for intersection """ + + text = """ + + + + +""" + text += """ + %s + + """ % vehicle_parameter(scenario) + + for i, edges in enumerate(routes): + text += """ + + + + """ % (i, edges) + + for i, edges in enumerate(extra_routes): + text += """ + + + + """ % (i, edges) + + text += "" + + with open(f_name, "w") as f: + f.write(text) + + +def writeDetectorFile(f_name, output, lanes): + text = """ + +""" + + for i, lane in enumerate(lanes): + text += """ + + """ % (i, lane, join(output, "lane%d" % i)) + + text += "" + + with open(f_name, 'w') as f: + f.write(text) + + +def read_result(folder, **kwargs): + flow = 0 + + for f in os.listdir(folder): + if not f.endswith(".xml"): + continue + + total = 0 + end = 0 + + for _, elem in ET.iterparse(join(folder, f), events=("end",), + tag=('interval',), + remove_blank_text=True): + + begin = float(elem.attrib["begin"]) + end = float(elem.attrib["end"]) + if begin < 60: + continue + + total += float(elem.attrib["nVehContrib"]) + + flow += total * (3600 / (end - 60)) + + kwargs["flow"] = flow + return kwargs + + +def run(args, nodes): + print("Running scenario: " + args.scenario) + + if args.to_index <= 0: + args.to_index = len(nodes) + + i = 0 + + for x in range(args.from_index, args.to_index): + node = nodes[x] + i += 1 + + print("####################################################################") + print("Junction id: " + node._id) + + folder = join(args.runner, "detector") + p_network = join(args.runner, "filtered.net.xml") + + edges = [c.getFrom() for c in node.getConnections()] + [c.getTo() for c in node.getConnections()] + + filter_network(netconvert, args.network, edges, p_network, ["--no-internal-links", "false"]) + + pairs = set((c.getFrom(), c.getTo()) for c in node.getConnections() if c._direction != c.LINKDIR_TURN) + + res = [] + + for fromEdge, toEdge in pairs: + + # Clean old data + shutil.rmtree(folder, ignore_errors=True) + os.makedirs(folder, exist_ok=True) + + p_scenario = join(args.runner, "scenario.sumocfg") + p_routes = join(args.runner, "route.rou.xml") + p_detector = join(args.runner, "detector.add.xml") + + routes = [] + + # Build routes by trying to use incoming edge, when it is too short + if fromEdge._length < 30: + routes = [k._id + " " + fromEdge._id + " " + toEdge._id for k, v in fromEdge._incoming.items() if + all(d._direction not in (d.LINKDIR_TURN, d.LINKDIR_LEFT, d.LINKDIR_RIGHT) for d in v)] + + if not routes: + routes = [fromEdge._id + " " + toEdge._id] + + extra_routes = [] + # Produce car traffic on the other connections + for c in node.getConnections(): + if c._direction == c.LINKDIR_TURN: + continue + + if c.getFrom() == fromEdge or c.getTo() == toEdge: + continue + + r = c.getFrom()._id + " " + c.getTo()._id + if r not in extra_routes: + extra_routes.append(r) + + lanes = [fromEdge._id + "_" + str(i) for i in range(len(fromEdge._lanes))] + + writeRouteFile(p_routes, routes, extra_routes, args.scenario) + + writeDetectorFile(p_detector, "detector", lanes) + + write_scenario(p_scenario, basename(p_network), basename(p_routes), basename(p_detector), args.step_length, + time=1800) + + go(p_scenario, args) + + # Read output + res.append(read_result(folder, + junctionId=node._id, + fromEdgeId=fromEdge._id, + toEdgeId=toEdge._id)) + + df = pd.DataFrame(res) + df.to_csv(join(args.output, "%s.csv" % node._id), index=False) + + print("####################################################################") + print("[" + str(i) + " / " + str(args.to_index - args.from_index) + "]") + + +def go(scenario, args): + traci.start([sumoBinary, "-c", scenario]) + + end = int(1800 * (1 / args.step_length)) + + try: + for step in range(0, end): + traci.simulationStep() + except Exception as e: + print(e) + + traci.close() + sys.stdout.flush() + + +def setup(parser: ArgumentParser): + setup_parser(parser) + + +def main(args): + args = create_args(args) + + # read in intersections + with open(args.input[0]) as f: + selection = set(f.read().splitlines()) + + net = sumolib.net.readNet(args.network, withConnections=True, withInternal=False, withFoes=False) + allNodes = net.getNodes() # all type of nodes + + traffic_intersections = [] + for node in allNodes: + if node._type != "internal" and node._id in selection: + traffic_intersections.append(node) + + print("Total number of junctions:", len(traffic_intersections)) + + init_workload(args, traffic_intersections) + + print("Processing: ", args.from_index, ' to ', args.to_index) + + run(args, traffic_intersections) + + +if __name__ == "__main__": + parser = ArgumentParser(prog=METADATA[0], description=METADATA[1]) + setup(parser) + main(parser.parse_args()) + diff --git a/matsim/scenariogen/network/run_opt_freespeed.py b/matsim/scenariogen/network/run_opt_freespeed.py new file mode 100644 index 0000000..3ab33a5 --- /dev/null +++ b/matsim/scenariogen/network/run_opt_freespeed.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python + +import argparse +import json +import os +import time +from dataclasses import dataclass +from functools import reduce +from random import Random + +import numpy as np +import jax.numpy as jnp +import optax +from jax import grad, random +from requests import post +from tqdm import trange + +URL = "http://localhost:%d" + +METADATA = "network-opt-freespeed", "Optimize parameters for free-speed model. Server must be running before starting." + + +def as_list(array): + return [float(x) for x in array] + + +def req(port, priority, rbl, traffic_light): + req = { + "priority": as_list(priority), + "right_before_left": as_list(rbl), + "traffic_light": as_list(traffic_light), + } + + results = [post(URL % p, json=req).json() for p in port] + + data = {} + for k in results[0]["data"].keys(): + data[k] = reduce(lambda x, y: x + y, [d["data"][k] for d in results]) + + res = { + "rmse": np.mean([x["rmse"] for x in results]), + "mae": np.mean([x["mae"] for x in results]), + "data": data + } + + return req, res + + +@dataclass +class Model: + name: str + module: object + optimizer: optax.adam + opt_state: object + params: jnp.array + loss: callable + + +def setup(parser: argparse.ArgumentParser): + parser.add_argument("--steps", type=int, help="Number of training steps", default=1500) + parser.add_argument("--resume", help="File with parameters to to resume", default=None) + parser.add_argument("--port", type=int, nargs="+", help="Port to connect on", default=[9090]) + parser.add_argument("--ref-model", required=False, default=None, + help="Use an integrated model instead of importing", choices=["tree", "germany"]) + parser.add_argument("--learning-rate", type=float, help="Start learning rate", default=1e-4) + parser.add_argument("--batch-size", type=int, help="Batch size", default=128) + parser.add_argument("--output", help="Output folder for params", default="output-params") + + +def main(args): + batch_size = args.batch_size + batches = 5 + + models = {} + resume = {} + + if args.ref_model == "tree": + from .ref_model import tree as p + rbl = tl = p + elif args.ref_model == "germany": + from .ref_model.germany import speedRelative_priority as p + from .ref_model.germany import speedRelative_right_before_left as rbl + from .ref_model.germany import speedRelative_traffic_light as tl + else: + # Import model, must be present on path + from gen_code import speedRelative_priority as p + from gen_code import speedRelative_right_before_left as rbl + from gen_code import speedRelative_traffic_light as tl + + if args.resume: + print("Resuming from", args.resume) + with open(args.resume) as f: + resume = json.load(f) + + for (module, name) in ((p, "priority"), (tl, "traffic_light"), (rbl, "right_before_left")): + schedule = optax.exponential_decay( + init_value=args.learning_rate, decay_rate=0.9, + # Every 5% steps, decay 0.9 + transition_steps=int(batches * args.steps / 20), transition_begin=int(0.35 * args.steps * batches), + staircase=False + ) + + optimizer = optax.adam(schedule) + params = jnp.array(resume[name] if name in resume else module.params) + opt_state = optimizer.init(params) + + models[name] = Model( + name, module, optimizer, opt_state, params, grad(module.batch_loss) + ) + + r = Random(42) + + out = os.path.join(args.output, time.strftime("%Y%m%d-%H%M")) + os.makedirs(out, exist_ok=True) + + print("Writing to", out) + + with trange(args.steps) as outer: + + # A simple update loop. + for i in outer: + params, result = req(args.port, models["priority"].params, + models["right_before_left"].params, models["traffic_light"].params) + + name = "it%04d_mae_%.3f_rmse_%.3f.json" % (i, result["mae"], result["rmse"]) + + with open(os.path.join(out, name), "w") as f: + json.dump(params, f) + + outer.set_postfix(mae=result["mae"], rmse=result["rmse"]) + data = result["data"] + + for k, m in models.items(): + + xs = [d["x"] for d in data[k]] + xs = jnp.array(xs) + + ys = [d["yTrue"] for d in data[k]] + ys = jnp.array(ys) + + for j in range(batches): + key = random.PRNGKey(r.getrandbits(31)) + + idx = random.choice(key, jnp.arange(0, xs.shape[0]), shape=(batch_size,)) + + grads = m.loss(m.params, xs[idx], ys[idx]) + + updates, m.opt_state = m.optimizer.update(grads, m.opt_state) + m.params = optax.apply_updates(m.params, updates) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(prog=METADATA[0], description=METADATA[1]) + setup(parser) + main(parser.parse_args()) diff --git a/matsim/scenariogen/network/run_routes.py b/matsim/scenariogen/network/run_routes.py new file mode 100644 index 0000000..4b3fbc9 --- /dev/null +++ b/matsim/scenariogen/network/run_routes.py @@ -0,0 +1,184 @@ +#!/usr/bin/env python +# @author Angelo Banse, Ronald Nippold, Christian Rakow + +import os +import sys +from argparse import ArgumentParser +from os.path import join, basename +from traceback import print_exc + +from .utils import init_workload, setup_parser, create_args, write_scenario, filter_network_polygon, vehicle_parameter +from .randomTrips import get_options, main as gen_trips + +import sumolib.net +import traci # noqa + +from sumolib import checkBinary # noqa + +import lxml.etree as ET + +import pandas as pd + +sumoBinary = checkBinary('sumo') +netconvert = checkBinary('netconvert') + +METADATA = "sumo-routes", "Determine avg. uncongested link speed with SUMO." + + +def writeRouteFile(f_name, fromEdge, toEdge, veh, end, scenario): + """ Write route file using flow """ + # https://sumo.dlr.de/docs/Demand/Shortest_or_Optimal_Path_Routing.html + # https://sumo.dlr.de/docs/Definition_of_Vehicles%2C_Vehicle_Types%2C_and_Routes.html#incomplete_routes_trips_and_flows + + text = f""" + + + {vehicle_parameter(scenario)} + + + + +""" + + with open(f_name, "w") as f: + f.write(text) + + +def writeDetectorFile(f_name, begin): + """ Write files needed for analysis """ + + # https://sumo.dlr.de/docs/Simulation/Output/Lane-_or_Edge-based_Traffic_Measures.html + + text = f""" + + + + """ % begin + + with open(f_name, 'w') as f: + f.write(text) + + +def read_result(out): + """ Reads result from output xml """ + + data = [] + + for _, elem in ET.iterparse(out, events=("end",), + tag=('edge',), + remove_blank_text=True): + d = { + "edgeId": elem.attrib["id"] + } + for a in ("traveltime", "density", "waitingTime", "timeLoss", "speed", "speedRelative"): + d[a] = float(elem.attrib.get(a, float("nan"))) + + # Skip the non primary routes + if int(elem.attrib.get("entered", "0")) < 100 and int(elem.attrib.get("left", "0")) < 100: + continue + + data.append(d) + + return pd.DataFrame(data) + + +def run(args, routes, location_offset): + i = 0 + + if args.to_index <= 0: + args.to_index = len(routes) + + for x in range(args.from_index, args.to_index): + route = routes.iloc[x] + i += 1 + + print(route) + + p_network = join(args.runner, "filtered.net.xml") + p_routes = join(args.runner, "route.rou.xml") + p_detector = join(args.runner, "detector.add.xml") + p_trips = join(args.runner, "trips.trips.xml") + + # 1hour simulation plus travel time + end = int(route.travel_time + 3600) + + filter_network_polygon(netconvert, args.network, location_offset, route.geometry, p_network) + + # Nearly uncongested vehicle flow + writeRouteFile(p_routes, route.fromEdge, route.toEdge, int(route.min_capacity * 0.3), end, args.scenario) + writeDetectorFile(p_detector, route.travel_time) + + # Produce some very light traffic on the other roads + gen_trips(get_options(["-n", p_network, "-o", p_trips, "-r", join(args.runner, "random_routes.rou.xml"), + "--validate", "-e", end, '-t type="vDist"', + "--insertion-density", args.insertion_density, "--fringe-factor", "max"])) + + p_scenario = join(args.runner, "scenario.sumocfg") + + write_scenario(p_scenario, basename(p_network), basename(p_routes) + "," + "trips.trips.xml", + basename(p_detector), args.step_length, end) + + try: + go(p_scenario, p_network, end, route.fromEdge + "_" + route.toEdge, args) + except Exception as e: + print_exc() + + print("####################################################################") + print("[" + str(i) + " / " + str(args.to_index - args.from_index) + "]") + + +def go(scenario, network, end, f, args): + # Clean existing output + out = join(args.runner, "out.xml") + + if os.path.exists(out): + os.remove(out) + + traci.start([sumoBinary, "-n", network], port=args.port) + + steps = int(end * (1 / args.step_length)) + + # Load scenario with desired traffic scaling + traci.load(["-c", scenario]) + try: + for step in range(0, steps): + traci.simulationStep() + except Exception as e: + print(e) + + traci.close() + + res = read_result(out) + res.to_csv(join(args.output, f + ".csv"), index=False) + + sys.stdout.flush() + + +def setup(parser: ArgumentParser): + setup_parser(parser) + + parser.add_argument("--insertion-density", type=float, default=10, help="Density of background vehicles") + + +def main(args): + + args = create_args(args) + + # Net is needed to get the bounds + net = sumolib.net.readNet(args.network, withConnections=False, withInternal=False, withFoes=False) + + df = pd.read_csv(args.input[0]) + + init_workload(args, df) + + print("Total number of routes:", len(df)) + print("Processing: ", args.from_index, ' to ', args.to_index) + + run(args, df, net.getLocationOffset()) + + +if __name__ == "__main__": + parser = ArgumentParser(prog=METADATA[0], description=METADATA[1]) + setup(parser) + main(parser.parse_args()) + diff --git a/matsim/scenariogen/network/run_train_model.py b/matsim/scenariogen/network/run_train_model.py new file mode 100644 index 0000000..8c82824 --- /dev/null +++ b/matsim/scenariogen/network/run_train_model.py @@ -0,0 +1,229 @@ +#!/usr/bin/env python + +import random +from argparse import ArgumentParser +from os import makedirs +from os.path import join + +import optuna +import sklearn.ensemble +from sklearn.metrics import mean_absolute_error +from sklearn.model_selection import KFold + +from .features import build_datasets +from .models import create_regressor, model_to_java, model_to_py + +METADATA = "network-train-model", "Train models for network capacity and freeflow speed." + + +def setup(parser: ArgumentParser): + parser.add_argument("--n-trials", type=int, help="Number of trials", default=250) + parser.add_argument("--name", help="Name of the model", default="Model") + parser.add_argument("--package", help="Package name", default="org.matsim.prepare.network") + parser.add_argument("--output", help="Output folder", default="gen_code") + parser.add_argument("--network-features", type=str, nargs="+", help="Path to file with edge features", required=True) + parser.add_argument("--input-intersections", type=str, nargs="+", help="Path to file with intersection results", + required=True) + parser.add_argument("--input-routes", type=str, nargs="+", help="Path to file with route results.", required=True) + parser.add_argument("--model-type", help="Type of model (features to use)", choices=["default", "extended"], + default="default") + + +def main(args): + dfs = build_datasets(args.network_features, args.input_intersections, args.input_routes, args.model_type) + targets = dfs.keys() + + def get(idx, t): + if idx is not None: + df = dfs[t].iloc[idx] + else: + df = dfs[t] + + return df.drop(columns=["target"]), df.target.to_numpy() + + scaler = {} + + for t in targets: + _scaler = sklearn.preprocessing.StandardScaler(with_mean=True) + + df = get(None, t)[0] + + norm = ["length", "speed", "num_lanes"] + if args.model_type == "full": + norm += ["num_foes", "junction_inc_lanes"] + + scaler[t] = sklearn.compose.ColumnTransformer([ + ("scale", _scaler, [df.columns.get_loc(x) for x in norm]) # column indices + ], + remainder="passthrough" + ) + + scaler[t].fit(df) + + print("Model targets", targets) + + # %% + + def best_model(ms, t): + errors = [] + for m in ms: + X, y = get(None, t) + X = scaler[t].transform(X) + + pred = m.predict(X) + err = mean_absolute_error(y, pred) + + errors.append((m, err)) + + errors = sorted(errors, key=lambda m: m[1]) + + return errors[0] + + fold = KFold(n_splits=6, shuffle=True) + + classifier = { + 'mean', + 'XGBRFRegressor', + 'XGBRegressor', + 'RandomForestRegressor', + 'ExtraTreesRegressor', + 'LGBMRegressor', + 'DecisionTreeRegressor', + 'PassiveAggressiveRegressor', + # More + # 'SVR', + # 'KernelSVC', + # 'QLatticeRegressor', + # 'LinearSVR', + # 'Ridge', + # 'SGDRegressor', + # 'LogisticRegression', + # 'AdaGradRegressor', + # 'CDRegressor', + # 'FistaRegressor', + # 'SDCARegressor', + # 'Lasso', + # 'ElasticNet' + } + + def objective(classifier_name, target): + global model + + def _fn(trial): + global model + + r = random.Random(42) + + random_state = r.getrandbits(31) + + seq = iter(fold.split(dfs[target])) + + error = 0 + i = 0 + + candidates = [] + + for train, test in seq: + model = create_regressor(trial, classifier_name, random_state) + + candidates.append(model) + + X, y = get(train, target) + X = scaler[t].transform(X) + + model.fit(X, y) + + Xval, yval = get(test, target) + Xval = scaler[t].transform(Xval) + + pred = model.predict(Xval) + + error += mean_absolute_error(yval, pred) + + i += 1 + + best = best_model(candidates, t)[0] + + return error / i + + return _fn + + def callback(study, trial): + global best + global model + if study.best_trial == trial: + best = model + + models = {} + for t in targets: + + print("Training", t) + + models[t] = {} + + for m in classifier: + print("Running model", m) + + study = optuna.create_study(sampler=optuna.samplers.TPESampler(seed=42), direction='minimize') + study.optimize(objective(m, t), n_trials=args.n_trials, callbacks=[callback], show_progress_bar=True) + + models[t][m] = best + + for t in targets: + print("#### ", t) + + m = best_model(models[t].values(), t) + + print("Best model", m) + + makedirs(args.output, exist_ok=True) + + with open(join(args.output, "__init__.py"), "w") as f: + f.write("") + + name = args.name + "_" + t + + with open(join(args.output, args.name + ".java"), "w") as f: + f.write("""package %(package)s; + +import org.matsim.application.prepare.network.opt.FeatureRegressor; +import org.matsim.application.prepare.network.opt.NetworkModel; + +public class %(name)s implements NetworkModel { + @Override + public FeatureRegressor capacity(String junctionType) { + return switch (junctionType) { + case "traffic_light" -> %(name)s_capacity_traffic_light.INSTANCE; + case "right_before_left" -> %(name)s_capacity_right_before_left.INSTANCE; + case "priority" -> %(name)s_capacity_priority.INSTANCE; + default -> throw new IllegalArgumentException("Unknown type: " + junctionType); + }; + } + + @Override + public FeatureRegressor speedFactor(String junctionType) { + return switch (junctionType) { + case "traffic_light" -> %(name)s_speedRelative_traffic_light.INSTANCE; + case "right_before_left" -> %(name)s_speedRelative_right_before_left.INSTANCE; + case "priority" -> %(name)s_speedRelative_priority.INSTANCE; + default -> throw new IllegalArgumentException("Unknown type: " + junctionType); + }; + } +} +""" % dict(package=args.package, name=args.name)) + + with open(join(args.output, name + ".java"), "w") as f: + code = model_to_java(name, args.package, m[0], scaler[t], get(None, t)[0]) + f.write(code) + + with open(join(args.output, t + ".py"), "w") as f: + code = model_to_py(t, m[0], scaler[t], get(None, t)[0]) + f.write("# -*- coding: utf-8 -*-\n") + f.write("\"\"\"%s\nError: %f\"\"\"\n" % m) + f.write(code) + + +if __name__ == "__main__": + parser = ArgumentParser(prog=METADATA[0], description=METADATA[1]) + setup(parser) + main(parser.parse_args()) diff --git a/matsim/scenariogen/network/setup.sh b/matsim/scenariogen/network/setup.sh new file mode 100755 index 0000000..29f4cfa --- /dev/null +++ b/matsim/scenariogen/network/setup.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +python3.9 -m venv venv +source venv/bin/activate + +pip install --upgrade pip +pip install optuna geopandas rtree pygeos eclipse-sumo sumolib traci lxml optax requests tqdm sklearn + +# install matsim tools +pip install "matsim-tools[scenariogen] @ git+https://github.com/matsim-vsp/matsim-python-tools.git@scenario-creation" \ No newline at end of file diff --git a/matsim/scenariogen/network/utils.py b/matsim/scenariogen/network/utils.py new file mode 100644 index 0000000..a2a6a4c --- /dev/null +++ b/matsim/scenariogen/network/utils.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python + +import os +import sys +from subprocess import call + +from shapely import wkt +from shapely.ops import transform + +if 'SUMO_HOME' in os.environ: + tools = os.path.join(os.environ['SUMO_HOME'], 'tools') + sys.path.append(tools) + +def setup_parser(parser): + parser.add_argument("input", nargs=1, help="Path to input csv") + + parser.add_argument("--output", default="output", help="Path to output folder") + parser.add_argument("--network", type=str, default="../../../../scenarios/input/sumo.net.xml", + help="Path to network file") + parser.add_argument("--veh", type=int, default=5000, help="Vehicles per hour per lane to simulate") + parser.add_argument("--scenario", type=str, default="base", choices=["base", "sst", "st", "mt", "lt"], + help="Name of scenario for vehicle share and capabilities") + parser.add_argument("--from-index", type=int, default=0, help="Start from number") + parser.add_argument("--to-index", type=int, default=-1, help="Stop at number") + parser.add_argument("--step-length", type=float, default=0.2, help="SUMO step length") + parser.add_argument("--runner", type=str, default="runner0", help="Runner name") + parser.add_argument("--runner-total", type=int, default=0, help="Total number of runners") + parser.add_argument("--runner-index", type=int, default=0, help="Runner index") + + +def create_args(args): + import sumolib + + args.port = sumolib.miscutils.getFreeSocketPort() + + os.makedirs(args.output, exist_ok=True) + os.makedirs(args.runner, exist_ok=True) + + return args + +def vehicle_parameter(scenario): + """ Predefined scenarios for vehicle parameters """ + + if scenario == "base": + return """ + + + """ + + elif scenario == "sst": + return """ + + + """ + + elif scenario == "st": # 5-10 years + return """ + + + """ + elif scenario == "mt": # 15-20 years + return """ + + + + """ + elif scenario == "lt": # 25+ years + return """ + + + + """ + + raise Exception("Unknown scenario: " + scenario) + + +def init_workload(args, items): + """ Set indices for the runner automatically """ + if args.runner_total <= 1: + return + + n = len(items) + step = n // args.runner_total + + args.from_index = args.runner_index * step + args.to_index = min((args.runner_index + 1) * step, n) + + +def write_scenario(f, network_file, route_file, additional_file, step_length=0.2, time=600): + """ Write sumo scenario file """ + + with open(f, "w") as fn: + fn.write(""" + + + + + + + + + + +""" % (network_file, route_file, additional_file, time, step_length)) + + +def filter_network(netconvert, netfile, edge, output, args=None): + if isinstance(edge, list): + x = [s[0] for e in edge for s in e.getShape()] + y = [s[1] for e in edge for s in e.getShape()] + else: + x = [s[0] for s in edge.getShape()] + y = [s[1] for s in edge.getShape()] + + # minX,minY,maxX,maxY + boundary = ",".join(str(s) for s in [min(x) - 50, min(y) - 50, max(x) + 50, max(y) + 50]) + + cmd = [netconvert, '-s', netfile, "--keep-edges.in-boundary", boundary] + + if args: + cmd += args + + cmd += ['-o', output] + + call(cmd) + + +def filter_network_polygon(netconvert, netfile, location_offset, geometry, output): + """ Filter network with a list of polygon coordinates""" + + polygon = wkt.loads(geometry) + + polygon = transform(lambda x, y: (x + location_offset[0], y + location_offset[1]), polygon) + + coords = ",".join("%.2f,%.2f" % f for f in polygon.exterior.coords) + + cmd = [netconvert, '-s', netfile, "--keep-edges.in-boundary", coords, "--no-internal-links", "false"] + cmd += ['-o', output] + + call(cmd) \ No newline at end of file diff --git a/setup.py b/setup.py index f7d1e31..c803423 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import pathlib -from setuptools import setup +from setuptools import setup, find_packages # The directory containing this file HERE = pathlib.Path(__file__).parent @@ -13,7 +13,7 @@ setup( version=VERSION, name="matsim-tools", - description="MATSim Agent-Based Transportation Simulation Framework - official python analysis tools", + description="MATSim Agent-Based Transportation Simulation Framework - official python tools", long_description_content_type="text/markdown", url="https://github.com/matsim-vsp/matsim-python-tools", author="VSP-Berlin", @@ -23,19 +23,24 @@ "License :: OSI Approved :: GNU General Public License (GPL)", "Programming Language :: Python :: 3", ], - packages=["matsim", "matsim.pb"], + packages=["matsim"] + ["matsim." + x for x in find_packages(where="matsim")], install_requires=[ "protobuf >= 3.10.0", "xopen", - "pandas", # "shapely", "geopandas >= 0.6.0" + "pandas", ], - extras_require = { - 'calibration': ["optuna >= 2.7.0"] + extras_require={ + 'calibration': ["optuna >= 2.7.0", "shapely", "geopandas >= 0.6.0"], + # m2cgen has problems with newer xgb, see this issue + # https://github.com/BayesWitnesses/m2cgen/issues/581 + 'scenariogen': ["sumolib", "traci", "lxml", "optax", "requests", "tqdm", "scikit-learn", "xgboost==1.7.1", "lightgbm", + "sklearn-contrib-lightning", "numpy", "sympy", "m2cgen", "shapely", "optuna"] }, tests_require=["assertpy", "pytest"], - entry_points = { + entry_points={ 'console_scripts': [ - 'matsim-tools=matsim.cli.main:main' + 'matsim-tools=matsim.cli.main:main', + 'matsim-scenariogen=matsim.scenariogen:main' ] }, long_description=README,