// File: DivyanshuSaxena[P]green-vrp/Vehicle.cpp
// Function: Vehicle::addCustomerDepot(int)
void Vehicle::addCustomerDepot(int customerId) {
    Customer customer = customers.at(customerId);
    Node depot;
    depot.id = 0;
    this->currentNodeId = 0;
    time_type timeToDepot = travelTimes.at(this->currentNodeId).at(0);
    time_type timeDepotToCustomer = travelTimes.at(0).at(customer.id);
    double travelCostDepot = travelCosts.at(this->currentNodeId).at(0);
    depot.arrival_time = this->route.at(this->route.size()-2).departure_time + timeToDepot;
    depot.departure_time = depot.arrival_time + chargingTimeDepot;
    auto it = this->route.end();
    this->route.insert(--it, depot);

    Node node;
    node.id = customerId;
    node.arrival_time = depot.departure_time + timeDepotToCustomer;
    node.departure_time = node.arrival_time + serviceTime;
    this->currentNodeId = customer.id;
    it = this->route.end();
    this->route.insert(--it, node);

    // Update costs
    double travelCost = travelCosts.at(this->currentNodeId).at(customer.id);
    this->travellingCost += travelCost;
    double waitCost = (customer.timeWindowStarts > node.arrival_time) ? (customer.timeWindowStarts - node.arrival_time)*waiting_factor : 0; 
    this->waitingCost += (waitCost + waitingCostDepot);
    updateTotalCost();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movslq -0xc(%rbp), %rsi
leaq 0xdfd0(%rip), %rdi      # 0x11248
callq 0x3a20
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
movl $0x38, %edx
callq 0x2150
leaq -0x60(%rbp), %rdi
callq 0x3920
movq -0xd8(%rbp), %rax
movl $0x0, -0x60(%rbp)
movl $0x0, 0x70(%rax)
movslq 0x70(%rax), %rsi
leaq 0xdf61(%rip), %rdi      # 0x11218
callq 0x3ad0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3b10
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq 0xdf40(%rip), %rdi      # 0x11218
xorl %eax, %eax
movl %eax, %esi
callq 0x3ad0
movq %rax, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3b10
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x70(%rbp)
movslq 0x70(%rax), %rsi
leaq 0xdedd(%rip), %rdi      # 0x111e8
callq 0x3ad0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3b10
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0xf0(%rbp)
addq $0x8, %rdi
callq 0x3aa0
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x3a60
movq -0xd8(%rbp), %rdi
movsd 0x10(%rax), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
leaq 0xdf78(%rip), %rax      # 0x112f0
addsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
addq $0x8, %rdi
callq 0x3b90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x80(%rbp)
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3dc0
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x3de0
movq -0xe8(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x3bc0
movq %rax, -0x90(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3920
movq -0xd8(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0xa8(%rbp)
movsd -0x50(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
leaq 0xdd9a(%rip), %rax      # 0x111b0
addsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0x48(%rbp), %eax
movl %eax, 0x70(%rdi)
addq $0x8, %rdi
callq 0x3b90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xb0(%rbp)
movq -0xb0(%rbp), %rcx
movq %rcx, -0x80(%rbp)
addq $0x8, %rax
movq %rax, -0xe0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3dc0
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3de0
movq -0xe0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x3bc0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xc0(%rbp)
movslq 0x70(%rax), %rsi
leaq 0xdd42(%rip), %rdi      # 0x111e8
callq 0x3ad0
movq %rax, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3b10
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movsd -0x20(%rbp), %xmm0
ucomisd -0xa0(%rbp), %xmm0
jbe 0x3514
movsd -0x20(%rbp), %xmm0
subsd -0xa0(%rbp), %xmm0
leaq 0xddf6(%rip), %rax      # 0x112f8
cvtsi2sdl (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
jmp 0x3521
xorps %xmm0, %xmm0
movsd %xmm0, -0xf8(%rbp)
jmp 0x3521
movq -0xd8(%rbp), %rdi
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
leaq 0xddc1(%rip), %rax      # 0x11308
addsd (%rax), %xmm0
addsd 0x38(%rdi), %xmm0
movsd %xmm0, 0x38(%rdi)
callq 0x2b20
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)