uxsim.scenario_reader_writer¶
Scenario reader and writer using toml.
Functions
|
A decorator to record arguments of World.addVehicle, World.adddemand, etc used in secenario definition in World object. |
|
Convert an instance's attributes to a dictionary of constructor arguments. |
|
Load scenario data from a file. |
|
Save scenario data to a file. |
- uxsim.scenario_reader_writer.demand_info_record(func)[source]¶
A decorator to record arguments of World.addVehicle, World.adddemand, etc used in secenario definition in World object.
- uxsim.scenario_reader_writer.instance_to_arg_dict(instance)[source]¶
Convert an instance’s attributes to a dictionary of constructor arguments.
This function inspects an object instance and creates a dictionary of arguments that could be used to recreate the instance. It uses the signature of the class’s __init__ method to determine which attributes to include.
- Parameters:
instance (object) – The instance to convert to a dictionary of arguments.
- Returns:
A dictionary where keys are parameter names and values are the corresponding attribute values from the instance.
- Return type:
dict
Notes
Parameters with default values are omitted if the instance’s value matches the default.
The ‘self’ parameter is always ignored.
The ‘W’ parameter, if present, is removed from the resulting dictionary.
Attributes of type ‘Node’ or ‘Link’ are replaced with their ‘name’ attribute.
- uxsim.scenario_reader_writer.load_scenario(W, fname, network=True, demand=True)[source]¶
Load scenario data from a file.
This function loads various components of a scenario, including meta data, network information (nodes and links), and demand information, from a file created by the save_scenario function.
- Parameters:
W (World) – The world to which the scenario data will be loaded.
fname (str) – The file name or path from which the scenario data will be loaded.
network (bool, optional) – If True, load network information (nodes and links). Default is True.
demand (bool, optional) – If True, load demand information. Default is True.
- uxsim.scenario_reader_writer.save_scenario(W, fname, network=True, demand=True)[source]¶
Save scenario data to a file.
This function saves various components of a scenario, including meta data, network information (nodes and links), and demand information, to a file using pickle serialization.
- Parameters:
W (World) – The world to be saved
fname (str) – The file name or path where the scenario data will be saved.
network (bool, optional) – If True, save network information (nodes and links). Default is True.
demand (bool, optional) – If True, save demand information. Default is True.
Notes
The function uses the pickle module to serialize the data. The saved file will be in binary format.
The saved data structure is a dictionary containing: - ‘meta_data’: Meta data from W.meta_data - ‘Nodes’ and ‘Links’: Network information (if network=True) - Demand information from W.demand_info (if demand=True)