quetzal.engine.linearsolver_utils module
- quetzal.engine.linearsolver_utils.build_constraints(indicator, values_links, od_stack, bounds_A, bounds_emissions, bounds_tot_emissions, pas_distance, volume_column='volume_pt')[source]
Ici on construit l’objectif et les contraintes du problème d’optimisation suivant: variable: pivot A min_A ||Rc - Rm|| = ||indic*volumes*A - constrained values|| sous contraintes:
Pg < volumes*A - e/a < Pg ((C1): émissions et attractions par zone conservées)
Pg’ < sum(volumes*A) - e/a_tot < Pg’ ((C2) émissions et attractions totales conservées)
Pd < <D,X> - distance_moyenne < Pd ((C3) distance moyenne conservée)
bound_A_min < A(i) < bound_A_max ((B) bornes du problème) forall i
Comme l’objectif n’est pas linéaire, on décide d’utiliser la norme 1 et de linéariser la valeur absolue en ajoutant une nouvelle variable y:
(~~ y(i) = |indic*volumes*A - constrained values|(i))
- Le problème devient alors:
min y
- sous contraintes
y(i) >= (indic*volumes*A - constrained values)(i) forall i (C4)
y(i) >= - (indic*volumes*A - constrained values)(i) forall i (C5)
(mêmes contraintes que précedemment en plus)
Parameters: :param indicator: indicator of the model :param values_links (tuple): values of constrained links :param od_stack (pd.DataFrame): od_stack of the model :param bounds_A (list): upper and lower bound of coefficients of the pivot :param bounds_emissions (list): upper and lower bound of the multiplicative
coefficient on emissions and attractions per cluster
- Parameters
(list) (bounds_tot_emissions) – idem but for emisisons and attractions of the entire model
(int) (pas_distance) – additive pas on the mean distance
- Return objectif
objective of the function
- Return A_ub
matrix of inequality constraint (left side)
- Return b_ub
vector of inequality constraint (right side)
- quetzal.engine.linearsolver_utils.build_indicator(od_stack, constrained_links, link_path_column='link_path')[source]
- Parameters
(pd.DataFrame) (od_stack) – od_stack of the model
(dict) (constrained_links) – constrained links and their volumes
- Returns indicator (DataFrame)
indicator for the model
- quetzal.engine.linearsolver_utils.extrapolate(agg_pivot_stack_matrix, od_stack, cluster_series)[source]
Extrapolates the model. Given the aggregated model and its pivot_stack_matrix, we build the pivot_stack_matrix for the whole model.
- Parameters
agg_pivot_stack_matrix – agg_pivot_stack_matrix of the aggregated model
(pd.DataFrame) (od_stack) – od_stack of the entire model
:param cluster_series (pd.Series) :return grouped (pd.DataFrame): pivot_stack_matrix of the whole model :return od_stack: od_stack of the whole model, with pivot column updated
- quetzal.engine.linearsolver_utils.linearsolver(indicator, constrained_links, od_stack, bounds_A, bounds_emissions, bounds_tot_emissions, pas_distance, maxiter, tolerance, **kwargs)[source]
Cette fonction est le coeur de la méthode linear_solver. - Elle construit les contraintes et l’objectif dans build_constraints - Elle résoud le problème d’optimisation linéaire ainsi formé, avec les bonnes contraintes et paramètres.
- Parameters
(pd.DataFrame) (od_stack) – indicator of the model
(dict) (constrained_links) – dict of constrained links with volumes
(pd.DataFrame) – od_stack of the model
pas_distance (bounds_A, bounds_emissions, bounds_tot_emissions,) – parameters for building constraints
(int) (maxiter, tolerance) – maximum iterations and tolerance on objective for the linprog function
- Returns pivot_stack_matrix (pd.DataFrame)
elements of pivot_stack_matrix.
- quetzal.engine.linearsolver_utils.reduce_indicator(big_indicator, cluster_series, volumes, volume_column='volume_pt')[source]
- Parameters
(pd.DataFrame) (volumes) – indicator of the entire model
(pd.Serie) (cluster_series) – correspondance between zones and clusters
(pd.DataFrame) – od_stack of the model
- Returns indicator (DataFrame)
reduced indicator for the aggregated model