fleetmanager.model package

Subpackages

Submodules

fleetmanager.model.model module

class fleetmanager.model.model.ConsequenceCalculator(timeframe=None, states=None)[source]

Bases: object

ConsequenceCalculator class for computing economical, transport and emission consequences of a simulation

Attributes

capacity_source : bokeh ColumnDataSource for containing capacity computed by the simulation

consequence_table : bokeh ColumnDataSource for containing consequences computed by the simulation

compute(simulation, drivingallowance, tco_period)[source]

The compute function that calculate the consequences; 1) explicit CO2 emission,

Calculated by taking the product of each vehicle’s allocated km to a yearly approximation and the vehicle’s explict noted gram CO2-emission pr. kilometer. Since this is only relevant for fossile vehicles, we don’t report this number because it would always show the electrical vehicles to have 0 emission. Hence, we refer to 6) yearly CO2-e.

  1. number of trips without vehicle,

    Sum of all trips that have no vehicle assigned. Displayed in the simulation.trips.[inventory_type_column] with a value of -1.

  2. pay out in driving allowance,

    In order to punish the unallocated trips driving allowance is simulated. All unallocated trips are summed to a yearly approximation. The driving allowance is paid in rates; 3.44 kr. pr. km. under 840 kilometer threshold and 1.90 kr. pr. km. above 840 kilometer threshold.

  3. yearly average expense on hardware

    Is calculated by taking the sum of the reported “omkostning_aar” for all vehicles

  4. yearly expense on fuel

    Is calculated through the tco_calcluate.TCOCalculator, which is based on the tool “tco-vaerktoej-motorkoeretoejer” from POGI. Check the details on the class.

  5. yearly CO2-e expense (implicit CO2 emission)

    Is calculated through the tco_calcluate.TCOCalculator, which is based on the tool “tco-vaerktoej-motorkoeretoejer” from POGI. Check the details on the class.

  6. total yearly expense

    Is calculated by taking the sum of driving allowance, yearly average expense on hardware and yearly expense on fuel.

simulationmodel.Simulation class - the simulation class with it’s associated trips. The inventory - and distance columns of the

simulation.trips frame holds the necessary data to calculate the aforementioned values.

drivingallowance : model.DrivingAllowance - a DrivingAllowance class or None. tco_period : list of two ints ([0, 1]) - the selected tco_period which is passed to the TCO_Calculator object.

First int to define projection periode, second int to define the evaluation period.

get_html_information()[source]

Function for producing html used on infromation panel

update_capacity_source()[source]
update_consequence_table()[source]

Update the consequence table

class fleetmanager.model.model.DrivingAllowance[source]

Bases: object

Class for containing and manipulating driving allowance.

calculate_allowance(yearly_distance)[source]

Method for calculating the driving allowance for unallocated trips. Defines a threshold of 840 km which is eligible to get the high allowance fee, from which the fee drops to the low allowance. Especially useful in tabu search in order not to favor unallocated trips because it is cheap.

yearly_distance : int - sum of kilometers without an allocated vehicle

driving allowance : int - sum of money paid out in driving allowance to attribute the unallocated trips

class fleetmanager.model.model.FleetManager[source]

Bases: object

FleetManager class keeps track of the fleets and the booking.

options: options of type model.OptionsFile

vehicle_factory : types of vehicles in fleet of type vehicle.VehicleFactory simulation_fleet : simulation fleet of type vehicle.FleetInventory current_fleet : current fleet of type vehicle.FleetInventory

get_html_information()[source]

Function for producing html used on infromation panel

set_current_fleet(bikes=0, ebikes=0, ecars=0, cars=0)[source]

Set current fleet composition

set_simulation_fleet(bikes=0, ebikes=0, ecars=0, cars=0)[source]

Set simulation fleet composition

set_timestamps(ts)[source]

Set timestamps of fleets

class fleetmanager.model.model.Model(location=None, dates=None, tco_period=(0, 1))[source]

Bases: object

Model class for MVC pattern of the simulation tool.

