I am currently trying to solve a problem where I need to minimise transport cost through the choice of vehicle (and how many of each choice) subject to a given demand.

The problem:

There are currently 3 vehicle sizes corresponding to their haulage capacity, an associated daily cost, and a daily demand.

I need an objective function that minimises the cost through the choice of vehicle whilst satisfying the sales demand, however, I do not know how to define an expression that is based on the number of vehicles used * the cost per day, as it depends on the weight.


# Vehicle capacity
truck_capacity_dict = {
    '7.5T': {'capacity': 7500},
    '12T': {'capacity': 12000},
    '44T': {'capacity': 44000}

# Vehicle daily costs
truck_capacity_dict = {
    '7.5T': {'rate': 350},
    '12T': {'rate': 660},
    '44T': {'rate': 2000}

# Daily demand 
sales_demand_tonnes = {
'2020-01-01': 300,
'2020-01-02': 293,
'2020-01-03': 176

Mathematically, this is similar to the below expression where the OF is to minimise the costs based on the choice of vehicle:

$$\min \sum V_{t, v} \cdot C_{t, v} \forall t \subset T, v \subset V$$

However, I do not know how to formulate an expression in python that determines how many vehicles are chosen, as this depends on the weight.

  • $\begingroup$ Are you trying to model a VRP variant or it is about the cargo optimization problem? $\endgroup$
    – A.Omidi
    Dec 16, 2020 at 9:19

2 Answers 2


I suggest introducing $3n$ variables. Let $ c_{i} $ be the daily rate of each vehicle $i=1,2,3$.

$ x_{i,j} $ designates the quantity of vehicles which will be used every day: the subscript $j$ indicates the day in interest. Supposing to consider $n$ days, we have $j=1, 2, \ldots, n$ days. Clearly, $ x_{i,j} $ is a non-negative integer numbe and $ x_{i,j}=0$ means that no vehicle of kind $i-th$ is used in $j-th$ day.

The total cost based on the number of vehicles used is $ \min \sum_{j=1}^n \sum_{j=1}^3 c_i \cdot x_{ij}$


I am not sure of the bounds of the problem, but I'll try to provide an answer.

Let's consider the following two sets: $$ V = \{v: vehicles\} \\ T = \{t: days\} $$ Now, we have the parameters you have provided, which I understand are the following:

$$ VCAP_v: \text{capacity of vehicle v} \\ VCOST_v: \text{cost of vehicle v}\\ D_t: \text{demand of day t} $$

The only decision variable is the number of trucks that you have to deploy (each day?) to meet the demands. Therefore.

$$ n_{t,v}: \text{integer variable that indicates the number of vehicles v that are deployed on day t} $$

You only have one constraint, which is the demand satisfaction constraint:

$$ \sum_{v\in V}{n_{t,v}VCAP_v} \geq D_t \qquad \forall t\in T$$

And the objective function is simply:

$$ \min z = \sum_{v\in V}\sum_{t\in T}n_{t,v}VCOST_v$$

If, on the other hand, you cannot change the election of trucks, this means, you have to decide which trucks to buy, the integer variable would lose a set ($t$).

If the question was however how to introduce integer variables, it depends on the progamming language. GAMS and Pyomo (I think) can directly establish a variable as integer. Otherwise, I think you have to manually use binary variables to establish the integer variables.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.