I am reaching out with the following issue, I am trying to assign some private vehicles as background traffic through preload but, when I do (see attached code) the assignment results in a never ending printing of "Reset Line Search", which I understand means that BFW cannot define the size of the next step. I have tried different values for my background traffic load, but even very small values (which I expected would not impact convergence) cause this behavior. Switching to MSA prevent the "Reset Line Search" message, as expected, but the assignment runs indefinitely. Removing the preload lets the code revert to normal behavior.
Am I implementing preload wrong? I already checked and the size of the preload dataframe, the direction of the edges (all unidirectional) and the flow values all seem to be correct (right length, format, etc.)
Please let me know if more information is needed, in the meantime thank you for your work and your time.
Best Regards,
Serio Agriesti
CODE:
from aequilibrae.paths import TrafficAssignment, TrafficClass
# Configuration
weight = "travel_time"
RGAP_TARGET = 1e-5
MAX_ITER = 5000
ALGORITHM = "bfw"
VDF = "BPR"
VDF_PARAMS = {"alpha": "alpha", "beta": "beta"}
# WITHOUT PRELOAD
# Set up traffic class
traffic_class = TrafficClass(name=period_name, graph=ae_graph, matrix=ae_od_aem)
# Create assignment
assignment = TrafficAssignment()
assignment.set_classes([traffic_class])
assignment.set_vdf(VDF)
assignment.set_vdf_parameters(VDF_PARAMS)
assignment.set_capacity_field("capacity")
assignment.set_time_field(weight)
# Set algorithm parameters
assignment.set_algorithm(ALGORITHM)
assignment.max_iter = MAX_ITER
assignment.rgap_target = RGAP_TARGET
# Execute assignment
print(f"Executing {period_name} assignment...")
assignment.execute()
skims = traffic_class.results.skims
zone_ids = list(skims.index)
skim_df = pd.DataFrame(skims.matrix[weight], index=zone_ids, columns=zone_ids)
skim_df_sec = skim_df * 3600 # transform travel times from hours to seconds
network_df = env.model_transp.traffic_assignment["CAR"]["network"].copy()
res = assignment.results()
flows = network_df.merge(res, on="link_id", how="left")
# # WITH PRELOAD
print("WITH PRELOAD STARTING NOW...")
# Set up traffic class
traffic_class = TrafficClass(name=period_name, graph=ae_graph, matrix=ae_od_aem)
# Create assignment
assignment = TrafficAssignment()
assignment.set_classes([traffic_class])
assignment.set_vdf(VDF)
assignment.set_vdf_parameters(VDF_PARAMS)
assignment.set_capacity_field("capacity")
assignment.set_time_field(weight)
preload_df = pd.DataFrame({
'link_id': ae_graph.graph.link_id.values,
'direction': 1,
'preload': flows["matrix_tot"] # np.random.rand(len(ae_graph.graph)) * 35 # Example preload values, replace with actual data
})
# Add preload to the assignment
assignment.add_preload(preload_df, period_name)
# Set algorithm parameters
assignment.set_algorithm(ALGORITHM)
assignment.max_iter = MAX_ITER
assignment.rgap_target = RGAP_TARGET
assignment.assignment.preload
# Execute assignment
print(f"Executing {period_name} assignment...")
assignment.execute()
skims = traffic_class.results.skims
zone_ids = list(skims.index)
skim_df = pd.DataFrame(skims.matrix[weight], index=zone_ids, columns=zone_ids)
skim_df_sec_1 = skim_df * 3600 # transform travel times from hours to seconds
(skim_df_sec_1-skim_df_sec).sum().sum()