location : int - id of the location selected for the simulation dates : list of datetime - the selected time frame for the trips to simulated - i.e. [start time, end time]

will define the period from which the trips will be pulled.

compute_histogram(mindist=0, maxdist=None)[source]

Compute histograms for current and simulation

mindist : defaults to 0. Minimum distance to use for histograms maxdist : Maximum distance to use for histograms. If None, use the maximum distance of the trips

run_simulation(intelligent_simulation, bike_max_distance=5, bike_time_slots=None, max_bike_time_slot=0, bike_percentage=100, km_aar=False)[source]

Create and run a simulation. Updates histograms and consequence information. Sets up the simulation and initialises the fleets and runs the simulation.

intelligent_simulation : bool - to be passed to the simulation object bike_max_distance : int - to define bike configuration, max allowed distance for a bike trip bike_time_slots : bike configuration time slot, when are bike vehicles allowed to accept trips max_bike_time_slot : bike configuration, how many bike slots are available for bikes bike_percentage : how many percentage of the trips that qualifies for bike trip should be accepted km_aar : bool - should the vehicles associated km_aar constrain the vehicle from accepting trips when the

yearly capacity is reached. Only available on intelligent_simulation = False

class fleetmanager.model.model.Simulation(trips, fleet_manager, progress_callback, tabu=False, intelligent_simulation=False, timestamps_set=False)[source]

Bases: object

The major Simulation class for performing simulation on trips.

trips : trips for simulation of type modelTrips fleet_manager : fleet manager for handling fleets of type model.FleetManager progress_callback : None tabu : bool - to let the simulation know if it’s a tabu simulation. If so, only the simulation setup will be

simulated, and not the current.

intelligent_simulation : bool - should intelligent simulation be used, i.e. Qampo algorithm to allocate trips. timestamp_set : bool - whether the simulation trips already have generated timeslots

generate_qampo_data(fleet_inventory, trips)[source]

Convenience function for converting fleet inventory and trips data to json format required by qampo api.

fleet_inventory : fleet inventory to run simualtion on. Type model.FleetInventory. trips: trip data to run simulation on.

run()[source]

Runs simulation of current and simulation fleet

run_single(fleet_inventory)[source]

Convenience function for running simualtion on a single fleet

Takes the fleet and iterates over the trips to see which, if any, vehicle is available for booking. If the fleet_inventory name is current, the vehicles are booked according to its recorded trips. This will overwrite any rules implied by the simulation, e.g. vehicle cannot be booked for a trip on the same minute stamp as it ends a trips, sleep rules for electrical cars etc.

The vehicles should be sorted according to the desired priority (defaults to co2 emission). For every trip the first available vehicle is booked for the trips.

fleet_inventory : fleet inventory to run simualtion on. Type model.FleetInventory.

run_single_qampo(fleet_inventory, algorithm_type='exact_mip')[source]

Convenience function for running simualtion on a single fleet through qampo api.

fleet_inventory : fleet inventory to run simualtion on. Type model.FleetInventory. algorithm_type : the algorithm the qampo api uses. must be either ‘exact_mip’, ‘greedy’ or ‘exact_cp’

class fleetmanager.model.model.Trips(location=None, dataset=None, dates=None)[source]

Bases: object

Trips class for containing and manipulating trips of the simulation.

dataset : name (string) of dummy dataset to load. If dataset is a pandas DataFrame it is loaded as trips.all_trips.

all_trips : All trips in dataset (no filtering) trips : Trips in dataset applying date and department filter date_filter : boolean numpy array with same length as all_trips department_filter : boolean numpy array with same length as all_trips

get_dummy_trips(n=10)[source]

Helper function to generate fake data for testing

set_assignment()[source]

Method for setting up necessary columns on the trips in order to book-keep the allocated vehicles on the trips.

set_filtered_trips()[source]

Applies date and department filter and sets model.trips accordingly.

set_timestamps(timestamps)[source]

Set timestamps of Trips and mapped all trips to the corresponding timeslots.

timestamps : pandas PeriodIndex

