GithubHelp home page GithubHelp logo

trainline-eu / csa-challenge Goto Github PK

View Code? Open in Web Editor NEW
148.0 148.0 39.0 29.07 MB

Compare various implementations of the connections scan algorithm

License: Do What The F*ck You Want To Public License

Ruby 13.20% C++ 8.20% Go 5.44% Haskell 8.96% Java 9.07% Python 6.72% Lua 4.51% Makefile 0.70% Rust 8.54% C 8.81% PHP 3.95% Pascal 7.27% Swift 8.36% JavaScript 4.23% Shell 2.04%

csa-challenge's People

Contributors

aquilax avatar baarde avatar brechtvdv avatar espadrine avatar icholy avatar jbbarth avatar kemenaran avatar martoche avatar matthieuprat avatar n-b avatar renaudguerin avatar signez avatar skade avatar tristramg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csa-challenge's Issues

Addressing the limitations

Do you have any guidance as to how to address any of the limitations? Specifically I'm looking to address:

it computes the earliest arrival. However, a better solution might leaver later and arrive at the same time

undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)

Hi,

I have this issue running ruby test.rb *

ruby test.rb ./csa_cpp
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
  /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:1:in `<top (required)>'
  test.rb:3:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit/testcase.rb:8:in `<module:Unit>'
/Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>': undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
    from /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
    from /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
    from /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
    from /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/poc/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from test.rb:3:in `<main>'

I can run ruby bench.rb *

Rust refactor

Hello. I enjoyed this, thanks for sharing it.

I refactored the Rust version to be easier for me to read. That's a subjective goal, and most of the changes I made are departures from the reference implementation. I still wanted to share, though, so I'm posting a link to a gist instead of a pull request.

https://gist.github.com/m-n/8a15d864099778154529

I shortened some of the variable names and made an explicit Query struct. I use a corresponding parse function to move the query parsing logic out of the control loop. In my version (and the official Rust version), the timetable is not its own struct, though -- just a vector of connections.

The biggest change was refactoring the CSA. I kept two functions: query, which takes a timetable and a query and returns the best route as a vector of connections, and print_result, which iterates over the vector of connections and prints them.

Readability?

Does the code has really to be the the "most unreadable" (see README)?

file not found

error

Hello,
I am trying to do "ruby test.rb ./csa_hs" on my comuter but I have a message "File not found" whereas both files: test.rb and csa_hs are in the folder for which I am calling them. Can somebody explain me what I am doing wrong? Thanks in advance.

The algorithm does not work for certain cases

The example in the readme works fine

#input.txt
1 2 3600 7200
2 3 7800 9000

1 3 3000
$ cat input.txt | ./csa_cpp
1 2 3600 7200
2 3 7800 9000

but if the input connections are inverted, the algorithm does not output a solution.

#input2.txt
2 3 7800 9000
1 2 3600 7200

1 3 3000
$ cat input2.txt | ./csa_cpp
NO_SOLUTION

The algorithm seems very similar to the Bellman–Ford shortest path algorithm. I think to fix the algorithm you have to repeat the computation of computing the earliest arrival for the number of stations - 1, so something like:

For #station - 1
    For each connection c
        if arrival_timestamp[c.departure_station] < c.departure_timestamp and arrival_timestamp[c.arrival_station] > c.arrival_timestamp
            arrival_timestamp[c.arrival_station] ← c.arrival_timestamp
            in_connection[c.arrival_station] = c

Incorrect pruning condition in multiple implementations

In many implementations the pruning condition is
if connection.arrivalTime > earliestArrivalTime then break loop
This is incorrect since we can't make assumptions on arrival times.

The correct pruning condition is
if connection.departureTime >= earliestArrivalTime then break loop

Pull request that addresses the issue: #32

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.