// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x40(%rsp), %r13
movl %edx, (%r13)
movslq 0x70(%rdi), %rsi
leaq 0x6742(%rip), %rdi      # 0x91b0
callq 0x30f8
movslq %r14d, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3116
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movslq 0x70(%rbx), %rsi
leaq 0x66ea(%rip), %r12      # 0x9180
movq %r12, %rdi
callq 0x30f8
movq %rax, %rdi
movq %r15, %rsi
callq 0x3116
movsd (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x8(%rbx), %r14
movq 0x10(%rbx), %rax
subq 0x8(%rbx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
leaq -0x2(%rax), %rsi
movq %r14, %rdi
callq 0x30da
movsd 0x8(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
leaq 0x6796(%rip), %rax      # 0x9280
addsd (%rax), %xmm0
movsd %xmm0, 0x10(%r13)
movl %r15d, 0x70(%rbx)
movq 0x10(%rbx), %rsi
addq $-0x18, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x3138
leaq 0x28(%rsp), %r13
movl %ebp, (%r13)
movslq %ebp, %rsi
leaq 0x66c2(%rip), %rdi      # 0x91e0
callq 0x30bc
movslq (%rax), %rbp
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movslq 0x70(%rbx), %rsi
leaq 0x6674(%rip), %rdi      # 0x91b0
callq 0x30f8
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3116
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movslq 0x70(%rbx), %rsi
movq %r12, %rdi
callq 0x30f8
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3116
movq 0x10(%rbx), %rcx
subq 0x8(%rbx), %rcx
movq %rax, %rdi
movq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq -0x2(%rax), %rsi
movapd 0x10(%rsp), %xmm0
addsd (%rdi), %xmm0
movapd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x30da
movsd 0x20(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
leaq 0x6591(%rip), %rax      # 0x9148
addsd (%rax), %xmm0
movsd %xmm0, 0x10(%r13)
movl %ebp, 0x70(%rbx)
movq 0x10(%rbx), %rsi
addq $-0x18, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x3138
movsd 0x8(%r13), %xmm0
movsd 0x8(%rsp), %xmm3
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
leaq 0x669e(%rip), %rax      # 0x9290
cvtsi2sdl (%rax), %xmm2
mulsd %xmm1, %xmm2
cmpltsd %xmm3, %xmm0
andpd %xmm2, %xmm0
addsd 0x38(%rbx), %xmm0
movsd %xmm0, 0x38(%rbx)
leaq 0x6684(%rip), %rax      # 0x9298
movupd 0x28(%rbx), %xmm0
movsd (%rax), %xmm1
unpcklpd 0x10(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
addpd %xmm0, %xmm1
movupd %xmm1, 0x28(%rbx)
movq %rbx, %rdi
callq 0x27ec
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop