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

Merge master updates into develop #30

Merged
merged 7 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ fast-trips is a Dynamic Transit Assignment tool written in Python and supplement
Follow the steps below to setup up fast-trips:
* Install [Git][git-url] and clone the fast-trips repository (https://github.com/MetropolitanTransportationCommission/fast-trips.git) to a local directory: `<fast-trips-dir>`. If the user plans on making changes to the code, it is recommended that the repository be [forked][git-fork-url] before cloning.
* Switch to the `develop` branch of the repository.
* Download and install a *data analytics* Python 2.7 distribution: [Anaconda][anaconda-url].
* Install [Microsoft Visual C++ Compiler for Python 2.7][python-vcpp-url].
* Download and install [numpy][numpy-url] and [pandas][pandas-url]. One option is to install a *data analytics* Python 2.7 distribution which bundles these, like [Anaconda][anaconda-url]. Windows users can also find package installers [here][python-packages-windows-url].
* If compiling on Windows, install [Microsoft Visual C++ Compiler for Python 2.7][python-vcpp-url]. On Linux, install the python-dev package.
* Install the python package [transitfeed][python-transitfeed-url] for reading GTFS.
* Set the `PYTHONPATH` environment variable to the location of your fast-trips repo, which we're calling `<fast-trips-dir>`.
* To build, in the fast-trips directory `<fast-trips-dir>`, run the following in a command prompt: `python setup.py build_ext --inplace`.

### Test Sample Input
Expand Down Expand Up @@ -52,8 +53,11 @@ Type of Assignment:
[git-url]: <https://git-scm.com/>
[git-fork-url]: <https://help.github.com/articles/fork-a-repo/>
[python-vcpp-url]: <http://www.microsoft.com/en-us/download/details.aspx?id=44266>
[numpy-url]: <http://www.numpy.org/>
[pandas-url]: <http://pandas.pydata.org/>
[anaconda-url]: <https://www.continuum.io/downloads>
[python-packages-windows-url]: <http://www.lfd.uci.edu/~gohlke/pythonlibs/>
[python-transitfeed-url]: <https://github.com/google/transitfeed/wiki/TransitFeed>
[git-repo-url]: <https://github.com/MetropolitanTransportationCommission/fast-trips.git>
[network-standard-url]: <https://github.com/osplanning-data-standards/GTFS-PLUS>
[demand-standard-url]: <https://github.com/osplanning-data-standards/dyno-demand>
[demand-standard-url]: <https://github.com/osplanning-data-standards/dyno-demand>
24 changes: 24 additions & 0 deletions scripts/runAllTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# test network with 2 paths (essentially)

# deterministic, 2 iterations, capacity constraints on
python scripts/runTest.py deterministic 2 True Examples/test_network/input Examples/test_network/demand_twopaths Examples/test_network/output

# stochatic, 1 iterations, capacity constraint off
python scripts/runTest.py stochastic 1 False Examples/test_network/input Examples/test_network/demand_twopaths Examples/test_network/output

# stochatic, 2 iterations, capacity constraint on
python scripts/runTest.py stochastic 2 True Examples/test_network/input Examples/test_network/demand_twopaths Examples/test_network/output


# test network with regular demand

# deterministic, 2 iterations, capacity constraints on
python scripts/runTest.py deterministic 2 True Examples/test_network/input Examples/test_network/demand_reg Examples/test_network/output

# stochatic, 1 iterations, capacity constraint off
python scripts/runTest.py stochastic 1 False Examples/test_network/input Examples/test_network/demand_reg Examples/test_network/output

# stochatic, 2 iterations, capacity constraint on
python scripts/runTest.py stochastic 2 True Examples/test_network/input Examples/test_network/demand_reg Examples/test_network/output
3 changes: 2 additions & 1 deletion src/LabelStopQueue.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cassert>
#include <exception>
#include <stdexcept>

namespace fasttrips {

Expand Down Expand Up @@ -174,4 +175,4 @@ namespace fasttrips {
}
};

};
};
45 changes: 38 additions & 7 deletions src/pathfinder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "pathfinder.h"

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#else
#include <sys/time.h>
#endif

#include <assert.h>
#include <sstream>
Expand Down Expand Up @@ -378,7 +383,11 @@ namespace fasttrips {
ss << output_dir_ << kPathSeparator;
ss << "fasttrips_trace_" << path_spec.path_id_ << ".log";
// append because this will happen across iterations
trace_file.open(ss.str().c_str(), (std::ios_base::out | (path_spec.iteration_ == 1 ? 0 : std::ios_base::app)));
std::ios_base::openmode omode = std::ios_base::out;
if (path_spec.iteration_ != 1) {
omode = omode | std::ios_base::app; // append
}
trace_file.open(ss.str().c_str(), omode);
trace_file << "Tracing assignment of passenger " << path_spec.passenger_id_ << " with path id " << path_spec.path_id_ << std::endl;
trace_file << "iteration_ = " << path_spec.iteration_ << std::endl;
trace_file << "outbound_ = " << path_spec.outbound_ << std::endl;
Expand All @@ -396,21 +405,26 @@ namespace fasttrips {
std::ostringstream ss2;
ss2 << output_dir_ << kPathSeparator;
ss2 << "fasttrips_labels_ids_" << path_spec.path_id_ << ".csv";
stopids_file.open(ss2.str().c_str(), (std::ios_base::out | (path_spec.iteration_ == 1 ? 0 : std::ios_base::app)));
stopids_file.open(ss2.str().c_str(), omode);
stopids_file << "stop_id,stop_id_label_iter" << std::endl;
}

StopStates stop_states;
LabelStopQueue label_stop_queue;
HyperpathStopStates hyperpath_ss;

// TODO: make this platform-agnostic. probably with std::chrono.
#ifdef _WIN32
// QueryPerformanceFrequency reference: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx
LARGE_INTEGER frequency;
LARGE_INTEGER labeling_start_time, labeling_end_time, pathfind_end_time;
LARGE_INTEGER label_elapsed, pathfind_elapsed;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&labeling_start_time);
#else
// using gettimeofday() since std::chrono is only c++11
struct timeval labeling_start_time, labeling_end_time, pathfind_end_time;
gettimeofday(&labeling_start_time, NULL);
#endif

