AnsweredAssumed Answered

VRP: Index out of range (E-1002) and big M

Question asked by ralf.steilen on Jun 5, 2018
Latest reply on Jun 22, 2018 by ralf.steilen

Hello,

 

I am new in the Fico community.

 

During the modelling of a VRP I have run into a bunch of problems. Some I have solved, some I do not seem able to fix myself. I`d highly appriceate any help for the following two issues:

 

1.     In the attached code I continously encounter the issue of an index being out of range, but I cannot seem to be able to pinpoint which index is causing the problem or how to fix it...

2.     In addition to the described issue I am sturggeling to implement/define "M" (Big M) and am unaware of an explnanation on how to do so (exact points highlighted in orange).

 

Any help would go a long way. Thank you.

 

Code:

model "VDRPTW"

  uses "mmxprs"

 

  parameters

    ! Insert runtime parameters here

    C1 = 100

    C2 = 0.4

    C3 = 5

  end-parameters

  ! **** Declare public data **** !

  !@insight.manage input

  public declarations

    ! Insert declarations of entities that are used by the UI here

    !@insight.alias Array Indices

    V = 20

    !Number of nodes

    n = 10

    ! number of customers

    I_VL = 0..n

    ! starting nodes

    I_VR = 1..n+1

    ! end nodes

    Trucks = 1..2

    ! Trucks

    Bikes = 1..2

    ! Bikes

    N = 1..10

    ! nodes of customers

    NQ = 1..8

    ! nodes of customers for drones

    NB = 1..2

    !nodes of customers for bikes

    !@insight.alias Input Array

    d: array(I_VL, I_VR) of integer

    ! distance from start to end

    dq1: array(I_VL, NQ) of integer

    ! distance from Vl to NQ (Customer)

    dq2: array(NQ, I_VR) of integer

    ! distance from Customer to truck

    db: array(I_VL, I_VR) of integer

    x: array(Trucks, I_VL, I_VR) of integer

    ! decision variable indicating if node belongs to truck route

    y: array(Trucks, I_VL, NQ, I_VR) of integer

    ! decision variable indicating if node belongs to drone route

    r: array(Bikes, I_VL, N) of integer

    ! descision variable indicating if node belongs to bike route (mpvar)

    C = 50

    !maximum capacity

    E = 15

    !maximum travel distance of drone

    G = 15

    !maximum weight of parcel for drone delivery

    D = 5

    ! maximum simultaneous drone deliveries

    a: integer

    ! continous variable indicating the serving time

    g: array(N) of integer

    !weight of parcel

    p: array(Trucks, I_VL, I_VR) of integer

    !binary variable determining order of satisfaction/delivery

    v = 25

    !average speed of truck

    vq = 55

    !average speed of drone

    s = 2

    !Service time at customer for the truck

    sq = 1

    !service time at customer for the drone

    !tq

    !service time at customer for the

    T = 4

    !maximum wait time

    z: boolean

    !binary variable determining drone delivery for i, w, j from truck k and a precedes node i and e follows j

    u: array(Trucks, N) of integer

    !integer variable determining position of node i in route of truck k

    q: array(N) of integer

    ! demand for node i of N

   !M: array(

    !Big M

   

   

    !total_cost: is_integer

    !result: integer

   

  end-declarations

  !@insight.manage result

 

  ! *** Loading input data *** !

  !procedure datainput

    ! Insert model code here to initialize the input data (run when a scenario is loaded)

  !  initializations from "input.dat"

  !    MY_INTEGER

  !    input

  !  end-initializations

  !end-procedure

 

  !case insightgetmode of

   ! INSIGHT_MODE_LOAD: do

      ! Prepare the input data then exit

    !  datainput

    !  exit(0)

    !end-do

    !INSIGHT_MODE_RUN: do

      ! Populate the model with input data from the Xpress Insight scenario, then solve the model

    !  insightpopulate

    !end-do

    !INSIGHT_MODE_NONE: do

      ! When the model is run in standalone Mosel (outside of Xpress Insight), load the input data then solve the model

    !  datainput

    !end-do

  !else

  !  writeln("Unknown execution mode")

  !  exit(1)

  !end-case

 

  ! *** Executing the model *** !

(! Insert model code here to execute the scenario, e.g. for an optimization application:

    * calculation of derived data

    * definition & solving of an optimization problem

    * result processing and solution reporting

  !)

  !route definition

  forall(k in Trucks) do

    Ctr0:= sum(j in N) x(k, 0, j) - sum(i in N) x(k, i, n+1) = 0

  end-do

  forall(k in Trucks) do

  Ctr1:= sum(j in N) x(k, 0, j) = sum(i in N) x(k, i, n+1)

  end-do

  forall(k in Trucks, h in N) do

    Ctr2:= sum(i in I_VL) x(k, i, h) = sum(j in I_VR) x(k, j, h)

  end-do

  forall(k in Trucks) do

    Ctr3:= sum(j in N) x(k, 0, j) <= 1

  end-do

  (!All customers have to be served

   forall(j in N) do

    Ctr4:= sum(i in I_VL, k in Trucks) x(k, i, j) +

      sum(l in I_VL, m in I_VR, k in Trucks) y(k, l, j, m) = 1

        !sum(b in Bikes, n in I_VL, o in I_VR) r(b, n, o)

        !  = 1

  end-do          !)!expression issues

  !definition of y

  forall(k in Trucks, i in N, w in NQ, j in I_VR) do

    Ctr5:= 2 * y(k, i, w, j) <= sum(h in I_VL) x(k, h, i) + sum(l in N) x(k, l, j)

  end-do

  forall(w in NQ, j in I_VR, k in Trucks) do

    Ctr6:= y(k, 0, w, j) <= sum(h in I_VL) x(k, h, j)

  end-do               

  !order of customer satisfaction

  forall(k in Trucks, i in N, j in I_VR) do

    Ctr7:= u(k, i) - u(k, j) <= (n+1) * (1-x(k, i, j))

  end-do     

  forall(k in Trucks, i in N, w in NQ, j in I_VR) do

   Ctr8:= u(k, j) - u(k, i) >= 1 - (n+1) * (1-y(k, i, w, j))

  end-do        

  (!definition of p

  forall(k in Trucks, i in N, j in I_VR) do

    Ctr9:= u(k, i) - u(k, j) >= 1 - (n+1) * (p(k, i, j))

  end-do          !)      !syntax error... p needs to be boolean

  forall(k in Trucks, i in N, j in I_VR) do

    Ctr10:= u(k, i) - u(k, j) <= -1 + (n+1) * (1-p(k, i, j))

  end-do

  (! forall(k in Trucks, a in I_VL, i in N, w in NQ, j in N, e in I_VR) do

    Ctr11:= 3 * z(k, a, i, w, j, e) <= y(k, a, w, e) + p(k, a, i) + p(k, j, e)

  end-do      !identifier issues for a and no definition of i, w, j, ctr11

  forall(k in Trucks, a in I_VL, i in N, w in NQ, j in N, e in I_VR) do

    Ctr12:= 2 + z(k, a, i, w, j, e) >= y(k, a, w, e) + p(k, a, i) + p(k, j, e)

  end-do                !identifier issues for a and no definition of i, w, j, ctr12

  !starting service time at customer

  forall(k in Trucks, i in I_VL, j in I_VR) do

    Ctr13:= M(i, j) * (x(k, i, j) - 1) + a(k, i) + s(i) + t(i, j) <= a(k, j)

  end-do            !define M

  forall(k in Trucks, i in I_VL, w in NQ, j in I_VR) do

    Ctr14:= M(i,w) * (y(k, i, w, j) - 1) + t(i, w) + a(k, i) <= a(k, w)

  end-do          !define M

  forall(k in Trucks, i in I_VL, w in NQ, j in I_VR) do

    Ctr15:= M(w, j) * (y(k, i, w, j) - 1) + a(k, w) + sq(w) + tq(w, j) <= a(k, j)

  end-do          !define M

  forall(k in Trucks, i in I_VL, w in NQ, j in I_VR) do

    Ctr16:= M(i, w) * (y(k, i, w, j) - 1) + a(k, w) - tq(i, w) - a(k, i) <= T

  end-do          !define M

  forall(k in Trucks, i in I_VL, w in NQ, j in I_VR) do

    Ctr17:= M(w, j) * (y(k, i, w, j) - 1) + a(k, j) - tq(w, j) - a(k, w) - sq(w) <= T

  end-do       !)     !define M

  !feasibility of drone delivery

  forall(k in Trucks, i in I_VL, j in I_VR, w in NQ) do

    Ctr18:= (dq1(i, w) + dq2(w, j)) * y(k, i, w, j) <= E

  end-do

  !forall(n in N) do

  !  Ctr19:= g(n) <= G

  !end-do

  !Capacity constraint for the truck

  forall(k in Trucks) do

    Ctr20:= sum(i in I_VL) q(i) *

      sum(j in I_VR) x(k, i, j) +

        sum(w in NQ) q(w) *

          sum(i in I_VL, j in I_VR) y(k, i, w, j) <= C

  end-do

  (!Simultaneous drone delivery constraint

  forall(k in Trucks, i in I_VL, j in I_VR) do

    Ctr21:= M(i, j) * (x(k, i, j) - 1) +

      sum(l in NQ, m in I_VR) y(k, i, l, m) +

        sum(p in I_VL, q in NQ) y(k, p, q, j) +

          sum(w in NQ) y(k, i, w, j) +

            sum(a in I_VL, w in NQ, e in I_VR) z(k, a, i, w, j, e) <= D

  end-do              !define M

  !time window satisfaction

  forall(k in Trucks, j in N) do

    Ctr22:= l(j) <= a(k, j) <= u(j)

  end-do      !)         

 

  cost_truck := C1 * sum(i in I_VL, j in I_VR, k in Trucks) d(i, j) * x(k, i, j)

  cost_drones := C2 * sum(i in I_VL, j in I_VR, k in Trucks, w in NQ) (dq1(i,j) + dq2(i,j)) * y(k, i, w, j)

  cost_bikes := C3 * sum(i in I_VL, j in I_VR, b in Bikes) d(i,j) * r(b, i, j)

  total_cost := cost_truck + cost_drones + cost_bikes

 

  minimise(total_cost)

  writeln (total_cost)

  end-model

Outcomes