fleetmanager.model.roundtripgenerator module

fleetmanager.model.roundtripgenerator.calc_distance(coord1, coord2)[source]

Simple distance function to measure the distance in km from two coordinates (lat, long) (lat, long) Parameters ———- coord1 : (latitude, longitude) coord2 : (latitude, longitude)

distance in km

fleetmanager.model.roundtripgenerator.get_car_starts(trips, allowed_starts_)[source]

Function to retrieve allowed starts for the cars. Iterates over all trips for a specific car and finds the start to which it’s closest. If the distance to an allowed start is less than .2 km the start is accepted. The 3 most frequent starts for each car is returned for use in the later process when the roundtrips are defined

trips : trips from the table expected in pandas format. At least “car_id”, “start_latitude”, “start_longitude” allowed_starts : list of cordinates (lat, lon) that are accepted start locations

dictionary for each car id that contain the 3 most frequent starts for the car {car_id: [(lat,lon), (lat,lon), (lat,lon)], car_id: [(lat,lon), (lat,lon), (lat,lon)] …}

fleetmanager.model.roundtripgenerator.get_consective_groups(car_trips, routes)[source]

Extracts the untripped trips from the car trips dataframe. The trip_extractor returns the aggregated trips, from the original frame we can extract the trips logs that are not used in a qualified roundtrip. The logs that have adjacent logs will be sought to be grouped and added together in order to attribute these logs in the roundtrip frame. Otherwise, we end up having less trips in the dataset than what has actually be driven. Parameters ———- car_trips : dataframe, the trips routes : routes, the aggregated routes

not_in : dataframe, the trips that are not used in a route groups : list, list of index groups that are adjacent and unused

fleetmanager.model.roundtripgenerator.group_exceeded(group, skip_last=False)[source]

Function for collecting un-aggregated trips. The trip_extractor returns the aggregated trips, from the original frame we can extract the trips logs that are not used in a qualified roundtrip. The logs that have adjacent logs will be sought to be grouped and added together in order to attribute these logs in the roundtrip frame. Otherwise, we end up having less trips in the dataset than what has actually be driven. Calls the route_check to check the coherence of the collection of trips.

Iterates over the group, and adds the trip to a route if the log is started less than .75 hour from the last log

group : dataframe, the collected trips that are adjacent skip_last : bool, if the group is part of the last pulled trips on the major trip frame,

we skip adding as a route to allow the next aggregation job to properly aggregate these trips

list of routes

fleetmanager.model.roundtripgenerator.inb(row, ts)[source]

Checks that there are no overlapping timestamps. Sometimes the APIs return invalid data.

row : dataframe row ts : times of the trips in route

False if everything is ok, else ids for overlapping

fleetmanager.model.roundtripgenerator.point_to_starts(coordinate, starts)[source]

Function used to measure the distance between a selected start to a list of starts iterates over the starts list and returns the distance and coordinates to the starting location to which there’s the shortest distance.

coordinate : (lat, lon) starts : list of (lat, lon) - [(lat, lon), (lat, lon), (lat, lon) …]

(min_distance, best_start) - distance to closest start, (lat, lon) to closest start

fleetmanager.model.roundtripgenerator.post_routing_sanitation(routes, trips, starts_)[source]

Function used post routing to do sanitation - especially useful to scrutinise the trips that doesn’t “make sense” from a distance or time perspective. The time (7 days) and distance (200 km) criteria defines which routes will be sought to be re-defined. For the selected routes it selects the trips points from the start - and end time, new starting locations are defined - isolated to those present as opposed to all log points for the car. The trips log points and new locations are sent to the trip extractor to define possible new routes.

routes : the defined routes from trip_extractor trips : the trips frame starts_ : frame holding the allowed starts from the allowed_starts table

routes that were originally accepted and possible sanitized routes

fleetmanager.model.roundtripgenerator.route_check(route)[source]

Convenience function to check if a list of trips qualifies to a roundtrip. Checks that the distance of the trip is above .5 km and the duration is less than 16.9 hours. Criteria are hardcoded since the function is only called with roundtrips that are aggregated based on trips that could not be aggregated with trip_extractor.

