cleanup routing API and examples on transits
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
import com.google.ortools.constraintsolver.Assignment;
|
||||
import com.google.ortools.constraintsolver.FirstSolutionStrategy;
|
||||
import com.google.ortools.constraintsolver.IntIntToLong;
|
||||
import com.google.ortools.constraintsolver.IntToLong;
|
||||
import com.google.ortools.constraintsolver.LongLongToLong;
|
||||
import com.google.ortools.constraintsolver.LongToLong;
|
||||
import com.google.ortools.constraintsolver.IntVar;
|
||||
import com.google.ortools.constraintsolver.RoutingDimension;
|
||||
import com.google.ortools.constraintsolver.RoutingIndexManager;
|
||||
@@ -87,10 +87,10 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows {
|
||||
* @param manager Node Index Manager.
|
||||
* @param costCoefficient The coefficient to apply to the evaluator.
|
||||
*/
|
||||
private IntIntToLong buildManhattanCallback(RoutingIndexManager manager, int costCoefficient) {
|
||||
return new IntIntToLong() {
|
||||
private LongLongToLong buildManhattanCallback(RoutingIndexManager manager, int costCoefficient) {
|
||||
return new LongLongToLong() {
|
||||
@Override
|
||||
public long run(int firstIndex, int secondIndex) {
|
||||
public long run(long firstIndex, long secondIndex) {
|
||||
try {
|
||||
int firstNode = manager.indexToNode(firstIndex);
|
||||
int secondNode = manager.indexToNode(secondIndex);
|
||||
@@ -179,16 +179,16 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows {
|
||||
|
||||
// Setting up dimensions
|
||||
final int bigNumber = 100000;
|
||||
final IntIntToLong callback = buildManhattanCallback(manager, 1);
|
||||
final LongLongToLong callback = buildManhattanCallback(manager, 1);
|
||||
final String timeStr = "time";
|
||||
model.addDimension(
|
||||
model.registerTransitCallback(callback), bigNumber, bigNumber, false, timeStr);
|
||||
RoutingDimension timeDimension = model.getMutableDimension(timeStr);
|
||||
|
||||
IntToLong demandCallback =
|
||||
new IntToLong() {
|
||||
LongToLong demandCallback =
|
||||
new LongToLong() {
|
||||
@Override
|
||||
public long run(int index) {
|
||||
public long run(long index) {
|
||||
try {
|
||||
int node = manager.indexToNode(index);
|
||||
if (node < numberOfOrders) {
|
||||
@@ -207,7 +207,7 @@ public class CapacitatedVehicleRoutingProblemWithTimeWindows {
|
||||
RoutingDimension capacityDimension = model.getMutableDimension(capacityStr);
|
||||
|
||||
// Setting up vehicles
|
||||
IntIntToLong[] callbacks = new IntIntToLong[numberOfVehicles];
|
||||
LongLongToLong[] callbacks = new LongLongToLong[numberOfVehicles];
|
||||
for (int vehicle = 0; vehicle < numberOfVehicles; ++vehicle) {
|
||||
final int costCoefficient = vehicleCostCoefficients.get(vehicle);
|
||||
callbacks[vehicle] = buildManhattanCallback(manager, costCoefficient);
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
import com.google.ortools.constraintsolver.Assignment;
|
||||
import com.google.ortools.constraintsolver.FirstSolutionStrategy;
|
||||
import com.google.ortools.constraintsolver.IntIntToLong;
|
||||
import com.google.ortools.constraintsolver.IntToLong;
|
||||
import com.google.ortools.constraintsolver.LongLongToLong;
|
||||
import com.google.ortools.constraintsolver.LongToLong;
|
||||
import com.google.ortools.constraintsolver.RoutingIndexManager;
|
||||
import com.google.ortools.constraintsolver.RoutingModel;
|
||||
import com.google.ortools.constraintsolver.RoutingSearchParameters;
|
||||
@@ -29,7 +29,7 @@ class Tsp {
|
||||
System.loadLibrary("jniortools");
|
||||
}
|
||||
|
||||
static class RandomManhattan extends IntIntToLong {
|
||||
static class RandomManhattan extends LongLongToLong {
|
||||
public RandomManhattan(RoutingIndexManager manager, int size, int seed) {
|
||||
this.xs = new int[size];
|
||||
this.ys = new int[size];
|
||||
@@ -42,7 +42,7 @@ class Tsp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long run(int firstIndex, int secondIndex) {
|
||||
public long run(long firstIndex, long secondIndex) {
|
||||
int firstNode = indexManager.indexToNode(firstIndex);
|
||||
int secondNode = indexManager.indexToNode(secondIndex);
|
||||
return Math.abs(xs[firstNode] - xs[secondNode]) + Math.abs(ys[firstNode] - ys[secondNode]);
|
||||
@@ -53,9 +53,9 @@ class Tsp {
|
||||
private RoutingIndexManager indexManager;
|
||||
}
|
||||
|
||||
static class ConstantCallback extends IntToLong {
|
||||
static class ConstantCallback extends LongToLong {
|
||||
@Override
|
||||
public long run(int index) {
|
||||
public long run(long index) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ class Tsp {
|
||||
// Put a permanent callback to the distance accessor here. The callback
|
||||
// has the following signature: ResultCallback2<int64, int64, int64>.
|
||||
// The two arguments are the from and to node inidices.
|
||||
IntIntToLong distances = new RandomManhattan(manager, size, seed);
|
||||
LongLongToLong distances = new RandomManhattan(manager, size, seed);
|
||||
routing.setArcCostEvaluatorOfAllVehicles(routing.registerTransitCallback(distances));
|
||||
|
||||
// Forbid node connections (randomly).
|
||||
|
||||
@@ -14,7 +14,7 @@ import static java.lang.Math.abs;
|
||||
|
||||
import com.google.ortools.constraintsolver.Assignment;
|
||||
import com.google.ortools.constraintsolver.FirstSolutionStrategy;
|
||||
import com.google.ortools.constraintsolver.IntIntToLong;
|
||||
import com.google.ortools.constraintsolver.LongLongToLong;
|
||||
import com.google.ortools.constraintsolver.RoutingDimension;
|
||||
import com.google.ortools.constraintsolver.RoutingIndexManager;
|
||||
import com.google.ortools.constraintsolver.RoutingModel;
|
||||
@@ -66,7 +66,7 @@ class DataProblem {
|
||||
/// @details It uses an array of positions and computes
|
||||
/// the Manhattan distance between the two positions of
|
||||
/// two different indices.
|
||||
class ManhattanDistance extends IntIntToLong {
|
||||
class ManhattanDistance extends LongLongToLong {
|
||||
private int[][] distances;
|
||||
private RoutingIndexManager indexManager;
|
||||
|
||||
@@ -87,7 +87,7 @@ class ManhattanDistance extends IntIntToLong {
|
||||
|
||||
@Override
|
||||
/// @brief Returns the manhattan distance between the two nodes.
|
||||
public long run(int fromIndex, int toIndex) {
|
||||
public long run(long fromIndex, long toIndex) {
|
||||
int fromNode = indexManager.indexToNode(fromIndex);
|
||||
int toNode = indexManager.indexToNode(toIndex);
|
||||
return distances[fromNode][toNode];
|
||||
@@ -147,7 +147,7 @@ class Vrp {
|
||||
|
||||
// Setting the cost function.
|
||||
// [todo]: protect callback from the GC
|
||||
IntIntToLong distanceEvaluator = new ManhattanDistance(data, manager);
|
||||
LongLongToLong distanceEvaluator = new ManhattanDistance(data, manager);
|
||||
int distanceIndex = routing.registerTransitCallback(distanceEvaluator);
|
||||
routing.setArcCostEvaluatorOfAllVehicles(distanceIndex);
|
||||
addDistanceDimension(routing, data, distanceIndex);
|
||||
|
||||
Reference in New Issue
Block a user