// todo: handle failure
bool success = initializeStopStates(path_spec, trace_file, stop_states, label_stop_queue, hyperpath_ss);
Expand All @@ -420,10 +434,15 @@ namespace fasttrips {
std::vector<StopState> taz_state;
finalizeTazState(path_spec, trace_file, stop_states, label_stop_queue, performance_info.label_iterations_, hyperpath_ss);

#ifdef _WIN32
QueryPerformanceCounter(&labeling_end_time);
#else
gettimeofday(&labeling_end_time, NULL);
#endif

getFoundPath(path_spec, trace_file, stop_states, hyperpath_ss, path, path_info);

#ifdef _WIN32
QueryPerformanceCounter(&pathfind_end_time);

label_elapsed.QuadPart = labeling_end_time.QuadPart - labeling_start_time.QuadPart;
Expand All @@ -441,6 +460,18 @@ namespace fasttrips {

performance_info.milliseconds_labeling_ = (long)label_elapsed.QuadPart;
performance_info.milliseconds_enumerating_ = (long)pathfind_elapsed.QuadPart;
#else
gettimeofday(&pathfind_end_time, NULL);

// microseconds
long int diff = (labeling_end_time.tv_usec + 1000000*labeling_end_time.tv_sec) -
(labeling_start_time.tv_usec + 1000000*labeling_start_time.tv_sec);
performance_info.milliseconds_labeling_ = 0.001*diff;

diff = (pathfind_end_time.tv_usec + 1000000*pathfind_end_time.tv_sec) -
(labeling_end_time.tv_usec + 1000000*labeling_end_time.tv_sec);
performance_info.milliseconds_enumerating_ = 0.001*diff;
#endif

if (path_spec.trace_) {

Expand Down Expand Up @@ -687,7 +718,7 @@ namespace fasttrips {
std::ostringstream ss;
ss << output_dir_ << kPathSeparator;
ss << "fasttrips_labels_" << path_spec.path_id_ << ".csv";
label_file.open(ss.str().c_str(), (std::ios_base::out | (path_spec.iteration_ == 1 ? 0 : std::ios_base::app)));
label_file.open(ss.str().c_str(), (path_spec.iteration_ == 1 ? std::ios_base::out : std::ios_base::out | std::ios_base::app));
label_file << "label_iteration,link,node ID,time,mode,trip_id,link_time,link_cost,cost,AB" << std::endl;
}

Expand Down Expand Up @@ -1242,7 +1273,7 @@ namespace fasttrips {
}
// stop is processing
hyperpath_ss[current_label_stop.stop_id_].process_count_ += 1;
max_process_count = max(max_process_count, hyperpath_ss[current_label_stop.stop_id_].process_count_);
max_process_count = std::max(max_process_count, hyperpath_ss[current_label_stop.stop_id_].process_count_);
}

// no transfers to the stop
Expand Down Expand Up @@ -1399,9 +1430,9 @@ namespace fasttrips {
ssi != current_stop_state.end(); ++ssi)
{
if (path_spec.outbound_) {
earliest_dep_latest_arr = min(earliest_dep_latest_arr, ssi->deparr_time_);
earliest_dep_latest_arr = std::min(earliest_dep_latest_arr, ssi->deparr_time_);
} else {
earliest_dep_latest_arr = max(earliest_dep_latest_arr, ssi->deparr_time_);
earliest_dep_latest_arr = std::max(earliest_dep_latest_arr, ssi->deparr_time_);
}
}
nonwalk_label = calculateNonwalkLabel(current_stop_state);
Expand Down
17 changes: 11 additions & 6 deletions src/pathfinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

#if __APPLE__
#include <tr1/unordered_set>
#elif _WIN32
#elif __linux__
#include <tr1/unordered_set>
#else
#include <unordered_set>
#endif

#if _WIN32
// suppress warning C4503: decorated name length exceeded, name was truncated
#pragma warning(disable:4503)
#endif
Expand Down Expand Up @@ -328,11 +333,11 @@ namespace fasttrips {
* Tally the link cost, which is the sum of the weighted attributes.
* @return the cost.
*/
double PathFinder::tallyLinkCost(const int supply_mode_num,
const PathSpecification& path_spec,
std::ofstream& trace_file,
const NamedWeights& weights,
const Attributes& attributes) const;
double tallyLinkCost(const int supply_mode_num,
const PathSpecification& path_spec,
std::ofstream& trace_file,
const NamedWeights& weights,
const Attributes& attributes) const;

void addStopState(const PathSpecification& path_spec,
std::ofstream& trace_file,
Expand Down