18
18
package com .graphhopper .jsprit .core .algorithm .recreate ;
19
19
20
20
import com .graphhopper .jsprit .core .problem .VehicleRoutingProblem ;
21
- import com .graphhopper .jsprit .core .problem .job . Break ;
21
+ import com .graphhopper .jsprit .core .problem .constraint . DependencyType ;
22
22
import com .graphhopper .jsprit .core .problem .job .Job ;
23
23
import com .graphhopper .jsprit .core .problem .solution .route .VehicleRoute ;
24
24
import com .graphhopper .jsprit .core .problem .vehicle .VehicleFleetManager ;
@@ -51,7 +51,7 @@ public class RegretInsertionFast extends AbstractInsertionStrategy {
51
51
52
52
private boolean switchAllowed = true ;
53
53
54
-
54
+ private DependencyType [] dependencyTypes = null ;
55
55
56
56
public RegretInsertionFast (JobInsertionCostsCalculator jobInsertionCalculator , VehicleRoutingProblem vehicleRoutingProblem , VehicleFleetManager fleetManager ) {
57
57
super (vehicleRoutingProblem );
@@ -78,6 +78,10 @@ public void setSwitchAllowed(boolean switchAllowed) {
78
78
this .switchAllowed = switchAllowed ;
79
79
}
80
80
81
+ public void setDependencyTypes (DependencyType [] dependencyTypes ){
82
+ this .dependencyTypes = dependencyTypes ;
83
+ }
84
+
81
85
private Set <String > getInitialVehicleIds (VehicleRoutingProblem vehicleRoutingProblem ) {
82
86
Set <String > ids = new HashSet <String >();
83
87
for (VehicleRoute r : vehicleRoutingProblem .getInitialVehicleRoutes ()){
@@ -101,25 +105,25 @@ public String toString() {
101
105
public Collection <Job > insertUnassignedJobs (Collection <VehicleRoute > routes , Collection <Job > unassignedJobs ) {
102
106
List <Job > badJobs = new ArrayList <Job >(unassignedJobs .size ());
103
107
104
- Iterator <Job > jobIterator = unassignedJobs .iterator ();
105
- while (jobIterator .hasNext ()){
106
- Job job = jobIterator .next ();
107
- if (job instanceof Break ){
108
- VehicleRoute route = InsertionDataUpdater .findRoute (routes , job );
109
- if (route == null ){
110
- badJobs .add (job );
111
- }
112
- else {
113
- InsertionData iData = insertionCostsCalculator .getInsertionData (route , job , NO_NEW_VEHICLE_YET , NO_NEW_DEPARTURE_TIME_YET , NO_NEW_DRIVER_YET , Double .MAX_VALUE );
114
- if (iData instanceof InsertionData .NoInsertionFound ) {
115
- badJobs .add (job );
116
- } else {
117
- insertJob (job , iData , route );
118
- }
119
- }
120
- jobIterator .remove ();
121
- }
122
- }
108
+ // Iterator<Job> jobIterator = unassignedJobs.iterator();
109
+ // while (jobIterator.hasNext()){
110
+ // Job job = jobIterator.next();
111
+ // if(job instanceof Break){
112
+ // VehicleRoute route = InsertionDataUpdater.findRoute(routes, job);
113
+ // if(route == null){
114
+ // badJobs.add(job);
115
+ // }
116
+ // else {
117
+ // InsertionData iData = insertionCostsCalculator.getInsertionData(route, job, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE);
118
+ // if (iData instanceof InsertionData.NoInsertionFound) {
119
+ // badJobs.add(job);
120
+ // } else {
121
+ // insertJob(job, iData, route);
122
+ // }
123
+ // }
124
+ // jobIterator.remove();
125
+ // }
126
+ // }
123
127
124
128
List <Job > jobs = new ArrayList <Job >(unassignedJobs );
125
129
TreeSet <VersionedInsertionData >[] priorityQueues = new TreeSet [vrp .getJobs ().values ().size () + 2 ];
@@ -130,15 +134,15 @@ public Collection<Job> insertUnassignedJobs(Collection<VehicleRoute> routes, Col
130
134
while (!jobs .isEmpty ()) {
131
135
List <Job > unassignedJobList = new ArrayList <Job >(jobs );
132
136
List <Job > badJobList = new ArrayList <Job >();
133
- if (!firstRun && lastModified == null ) throw new IllegalStateException ("fooo " );
137
+ if (!firstRun && lastModified == null ) throw new IllegalStateException ("last modified route is null. this should not be. " );
134
138
if (firstRun ){
139
+ updateInsertionData (priorityQueues , routes , unassignedJobList , updateRound , firstRun , lastModified , updates );
135
140
firstRun = false ;
136
- updateInsertionData (priorityQueues , routes , unassignedJobList , updateRound );
137
- for (VehicleRoute r : routes ) updates .put (r ,updateRound );
138
141
}
139
142
else {
140
- updateInsertionData (priorityQueues , Arrays .asList (lastModified ), unassignedJobList , updateRound );
141
- updates .put (lastModified ,updateRound );
143
+ //update for all routes || remove history and only update modified route
144
+ updateInsertionData (priorityQueues , routes , unassignedJobList , updateRound , firstRun , lastModified , updates );
145
+ // updates.put(lastModified,updateRound);
142
146
}
143
147
updateRound ++;
144
148
ScoredJob bestScoredJob = InsertionDataUpdater .getBest (switchAllowed ,initialVehicleIds ,fleetManager ,insertionCostsCalculator ,scoringFunction ,priorityQueues ,updates ,unassignedJobList ,badJobList );
@@ -159,12 +163,31 @@ public Collection<Job> insertUnassignedJobs(Collection<VehicleRoute> routes, Col
159
163
return badJobs ;
160
164
}
161
165
162
- private void updateInsertionData (TreeSet <VersionedInsertionData >[] priorityQueues , Collection <VehicleRoute > routes , List <Job > unassignedJobList , int updateRound ) {
166
+ private void updateInsertionData (TreeSet <VersionedInsertionData >[] priorityQueues , Collection <VehicleRoute > routes , List <Job > unassignedJobList , int updateRound , boolean firstRun , VehicleRoute lastModified , Map < VehicleRoute , Integer > updates ) {
163
167
for (Job unassignedJob : unassignedJobList ) {
164
168
if (priorityQueues [unassignedJob .getIndex ()] == null ){
165
169
priorityQueues [unassignedJob .getIndex ()] = new TreeSet <VersionedInsertionData >(InsertionDataUpdater .getComparator ());
166
170
}
167
- InsertionDataUpdater .update (switchAllowed , initialVehicleIds ,fleetManager ,insertionCostsCalculator , priorityQueues [unassignedJob .getIndex ()], updateRound , unassignedJob , routes );
171
+ if (firstRun ) {
172
+ InsertionDataUpdater .update (switchAllowed , initialVehicleIds , fleetManager , insertionCostsCalculator , priorityQueues [unassignedJob .getIndex ()], updateRound , unassignedJob , routes );
173
+ for (VehicleRoute r : routes ) updates .put (r ,updateRound );
174
+ }
175
+ else {
176
+ if (dependencyTypes == null || dependencyTypes [unassignedJob .getIndex ()] == null ){
177
+ InsertionDataUpdater .update (switchAllowed , initialVehicleIds , fleetManager , insertionCostsCalculator , priorityQueues [unassignedJob .getIndex ()], updateRound , unassignedJob , Arrays .asList (lastModified ));
178
+ for (VehicleRoute r : routes ) updates .put (r ,updateRound );
179
+ }
180
+ else {
181
+ DependencyType dependencyType = dependencyTypes [unassignedJob .getIndex ()];
182
+ if (dependencyType .equals (DependencyType .INTER_ROUTE ) || dependencyType .equals (DependencyType .INTRA_ROUTE )) {
183
+ InsertionDataUpdater .update (switchAllowed , initialVehicleIds , fleetManager , insertionCostsCalculator , priorityQueues [unassignedJob .getIndex ()], updateRound , unassignedJob , routes );
184
+ for (VehicleRoute r : routes ) updates .put (r ,updateRound );
185
+ } else {
186
+ InsertionDataUpdater .update (switchAllowed , initialVehicleIds , fleetManager , insertionCostsCalculator , priorityQueues [unassignedJob .getIndex ()], updateRound , unassignedJob , Arrays .asList (lastModified ));
187
+ updates .put (lastModified ,updateRound );
188
+ }
189
+ }
190
+ }
168
191
}
169
192
}
170
193
0 commit comments