mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge pull request #265 from braktar/cluster
Add clusterRuin to xml algorithm config
This commit is contained in:
commit
ec298f9504
3 changed files with 56 additions and 6 deletions
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.graphhopper.jsprit.core.algorithm.ruin;
|
||||||
|
|
||||||
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
|
||||||
|
public class ClusterRuinStrategyFactory implements RuinStrategyFactory {
|
||||||
|
|
||||||
|
private int initialNumberJobsToRemove;
|
||||||
|
private JobNeighborhoods jobNeighborhoods;
|
||||||
|
|
||||||
|
public ClusterRuinStrategyFactory(int initialNumberJobsToRemove, JobNeighborhoods jobNeighborhoods) {
|
||||||
|
super();
|
||||||
|
this.initialNumberJobsToRemove = initialNumberJobsToRemove;
|
||||||
|
this.jobNeighborhoods = jobNeighborhoods;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuinStrategy createStrategy(VehicleRoutingProblem vrp) {
|
||||||
|
return new RuinClusters(vrp, initialNumberJobsToRemove, jobNeighborhoods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -26,6 +26,9 @@ import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmLis
|
||||||
import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule;
|
import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule;
|
||||||
import com.graphhopper.jsprit.core.algorithm.recreate.InsertionStrategy;
|
import com.graphhopper.jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||||
import com.graphhopper.jsprit.core.algorithm.recreate.listener.InsertionListener;
|
import com.graphhopper.jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||||
|
import com.graphhopper.jsprit.core.algorithm.ruin.ClusterRuinStrategyFactory;
|
||||||
|
import com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoods;
|
||||||
|
import com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsFactory;
|
||||||
import com.graphhopper.jsprit.core.algorithm.ruin.RadialRuinStrategyFactory;
|
import com.graphhopper.jsprit.core.algorithm.ruin.RadialRuinStrategyFactory;
|
||||||
import com.graphhopper.jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
import com.graphhopper.jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
||||||
import com.graphhopper.jsprit.core.algorithm.ruin.RuinStrategy;
|
import com.graphhopper.jsprit.core.algorithm.ruin.RuinStrategy;
|
||||||
|
|
@ -839,18 +842,25 @@ public class VehicleRoutingAlgorithms {
|
||||||
if (ruin_name == null) throw new IllegalStateException("module.ruin[@name] is missing.");
|
if (ruin_name == null) throw new IllegalStateException("module.ruin[@name] is missing.");
|
||||||
String ruin_id = moduleConfig.getString("ruin[@id]");
|
String ruin_id = moduleConfig.getString("ruin[@id]");
|
||||||
if (ruin_id == null) ruin_id = "noId";
|
if (ruin_id == null) ruin_id = "noId";
|
||||||
String shareToRuinString = moduleConfig.getString("ruin.share");
|
|
||||||
if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing.");
|
|
||||||
double shareToRuin = Double.valueOf(shareToRuinString);
|
|
||||||
final RuinStrategy ruin;
|
final RuinStrategy ruin;
|
||||||
ModKey ruinKey = makeKey(ruin_name, ruin_id);
|
ModKey ruinKey = makeKey(ruin_name, ruin_id);
|
||||||
if (ruin_name.equals("randomRuin")) {
|
if (ruin_name.equals("randomRuin")) {
|
||||||
|
String shareToRuinString = moduleConfig.getString("ruin.share");
|
||||||
|
if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing.");
|
||||||
|
double shareToRuin = Double.valueOf(shareToRuinString);
|
||||||
ruin = getRandomRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin);
|
ruin = getRandomRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin);
|
||||||
} else if (ruin_name.equals("radialRuin")) {
|
} else if (ruin_name.equals("radialRuin")) {
|
||||||
|
String shareToRuinString = moduleConfig.getString("ruin.share");
|
||||||
|
if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing.");
|
||||||
|
double shareToRuin = Double.valueOf(shareToRuinString);
|
||||||
JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts());
|
JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts());
|
||||||
ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance);
|
ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance);
|
||||||
} else
|
} else if (ruin_name.equals("clusterRuin")) {
|
||||||
throw new IllegalStateException("ruin[@name] " + ruin_name + " is not known. Use either randomRuin or radialRuin.");
|
String initialNumberJobsToRemoveString = moduleConfig.getString("ruin.initRemoveJobs");
|
||||||
|
if (initialNumberJobsToRemoveString == null) throw new IllegalStateException("module.ruin.initRemoveJobs is missing.");
|
||||||
|
int initialNumberJobsToRemove = Integer.valueOf(initialNumberJobsToRemoveString);
|
||||||
|
ruin = getClusterRuin(vrp, routeStates, definedClasses, ruinKey, initialNumberJobsToRemove);
|
||||||
|
} else throw new IllegalStateException("ruin[@name] " + ruin_name + " is not known. Use either randomRuin or radialRuin.");
|
||||||
|
|
||||||
String insertionName = moduleConfig.getString("insertion[@name]");
|
String insertionName = moduleConfig.getString("insertion[@name]");
|
||||||
if (insertionName == null)
|
if (insertionName == null)
|
||||||
|
|
@ -877,7 +887,8 @@ public class VehicleRoutingAlgorithms {
|
||||||
"\n\tcurrently there are following modules available: " +
|
"\n\tcurrently there are following modules available: " +
|
||||||
"\n\tbestInsertion" +
|
"\n\tbestInsertion" +
|
||||||
"\n\trandomRuin" +
|
"\n\trandomRuin" +
|
||||||
"\n\tradialRuin");
|
"\n\tradialRuin" +
|
||||||
|
"\n\tclusterRuin");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RuinStrategy getRadialRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) {
|
private static RuinStrategy getRadialRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) {
|
||||||
|
|
@ -890,6 +901,17 @@ public class VehicleRoutingAlgorithms {
|
||||||
return ruin;
|
return ruin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static RuinStrategy getClusterRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, int initialNumberJobsToRemove) {
|
||||||
|
JobNeighborhoods jobNeighborhoods = new JobNeighborhoodsFactory().createNeighborhoods(vrp, new AvgServiceAndShipmentDistance(vrp.getTransportCosts()));
|
||||||
|
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
|
||||||
|
RuinStrategy ruin = definedClasses.get(stratKey);
|
||||||
|
if (ruin == null) {
|
||||||
|
ruin = new ClusterRuinStrategyFactory(initialNumberJobsToRemove, jobNeighborhoods).createStrategy(vrp);
|
||||||
|
definedClasses.put(stratKey, ruin);
|
||||||
|
}
|
||||||
|
return ruin;
|
||||||
|
}
|
||||||
|
|
||||||
private static RuinStrategy getRandomRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) {
|
private static RuinStrategy getRandomRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) {
|
||||||
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
|
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
|
||||||
RuinStrategy ruin = definedClasses.get(stratKey);
|
RuinStrategy ruin = definedClasses.get(stratKey);
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,13 @@
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
<xs:element name="initRemoveJobs" minOccurs="0" maxOccurs="1">
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:integer">
|
||||||
|
<xs:minInclusive value="1"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:element>
|
||||||
<xs:element name="distance" minOccurs="0" maxOccurs="1">
|
<xs:element name="distance" minOccurs="0" maxOccurs="1">
|
||||||
<xs:simpleType>
|
<xs:simpleType>
|
||||||
<xs:restriction base="xs:string">
|
<xs:restriction base="xs:string">
|
||||||
|
|
@ -218,6 +225,7 @@
|
||||||
<xs:restriction base="xs:string">
|
<xs:restriction base="xs:string">
|
||||||
<xs:enumeration value="randomRuin"/>
|
<xs:enumeration value="randomRuin"/>
|
||||||
<xs:enumeration value="radialRuin"/>
|
<xs:enumeration value="radialRuin"/>
|
||||||
|
<xs:enumeration value="clusterRuin"/>
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue