// File: DivyanshuSaxena[P]green-vrp/Vehicle.cpp
// Function: Vehicle::addCustomerCS(int, int)
void Vehicle::addCustomerCS(int customerId, int chargingStation) {
    Node cs;
    cs.id = chargingStation;
    time_type timeToCS = travelTimes.at(this->currentNodeId).at(chargingStation);
    double travelCostCS = travelCosts.at(this->currentNodeId).at(chargingStation);
    cs.arrival_time = this->route.at(this->route.size()-2).departure_time + timeToCS;
    cs.departure_time = cs.arrival_time + chargingTimeCS;
    this->currentNodeId = chargingStation;
    auto it = this->route.end();
    this->route.insert(--it, cs);
    
    Node node;
    node.id = customerId;
    Customer customer = customers.at(customerId);
    time_type timeTaken = travelTimes.at(this->currentNodeId).at(customer.id);
    double travelCost = travelCosts.at(this->currentNodeId).at(customer.id);
    node.arrival_time = this->route.at(this->route.size()-2).departure_time + timeTaken;
    node.departure_time = node.arrival_time + serviceTime;
    this->currentNodeId = customer.id;
    it = this->route.end();
    this->route.insert(--it, node);

    // Update costs
    this->travellingCost += (travelCost + travelCostCS);
    double waitCost = (customer.timeWindowStarts > node.arrival_time) ? (customer.timeWindowStarts - node.arrival_time)*waiting_factor : 0; 
    this->waitingCost += waitCost;
    this->chargingCost += chargingCostStation;
    updateTotalCost();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3920
movq -0xd8(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x28(%rbp)
movslq 0x70(%rax), %rsi
leaq 0xe2d7(%rip), %rdi      # 0x11218
callq 0x3ad0
movq %rax, %rdi
movslq -0x10(%rbp), %rsi
callq 0x3b10
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
movslq 0x70(%rax), %rsi
leaq 0xe278(%rip), %rdi      # 0x111e8
callq 0x3ad0
movq %rax, %rdi
movslq -0x10(%rbp), %rsi
callq 0x3b10
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0xf8(%rbp)
addq $0x8, %rdi
callq 0x3aa0
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x3a60
movq -0xd8(%rbp), %rdi
movsd 0x10(%rax), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
leaq 0xe30b(%rip), %rax      # 0x112e8
addsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, 0x70(%rdi)
addq $0x8, %rdi
callq 0x3b90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x40(%rbp)
addq $0x8, %rax
movq %rax, -0xf0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3dc0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x3de0
movq -0xf0(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x3bc0
movq %rax, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3920
movl -0xc(%rbp), %eax
movl %eax, -0x68(%rbp)
movslq -0xc(%rbp), %rsi
leaq 0xe1f3(%rip), %rdi      # 0x11248
callq 0x3a20
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
movl $0x38, %edx
callq 0x2150
movq -0xd8(%rbp), %rax
movslq 0x70(%rax), %rsi
leaq 0xe198(%rip), %rdi      # 0x11218
callq 0x3ad0
movq %rax, %rdi
movslq -0xa0(%rbp), %rsi
callq 0x3b10
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0xa8(%rbp)
movslq 0x70(%rax), %rsi
leaq 0xe133(%rip), %rdi      # 0x111e8
callq 0x3ad0
movq %rax, %rdi
movslq -0xa0(%rbp), %rsi
callq 0x3b10
movq -0xd8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
addq $0x8, %rdi
callq 0x3aa0
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0x3a60
movq -0xd8(%rbp), %rdi
movsd 0x10(%rax), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
leaq 0xe085(%rip), %rax      # 0x111b0
addsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, 0x70(%rdi)
addq $0x8, %rdi
callq 0x3b90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xb8(%rbp)
movq -0xb8(%rbp), %rcx
movq %rcx, -0x40(%rbp)
addq $0x8, %rax
movq %rax, -0xe0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3dc0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x3de0
movq -0xe0(%rbp), %rdi
movq -0xc0(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x3bc0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xc8(%rbp)
movsd -0xb0(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movsd -0x78(%rbp), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x31f3
movsd -0x78(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
leaq 0xe117(%rip), %rax      # 0x112f8
cvtsi2sdl (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x3200
xorps %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x3200
movq -0xd8(%rbp), %rdi
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
addsd 0x38(%rdi), %xmm0
movsd %xmm0, 0x38(%rdi)
leaq 0xe0d0(%rip), %rax      # 0x11300
movsd (%rax), %xmm0
addsd 0x28(%rdi), %xmm0
movsd %xmm0, 0x28(%rdi)
callq 0x2b20
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)