0

I have a problem regarding formulating the following with math notation. My goal is that if shop i’s arrival time is lower than all the other shop’s arrival times, then shop i must be allocated to the palletspace with the lowest distance (to obtain this, the solution would choose the port accordingly, I imagine)

My parameters are:

  1. SL denoting shop labels (i)
  2. PL denoting port labels (j)
  3. PSL denoting palletspace labels (l)
  4. A_i denoting the arrival times for a shop to a port (same no matter which port)
  5. D_jl denoting the distance from port j to palletspace l
  6. S =range(0, len(SL)
  7. P =range(0, len(PL)
  8. PS =range(0, len(PSL)

Variables: x_ijl = 1 if shop i is using pallet space l through port j y_ij = 1 if shop i is using port j

Now for the constraint I imagine it could be formulated as such: If A_i <= A_k, forall i in S, forall k in S Then x_ijl must be assigned to the pallet space with the lowest distance which isn’t already used by another shop (I have a constraint which ensures that one palletspace can’t be used by another).

So maybe something like: If A_i <= A_k, then x_ijl**distance_jl <= x_kjl*distance_jl

I don’t know guys, I’ve never wrote a linear program for this kind of if statement with multiple indexes…

I read this stack exchange post but I can’t adapt it to my problem… How to write if else statement in Linear programming?

RobPratt
  • 50,938
  • 1
    Is $A_i$ a decision variable or an input parameter? – RobPratt Sep 09 '23 at 18:50
  • Hi @RobPratt. A_i is an input parameter containing an array as long as SL. For instance, 1, 4, 3, 2 meaning shop_1 should have the lowest distance palletspace, shop_4 should have the second lowest distance palletspace, shop_3 should have the third lowest distance palletspace and so on. Thanks for asking for clarification :) – Alexander Strarup Sep 09 '23 at 18:59

1 Answers1

0

Because the arrival times are known, you don't need anything complicated. For $r\in\{1,\dots,|SL|\}$, let $i_r$ be the index of the shop with the $r$th lowest arrival time. In your example, $(i_1,i_2,i_3,i_4)=(1,4,3,2)$.

The desired constraints are $$\sum_{j,l} d_{jl} x_{i_rjl} \le \sum_{j,l} d_{jl} x_{i_{r+1}jl} \quad \text{for all $r\in\{1,\dots,|SL|-1\}$}.$$ Note that this formulation assumes that $$\sum_{j,l} x_{ijl} = 1 \quad \text{for all $i$}.$$ That is, each shop is assigned to exactly one port and pallet space.

RobPratt
  • 50,938
  • Hi @RobPratt, the problem I face is that i is not the index of the shop with the lowest arrival time. It is merely the shop i. So for the constraint to work, I would imagine I need to sort the shops with respect to their arrival times.

    In Python I would do this as: sorted_shop_indexes = sorted(range(len(arrival_times)), key=lambda i: arrival_times[i]) and then have a new decision variable, q, iterate over this list. So q(sorted_shop_indexes, ports, pallet spaces)

    – Alexander Strarup Sep 09 '23 at 19:13
  • Hi @RobPratt, sorry for the late reply. Thanks for your fast adjustment of the constraint. The assumption is not met as palletspaces can’t accommodate the entire demand of a shop. So a shop would be using multiple palletspaces, but only one port. But maybe that can be resolved by looping over l as well. So, for all sorted_retailer, for all palletspaces, the total distance for shop i picking from palletspace l through port j, should be less than or equal to the distance of the next shop. I will try to implement this – Alexander Strarup Sep 10 '23 at 09:13
  • I rearranged the retailer list with respect to arrival times. Indeed, we can just iterate of the length of retailers. I did this as so (your constraint):
    model.arrivalkortestdistance=pyomo.ConstraintList()
    for i in range(1, len(model.retailer_labels)):
        model.arrivalkortestdistance.add(expr=sum(model.distance_matrix[j][l]*model.x[i-1,j,l] for j in model.loading_ports for l in model.palletspaces)
    

    <= sum(model.distance_matrix[j][l]*model.x[i,j,l] for j in model.loading_ports for l in model.palletspaces))

    – Alexander Strarup Sep 10 '23 at 11:39