'use strict';

/* A RoutesGenerator generates a list of routes. */
class RoutesGenerator {
    constructor(region, edges) {
        this.region = region;
        this.edges = edges; // [ ... { from, to } ... ]; tripId's are their index in this array
        this.nextTripId = 0;
        this.routes = []; // [ ... { routeId, [ ... edgeId ... ] } ... ]
        this.debugpoints = [];
    }

    addRoute(edges){
        this.addRouteRaw(edges, null);
    }

    addRouteRaw(edges, trips){
        var routeId = this.routes.length;
        var size = 0;
        edges.forEach(edge => size = size + edge.from.size + edge.to.size);
        var route = { routeId: routeId, edges: edges, trips: trips, size: size };
        this.routes.push(route);
        edges.forEach(edge => edge.route = route);
    }

    generate() {
        throw new Error('RoutesGenerator#generate() has not been implemented yet.');
    }

    getRoutes() {
        return this.routes;
    }
}

module.exports = RoutesGenerator;
'use strict';

/* A RoutesGenerator generates a list of routes. */
class RoutesGenerator {
    constructor(region, edges) {
        this.region = region;
        this.edges = edges; // [ ... { from, to } ... ]; tripId's are their index in this array
        this.nextRouteId = 0;
        this.routes = []; // [ ... { routeId, [ ... edgeId ... ] } ... ]
        this.debugpoints = [];
    }

    addRoute(edges){
        this.addRouteRaw(edges, null);
    }

    addRouteRaw(edges, trips){
        var routeId = this.nextRouteId++;
        var size = 0;
        edges.forEach(edge => size = size + edge.from.size + edge.to.size);
        var route = { routeId: routeId, edges: edges, trips: trips, size: size };
        this.routes.push(route);
        edges.forEach(edge => edge.route = route);
    }

    generate() {
        throw new Error('RoutesGenerator#generate() has not been implemented yet.');
    }

    getRoutes() {
        return this.routes;
    }
}

module.exports = RoutesGenerator;
Fix duplicate route id's This was possible because of the routes array that was being spliced, so we can not ensure that the route array length is usable for id identification.
Fix duplicate route id's
This was possible because of the routes array that was being spliced, so we can not ensure that the route array length is usable for id identification.
