mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
break feature
This commit is contained in:
parent
a55ea8f3cf
commit
1919c05ceb
6 changed files with 34 additions and 247 deletions
|
|
@ -17,6 +17,7 @@ import jsprit.core.problem.constraint.ConstraintManager;
|
|||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.BreakActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
|
|
@ -485,8 +486,10 @@ public class Jsprit {
|
|||
vra.addListener(noiseMaker);
|
||||
vra.addListener(noise);
|
||||
vra.addListener(clusters);
|
||||
vra.addListener(new RuinBreaks());
|
||||
handleExecutorShutdown(vra);
|
||||
vra.setMaxIterations(Integer.valueOf(properties.getProperty(Parameter.ITERATIONS.toString())));
|
||||
|
||||
return vra;
|
||||
|
||||
}
|
||||
|
|
@ -546,15 +549,24 @@ public class Jsprit {
|
|||
@Override
|
||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.;
|
||||
|
||||
for (VehicleRoute route : solution.getRoutes()) {
|
||||
costs += route.getVehicle().getType().getVehicleCostParams().fix;
|
||||
boolean hasBreak = false;
|
||||
TourActivity prevAct = route.getStart();
|
||||
for (TourActivity act : route.getActivities()) {
|
||||
if(act instanceof BreakActivity) hasBreak = true;
|
||||
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
|
||||
prevAct = act;
|
||||
}
|
||||
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
if(route.getVehicle().getBreak() != null){
|
||||
if(!hasBreak){
|
||||
//break defined but not assigned penalty
|
||||
costs += maxCosts * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
costs += solution.getUnassignedJobs().size() * maxCosts * 2;
|
||||
return costs;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class RuinBreaks implements RuinListener {
|
|||
Break aBreak = r.getVehicle().getBreak();
|
||||
if(aBreak != null){
|
||||
r.getTourActivities().removeJob(aBreak);
|
||||
logger.trace("ruin: " + aBreak.getId());
|
||||
logger.trace("ruin: {}",aBreak.getId());
|
||||
unassignedJobs.add(aBreak);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
|
@ -22,13 +22,13 @@ import jsprit.core.problem.Skills;
|
|||
|
||||
/**
|
||||
* Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit.
|
||||
*
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class Break extends Service {
|
||||
|
||||
public static class Builder extends Service.Builder {
|
||||
public static class Builder extends Service.Builder<Break> {
|
||||
|
||||
/**
|
||||
* Returns a new instance of builder that builds a pickup.
|
||||
|
|
@ -76,5 +76,5 @@ public class Break extends Service {
|
|||
public boolean hasVariableLocation(){
|
||||
return variableLocation;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,11 +88,12 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
public Skills getSkills() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Break getBreak() { return null; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder that builds the vehicle.
|
||||
|
|
@ -179,28 +180,6 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times.
|
||||
*
|
||||
* @param earliest_startTime the earliest start time / departure time of the vehicle at its start location
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setEarliestStart(double earliest_startTime){
|
||||
this.earliestStart = earliest_startTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the latest arrival at vehicle's end-location which is the upper bound of the vehicle's arrival times.
|
||||
*
|
||||
* @param latest_arrTime the latest arrival time of the vehicle at its end location
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder setLatestArrival(double latest_arrTime){
|
||||
this.latestArrival = latest_arrTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times.
|
||||
*
|
||||
|
|
@ -292,8 +271,6 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return new NoVehicle();
|
||||
}
|
||||
|
||||
private final String id;
|
||||
|
||||
private final String id;
|
||||
|
||||
private final VehicleType type;
|
||||
|
|
@ -333,29 +310,15 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id="+id+"]" +
|
||||
"[type="+type+"]" +
|
||||
"[startLocation="+startLocation+"]" +
|
||||
"[endLocation=" + endLocation+"]" +
|
||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||
"[skills="+ skills + "]";
|
||||
|
||||
/**
|
||||
* Returns String with attributes of this vehicle
|
||||
* <p/>
|
||||
* <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + "]" +
|
||||
"[type=" + type + "]" +
|
||||
"[startLocation=" + startLocation + "]" +
|
||||
"[endLocation=" + endLocation + "]" +
|
||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||
"[skills=" + skills + "]";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getEarliestDeparture() {
|
||||
return earliestDeparture;
|
||||
|
|
@ -437,7 +400,5 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue