src: solver API

This module solves vehicle routing problems using branch&cut&price methods

Model()

Define a routing model.

Point(id[, name, id_customer, ...])

Define a point of graph (customer or depot).

Customer(id[, name, id_customer, penalty, ...])

Define a point customer of graph.

Depot(id[, name, cost, service_time, ...])

Define a point depot of graph.

Link(start_point_id, end_point_id[, name, ...])

Define a link of graph.

VehicleType(id[, start_point_id, ...])

Define a vehicle type with different attributes.

Parameters([time_limit, upper_bound, ...])

Define all parameters from model

Solution([json_input, status])

Contains all elements of solution after running model.solve().

Route(json_input)

Define a route from solution

Model

class src.solver.Model

Define a routing model.

add_customer(id, name='', id_customer=0, service_time=0.0, penalty=0.0, tw_begin=0.0, tw_end=0.0, demand=0, incompatible_vehicles=[])

Add customer in dictionary points

add_depot(id, name='', service_time=0.0, cost=0.0, tw_begin=0.0, tw_end=0.0, incompatible_vehicles=[])

Add depot in dictionary points

Add Link in dictionary links

add_point(id, name='', id_customer=0, service_time=0.0, penalty_or_cost=0.0, tw_begin=0.0, tw_end=0.0, demand=0, incompatible_vehicles=[])

Add Point in dictionary points, if we want to add Depot, id_customer must be equal to 0, otherwise it cannot be greater than 1022 for a Customer

add_vehicle_type(id: int, start_point_id=-1, end_point_id=-1, name='', capacity=0, fixed_cost=0.0, var_cost_dist=0.0, var_cost_time=0.0, max_number=1, tw_begin=0.0, tw_end=0.0)

Add VehicleType in dictionary vehicle_types

check_depots()

Update the model if there are defined intermediate depots not used by vehicles

delete_customer(id: int)

Delete a customer by giving his id

delete_depot(id: int)

Delete a depot by giving his id

Delete a link by giving start point id and end point id

delete_vehicle_type(id: int)

Delete a vehicle type by giving his id

export(name='instance', all_elements=False)

Export the model for debugging model, we can specify the file name. If you put all_elements to True, it exports the model with preprocessing elements.

contains the set of links

property max_total_vehicles_number

the maximum total vehicles number

property message

int : indicates the message associated with status

property parameters

getter function of parameters

property points

contains the set of customers and depots

Type:
  • PointsDict : dictionary contains only points

Informations:
  • It’s possible to resolve the problem until 1022 points.

  • For the moment, the capacity of depot is not considered

set_json()

Set model in json format with all elements of model

set_parameters(time_limit=300, upper_bound=1000000, heuristic_used=False, time_limit_heuristic=20, config_file='', solver_name='CLP', print_level=-1, action='solve', cplex_path='')

Set parameters of the model. For more advanced parameters please indicates a configuration file on config_file variable. solver_name : [CLP,CPLEX] action : [solve,enumAllFeasibleRoutes], print_level = [-2,-1,0]

solve()

Solve the routing problem by using the shared library bapcod.

Additional informations:

VRPSolverEasy is compatible with Windows 64x, Linux and macOS only

property status

int : indicates the status of solution

property vehicle_types

contains the set of vehicle types

Type:

VehicleTypesDict : dictionary contains only vehicle type

Informations:

  • For academic version, with CLP it’s possible to resolve the problem with only one vehicle type.

  • Ids of vehicle types must be greater than one

After you finish solving, you can find the status of the model and know whether you have reached optimality or not using the status attribute.

model.status

Status

numerical value

INFEASIBLE

-2

INTERRUPTED_BY_ERROR

-1

OPTIMAL_SOL_FOUND

0

BETTER_SOL_FOUND

1

BETTER_SOL_DOES_NOT_EXISTS

2

BETTER_SOL_NOT_FOUND

3

If you change the parameters to run an enumeration of all feasible solutions, the interpretation of status is different :

model.status

Status

numerical value

ENUMERATION_SUCCEEDED

0

ENUMERATION_NOT_SUCCEEDED

1

ENUMERATION_INFEASIBLE

2

Point

class src.solver.Point(id, name='', id_customer=0, penalty_or_cost=0.0, service_time=0, tw_begin=0, tw_end=0, demand=0, incompatible_vehicles=[])

Define a point of graph (customer or depot).

Additional informations:
  • service_time : It can represent the time of loading or unloading.

  • penalty_or_cost : If the point is a customer we can specify a penalty for not visiting the customer otherwise, if the point is a depot we can specify a cost to using the depot.

  • tw_begin : time windows begin

  • tw_end : time windows end

  • incompatible_vehicles : id of vehicles that cannot serve the customer or are not accepted in a depot.

__init__(id, name='', id_customer=0, penalty_or_cost=0.0, service_time=0, tw_begin=0, tw_end=0, demand=0, incompatible_vehicles=[])
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property cost

getter function of cost

property demand

getter function of demand

get_point(debug=False)

Get all components of a Point which are different of default value

property id

getter function of id

property id_customer

getter function of id customer

property incompatible_vehicles

getter function of incompatible_vehicles

property name

getter function of name

property penalty

getter function of penalty

property service_time

getter function of service_time

property time_windows

getter function of time windows

property tw_begin

getter function of time windows begin

property tw_end

getter function of time windows end

Customer

class src.solver.Customer(id, name='', id_customer=0, penalty=0.0, service_time=0, tw_begin=0, tw_end=0, demand=0, incompatible_vehicles=[])

Define a point customer of graph.

Additional informations:
  • id_customer(int): must be inferior or equal to 1022

  • penalty(float): represents the penalty of non visited customer

  • tw_begin(float): time window begin

  • tw_end(float): time window end

  • demand(int): must be an integer

__init__(id, name='', id_customer=0, penalty=0.0, service_time=0, tw_begin=0, tw_end=0, demand=0, incompatible_vehicles=[])

Depot

class src.solver.Depot(id, name='', cost=0, service_time=0, tw_begin=0, tw_end=0, incompatible_vehicles=[])

Define a point depot of graph.

Additional informations:

capacity: must be an integer

__init__(id, name='', cost=0, service_time=0, tw_begin=0, tw_end=0, incompatible_vehicles=[])

VehicleType

class src.solver.VehicleType(id: int, start_point_id=-1, end_point_id=-1, name='', capacity=0, fixed_cost=0.0, var_cost_dist=0.0, var_cost_time=0.0, max_number=1, tw_begin=0, tw_end=0)

Define a vehicle type with different attributes.

__init__(id: int, start_point_id=-1, end_point_id=-1, name='', capacity=0, fixed_cost=0.0, var_cost_dist=0.0, var_cost_time=0.0, max_number=1, tw_begin=0, tw_end=0)
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property capacity

–int : capacity of vehicle type

property end_point_id

the id of the end point

property fixed_cost

float : fixed cost of using vehicle type

get_vehicle_type(debug=False)

Get all components of a vehicle type which are differents of default value

property id

int : cannot be less than 1

property max_number

number of vehicles available

property name

str : name of vehicle type

property start_point_id

the id of the starting point

property tw_begin

time windows begin of vehicle type

property tw_end

time windows end of vehicle type

property var_cost_dist

variable cost per unit of distance :type var_cost_dist : float :

property var_cost_time

variable cost per unit of time

Parameters

class src.solver.Parameters(time_limit=300.0, upper_bound=1000000, heuristic_used=False, time_limit_heuristic=20.0, config_file='', solver_name='CLP', print_level=-1, action='solve', cplex_path='')

Define all parameters from model

__init__(time_limit=300.0, upper_bound=1000000, heuristic_used=False, time_limit_heuristic=20.0, config_file='', solver_name='CLP', print_level=-1, action='solve', cplex_path='')
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property action

str : indicates if we want to solve the problem (“solve”) or enumerate all feasible routes(“enumAllFeasibleRoutes”)

property config_file

str : indicates the path of the config file for more advanced settings

property cplex_path

str : path of library cplex 22.1. You can specify a path if you want to use cplex and replace the bapcod-shared library by the library using cplex

get_parameters(debug=False)

Get all parameters which are different of default value

property heuristic_used

bool : getter function of heuristic_used

property print_level

indicates the level of print from Bapcod during the resolution, we can choose (-2,-1,0)

property solver_name

str : indicates the solver used during the resolution, we can choose “CLP” or “CPLEX” solver

property time_limit

float : represents the limit time of resolution

property time_limit_heuristic

float : getter function of time_limit_heuristic

property upper_bound

float : represents the cost we want to reach

Solution

class src.solver.Solution(json_input=None, status=-23)

Contains all elements of solution after running model.solve().

__init__(json_input=None, status=-23)
__repr__()

Return repr(self).

__str__()

Return str(self).

__weakref__

list of weak references to the object (if defined)

export(name='instance')

Export solution for sharing or debugging model, we can specify the name of the file

is_defined()

return true if a solution is defined

property json

str : formatted string to print statistics in json format

property routes

list(Route) : contains the set of routes

property value

float : return the total cost of the solution

Statistics

class src.solver.Statistics(json_input='')

Define a statistics from solution

__init__(json_input='')
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property best_lb

float : best lower bound find during the resolution

property json_input

str : formatted string to print statistics in json format

property nb_branch_and_bound_nodes

int : number of branch and bound nodes from tree structure.

property root_lb

float : the root lower bound find during the resolution

property root_time

float : getter function of root_time

property solution_time

float : time computed to find the solution

Route

class src.solver.Route(json_input)

Define a route from solution

__init__(json_input)
__repr__()

Return repr(self).

__str__()

Return str(self).

__weakref__

list of weak references to the object (if defined)

property cap_consumption

list(float) : the loads at each point

property incoming_arc_names

list(str) : the names of incoming arc

property point_ids

list(int) : if of each point visited

property point_names

list(str) : names of visited points

property route

str : formatted string to print route in json format

property route_cost

float : cost incurred by variable and fixed costs

property time_consumption

list(float) : the time at each point

property vehicle_type_id

int : id of vehicle type making the trip