34
34
/**
35
35
* Created by schroeder on 11/10/16.
36
36
*/
37
- public class MaxDistanceConstraint implements HardActivityConstraint {
37
+ public class MaxDistanceConstraint implements HardActivityConstraint {
38
38
39
39
private StateManager stateManager ;
40
40
@@ -44,7 +44,7 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
44
44
45
45
private Double [] maxDistances ;
46
46
47
- public MaxDistanceConstraint (StateManager stateManager , StateId distanceId , TransportDistance distanceCalculator , Map <Vehicle ,Double > maxDistancePerVehicleMap ) {
47
+ public MaxDistanceConstraint (StateManager stateManager , StateId distanceId , TransportDistance distanceCalculator , Map <Vehicle , Double > maxDistancePerVehicleMap ) {
48
48
this .stateManager = stateManager ;
49
49
this .distanceId = distanceId ;
50
50
this .distanceCalculator = distanceCalculator ;
@@ -53,50 +53,50 @@ public MaxDistanceConstraint(StateManager stateManager, StateId distanceId, Tran
53
53
54
54
private void makeArray (Map <Vehicle , Double > maxDistances ) {
55
55
int maxIndex = getMaxIndex (maxDistances .keySet ());
56
- this .maxDistances = new Double [maxIndex + 1 ];
57
- for (Vehicle v : maxDistances .keySet ()){
58
- this .maxDistances [v .getIndex ()]= maxDistances .get (v );
56
+ this .maxDistances = new Double [maxIndex + 1 ];
57
+ for (Vehicle v : maxDistances .keySet ()) {
58
+ this .maxDistances [v .getIndex ()] = maxDistances .get (v );
59
59
}
60
60
}
61
61
62
62
private int getMaxIndex (Collection <Vehicle > vehicles ) {
63
63
int index = 0 ;
64
- for (Vehicle v : vehicles ){
65
- if (v .getIndex () > index ) index = v .getIndex ();
64
+ for (Vehicle v : vehicles ) {
65
+ if (v .getIndex () > index ) index = v .getIndex ();
66
66
}
67
67
return index ;
68
68
}
69
69
70
70
@ Override
71
71
public ConstraintsStatus fulfilled (JobInsertionContext iFacts , TourActivity prevAct , TourActivity newAct , TourActivity nextAct , double prevActDepTime ) {
72
- if (!hasMaxDistance (iFacts .getNewVehicle ())) return ConstraintsStatus .FULFILLED ;
72
+ if (!hasMaxDistance (iFacts .getNewVehicle ())) return ConstraintsStatus .FULFILLED ;
73
73
Double currentDistance = 0d ;
74
74
boolean routeIsEmpty = iFacts .getRoute ().isEmpty ();
75
- if (!routeIsEmpty ){
76
- currentDistance = stateManager .getRouteState (iFacts .getRoute (),iFacts .getNewVehicle (), distanceId ,Double .class );
75
+ if (!routeIsEmpty ) {
76
+ currentDistance = stateManager .getRouteState (iFacts .getRoute (), iFacts .getNewVehicle (), distanceId , Double .class );
77
77
}
78
78
double maxDistance = getMaxDistance (iFacts .getNewVehicle ());
79
- if (currentDistance > maxDistance ) return ConstraintsStatus .NOT_FULFILLED_BREAK ;
79
+ if (currentDistance > maxDistance ) return ConstraintsStatus .NOT_FULFILLED_BREAK ;
80
80
81
81
double distancePrevAct2NewAct = distanceCalculator .getDistance (prevAct .getLocation (), newAct .getLocation (), iFacts .getNewDepTime (), iFacts .getNewVehicle ());
82
82
double distanceNewAct2nextAct = distanceCalculator .getDistance (newAct .getLocation (), nextAct .getLocation (), iFacts .getNewDepTime (), iFacts .getNewVehicle ());
83
83
double distancePrevAct2NextAct = distanceCalculator .getDistance (prevAct .getLocation (), nextAct .getLocation (), prevActDepTime , iFacts .getNewVehicle ());
84
- if (prevAct instanceof Start && nextAct instanceof End ) distancePrevAct2NextAct = 0 ;
85
- if (nextAct instanceof End && !iFacts .getNewVehicle ().isReturnToDepot ()){
84
+ if (prevAct instanceof Start && nextAct instanceof End ) distancePrevAct2NextAct = 0 ;
85
+ if (nextAct instanceof End && !iFacts .getNewVehicle ().isReturnToDepot ()) {
86
86
distanceNewAct2nextAct = 0 ;
87
87
distancePrevAct2NextAct = 0 ;
88
88
}
89
89
double additionalDistance = distancePrevAct2NewAct + distanceNewAct2nextAct - distancePrevAct2NextAct ;
90
- if (currentDistance + additionalDistance > maxDistance ) return ConstraintsStatus .NOT_FULFILLED ;
90
+ if (currentDistance + additionalDistance > maxDistance ) return ConstraintsStatus .NOT_FULFILLED ;
91
91
92
92
93
93
double additionalDistanceOfPickup = 0 ;
94
- if (newAct instanceof DeliverShipment ){
94
+ if (newAct instanceof DeliverShipment ) {
95
95
int iIndexOfPickup = iFacts .getRelatedActivityContext ().getInsertionIndex ();
96
96
TourActivity pickup = iFacts .getAssociatedActivities ().get (0 );
97
97
TourActivity actBeforePickup ;
98
- if (iIndexOfPickup > 0 ) actBeforePickup = iFacts .getRoute ().getActivities ().get (iIndexOfPickup - 1 );
99
- else actBeforePickup = new Start (iFacts .getNewVehicle ().getStartLocation (),0 , Double .MAX_VALUE );
98
+ if (iIndexOfPickup > 0 ) actBeforePickup = iFacts .getRoute ().getActivities ().get (iIndexOfPickup - 1 );
99
+ else actBeforePickup = new Start (iFacts .getNewVehicle ().getStartLocation (), 0 , Double .MAX_VALUE );
100
100
TourActivity actAfterPickup ;
101
101
if (iIndexOfPickup < iFacts .getRoute ().getActivities ().size ())
102
102
actAfterPickup = iFacts .getRoute ().getActivities ().get (iIndexOfPickup );
@@ -114,21 +114,21 @@ public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prev
114
114
}
115
115
116
116
117
- if (currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance ){
117
+ if (currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance ) {
118
118
return ConstraintsStatus .NOT_FULFILLED ;
119
119
}
120
120
121
121
return ConstraintsStatus .FULFILLED ;
122
122
}
123
123
124
- private boolean hasMaxDistance (Vehicle newVehicle ){
125
- if (newVehicle .getIndex () >= this .maxDistances .length ) return false ;
124
+ private boolean hasMaxDistance (Vehicle newVehicle ) {
125
+ if (newVehicle .getIndex () >= this .maxDistances .length ) return false ;
126
126
return this .maxDistances [newVehicle .getIndex ()] != null ;
127
127
}
128
128
129
129
private double getMaxDistance (Vehicle newVehicle ) {
130
130
Double maxDistance = this .maxDistances [newVehicle .getIndex ()];
131
- if (maxDistance == null ) return Double .MAX_VALUE ;
131
+ if (maxDistance == null ) return Double .MAX_VALUE ;
132
132
return maxDistance ;
133
133
}
134
134
}
0 commit comments