route : list of frame objects that make up the

bool : roundtrip qualified

fleetmanager.model.roundtripgenerator.route_format(route, car_id, location, distance=None)[source]

Convenience function to convert to unified route format before saving to database

route : list of trips that makes up the route car_id : int, id of the car location : int, id of the location that should be enforced distance : int, the km distance of trip

dictionary of the trip

fleetmanager.model.roundtripgenerator.trip_aggregator(car, c_trips, allowed_starts=None, hour_threshold=16.9, definition_of_home=0.2, min_travel_distance=0.5)[source]

Function for handling the aggregation library. Called by the SkyHost - and FleetCompleteExtractor to easily aggregate the new trips. Handles the whole process.

car : car object, with a defined id and location id c_trips : dataframe, the car trips that will be sought to be aggregated into roundtrips allowed_starts : dataframe, the starts that are available to the car hour_threshold : int, the hour threshold for the aggregated trips definition_of_home int, the distance allowed to a start min_travel_distance int, the minimum travel distance for a trip.

list of aggregated trips in dictionary.

fleetmanager.model.roundtripgenerator.trip_extractor(frame, allowed_car_starts=None, start_frame=None, hour_threshold=16.9, definition_of_home=0.2, min_travel_distance=0.5, recurs=0, enforce_location=None)[source]

Major roundtrip generator function. Takes the trips pulled and the defined allowed starts for each car. Assumes that a route will start and end at the same location (+-definition of home), exists of at least 2 log points, travelled distance is more than 500 meters and driver is the same (except if driver defined moves from nan to driver_name or driver_name to nan once)

frame : trips frame from trips table allowed_car_starts : dictionary of allowed starts for each car_id present in trips frame start_frame: frame holding the allowed starts from the allowed_starts table hour_threshold : int, standard for limiting the allowed length of a trip. definition_of_home : int, allowed distance to home. If a log is definition_of_home close to an allowed start

at unstarted trip, the trip will begin. If a trip is underway, the trips ends if a log is seen that is definition_of_home close to the defined allowed start

min_travel_distance : int, the minimum travel distance for accepting the trip as a valid roundtrip recurs : int, should not be changed. Internal value for constraining the function to only recurs once to parse

unqualified roundtrips in to qualified roundtrips. E.g. There could be vehicles that find home after days because it has been lend out to another location, then the allowed start has been “wrongly” selected and should be defined to the location to which the vehicle has been lend in order to record the trips driven in the other location.

enforce_locationint, defining the location. In accordance with the aforementioned, this value will overwrite

the found location and always allocate the trip to the location to where the vehicle belong

list of accepted routes in dictionary format including following attributes: start_time, end_time, start_point,

end_point, car_id, distance, gps_points, driver, ids

fleetmanager.model.tabu module

class fleetmanager.model.tabu.TabuSearch(fleetoptimiser, location, dates, eval_km=5000, fixed_antal=None, co2e_goal=inf, expense_goal=inf, weight=5, intelligent=False, km_aar=False)[source]

Bases: object

Class for handling the tabu search algorithm. Sets a number of parameters before the algorithm can be started by calling the “run” method. In addition to the below-mentioned parameters (init), the following attributes are set.

minimum_cars is calculated in least_viable to find the minimum number of cars needed in the solution breakpoint_solution is the solution that is least viable - least number of cars needed in the solution total_trips is the whole set of trips selected based on the location id and dates slack is not yet used, but is intended as an adjustable parameter to allow solution to have undriven trips below a

specific distance; max_distance_for_undriven

bins is not yet used, but will be used when slack is used to bin the undriven trips - will punish trips above the

threshold heavily

dummy_trips is used in the least_viable and search to more efficiently search as oposed if this was done on the

whole set.

vehicle_properties is used in the tabu search to retrieve the cost/objective of each vehicle based on the eval_km cheap_list is an ordered list of the most expensive vehicles first. Used in the least_viable function which assumes

that the most expensive is the one with the best capacity.

vehicle2id, id2vehicle, vehicle2type are used in the algortihm all over to enable indexing from unique vehicles to

an id and vice versa

best_objective_value will hold the current best_objective_value, is first set in the run_current_setup when the

current solution is simulated

report value for holding the search report to be pulled by the frontend.

build_tabu_structure(allow_removal)[source]

Essential method for the tabu search that generates a structure to hold all the possible moves. For all indexes in the self.fixed list two moves are made; +1 and -1. E.g. a database holding 3 unique cars with one fixed car (a car that cannot be removed due to continued lease), could look like:

[0, 0, 1]

and allow_removal = False would yield a tabu structure:

{

(0, 1): {“tabu_time”: 0, “objective_value”: math.inf}, (0, -1): {“tabu_time”: 0, “objective_value”: math.inf}, (1, 1): {“tabu_time”: 0, “objective_value”: math.inf}, (1, -1): {“tabu_time”: 0, “objective_value”: math.inf}, (2, 1): {“tabu_time”: 0, “objective_value”: math.inf}, (2, -1): {“tabu_time”: 0, “objective_value”: math.inf},

}

allow_removalbool, is the search allowed to remove vehicles from the fixed. Useful if current solution

holds, to the simulation, redundant vehicles, i.e. if there are more vehicles than needed in the current solution to satisfy the need.

dict of key move (index, +1/-1) value (dict attributes)

calculate_slack(simulation, fleet_name='fleetinventory')[source]

Method used when calculating the allowed slack. Right now slack is set to 0, however one can allow that a specific number of trips below a certain distance length is unallocated. The unallocated trips that fall in the last bin will be punished by 10 as opposed to 1 - accounting for 10 unallocated trips.

simulation : model.Simulation object - with the trips frame after the simulation has been run fleet_name : the name of the fleet, in order to index the proper column

twv : int, the number of trips without a vehicle

calculate_vehicle_cost()[source]

Calculates the vehicle attributes: co2, co2e, cost, obj and expense based on the eval_km. Uses the TCOCalculator based on the tool “tco-vaerktoej-motorkoeretoejer” created by POGI. In tabu search the objective value is used and based on the weight; (normalised cost) + (normalised co2e * weight)

vehicles_dict : a dictionary; id of vehicle to its calculated attributes

control()[source]

Method for controlling the tabu search, which is called 4 times by default. It’s done in order to “diversify” the search, to have both solutions present that removes vehicles, and solutions present that adds vehicles. After running the tabu searches, we iterate over the solutions sorted on the best objective values. Then real simulation happens on the whole trip set, if the solution satisfies all criteria; minimum cars, expense goal, co2e goal and 0 unallocated trips, the solution is stored. If it doesn’t, the solution is stored as a fallback solution, in order to provide results in the case that no solution satis- fies all criteria. To improve efficiency, the tests are stopped after hitting 5 qualified solutions. In addition, it’s recorded for each solution how many of each vehicle type is used and if the combination satisfied the capacity need.

list, of the top 5 solutions based on the objective value.

Recursive method to find the least number of cars needed to satisfy the capacity needed for the trips pulled Starts with the number of fixed cars on one particular index, checks if the solution satisifies. If yes, choose the median number between the current checked and highest value that did not satisfy the need. If no, choose the median number between the current checked and the lowest value that did satisfy the need.

solution : the solution that should be checked down : if the next solution should go down old : the previously checked solution numbers_checked : a dictionary holding the number of vehicles and a bool for satisfaction iteration : number of iterations used to stop searching at max_iter max_iter : max number of iterations allowed start : the start solution number - always 0, which yelds a numbers_checked dict {0: False}

Bool for least viability found, solution for least viability

driving_checking(solution)[source]

Method called by drivability_search to test the solution. Will use the input solution and test against the dummy trip set to efficiently simulate.

solution : dict, key: vehicle, value: count

bool : is solution able to satisfy the need with no unallocated trips

get_expenses()[source]

Method currently unused. Useful for providing product solution to attribute matrix.

get_nabo(c_solution, allow_removal=True, min_cars=None)[source]

Method for generating neighbours to the current solution. I.e. from the tabu structure generate the specific solution from the current solution and the move. It checks if the solution satisfies the minimum number of cars criteria.

c_solution : list, the current solution from which new solutions will be build allow_removal : bool, is it allowed to remove vehicles from the fixed cars min_cars : int, the minimum number of cars that should be in the solution

generator, that yields the possible solutions.

initialise_real()[source]

Initialises and prepares the whole trip set defined by the location and selected time period

dataframe of roundtrips

initialise_trips()[source]

Initialises and prepares a dummy set for efficient search and test Pulls the peak day in the selected time period. Assumes that a fleet that can satisfy a peak day would be able to satisfy the whole period.

dataframe of roundtrips for the peak day

least_viable()[source]

Method to control the least viability search to find the minimum vehicles needed to satisfy the number of trips. Sets the starts to max_vehicles which is the current number of vehicles based on the time period times 1.5. If the breakpoint is not found, the minimum cars are set to current number times 1.5.

mapper()[source]

Method for generating mappers used all over the class in order to index the proper vehicle

vehicle_name_to_id : dictionary, name from vehicle_optimisation.FleetOptimisation to the assigned id id_to_vehicle_name : dictionary, id to the name from vehicle_optimisation.FleetOptimisation vehicle2type : dictionary, name from vehicle_optimisation.FleetOptimisation to the vehicle type

objective_value(solution, test=False)[source]

Method for providing the objective value of specific solution.

solution : dictionary of the solution to get the objective value of test : if the solution also should be tested

real_simulation(solution=None, small_set=True, fleet=None, special_name=None, intelligent=False)[source]

Method performing simulation and returning the consequences

solution : list, input solution if no fleet is defined, index is vehicle id, value is count. small_set : bool, if the small dummy_set should be used. fleet : vehicle.fleetinventory class if solution is none special_name : string, defining the name and booked column from Simulation.trips.trips intelligent : bool, intelligent simulation (Qampo)

expense, co2e, number of trips without vehicles

run()[source]

Method for handling the run of the tabu search. First calls the least_viable to get the least number of cars needed in the final solutions. It then gets the initial objective value, which is the current setup. The current solution is then “simulated” to get the current expense and co2e in order to calculate the expense - and co2e goal. Finally, the “control” method is run, which handles the tabu search and assigns the result to report.

run_current_setup()[source]

Method responsible for running the current setup on the whole selected trip set. It will take all the vehicles that were active in the selected time period no matter if they were not selected in the simulation setup. This is done in order to get the “real” value, otherwise one could select no vehicles and have an expense on 0, which would make it infeasible for the search to improve.

Initialises the fleet with the active vehicles in the selected time period Runs a “real” simulation on the whole trip set Calculates the expense - and co2e goal based on the input values

start_solution()[source]

Method for generating the start solution and building the structure for the search. Generates a start solution with all the cars that a fixed due to a running lease that does not end before the selected time period.

Returns:

solution : dictionary - id to count of the solution vehicle_types : dictionary - vehicle type to count of solution fixed : list - list of n available cars with value that defines how many of that index are fixed in the

final solution

swap_move(solution, move)[source]

Method used to make the move from the solution to the best move selected.

solution : list, solution index to number, e.g. [0,0,1,2,1,5,0] move : tuple, the move from the tabu structure to make, e.g. (5, -1)

list, the new solution with the move made

The tabu search algorithm.

Responsible for search the space for solutions and recording the immediate best solutions. From the input min_cars it’s calculated if the solutions should prioritise removing or adding vehicles to the current solution. From this information, the tabu structure is build and search starts. It’s always pushed towards a better objective value, and by punishing the unallocated trips it’s desired by the search to go into spaces where this condition is satisfied.

For new and better solutions the record is saved, and the time of the move is recorded such that we don’t fall into the same space over and over again. The move is however allowed if it improves the global best objective value.

min_cars : the minimum number of cars needed in the generated solutions.

dict, holding the recorded best solution during the search.

vehicle_ordered()[source]

Orders the vehicle in most expensive to least expensive. Useful for the least viable function as well as ordering the electrical bikes, bikes and unassigned type last.

fleetmanager.model.tco_calculator module

class fleetmanager.model.tco_calculator.TCOCalculator(**kwargs)[source]

Bases: object

Class used all over the project to calculate the consequence based on the methods provided in “Partnerskab for offentlige grønne indkøb”s tool “miljoestyrelsen-tco-vaerktoej-motorkoeretoejer”. Made to be independent of xlwings dependencies unavailable to linux. The methods have been written directly from the tool and thus makes the same assumptions. Originals can be seen in src.fleetmanager.model.pogi

driftsomkostninger()[source]

Calculates the summed fuel expense on the vehicle. Returns ——- list of expense on fuel over the selected evaluation period

drivmiddel_udvikling(pris, stigning)[source]

Projecting the development in price of the fuel.

pris : int, current price stigning : int, percentage rate of fuel increase

list of fuel price for the next 30 years

ekstern_miljoevirkning(sum_it=False)[source]
omkostning_yearly()[source]

Getting the yearly expense with the defined discount interest rate

omkostninger()[source]

Summing the expenses not related to fuel expense over the evaluation period

tco_yearly()[source]

fleetmanager.model.trip_generator module

fleetmanager.model.trip_generator.generate_trips_simulation(pool_id: int, seed: Optional[int] = None, padding: float = 1.2, dates: list = [])[source]

Generates two list of possible trips for specific pool

dateslist

The selected start - and end date of simulation period

pool_idint

The pool to simulate.

seedint

The seed of the random function that samples trips.

paddingfloat

increases the amount of simulated trips by a percentage

simulated_day: list[Dict]

A list of trips from an average simulated day.

peak_day: list[Dict]

The list of trips from the day with most trips.

fleetmanager.model.vehicle module

class fleetmanager.model.vehicle.Bike(*args, **kwargs)[source]

Bases: VehicleModel

Class for representing a bike

accept_trip(trip)[source]

Returns true if the trip is accepted, and false if its declined The bike will only accept if the following is true

distance for trip must be less than milage left trip start - and end time must be within the allowed driving slot

allowed_driving_time_slots = []
co2emission_per_km = 0
max_distance_per_day = 20
max_distance_pr_trip = 5
max_time_slot = 0
percentage = 100
vehicle_type_number = 3
class fleetmanager.model.vehicle.Car(*args, **kwargs)[source]

Bases: VehicleModel

Class for representing a car

accept_trip(trip)[source]

Returns true if the trip is accepted, and false if the yearly_set is true and the yearly_allowance is exceeded

co2emission_per_km = 150
counter = 0
fuel = 'benzin'
max_distance_per_day = 9999
vehicle_type_number = 0
wltp_fossil = 20
yearly_allowance = 999999
yearly_set = False
class fleetmanager.model.vehicle.ElectricBike(*args, **kwargs)[source]

Bases: VehicleModel

Class for representing an electric bike

accept_trip(trip)[source]

Returns true if the trip is accepted, and false if its declined The bike will only accept if the following is true

distance for trip must be less than milage left trip start - and end time must be within the allowed driving slot

allowed_driving_time_slots = []
co2emission_per_km = 0
max_distance_per_day = 50
max_distance_pr_trip = 5
max_time_slot = 0
percentage = 100
vehicle_type_number = 2
class fleetmanager.model.vehicle.ElectricCar(*args, **kwargs)[source]

Bases: VehicleModel

Class for representing an electric car

accept_trip(trip)[source]

Returns true if the trip is accepted, and false if its declined The electrical car will only accept if the following is true

distance for trip must be less than milage left vehicle must still be idle for at least self.sleep hours pr. 24 hours

co2emission_per_km = 0
counter = 0
fuel = 'el'
max_distance_per_day = 200
sleep = 7
vehicle_type_number = 1
wltp_el = 200
yearly_allowance = 999999
yearly_set = False
class fleetmanager.model.vehicle.FleetInventory(models, name='fleetinventory')[source]

Bases: object

Class for containing a fleet of vehicles.

models: available models type model.VehicleFactory name: string, name of the fleet, typically ‘simulation’ or ‘current’

copy_bike_fleet(name='fleetinventory')[source]

Convenience function used in intelligent simulation for copying only the bike fleet as the Qampo algorithms does not accept bikes and electrical bikes

get_total()[source]
initialise_fleet(km_aar=False)[source]

Initialise fleet by sorting on co2e priority, this results in vehicles being loaded in the following order bike, electical bike (wltp), electrical car (wltp), car (wltp)

print_timetable()[source]

Print timetable for fleet. Mostly for debugging.

set_count()[source]
set_timestamps(timestamps)[source]

set timestamps for all vehicles

class fleetmanager.model.vehicle.Unassigned(*args, **kwargs)[source]

Bases: VehicleModel

Class for representing an unassigned vehicle. Used for computing capacity.

accept_trip(trip)[source]

function that returns true if the given type of trip is possible for the vehicle given length, duration, milage_left should be overwritten for each type of vehicle

trip : pandas row with a trip

co2emission_per_km = 0
max_distance_per_day = 0
vehicle_type_number = -1
fleetmanager.model.vehicle.VehicleClassGenerator(name, vehicle_type=<class 'fleetmanager.model.vehicle.Car'>)[source]

Class used to create vehicle types from a dynamic list of vehicle models

class fleetmanager.model.vehicle.VehicleFactory[source]

Bases: object

Class for containing the vehicle types that are used in the simulation

get_new_vehicle(vtype, name, vehicle_id)[source]

Function for creating new vehicles

vtype : string, vtype as key into vmapper, one of (“Bike”, “ElectricBike”, “Car”, “ElectricCar”,”Unassigned”) name : string, name of vehicle vehicle_id : int, id of vehicle returns ——-

load_options()[source]

Load options from option file

class fleetmanager.model.vehicle.VehicleModel(name=None, vehicle_id=None)[source]

Bases: object

General vehicle model. Not directly instantiated but specific vehicle models inherit from it

accept_trip(trip)[source]

function that returns true if the given type of trip is possible for the vehicle given length, duration, milage_left should be overwritten for each type of vehicle

trip : pandas row with a trip

book_trip(trip)[source]

Function for trying to book trip on vehicle

trip : pandas row with a trip

booked : boolean, True if vehicle is booked on this vehile accept : boolean, True if it can accept the type of trip available: boolean, True if the vehicle is available in this timeperiod

bypass_book(trip)[source]
classmethod class_info()[source]
co2emission_per_km = None
location = None
max_distance_per_day = None
omkostning_aar = None
percentage_accept()[source]

Method that ensures that bike trips accepted gets as close to the input percentage as possible

print_info()[source]

Print info. Mostly for debugging

qampo_gr = 0
set_timestamps(new_timestamps)[source]

Initailize timeslot of vehicle to match timestamps.

new_timestamp : array of timestamps

vcprkm = 0
vehicle_type_number = None
yearly_set = False

fleetmanager.model.vehicle_optimisation module

class fleetmanager.model.vehicle_optimisation.FleetOptimisation(settings=None, km_aar=False)[source]

Bases: object

Class used by tabu search to handle the fleet and vehicles in the connected database

build_fleet_simulation(solution, name='fleetinventory')[source]

Method for building and initialising a fleet for simulation

solution : dict, solution to build name : string, name for the fleet

fleet : FleetInventory

get_active_vehicles()[source]

Method for loading the active vehicles. In order not to exhaust the resources, unique types of the vehicles are loaded in the uniquely value. If a car of a type that was removed because it was identical to a cheaper one, it’s added to the translation dictionary, which bookkeeps the vehicles.

active_vehicles : dict holding the currently active vehicles with key: count temp : dict, holding the unique cars available to the search

sort_settings(input_settings)[source]

loading the settings

Module contents