Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces triggers with check statements #455

Merged
merged 2 commits into from
Nov 1, 2023
Merged

Conversation

pedrocamargo
Copy link
Contributor

Makes use of the CHECK statements from SPATIALITE to help avoid issues such as AequilibraE/qaequilibrae#246

@pedrocamargo pedrocamargo self-assigned this Oct 9, 2023
Jake-Moss added a commit to Jake-Moss/aequilibrae that referenced this pull request Oct 17, 2023
@jamiecook jamiecook merged commit 783eac9 into develop Nov 1, 2023
27 checks passed
@jamiecook jamiecook deleted the pedro/check_statements branch November 1, 2023 23:43
pedrocamargo added a commit that referenced this pull request Nov 25, 2023
* fixes errors on qgis (#417)

* runs examples (#422)

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Update LICENSE.TXT (#427)

* fix matrix indices for memory-only matrices (#425)

* fix matrix indices for memory-only matrices

* run black

---------

Co-authored-by: Pelle Koster <pelle.koster@nginfra.nl>

* Pedro/cores skimming (#426)

* Moves the setting of number of cores to the right place

* Moves documentation to the right place

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Updates assignment logging (#423)

* assignment logging

* Updates logging

* Adds __config log

* Adds test and docs

* Update aequilibrae/paths/traffic_assignment.py

* Fixes tests

* fixes coverage testing

* merges testing changes

* style

* style

* style

* style

* narrows coverage test

* Update test_traffic_assignment.py

* Apply suggestions from code review

* Fixes test_traffic_assignment

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>
Co-authored-by: Pedro Camargo <c@margo.co>

* narrows coverage test (#429)

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* moves openmatrix to a primary dependency (#431)

* moves openmatrix to a primary dependency

* QGIS moved to Numpy 1.24 before moving to Python 3.10

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Updates software version for release

* Bumps up version

* Bumps up documentation version

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* minor change to test CI

* Fix multiple classes not being presented in the returned d (#438)

* Prevent invalid attribute names on AequilibraE data fields

This previously would have resulted in syntax error when accessing but
its best we don't accept them anyway.

* Fix multiple classes not being presented in the returned df

Bug report: https://groups.google.com/g/aequilibrae/c/y_q9nLNs6-Y/m/yWXNpey9AAAJ

* Style

* Skip if network fails

* Rounding

* fixes test

* Revert "Rounding"

Vatican City really did move huh

This reverts commit d9d0a5d.

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Update README.md (#439)

* Add implicit noexcept from Cython<3.0.0 (#440)

With the release of Cython 3.0.0 there are a few changes of note to use. Particularly the performance impact of the
removal of the implicit noexcept.

Now all cdefs allow exceptions by default meaning every cdef must require the gil at the end of the function regardless
of whether it was nogil or not. Adding the noexcept clause reverts to the old behaviour.

There is a compiler directive to result this old behaviour but better be be explicit when the solution is one regex away:
`^(cp?def(?:.|\n).*?)(nogil|):$`

https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html#exception-values-and-noexcept

* Disable select link (#443)

* Fix empty matrices not being saved (#444)

Introduced in 7c2beb6

* Matrix exports and deprecation warning (#435)

* Bumps up version

* Bumps up documentation version

* fixes matrix export

* fixes deprecations

* addresses SciPy versions

* addresses SciPy versions

* addresses SciPy versions

* addresses SciPy versions

* addresses SciPy versions

* fixes test

* fixes test

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Select link correctness fix (#447)

* Revert "Disable select link (#443)"

This reverts commit 0cd3d48.

* Add Kai Tang's test and data

* Potential select link fix

* Test formatting

* Fix tests imports

* Add select link test

This test asserts that the results of the select link on the links 7, and 13 are the same as the results of the
assignment. These links were chosen for this particular network to cover all paths used.

* Prevent data races in select link results

Memory for the multi-threaded runs are now allocated in MuliThreadedAoN along side the rest of the multi-threaded memory.

* Installs package to run documentation pipeline

* installing

* Install pandoc

---------

Co-authored-by: Pedro Camargo <c@margo.co>

* bumps up the version (#451)

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* new version

* Fix documentation bugs on latest (#456)

* Update requirements-docs.txt

modifies pydata theme version

* Update requirements-docs.txt

* PathResults.compute_path fix stale variables (#457)

Previously if a path that exists was computed, and then a path that does not exist was attempted, the old path variables
were not cleared.

* Replaces triggers with check statements (#455)

* replaces triggers with check statements

* Guarantees that links can be created without adding information on nodes

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Adds zones and connectors (#461)

* Better import from OSM and description of bicycle & bus data in network (#464)

Parameters file is a bit hidden/tricky to use for qaequilibrae users, this should help them for a better default OSM import which keep data for bus and bicycle
Have keep the same structure as OSM but this result in 3 fields for each one (3 for bicycle and 3 for bus).

Maybe we can think of a way to achieve only one field for bicycle and one for bus ? Might not so easy because of the number of combinations available in OSM, example : https://wiki.openstreetmap.org/wiki/Key:cycleway

Co-authored-by: Arthur Evrard <83211842+Art-Ev@users.noreply.github.com>

* Early exit Dijsktra's with path reuse (#466)

* Early exit Dijsktra's with path reuse

* Remove early exit arg from update_trace, add private state

Add a private variable which tracks the status of the tree from the
previous call to `compute_path`. Setting the `PathResults.early_exit`
be used to modify the behaviour of the `compute_path` call in
`update_trace`.

* Adds support for Python 3.12 (#453)

* Adds support for Python 3.12

* Update build_mac.yml

* Move from depreciated `license_file` as its now a build error

* `assertEquals` is a deprecated alias for `assertEqual`

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>
Co-authored-by: Jake-Moss <jake.moss@uqconnect.edu.au>

* Don't mark the path computation as `early_exit` when unreachable (#469)

* Initial A* implementation (#467)

* Initial A* implementation

This implementation uses a haversine distance heuristic, in theory
this a consistent heuristic [1] that would give us "an optimal path
without processing any node more than once" when the graph cost is set
to distance, however, in testing I've found that the distance
calculations based and lon/lat done by myself and QGIS do not align
with those in the project. Unfortunately this makes the heuristic not
admissible [2] meaning A* will not always find the least-cost path,
and may not do the minimum amount of work.

From some basic instrumenting I found A* is consistently an order of
magnitude better than the existing Dijkstra's implementation when it
comes to heap operation counts. Time wise I haven't performed real
benchmarks.

Currently there is only one heuristic implemented for distance, if the
graph cost field is set to `free_flow_time` the heuristic, while not
useless is theory, it is practically as the magnitudes of the distances
dominates any graph cost meaning A* will explore the whole network,
just like Dijkstra's.

[1] https://en.wikipedia.org/wiki/Consistent_heuristic
[2] https://en.wikipedia.org/wiki/Admissible_heuristic

* Indexing fixes found on Arkansas network

* Updates graph types

* A* improvements and corrections, equirectangular heuristic added

* Update "without a model" example

* fixup! A* improvements and corrections, equirectangular heuristic added

* Set lon/lat index manually instead of passing to prepare_graph

* fixup! Set lon/lat index manually instead of passing to prepare_graph

* Split path computation and skimming example, use Coquimbo over Sioux

* Add note about skimming with A*

* General clean up

* Extend existing test to include A* via subtests

* Style

* Add runtime heuristic switching

* Document heuristic switching

* Heuristic swithcing tests

* Python 3.7 compatibility

* Missed changes

* Add note for A* non-distance metrics

* Bumps up version for release

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

---------

Co-authored-by: Renata Imai <53949163+r-akemii@users.noreply.github.com>
Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>
Co-authored-by: PelleK <elfjes@users.noreply.github.com>
Co-authored-by: Pelle Koster <pelle.koster@nginfra.nl>
Co-authored-by: Jamie Cook <jimi.cook@gmail.com>
Co-authored-by: Jake Moss <jake.moss@uqconnect.edu.au>
Co-authored-by: Jamie Cook <jamie.cook@veitchlister.com.au>
Co-authored-by: Arthur Evrard <83211842+Art-Ev@users.noreply.github.com>
pedrocamargo added a commit that referenced this pull request Dec 16, 2023
* file transfer from the edsger package: shortest hyperpath algorithm

* first try on compiling the public transport module

* added the COO to CSC sparse format converter

* Python interface to the Cythonized Spiess & Florian algorithm

* assignment loop

* just making sure zero entries are removed from the demand matrix

* Spiess & Florian test case

* assign method S&F test

* added some compiler directives

* combined cdefs

* moved the allocation of f_i_vec outside of compute_SF_in

* cleanup

* moved the allocation of u_j_c_a_vec outside of compute_SF_in

* cleanup

* removed np.sum()

* moved the allocation of u_i_vec outside of compute_SF_in

* added a wrapper of the C function nqsort, in order to replace np.argsort

* moved the allocation of edges_indices outside of compute_SF_in

* released the gil in compute_SF_in

* comment fix

* added the initialization of the edge volume vector

* Attempt parallelising PuT assignment

* Further progress towards parallelisation

* initialized the module for the S&F transit graph creation

* handle the case of int data given as a float string

* renaming

* Complete parallelisation of PuT assignment over destinations

* u_j_c_a_vec was being initialised to an incorrect size

* Move parallelised call to compute_SF_in to separate function

Introduced new accumulation buffer and dropped reacquisition of the gil

* Use numpy asserts for nicer error messages

Using default tolerances of previous asserts

* Restore HyperpathGenerating.run() functionality

* Style

* create stop vertices

* renamed a column

* Fix openmp Windows

* Spelling and default to using all available threads

* Fix default thread amount

* Move hyperpath testing and adjust testing structure

Adds new parallel agreement test as well

* Credit Bell's network construction

* added the class global structure

* using nullable Int type

* filtering stops on a given time period

* filtering patterns, routes ans building a line segment dataframe

* bug fix

* bug fix + filtering the stops corresponding to the given time range

* removed a comment : segment index are 0-based and not 1-based as specifed before

* created a method for the line segments dataframe + now creating the boarding vertices dataframe

* creating the amighting vertices dataframe

* concatenating all the vertex dataframe into a single one

* computation the mean travel time for each (pattern, seq) couple

* fixes the segment travel time computation

* now creating the on-board edges

* Add create_od_vertices()

* Use sql over shape file, data must be mirgated to sqlite first.

* Add creation of connector edges

* Add attempt at dwell and inner transfer edges

* Add missing import

* small update

* temporarily using 2 sqlite connections in the parameters

* renaming within the SQL query

* dwell edges creation

* small code simplifcation

* alighting edges creation

* cleanup

* wip

* compute the mean headway

* renaming

* filling travel time missing values with travel times computed over all the trips_schedule (now limited to the given time range)

* fixed the mean headway computation part

* variable renaming

* boarding edges creation

* concatenate the edges of different types

* added a projected CRS to compute distances

* now merging within the SQL

* cleanup

* updated the connector edges creation

* creation of the inner stop transfer edges

* ability to add spatial noise to boarding and alighting vertex coordinates in order to visualize boarding, aligthing, transfer and collocated on-board edges

* creation of the outer stop transfer edges

* cleanup + divided the connector type into 2 types: access and egress

* added a boolean argument to activate the creation of the outer stop transfer edges

* creating some walking edges between the stops of a station

* Add overlapping regions for connectors construction.

Fix references to graph instead of self

* Fix missing edges, add max distance

* Fix memory blowout by joining on null and empty strings entries

* wip

* renaming + merge

* typo

* casting all stop and parent_station ids to text in sql queries

* Using consistent data types during graph transit creation

* fixed the cython compilation : added a noexcept in the declaration of _compare

* revert to the sequential assignment algorithm (in order to compile)

* comments + initialization

* Add preliminary db saving

Usage:
```python
graph = SF_graph_builder(pt_con, prj_con)
graph.create_vertices()
graph.create_edges()
graph.create_additional_db_fields()
graph.save_vertices()
graph.save_edges()
```

Caveats are noted in the comments of the functions.

* Add shifting for duplicated geometry when saving

* IDs should be index from 1

Allows the whole graph to be read back into aequilibrae

* Rename terms to be more consistent with AequilibraE, use wkb as well

We know use WKB format consistently and only convert out when need. String manipulation and regexs
have also been replaced.

type -> node_type, link_type
head_vert_id -> a_node
tail_vert_id -> b_node
coord -> geometry
vert_id -> node_id
edge_id -> link_id

* Copy over SQL specs for move from proj db to transit storage

* Mirror more triggers and tables into transit db

Includes files copied from network triggers with slight modifications

Need to remove unnecessary columns from links and nodes tables.

Zones are still saved to project db and also need to be migrated.

* renamed some variables

* moved the haversine distance function to the utils submodule

* comments

* Add custom loading of zones to drop dependence on project db

* revert back to the parallel version

* added Jake's fix to support Cython 3

* some code cleaning in the travel time computation

* Style

* cleanup and refactoring

* Add direction and to aeq graph conversion

* Integrate results saving for hp assignment

* typo

* Misc post merge fixes and formatting

* wip

* Add missing results.sql

* SQL query update

* comments

* sql update + public attributes made private

* More consistent datatypes

This does include a change to make stop_ids TEXT with sqlite. I haven't full explored the effects of this change.

* tried to fix an issue with some inverted tail and head IDs for access and egress connectors

* set the edge direction attribute to 1 for all edges (all edges are directed)

* quick fix to drop duplicated transfer edges

* now creating distinct origin and destination nodes

* now supporting the blocking_centroid_flows mode when creating the transit graph, where the origin and destination nodes are distinct

* added a method to convert taz ids to node ids in the demand matrix

* added the max_connectors_per_zone parameter to select at most k connectors per zone with smallest travel time

* Scipy 1.6 is 2 years old, prefer KDTree over the cKDTree alias

* Add initial connect project matching

* Allow troublesome triggers to be disabled

* Improvements on the project line string matching. Not complete

* Project matching progress

* Mimic changes in #455

* fixup! Allow troublesome triggers to be disabled

* PathResults.compute_path fix stale variables

Previously if a path that exists was computed, and then a path that does not exist was attempted, the old path variables
were not cleared.

* Working project matching

* Use existing line string data for a better result

* Refactor project matching into smaller method, add more detailed doc

* Misc doc changes + include trigger_settings in db creation

* Allow supplying zones as shapely objects, by default add zone

* Allow specifying the graph to match against

* Style

* Adjust to_aeq method to reflect other changes

* Use the constructed RNG generator

* Documentation overhaul

Format doc strings to RST. HTML generated docs look correct. Not sure how to set the class included in the TOC.

* Pandas warning fix

* Add Coquimbo public transit assignment example

* fixup! Add Coquimbo public transit assignment example

* updated the docstrings and default values

* include SF_graph_builder in the API documentation

* made many methods protected

* updated the graph builder docstring

* bug fix in the case where there is no transfer edges

* uniform argument naming when calling pd.read_sql

* bug fix dealing with the case of creating walking edges without any parent station

* used a newer pandas method to remove future warning

* new documentation about transit graph creation

* images associated with the transit graph documentation

* structure of a new documentation page

* completed the hyperpath documentation page

* more documentation (HyperpathGenerating)

* fix: added dwell edges

* PT Integration (#476)

* Models with no centroids (#472)

* Bumps up version for release

* Bumps up version for release

* docs

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Better network skimming and path computation headers and typo fix (#474)

* Integration scaffolding

* Transit assignment

* Change "id" variable naming to avoid double underscores

Double underscore variables are difficult to inherit without duplicating. I've tried my best to group all these renames
into a single commit to be revertible but some others are deep within a refactor.

This changes the convention of using `__id__` and `__graph_id__` to `_id` and `_graph_id`. Since these variables need to
be accessible to other methods they are not private. The double underscore worked previously since there was only ever
one class with these variables the name mangling was always correct.

* Create GraphBase and TransitGraph classes

* Create TransportClassBase and TransitClass classes

* Create AssignmentBass and TransitAssignment classes

* Create AssignmentResultsBase and AssignmentResultsTransit classes

* Comments, add OptimalStrategies class

* Incomplete (full) workflow

* fixup! Incomplete (full) workflow

* fixes export of omx matrices (#484)

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Move periods table

* Lots of changes

Limit graph loading and saving to a single graph for now
Flush out results API, including saving and loading
Move unrelated variables and methods

* Add Periods and Period classes, similar to Nodes and Links classes

* Remove period from database saving for now

* Propagate period ids and various changes

* Raise nicer errors

* Style

* removes use of necessary sqlite3 connection cursors and cached connections (#478)

* removes use of necessary sqlite3 connection cursors

* removes use of necessary sqlite3 connection cursors and saved connections

* removes silly use of a cursor

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

* improves on connection styles

---------

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Migrate docs to new api, fix reloading graphs and begin updating tests.

* Style and build errors

* Typing

* Revert changes to HyperpathGenerating and tests, use arrays instead

* Exclude abstract methods from coverage tests

* Period, Periods, TransitGraph, and TransitGraphBuilder tests

* Style

* Cleans graph creation (#482)

Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* Adds support page (#481)

* updates examples

* updates examples

* Lower coverage requirement, typos

* Remove patches

* updates examples

* fixup! Remove patches

* Missing var

* Deprecates Python 3.7

* Fixes documentation

* Fixes documentation

* code cleaning

* code cleaning

* code cleaning

* updates setup classifiers

* Fixes centroid assignment

---------

Co-authored-by: Pedro Camargo <c@margo.co>
Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>

* renaming

---------

Co-authored-by: djfrancesco <pacullfrancois@gmail.com>
Co-authored-by: Jake Moss <jake.moss@uqconnect.edu.au>
Co-authored-by: François Pacull <35044397+djfrancesco@users.noreply.github.com>
Co-authored-by: pveigadecamargo <pveigadecamargo@anl.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants