def prepare(self, graph: Graph) -> None: """ Prepares the object with dimensions corresponding to the graph object Args: *graph* (:obj:`Graph`): Needs to have been set with number of centroids and list of skims (if any) """ if not graph.cost_field: raise Exception( 'Cost field needs to be set for cost computation. use graph.set_graph("your_cost_field")' ) self.__integer_type = graph.default_types("int") self.__float_type = graph.default_types("float") self.nodes = graph.num_nodes + 1 self.zones = graph.centroids + 1 self.links = graph.num_links + 1 self.num_skims = graph.skims.shape[1] self.predecessors = np.zeros(self.nodes, dtype=self.__integer_type) self.connectors = np.zeros(self.nodes, dtype=self.__integer_type) self.reached_first = np.zeros(self.nodes, dtype=self.__integer_type) self.skims = np.zeros((self.nodes, self.num_skims), self.__float_type) self.__graph_id__ = graph.__id__ self.graph = graph
def prepare(self, graph: Graph, matrix: AequilibraeMatrix) -> None: """ Prepares the object with dimensions corresponding to the assignment matrix and graph objects Args: *graph* (:obj:`Graph`): Needs to have been set with number of centroids and list of skims (if any) *matrix* (:obj:`AequilibraeMatrix`): Matrix properly set for computation with matrix.computational_view(:obj:`list`) """ self.__float_type = graph.default_types("float") self.__integer_type = graph.default_types("int") if matrix.view_names is None: raise ("Please set the matrix_procedures computational view") else: self.classes["number"] = 1 if len(matrix.matrix_view.shape) > 2: self.classes["number"] = matrix.matrix_view.shape[2] self.classes["names"] = matrix.view_names if graph is None: raise ("Please provide a graph") else: self.compact_nodes = graph.compact_num_nodes self.compact_links = graph.compact_num_links self.nodes = graph.num_nodes self.zones = graph.num_zones self.centroids = graph.centroids self.links = graph.num_links self.num_skims = len(graph.skim_fields) self.skim_names = [x for x in graph.skim_fields] self.lids = graph.graph.link_id.values self.direcs = graph.graph.direction.values self.crosswalk = np.zeros(graph.graph.shape[0], self.__integer_type) self.crosswalk[graph.graph.__supernet_id__. values] = graph.graph.__compressed_id__.values self.__graph_ids = graph.graph.__supernet_id__.values self.__redim() self.__graph_id__ = graph.__id__
def __init__(self): self.skims = AequilibraeMatrix() self.cores = mp.cpu_count() self.links = -1 self.nodes = -1 self.zones = -1 self.num_skims = -1 self.__graph_id__ = None self.graph = Graph()
def prepare(self, graph: Graph, matrix: AequilibraeMatrix) -> None: """ Prepares the object with dimensions corresponding to the assignment matrix and graph objects Args: *graph* (:obj:`Graph`): Needs to have been set with number of centroids and list of skims (if any) *matrix* (:obj:`AequilibraeMatrix`): Matrix properly set for computation with matrix.computational_view(:obj:`list`) """ self.__float_type = graph.default_types("float") self.__integer_type = graph.default_types("int") if matrix.view_names is None: raise ("Please set the matrix_procedures computational view") else: self.classes["number"] = 1 if len(matrix.matrix_view.shape) > 2: self.classes["number"] = matrix.matrix_view.shape[2] self.classes["names"] = matrix.view_names if graph is None: raise ("Please provide a graph") else: self.nodes = graph.num_nodes self.zones = graph.num_zones self.centroids = graph.centroids self.links = graph.num_links self.num_skims = len(graph.skim_fields) self.skim_names = [x for x in graph.skim_fields] self.lids = graph.graph["link_id"] self.direcs = graph.graph["direction"] self.__redim() self.__graph_id__ = graph.__id__ # TODO: Enable these methods when the work for select link analysis and saving path files is completed self.__setSavePathFile(False) self.__setCriticalLinks(False)
def prepare(self, graph: Graph) -> None: """ Prepares the object with dimensions corresponding to the graph object Args: *graph* (:obj:`Graph`): Needs to have been set with number of centroids and list of skims (if any) """ if not graph.cost_field: raise Exception( 'Cost field needs to be set for cost computation. use graph.set_graph("your_cost_field")' ) self.__integer_type = graph.default_types("int") self.__float_type = graph.default_types("float") self.nodes = graph.num_nodes + 1 self.zones = graph.centroids + 1 self.links = graph.num_links + 1 self.num_skims = len(graph.skim_fields) self.predecessors = np.zeros(self.nodes, dtype=self.__integer_type) self.connectors = np.zeros(self.nodes, dtype=self.__integer_type) self.reached_first = np.zeros(self.nodes, dtype=self.__integer_type) if self.num_skims: self.skims = np.empty((graph.all_nodes[-1] + 1, self.num_skims), self.__float_type) self.skims.fill(np.inf) self._skimming_array = np.zeros((self.nodes, self.num_skims), self.__float_type) else: self._skimming_array = np.zeros((1, 2), self.__float_type) self.__graph_id__ = graph.__id__ # We can imagine somebody creating a worst-case scenario network (imagining that turn penalties are considered) # where one needs to traverse all links (or almost all) in both directions. self.__graph_sum = 2 * graph.cost.sum() self.graph = graph
def __init__(self, name: str, graph: Graph, matrix: AequilibraeMatrix) -> None: """ Instantiates the class Args: name (:obj:`str`): UNIQUE class name. graph (:obj:`Graph`): Class/mode-specific graph matrix (:obj:`AequilibraeMatrix`): Class/mode-specific matrix. Supports multiple user classes """ if not np.array_equal(matrix.index, graph.centroids): raise ValueError( "Matrix and graph do not have compatible sets of centroids.") if matrix.matrix_view.dtype != graph.default_types('float'): raise TypeError( "Matrix's computational view need to be of type np.float64") self.graph = graph self.matrix = matrix self.pce = 1.0 self.vot = 1.0 self.mode = graph.mode self.class_flow: np.array self.results = AssignmentResults() self.results.prepare(self.graph, self.matrix) self.fixed_cost = np.zeros(graph.graph.shape[0], graph.default_types('float')) self.fixed_cost_field = '' self.fc_multiplier = 1.0 self.results.reset() self._aon_results = AssignmentResults() self._aon_results.prepare(self.graph, self.matrix) self.__id__ = name