-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialSolution.cpp
651 lines (594 loc) · 27 KB
/
InitialSolution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
//how check feasibility of single trips work;input-old route,new route positions*2,p,multitrip)
#include "Solution.h"
#include "Problem.h"
#include "InitialSolution.h"
#include <algorithm>
#include <vector>
#include <iostream>
// template<typename T>
ostream& operator<< (ostream& out, const vector<SingleTrip> v) {
out << "{";
size_t last = v.size() - 1;
for(size_t i = 0; i < v.size(); ++i)
{
for(int j: v[i].cust_id)
out << j<<" ";
// for(int k: v[i].depot_early_start_time)
// out<<k<<" ";
out << endl;
out << v[i].depot_early_start_time << " " << v[i].depot_late_start_time << " " << v[i].trip_duration<<" "<<v[i].vehicletrip_id;
if (i != last)
out << ", ";
}
out << "}";
cout<<endl;
return out;
}
ostream& operator<< (ostream& out, const vector<VehicleTrips> v) {
out << "{";
size_t last = v.size() - 1;
for(size_t i = 0; i < v.size(); ++i) {
for(int j: v[i].Multi)
out << j<<" ";
if (i != last)
out << ", ";
}
out << "}";
cout<<endl;
return out;
}
//extern vector<SingleTrip> GlobalTrips;
bool ShrinkTrip_FeasiblityCheckingforSingleTrip(int tripindex,const int pindex,const int dindex,
LoadRequest& tempreq, Problem& p,Solution& S);
void InsertRequest(int tripindex,int pindex,int dindex,
LoadRequest& tempreq, Problem& p,Solution& S);
bool MultiTripFeasiblity(VehicleTrips& VT,Problem &p, Solution& S);
void createSingleTrip(LoadRequest& req, Problem& p, Solution& S);
void ShrinkTrip(SingleTrip& stemp,Problem& p, Solution& S);
using namespace std;
InitialSolution::InitialSolution()
{}
InitialSolution::~InitialSolution()
{}
Solution InitialSolution::InitialSolve(Problem& p, Solution& S)
{
// vector<SingleTrip> temptrip;
vector<int> temp_unrouted_custumer;
temp_unrouted_custumer.resize(p.num_of_request);
//assign unrouted customer to temp_unrouted_customer
int j;
cout<<"Initial Solution"<<endl;
for(unsigned i=0;i< p.sorted_request_id.size();i++)
{
temp_unrouted_custumer[i]=p.sorted_request_id[i];
cout<<p.sorted_request_id[i]<<" ";
}
//cout<<"temp_unrouted_and_sorted_custumer assigned"<<endl;
LoadRequest tempreq=p.requests[temp_unrouted_custumer[0]-1];//-1 done to get index
cout<<"Now Id is"<<tempreq.rid<<endl;
//getting the vehicle type for first request
VehicleTrips M1;
M1.TripVehicle=p.get_vehicle(tempreq.pickup);
//inserting location of trips in Global Trips in Multi vector;
M1.Multi.push_back(0);
M1.Multi.push_back(1);
//now adding the vector in single trip
SingleTrip strip;
//depot id entered
strip.cust_id.push_back(p.depot.id);
strip.cust_id.push_back(p.returndepot.id);
strip.vehicletrip_id=0;//vehicle trip start from id 1
S.GlobalTrips.push_back(strip);
S.servedSingleTrips.push_back(S.GlobalTrips.size()-1);//-----------------
M1.vehicletrip_id=0;
//assigning lunch trip to the vector
SingleTrip lunchtrip;
lunchtrip.depot_early_start_time=M1.TripVehicle.lunch_start_time;
lunchtrip.depot_late_start_time=M1.TripVehicle.lunch_end_time;
lunchtrip.trip_duration=M1.TripVehicle.lunch_duration;
lunchtrip.islunchtrip=true;
lunchtrip.vehicletrip_id=0;
S.GlobalTrips.push_back(lunchtrip);
S.servedLunchTrips.push_back(S.GlobalTrips.size()-1); //--------------
S.MTrips.push_back(M1);//S.Mtrips[GlobalTrips[i].vehicletrip_id];
bool isfeasible=ShrinkTrip_FeasiblityCheckingforSingleTrip(0,1,2,tempreq,p,S);
if(isfeasible)
{
InsertRequest(0,1,2,tempreq,p,S);//inside insert request we also need to calculate the cost
//-------------------- to complete the Insert Request
temp_unrouted_custumer.erase(temp_unrouted_custumer.begin());
}
cout<<"loop began main******"<<endl;
int nooftimesreloopdone=0;
int checkingforerr=0;
while(!temp_unrouted_custumer.empty())
{
bool isinserted=false;
LoadRequest tempreq=p.requests[temp_unrouted_custumer[0]-1];//
// cout<<"Now Id is"<<tempreq.rid<<endl<<endl<<endl<<endl;
for(auto i=0;i<S.GlobalTrips.size();i++)//make a bettr iterator based on some information like multi trip etc.
{
if(S.GlobalTrips[i].islunchtrip!=1)//to check using a variable;
//define new variable;
{
if(S.MTrips[S.GlobalTrips[i].vehicletrip_id].TripVehicle.type<tempreq.pickup.type_const)
{
int reloop=0;//to continue this loop to next customer id if the route is not feasible for a customer
int GlobalTripSize=S.GlobalTrips[i].cust_id.size();
SingleTrip& temps= S.GlobalTrips[i];//is this correct
for(auto m=1;m<GlobalTripSize-1;m++)
{
if( p.request_feasibility[p.getRequestID(tempreq.pickup.id)][p.getRequestID(temps.cust_id[m])]==0)
{
reloop=1;
break;
}
}
if(reloop==1)
{
nooftimesreloopdone++;
continue;
}
for(auto j=1;j<GlobalTripSize;j++)//first index
{
for(auto k=j+1;k<GlobalTripSize+1;k++)//second index
{
// cout<<"GlobalTrip index= "<<i<<"pindex= "<<j<<" dindex="<<k<<"----------------------------------------------------------"<<endl;
bool feas =ShrinkTrip_FeasiblityCheckingforSingleTrip(i,j,k,tempreq,p,S);
if(feas)
{
InsertRequest(i ,j,k,tempreq,p,S);//inside insert request we also need to calculate the cost
//-------------------- to complete the Insert Request
temp_unrouted_custumer.erase(temp_unrouted_custumer.begin());
//alt+shift change the language
isinserted=true;
break;
}
}
if(isinserted)
{
break;
}
}
if(isinserted)
{
break;
}
}
if(isinserted)
{
break;
}
}
if(isinserted)
{
break;
}
}
if(!isinserted)
{
cout<<"requested couldn't be inserted , now making a new trip for the request"<<tempreq.rid<<"\n\n";
createSingleTrip(tempreq,p,S);
temp_unrouted_custumer.erase(temp_unrouted_custumer.begin());
isinserted=true;
}
}
//cout<<"bi"<<endl;
cout<<S.GlobalTrips<<endl;
cout<<S.MTrips<<endl;
cout<<nooftimesreloopdone<<"############################### &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
// cout<<"number of trips scheduled"<< S.servedLunchTrips.size()<<"Num of vehicle "<<S.servedSingleTrips.size()<<endl;
// getchar();
return S;
}
//v.erase(std::remove_if(v.begin(), v.end(),[](const int& x) { return x > 10; }), v.end());// put your condition here
bool ShrinkTrip_FeasiblityCheckingforSingleTrip(int tripindex,const int pindex,const int dindex,
LoadRequest& tempreq, Problem& p,Solution& S)
{
SingleTrip& temps= S.GlobalTrips[tripindex];//is this correct
// cout<<temps.islunchtrip<<" "<<temps.cust_id[0];
temps.cust_id.insert(temps.cust_id.begin()+pindex,tempreq.pickup.id);//.insert(temps.cust_id.begin()+pindex);
temps.cust_id.insert(temps.cust_id.begin()+dindex,tempreq.delivery.id);//
double early_start=p.depot.start_time ,late_start=p.depot.end_time,duration=0;
double totaltripdistance=0,max_capacity=0,l_waittime=0;
for (auto i=1;i<temps.cust_id.size();i++)//checking and feasibility and finding the time window
{
Node N0=p.getNode(temps.cust_id[i-1]);//NO=
Node Ni=p.getNode(temps.cust_id[i]);
//cout<<"N0.id"<<N0.id<<"Ni.id"<<Ni.id<<endl;
double s0=N0.service_time;
double d01=p.distance[temps.cust_id[i-1]][temps.cust_id[i]];
//cout<<"d(i)(i-1)"<<d01<<"s(i-1)"<<s0<<endl;
double tempweight=Ni.demand;
//cout<<"tempweight"<<tempweight<<endl<<endl;
double ei=Ni.start_time;
double li=Ni.end_time;
// store service time and distancehere and add them;
// also find li and ei and ci and typecons-i
early_start=early_start+d01+s0;
late_start=late_start+d01+s0;
duration=duration+d01+s0;
if(duration>p.max_travel_time)//to complete
{
temps.cust_id.erase(temps.cust_id.begin()+dindex);
temps.cust_id.erase(temps.cust_id.begin()+pindex);
return false;
}
// capacity+=tempweight;declared below
//--------------------------------checking for time window
if(early_start>li)
{
// cout<<"early_start>li"<<endl;
temps.cust_id.erase(temps.cust_id.begin()+dindex);
temps.cust_id.erase(temps.cust_id.begin()+pindex);
return false;
}
else if (late_start<ei)
{
// cout<<"late_start<ei"<<endl;
l_waittime+=(ei-early_start);
duration=duration+(ei-early_start);
early_start=ei;late_start=ei;
}
else
{
// cout<<"3rd case"<<endl;
early_start=max(early_start,ei);
late_start=min(late_start,li);
//cout<<"after 3rd case early_start "<<early_start<<" late_start "<<late_start<<" duration"<<duration<<endl;
}
//--------------------------------capacity constraint checking
totaltripdistance+=d01;
max_capacity=std::max(max_capacity,max_capacity+tempweight);
//cout<<"capacity"<<capacity<<"S.MTrips[temps.vehicletrip_id].TripVehicle.Capacity"<<S.MTrips[temps.vehicletrip_id].TripVehicle.Capacity<<endl;
if(max_capacity>S.MTrips[temps.vehicletrip_id].TripVehicle.Capacity) //if current cap is more than cehicle capacity then reurn false
{
//cout<<"temps.vehicletrip_id"<<temps.vehicletrip_id<<"##############################################"<<endl;
//cout<<"capacity overflow"<<endl;
temps.cust_id.erase(temps.cust_id.begin()+dindex);
temps.cust_id.erase(temps.cust_id.begin()+pindex);
return false;
}
}
//if capacity and time window is feasible then temporarily change the temps and check for multitripfeasibility
//cout<<"p.max_travel_time"<<p.max_travel_time<< endl;
if(duration>p.max_travel_time)//to complete
{
temps.cust_id.erase(temps.cust_id.begin()+dindex);
temps.cust_id.erase(temps.cust_id.begin()+pindex);
return false;
}
else
{
// double oldtripdistance=temps.trip_distance;
// temps.trip_distance=totaltripdistance;
double olddepotstarttime=temps.depot_early_start_time;
temps.depot_early_start_time=early_start-duration;
double olddepotendtime=temps.depot_late_start_time;
temps.depot_late_start_time=late_start-duration;
double oldduration=temps.trip_duration;
temps.trip_duration=duration;
//cout<<"\nduration ---------------------"<<duration<<endl;
//requirement of vehicletripID before hand so have to modify the code accordingly
bool feasmulti=MultiTripFeasiblity(S.MTrips[temps.vehicletrip_id],p,S);
temps.trip_duration=oldduration;
temps.depot_early_start_time=olddepotstarttime;
temps.depot_late_start_time=olddepotendtime;
temps.cust_id.erase(temps.cust_id.begin()+dindex);
temps.cust_id.erase(temps.cust_id.begin()+pindex);
// cout<<tripindex<<" "<<pindex<<" "<<dindex<<" "<<"multitrip insertion feasibility= "<<int(feasmulti)<<endl;
return feasmulti;
}
//feasible is true then check the feasibility of multitrip
}
void InsertRequest(int tripindex,int pindex,int dindex,
LoadRequest& tempreq, Problem& p,Solution& S)
{
SingleTrip& temps= S.GlobalTrips[tripindex];
temps.cust_id.insert(temps.cust_id.begin()+pindex,tempreq.pickup.id);//.insert(temps.cust_id.begin()+pindex);
temps.cust_id.insert(temps.cust_id.begin()+dindex,tempreq.delivery.id);//
//cout<<"request inserted permanently"<<endl;
double early_start=p.depot.start_time ,late_start=p.depot.end_time,duration=0;
double totaltripdistance=0,max_capacity=0,l_waittime=0;
//to edit and make it better
bool feasible = true;
for (auto i=1;i<S.GlobalTrips[tripindex].cust_id.size();i++)//checking and feasibility and finding the time window
{
Node N0=p.getNode(temps.cust_id[i-1]);//NO=
Node Ni=p.getNode(temps.cust_id[i]);
double s0=N0.service_time;
double d01=p.distance[temps.cust_id[i-1]][temps.cust_id[i]];
double tempweight=Ni.demand;
double ei=Ni.start_time;
double li=Ni.end_time;
// store service time and distancehere and add them;
// also find li and ei and ci and typecons-i
early_start+=d01+s0;
late_start+=d01+s0;
duration+=d01+s0;
// capacity+=tempweight;
max_capacity=std::max(max_capacity,max_capacity+tempweight);
totaltripdistance+=d01;
//--------------------------------checking for time window
if(early_start>li)
{
cout<<"Error in entering request : start time not matching "<<endl<<endl;
}
else if (late_start<ei)
{
l_waittime+=(ei-early_start);
duration=duration+(ei-early_start);
early_start=ei;late_start=ei;
}
else
{
early_start=max(early_start,ei);
late_start=min(late_start,li);
}
}
temps.depot_early_start_time=early_start-duration;
temps.depot_late_start_time=late_start-duration;
temps.trip_duration=duration;
temps.max_weight=max_capacity;
temps.waitingtime=l_waittime;
temps.trip_distance=totaltripdistance;
}
//----------------------Multitrip Feasibility checking
bool MultiTripFeasiblity(VehicleTrips& VT,Problem &p, Solution& S)//this contains total trip of single variable
{
// sort multitrip on the basis of trip starttime window and then on duration;
//std::sort(VT.Multi.begin(),VT.Multi.end(), compareTripEarlyStartTime_duration);
int static count=0;
count++;
std::sort(VT.Multi.begin(),VT.Multi.end(),[S](int a, int b)->bool {
// Lambda function
// s->GlobalTrips
if(S.GlobalTrips[a].depot_early_start_time<S.GlobalTrips[b].depot_early_start_time)
return true;
else if(S.GlobalTrips[a].depot_early_start_time==S.GlobalTrips[b].depot_early_start_time
&& S.GlobalTrips[a].trip_duration<S.GlobalTrips[b].trip_duration)
return true;
return false;
});
//cout<<"newAfter sorting VT.multi.size()"<< VT.Multi.size()<<endl;
// cout<<"S.GlobalTrips.size()"<<S.GlobalTrips.size()<<endl;
double temp;
temp= S.GlobalTrips[ VT.Multi[0]].depot_early_start_time;
for(auto it=VT.Multi.begin()+1;it!=VT.Multi.end();it++)
{
temp=max(temp+S.GlobalTrips[*(it-1)].trip_duration+p.rest_time*!(S.GlobalTrips[*(it-1)].islunchtrip||S.GlobalTrips[*(it)].islunchtrip),//assumption lunch break time is more than disinfectiontime
S.GlobalTrips[*it].depot_early_start_time );
if( temp>S.GlobalTrips[*it].depot_late_start_time)
{
return false;
}
}
cout<<"coutnt "<<count<<endl;
return true;
}
//-------------Creating a new SingleTrip//It is fixed
void createSingleTrip(LoadRequest& req, Problem& p, Solution& S)
{
SingleTrip stemp;//to insert it in the GlobalTrips
stemp.cust_id.push_back(p.depot.id);
stemp.cust_id.push_back(req.pickup.id);
stemp.cust_id.push_back(req.delivery.id);
stemp.cust_id.push_back(p.returndepot.id);
stemp.islunchtrip=false;
int needed_vehicle_type=p.getVehicleID(req);//return type of vehicle
ShrinkTrip(stemp,p,S);
S.GlobalTrips.push_back(stemp);
S.servedSingleTrips.push_back(S.GlobalTrips.size()-1);
//cout<<"You are in createSingleTrip"<<endl;
//getvehicleID gives the least cost vehicle number for the vehicle
//try to insert the singletrip in each of the multitrip and get a good solution
int VTid=-1;
for(auto it=S.MTrips.begin();it!=S.MTrips.end();it++)
{
// cout<<"you are checking old multrips to assign customers"<<endl;
VTid++;
//assign it to any vehicle already present but that should less than type_cons
if(it->TripVehicle.type>=needed_vehicle_type&&it->TripVehicle.type< req.pickup.type_const)
{
//inserting only if vehicle type matches
int tripAddedNumber=S.GlobalTrips.size()-1;
it->Multi.push_back(tripAddedNumber);//changes done here
bool multifeas=MultiTripFeasiblity(*it,p,S);//sending the vehicletrip object to check for feasibility of multitrip
if(multifeas)
{
//keep the singletrip inside this vehicletrip
S.GlobalTrips.back().vehicletrip_id=VTid;
return;
}
//else erase the trip from inside the Multi
std::vector<int>& vec = it->Multi; // use shorter name
vec.erase(std::remove(vec.begin(), vec.end(), tripAddedNumber), vec.end());
}
// cout<<"VTid2 ==== "<<VTid<<endl;
}
// cout<<"The request can't be assigned to already present vehicle so new MultiTrip is being created"<<endl;
S.GlobalTrips.back().vehicletrip_id=S.MTrips.size();
VehicleTrips VT;
VT.TripVehicle=p.vehicles[needed_vehicle_type-1];
//GlobalTrips.size() gives the total element and '-1' give the index of the last element entered
VT.Multi.push_back(S.GlobalTrips.size()-1);//to get last element entered index
SingleTrip lunchtrip;
lunchtrip.depot_early_start_time=VT.TripVehicle.lunch_start_time;
lunchtrip.depot_late_start_time=VT.TripVehicle.lunch_end_time;
lunchtrip.trip_duration=VT.TripVehicle.lunch_duration;
lunchtrip.islunchtrip=true;
lunchtrip.vehicletrip_id=S.MTrips.size();
VT.vehicletrip_id=S.MTrips.size();
S.GlobalTrips.push_back(lunchtrip);
S.servedLunchTrips.push_back(S.GlobalTrips.size()-1);
VT.Multi.push_back(S.GlobalTrips.size()-1);
//cout<<"S.GlobalTrips.size()-1"<<S.GlobalTrips.size()-1<<endl;
S.MTrips.push_back(VT);
int feas=MultiTripFeasiblity(S.MTrips.back(),p,S);
//cout<<S.MTrips.size()<<endl;
if(feas)
{
cout<<S.MTrips.size()<<endl;
}
else
{
cout<<S.GlobalTrips<<endl;
cout<<S.MTrips<<endl;
S.displaySolution();
cout<<"this customer can't be allocated"<<req.rid<< endl;
exit(0);
}
}
void ShrinkTrip(SingleTrip& stemp,Problem& p, Solution& S)
{
double early_start=p.depot.start_time ,late_start=p.depot.end_time,duration=0;
double totaltripdistance=0,max_capacity=0,l_waittime=0;
for (auto i=1;i<stemp.cust_id.size();i++)//checking and feasibility and finding the time window
{
Node N0=p.getNode(stemp.cust_id[i-1]);//NO=
Node Ni=p.getNode(stemp.cust_id[i]);
double s0=N0.service_time;
double d01=p.distance[stemp.cust_id[i-1]][stemp.cust_id[i]];
double tempweight=Ni.demand;
double ei=Ni.start_time;
double li=Ni.end_time;
// totaltripdistance+=d01;
// store service time and distancehere and add them;
// also find li and ei and ci and typecons-i
early_start+=d01+s0;
late_start+=d01+s0;
duration+=d01+s0;
// capacity+=tempweight;declared below
//--------------------------------checking for time window
if(early_start>li)
{
cout<<"Infeasible new SingleTrip due to time window in ShrinkTrip: Request id is ="<<N0.id<<endl;
}
else if (late_start<ei)
{
l_waittime+=(ei-early_start);
duration=duration+(ei-early_start);
early_start=ei;late_start=ei;
}
else
{
early_start=max(early_start,ei);
late_start=min(late_start,li);
}
//capacity+=tempweight;
max_capacity=std::max(max_capacity,max_capacity+tempweight);
totaltripdistance+=d01;
}
if(duration>p.max_travel_time)//to complete
{
cout<<"Infeasible new SingleTrip due to duration in ShrinkTrip: Request id is ="<<p.getNode(stemp.cust_id[1]).id<<endl;
}
//update all the value of the stemp
stemp.depot_early_start_time=early_start-duration;
stemp.depot_late_start_time=late_start-duration;
stemp.trip_duration=duration;
stemp.max_weight=max_capacity;
stemp.trip_distance=totaltripdistance;
stemp.waitingtime=l_waittime;
cout<<"Shrink Trip duration"<<duration;
//cout<<"hi"<<endl;
cout<<"ID-----"<<p.getNode(stemp.cust_id[1]).id<<"updated"<<endl;
}
//reduce the time windows
//for (auto it = my_vector.rbegin(); it != my_vector.rend(); ++it)
// for (vector<my_class>::reverse_iterator i = my_vector.rbegin();
// i != my_vector.rend(); ++i ) {
// for(auto it=my_vector.rbegin()-1; it != my_vector.rend(); ++it)
// {
// it.late_start_time=min(it.late_start_time, (it+1).late_start_time-it.duration-rest_time;
// }
// }
// else(
// //permute the combination
// )
// return feasible;
//E(i)=max(E(i-1)+D(i-1)+delta,E(i))
//L(i)=min::(L(i+1)-D(i)-delta,L(i))
//
// //multitrip contain vectors of singletrip but we should always be dealing with vector of whole single trip
// //we should be able to delete singletrip from the multitrip vector and that should remain in the singletrip vector
// //we can sort the singletrip on the basis of different things;
// // https://stackoverflow.com/questions/31179517/c-same-object-in-two-different-vectors
// void UpdateMultipleTrip(VehicleTrips& VT,Problem &p)
// {
// std::sort(VT.Multi.begin(),VT.Multi.end(),compareTripEarlyStartTime_duration);// not required just for safety
// double temp;
// temp= S.GlobalTrips[ VT.Multi[0]].depot_early_start_time;
// for(auto it=VT.Multi.begin()+1;it!=VT.Multi.end();it++)
// {
// temp=max( VTstarttime+GlobalTrips[*(it-1)].trip_duration+VT.TripVehicle.lunch_duration*GlobalTrips[*(it-1)].islunchtrip,
// S.GlobalTrips[*it].lunch_start_time );
// if( temp>GlobalTrips[*it].depot_late_start_time)
// {
// return false;
// }
// }
// } no need of it as of now
// bool DynamicProgramming(VehicleTrips& VT,Problem &p, Solution& S)//this contains total trip of single variable
// {
// // cout<<"Yout are now in MultiTripFeasiblity"<<endl;
// // sort multitrip on the basis of trip starttime window and then on duration;
// //cout<<"old VT.multi.size()"<< VT.Multi.size()<<endl;
// //std::sort(VT.Multi.begin(),VT.Multi.end(), compareTripEarlyStartTime_duration);
// std::sort(VT.Multi.begin(),VT.Multi.end(),[S](int a, int b)->bool {
// // Lambda function
// // s->GlobalTrips
// if(S.GlobalTrips[a].depot_early_start_time<S.GlobalTrips[b].depot_early_start_time)
// return true;
// else if(S.GlobalTrips[a].depot_early_start_time==S.GlobalTrips[b].depot_early_start_time
// && S.GlobalTrips[a].trip_duration<S.GlobalTrips[b].trip_duration)
// return true;
// return false;
// });
// //cout<<"newAfter sorting VT.multi.size()"<< VT.Multi.size()<<endl;
// // cout<<"S.GlobalTrips.size()"<<S.GlobalTrips.size()<<endl;
// double temp;
// temp= S.GlobalTrips[ VT.Multi[0]].depot_early_start_time;
// // cout<<"GlobalTrips[ VT.Multi[0]].depot_early_start_time "<<S.GlobalTrips[ VT.Multi[0]].depot_early_start_time<<endl;
// for(auto it=VT.Multi.begin()+1;it!=VT.Multi.end();it++)
// {
// //cout<<"new loop ="<<*it<<endl;
// //cout<<"GlobalTrips[*(it-1)].trip_duration"<<S.GlobalTrips[*(it-1)].trip_duration<<endl;
// //cout<<"oldtemp"<<temp<<endl;
// temp=max(temp+S.GlobalTrips[*(it-1)].trip_duration+p.rest_time*!(S.GlobalTrips[*(it-1)].islunchtrip||S.GlobalTrips[*(it)].islunchtrip),//assumption lunch break time is more than disinfectiontime
// S.GlobalTrips[*it].depot_early_start_time );
// // cout<<"newtemp"<<temp<<endl<<"GlobalTrips[*it].depot_late_start_time"<<S.GlobalTrips[*it].depot_late_start_time<<endl;
// if( temp>S.GlobalTrips[*it].depot_late_start_time)
// {
// return false;
// }
// }
// return true;
// }
//cases if route is created and added to the multitrip and
//first make anew trip and try to add it to exissting vehicletrips
//if okay then it is inserted
//other wise make a new multi trip just as done above //also add lunch service time to trips
//erase the request
//if everuthhing done then find the total cost and display solution
//find operators then
// if(feasible)//checking for multitrip constraint
// {
// // feasible=MultiTripFeasibility(multitrip(vector of singletrip), vehicleno, );
// }
//check capacity constraint everytime, check duration contraint everytime; check time wndow constraint
//can we use static here to define a fix quantity;
//cout<<"i am in shrinktripbigger version inside the loop"<<endl;
// bool compareTripEarlyStartTime_duration(int a, int b)
// {
// if(GlobalTrips[a].depot_early_start_time<GlobalTrips[b].depot_early_start_time)
// return true;
// else if(GlobalTrips[a].depot_early_start_time==GlobalTrips[b].depot_early_start_time
// && GlobalTrips[a].trip_duration<GlobalTrips[b].trip_duration)
// return true;
// return false;
// }
//typedef enum { false, true } bool;
//we can also use different integer to denote different infeasibility
//so that it will help in taking corrective action
//like we don't need to insert any lunch time inside