// File: /workspace/github_cpp_makefile_star2_O2/DivyanshuSaxena[P]green-vrp/Main.cpp
// Function: main
int main() {
	cout << "Starting execution";
	fillGlobalVariables();
	while(customerPool.size()!=0){
		bool stoppingcondition=false;

		Vehicle v;//new object of type:vehicle
		//intialize the members of object "v" of type Vehicle

		vehicles.push_back(v);
		// vehicles.get(currentvehicle).addNode(depot);
		while(stoppingcondition!=true) {
			int mincustomer;
			double minCost=-1;
			double checkcost;

			for(int counter=0;counter<customerPool.size();counter++){
				if(vehicles.at(currentvehicle).feasible(customerPool.at(counter) )==true){
					checkcost=vehicles.at(currentvehicle).totalCost + checknewCustomerCost(vehicles.at(currentvehicle).currentNodeId, customerPool.at(counter)) ;
					//checknewCustomerCost should give travellingCost+waitingCost here.
					if(minCost>checkcost || minCost==-1){
						mincustomer= customerPool.at(counter);
						minCost=checkcost;
					}
				}
			}

			if(minCost!=-1){
				vehicles.at(currentvehicle).addCustomer(mincustomer);
				for(int p=0; p < customerPool.size(); p++){
					if(customerPool.at(p)==mincustomer) {
						customerPool.erase(customerPool.begin()+p);
						break;
						}
				}

			}
			else{
				//NO customer is feasible for adding
				stoppingcondition= vehicles.at(currentvehicle).addChargingStationOrDepot();
			}	
		}
	currentvehicle++;
	}
	// All customers are served until this line.

	//output in csv file
	ofstream outFile;
	outFile.open("solution.csv");
	outFile<<"trans_code,vehicle_type,dist_seq,distribute_lea_tm,distribute_arr_tm,distance,trans_cost,charge_cost,weight_cost,fixed_use_cost,total_cost,charge_cnt,\n";
	for ( int i=0;i<vehicles.size();i++)
	{
		outFile<<"DP"<<i+1<<",";
		outFile<<vehicles.at(i).type<<",";
		for(auto j = 0; j < vehicles.at(i).route.size();j++ )
		{
			outFile<<vehicles.at(i).route.at(j).id;
			if(j!=vehicles.at(i).route.size()-1)
				outFile<<";";
		}
		outFile<<",";
		outFile<<vehicles.at(i).route.at(0).arrival_time<<",";
		outFile<<vehicles.at(i).route.at(vehicles.at(i).route.size()-1).arrival_time<<",";
		outFile<<vehicles.at(i).distanceTravelled<<",";
		outFile<<vehicles.at(i).travellingCost<<",";
		outFile<<vehicles.at(i).chargingCost<<",";
		outFile<<vehicles.at(i).waitingCost<<",";
		outFile<<"200,";
		outFile<<vehicles.at(i).totalCost<<",";
		double countCharging=vehicles.at(i).chargingCost/chargingCostStation;
		outFile<<countCharging<<"\n";
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq 0x5a74(%rip), %rdi      # 0x8fd0
leaq 0x2b6d(%rip), %rsi      # 0x60d0
callq 0x2130
callq 0x3a6e
leaq 0x5c84(%rip), %r15      # 0x91f8
leaq 0x5c4d(%rip), %r12      # 0x91c8
movq 0x5c4e(%rip), %rax      # 0x91d0
cmpq 0x5c3f(%rip), %rax      # 0x91c8
je 0x3744
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x24ac
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4532
xorl %r13d, %r13d
testb %r13b, %r13b
jne 0x372f
xorl %ebx, %ebx
movsd 0x2a6b(%rip), %xmm0     # 0x6028
movsd %xmm0, 0x10(%rsp)
movq 0x5c06(%rip), %rax      # 0x91d0
subq 0x5bf7(%rip), %rax      # 0x91c8
sarq $0x2, %rax
cmpq %rbx, %rax
jbe 0x369e
movslq 0x5cc3(%rip), %rsi      # 0x92a8
movq %r15, %rdi
callq 0x455e
movq %rax, %r14
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31b2
movl (%rax), %esi
movq %r14, %rdi
callq 0x2534
testb %al, %al
je 0x3696
movslq 0x5c94(%rip), %rsi      # 0x92a8
movq %r15, %rdi
callq 0x455e
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movslq 0x5c7a(%rip), %rsi      # 0x92a8
movq %r15, %rdi
callq 0x455e
movl 0x70(%rax), %r14d
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31b2
movl (%rax), %esi
movl %r14d, %edi
callq 0x436e
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd 0x29c1(%rip), %xmm0     # 0x6028
jne 0x366b
jnp 0x3677
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3696
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31b2
movl (%rax), %ebp
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
incq %rbx
jmp 0x35c3
movsd 0x10(%rsp), %xmm0
ucomisd 0x297c(%rip), %xmm0     # 0x6028
movslq 0x5bf5(%rip), %rsi      # 0x92a8
jne 0x36b7
jnp 0x3717
movq %r15, %rdi
callq 0x455e
movq %rax, %rdi
movl %ebp, %esi
callq 0x28fa
pushq $-0x4
popq %rbx
xorl %r14d, %r14d
movq 0x5afa(%rip), %rax      # 0x91d0
subq 0x5aeb(%rip), %rax      # 0x91c8
sarq $0x2, %rax
cmpq %r14, %rax
jbe 0x35aa
movq %r12, %rdi
movq %r14, %rsi
callq 0x31b2
incq %r14
addq $0x4, %rbx
cmpl %ebp, (%rax)
jne 0x36cf
addq 0x5ac1(%rip), %rbx      # 0x91c8
movq %r12, %rdi
movq %rbx, %rsi
callq 0x457c
jmp 0x35aa
movq %r15, %rdi
callq 0x455e
movq %rax, %rdi
callq 0x2dfa
movl %eax, %r13d
jmp 0x35aa
incl 0x5b73(%rip)            # 0x92a8
leaq 0x20(%rsp), %rdi
callq 0x32be
jmp 0x357b
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x2200
leaq 0x298b(%rip), %rsi      # 0x60e3
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2040
leaq 0x2986(%rip), %rsi      # 0x60f0
leaq 0x18(%rsp), %rdi
callq 0x2130
xorl %ebp, %ebp
leaq 0x18(%rsp), %r14
leaq 0x5a76(%rip), %r12      # 0x91f8
pushq $0x18
popq %rbx
leaq 0x29ff(%rip), %r13      # 0x618b
movq 0x5a6d(%rip), %rax      # 0x9200
subq 0x5a5e(%rip), %rax      # 0x91f8
cqto
pushq $0x78
popq %rcx
idivq %rcx
cmpq %rbp, %rax
jbe 0x3a1c
movq %r14, %rdi
leaq 0x29d3(%rip), %rsi      # 0x6188
callq 0x2130
leaq 0x1(%rbp), %rsi
movq %rax, %rdi
movq %rsi, 0x8(%rsp)
callq 0x2210
movq %rax, %rdi
leaq 0x29bb(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movl (%rax), %esi
movq %r14, %rdi
callq 0x2210
movq %rax, %rdi
leaq 0x2997(%rip), %rsi      # 0x6190
callq 0x2130
xorl %r15d, %r15d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
movq %rcx, %rax
cqto
idivq %rbx
cmpq %r15, %rax
jbe 0x3878
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
addq $0x8, %rax
movq %rax, %rdi
movq %r15, %rsi
callq 0x30da
movl (%rax), %esi
movq %r14, %rdi
callq 0x2210
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
movq %rcx, %rax
cqto
idivq %rbx
decq %rax
cmpq %rax, %r15
je 0x3873
movq %r14, %rdi
movq %r13, %rsi
callq 0x2130
incq %r15
jmp 0x3801
movq %r14, %rdi
leaq 0x290e(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
addq $0x8, %rax
movq %rax, %rdi
xorl %esi, %esi
callq 0x30da
movsd 0x8(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x28d9(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movq %rax, %r15
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
addq $0x8, %r15
movq 0x10(%rax), %rcx
subq 0x8(%rax), %rcx
movq %rcx, %rax
cqto
idivq %rbx
leaq -0x1(%rax), %rsi
movq %r15, %rdi
callq 0x30da
movsd 0x8(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x2884(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x50(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x285d(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x30(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x2836(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x28(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x280f(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x38(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x27e8(%rip), %rsi      # 0x6190
callq 0x2130
movq %r14, %rdi
leaq 0x27d6(%rip), %rsi      # 0x618d
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x20(%rax), %xmm0
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x27b2(%rip), %rsi      # 0x6190
callq 0x2130
movq %r12, %rdi
movq %rbp, %rsi
callq 0x455e
movsd 0x28(%rax), %xmm0
divsd 0x589d(%rip), %xmm0     # 0x9298
movq %r14, %rdi
callq 0x21d0
movq %rax, %rdi
leaq 0x2779(%rip), %rsi      # 0x6186
callq 0x2130
movq 0x8(%rsp), %rbp
jmp 0x378c
leaq 0x18(%rsp), %rdi
callq 0x21a0
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3a48
jmp 0x3a59
jmp 0x3a59
jmp 0x3a48
jmp 0x3a59
jmp 0x3a48
jmp 0x3a59
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x21a0
jmp 0x3a66
jmp 0x3a59
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x32be
movq %rbx, %rdi
callq 0x2220