#optimization #18xx #graphics

n18route

Searches 18xx maps for optimal route combinations

1 unstable release

0.1.0 Oct 8, 2021

#6 in #18xx

Download history 3/week @ 2023-12-24 3/week @ 2024-01-07 1/week @ 2024-01-14 4/week @ 2024-02-04 7/week @ 2024-02-11 16/week @ 2024-02-18 33/week @ 2024-02-25 21/week @ 2024-03-03 20/week @ 2024-03-10 19/week @ 2024-03-17

93 downloads per month
Used in 7 crates (6 directly)

MIT/Apache

465KB
9K SLoC

Overview

This module solves the problem of finding the set of routes that can be run by a company to yield the highest possible revenue.

For example, the following function can find the best routes on a map for a specific company (identified here by their Token) that owns one or more trains, given (game-specific) rules about which elements may be reused by a single route (conflict_rule) and which elements may be shared by multiple routes (route_conflict_rule):

use n18route::{paths_for_token, Bonus, Criteria, ConflictRule, Trains, Routes};
use n18map::Map;
use n18token::Token;

fn find_best_routes(map: &Map, token: Token, trains: Trains,
                    bonuses: Vec<Bonus>) -> Routes {
    // Find all of the paths that the trains could operate.
    let criteria = Criteria {
        token,
        path_limit: trains.path_limit(),
        // NOTE: game-specific rule.
        conflict_rule: ConflictRule::TrackOrCityHex,
        // NOTE: game-specific rule.
        route_conflict_rule: ConflictRule::TrackOnly,
    };
    let paths = paths_for_token(&map, &criteria);

    // Return the best routes out of the available paths.
    trains
        .select_routes(paths, bonuses)
        .expect("Could not find an optimal set of routes")
}

See the route-finding documentation for details.

Dependencies

~9MB
~190K SLoC