src/route.c
/*
 * Spin through the routes and assign them to transit units. For now. just do it 
 * greedily from the front, for simplicity
 */
Spin through the routes and assign them to transit units. For now. just do it
greedily from the front, for simplicity
Spin through the routes and assign them to transit units . For now . just do it greedily from the front for simplicity
int allocate_transit_units() {
    int num_transit_units = 1;
    int i=0;
    route_set_t* curr_set = NULL;
    route_set_t* prev_set = NULL;
    route_set_list_l = create_set();
    for(i=0; i < g_total_routes; i++) {
        curr_set = route_set_list_l; 
        while(add_route(curr_set, &route_list[i]) != 0) {
            if (curr_set->next == NULL) {
                curr_set->next = create_set();
                num_transit_units++;
            }
            curr_set = curr_set->next;
        }
    }
    route_set_list = (route_set_t*)calloc(num_transit_units, sizeof(route_set_t));
    curr_set = route_set_list_l;
    i=0;
    while(curr_set != NULL) {
        memcpy(&(route_set_list[i]), curr_set, sizeof(route_set_t));
        i++;
        prev_set = curr_set;
        curr_set = curr_set->next;
        free(prev_set);
    }
    return num_transit_units;
}
int allocate_transit_units ( ) { int num_transit_units = 1 ; int i = 0 ; route_set_t * curr_set = NULL ; route_set_t * prev_set = NULL ; route_set_list_l = create_set ( ) ; for ( i = 0 ; i < g_total_routes ; i ++ ) { curr_set = route_set_list_l ; while ( add_route ( curr_set , & route_list [ i ] ) != 0 ) { if ( curr_set -> next == NULL ) { curr_set -> next = create_set ( ) ; num_transit_units ++ ; } curr_set = curr_set -> next ; } } route_set_list = ( route_set_t * ) calloc ( num_transit_units , sizeof ( route_set_t ) ) ; curr_set = route_set_list_l ; i = 0 ; while ( curr_set != NULL ) { memcpy ( & ( route_set_list [ i ] ) , curr_set , sizeof ( route_set_t ) ) ; i ++ ; prev_set = curr_set ; curr_set = curr_set -> next ; free ( prev_set ) ; } return num_transit_units ; }
Spin through the routes and assign them to transit units.
Spin through the routes and assign them to transit units .
// The idea is that someday I can replace this with something that // implements a heuristic for assigning physical vehicles to runs. // For now, its silly, but easy to implement. // Start off with one // Spin through all the routes and add them to the first // set that will take them. Make a new one if none will. // Are we at the end of the list? // Allocate a new one // Since we needed a new one, that amounts to an additional // transit unit, so bump the count // For ease of assigning the route sets to transit units, lets map them into an array