constraint_solver: export from google3
This commit is contained in:
@@ -21,6 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.ortools.Loader;
|
||||
import com.google.ortools.constraintsolver.RoutingModelParameters;
|
||||
import com.google.ortools.constraintsolver.RoutingSearchParameters;
|
||||
import com.google.protobuf.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.LongBinaryOperator;
|
||||
@@ -692,21 +694,21 @@ public final class RoutingSolverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundCost_Ctor() {
|
||||
public void testBoundCost_ctor() {
|
||||
// Create Routing Index Manager
|
||||
BoundCost boundCost = new BoundCost();
|
||||
assertNotNull(boundCost);
|
||||
assertEquals(0, boundCost.getBound());
|
||||
assertEquals(0, boundCost.getCost());
|
||||
|
||||
boundCost = new BoundCost(97 /*bound*/, 101 /*cost*/);
|
||||
boundCost = new BoundCost(/*bound=*/97, /*cost=*/101);
|
||||
assertNotNull(boundCost);
|
||||
assertEquals(97, boundCost.getBound());
|
||||
assertEquals(101, boundCost.getCost());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoutingDimension_Ctor() {
|
||||
public void testRoutingDimension_ctor() {
|
||||
final RoutingIndexManager manager = new RoutingIndexManager(31, 7, 3);
|
||||
assertNotNull(manager);
|
||||
final RoutingModel model = new RoutingModel(manager);
|
||||
@@ -718,10 +720,11 @@ public final class RoutingSolverTest {
|
||||
});
|
||||
assertTrue(model.addDimension(transitIndex, 100, 100, true, "Dimension"));
|
||||
final RoutingDimension dimension = model.getMutableDimension("Dimension");
|
||||
assertNotNull(dimension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoutingDimension_SoftSpanUpperBound() {
|
||||
public void testRoutingDimension_softSpanUpperBound() {
|
||||
final RoutingIndexManager manager = new RoutingIndexManager(31, 7, 3);
|
||||
assertNotNull(manager);
|
||||
final RoutingModel model = new RoutingModel(manager);
|
||||
@@ -734,7 +737,7 @@ public final class RoutingSolverTest {
|
||||
assertTrue(model.addDimension(transitIndex, 100, 100, true, "Dimension"));
|
||||
final RoutingDimension dimension = model.getMutableDimension("Dimension");
|
||||
|
||||
final BoundCost boundCost = new BoundCost(97 /*bound*/, 101 /*cost*/);
|
||||
final BoundCost boundCost = new BoundCost(/*bound=*/97, /*cost=*/101);
|
||||
assertNotNull(boundCost);
|
||||
assertFalse(dimension.hasSoftSpanUpperBounds());
|
||||
for (int v : IntStream.range(0, manager.getNumberOfVehicles()).toArray()) {
|
||||
@@ -748,7 +751,7 @@ public final class RoutingSolverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoutingDimension_QuadraticCostSoftSpanUpperBound() {
|
||||
public void testRoutingDimension_quadraticCostSoftSpanUpperBound() {
|
||||
final RoutingIndexManager manager = new RoutingIndexManager(31, 7, 3);
|
||||
assertNotNull(manager);
|
||||
final RoutingModel model = new RoutingModel(manager);
|
||||
@@ -761,7 +764,7 @@ public final class RoutingSolverTest {
|
||||
assertTrue(model.addDimension(transitIndex, 100, 100, true, "Dimension"));
|
||||
final RoutingDimension dimension = model.getMutableDimension("Dimension");
|
||||
|
||||
final BoundCost boundCost = new BoundCost(97 /*bound*/, 101 /*cost*/);
|
||||
final BoundCost boundCost = new BoundCost(/*bound=*/97, /*cost=*/101);
|
||||
assertNotNull(boundCost);
|
||||
assertFalse(dimension.hasQuadraticCostSoftSpanUpperBounds());
|
||||
for (int v : IntStream.range(0, manager.getNumberOfVehicles()).toArray()) {
|
||||
|
||||
@@ -252,15 +252,12 @@ import java.util.function.LongBinaryOperator;
|
||||
%rename (getCumulVarSoftUpperBoundCoefficient) RoutingDimension::GetCumulVarSoftUpperBoundCoefficient;
|
||||
%rename (getGlobalSpanCostCoefficient) RoutingDimension::global_span_cost_coefficient;
|
||||
%rename (getLocalOptimizerOffsetForVehicle) RoutingDimension::GetLocalOptimizerOffsetForVehicle;
|
||||
|
||||
%rename (setSoftSpanUpperBoundForVehicle) RoutingDimension::SetSoftSpanUpperBoundForVehicle;
|
||||
%rename (hasSoftSpanUpperBounds) RoutingDimension::HasSoftSpanUpperBounds;
|
||||
%rename (getSoftSpanUpperBoundForVehicle) RoutingDimension::GetSoftSpanUpperBoundForVehicle;
|
||||
|
||||
%rename (setQuadraticCostSoftSpanUpperBoundForVehicle) RoutingDimension::SetQuadraticCostSoftSpanUpperBoundForVehicle;
|
||||
%rename (hasQuadraticCostSoftSpanUpperBounds) RoutingDimension::HasQuadraticCostSoftSpanUpperBounds;
|
||||
%rename (getQuadraticCostSoftSpanUpperBoundForVehicle) RoutingDimension::GetQuadraticCostSoftSpanUpperBoundForVehicle;
|
||||
|
||||
%rename (getGroupDelay) RoutingDimension::GetGroupDelay;
|
||||
%rename (getNodeVisitTransitsOfVehicle) RoutingDimension::GetNodeVisitTransitsOfVehicle;
|
||||
%rename (getSpanCostCoefficientForVehicle) RoutingDimension::GetSpanCostCoefficientForVehicle;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from ortools.constraint_solver import pywrapcp
|
||||
|
||||
|
||||
|
||||
@@ -88,8 +88,7 @@ class TestRoutingIndexManager(unittest.TestCase):
|
||||
for i in range(manager.GetNumberOfVehicles()):
|
||||
self.assertEqual(i + 1,
|
||||
manager.IndexToNode(manager.GetStartIndex(i)))
|
||||
self.assertEqual(i + 4,
|
||||
manager.IndexToNode(manager.GetEndIndex(i)))
|
||||
self.assertEqual(i + 4, manager.IndexToNode(manager.GetEndIndex(i)))
|
||||
|
||||
|
||||
class TestRoutingModel(unittest.TestCase):
|
||||
@@ -403,8 +402,7 @@ class TestRoutingModel(unittest.TestCase):
|
||||
partial(TransitDistance, manager))
|
||||
model.SetArcCostEvaluatorOfAllVehicles(transit_idx)
|
||||
# Add constant dimension
|
||||
constant_id, success = model.AddConstantDimension(
|
||||
1, 100, True, 'count')
|
||||
constant_id, success = model.AddConstantDimension(1, 100, True, 'count')
|
||||
self.assertTrue(success)
|
||||
self.assertEqual(transit_idx + 1, constant_id)
|
||||
count_dimension = model.GetDimensionOrDie('count')
|
||||
@@ -492,8 +490,7 @@ class TestRoutingModel(unittest.TestCase):
|
||||
index = model.Start(0)
|
||||
cumul = 0
|
||||
while not model.IsEnd(index):
|
||||
self.assertEqual(cumul,
|
||||
assignment.Value(dimension.CumulVar(index)))
|
||||
self.assertEqual(cumul, assignment.Value(dimension.CumulVar(index)))
|
||||
prev_index = index
|
||||
index = assignment.Value(model.NextVar(index))
|
||||
cumul += matrix[manager.IndexToNode(prev_index)][
|
||||
|
||||
@@ -2673,8 +2673,10 @@ class TypeRegulationsConstraint : public Constraint {
|
||||
struct BoundCost {
|
||||
int64_t bound;
|
||||
int64_t cost;
|
||||
BoundCost(int64_t bound = 0, int64_t cost = 0): bound(bound), cost(cost) {}
|
||||
BoundCost(): bound(0), cost(0) {}
|
||||
BoundCost(int64_t bound, int64_t cost): bound(bound), cost(cost) {}
|
||||
};
|
||||
|
||||
class SimpleBoundCosts {
|
||||
public:
|
||||
SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
|
||||
|
||||
@@ -1846,7 +1846,7 @@ bool DimensionCumulOptimizerCore::SetRouteCumulConstraints(
|
||||
}
|
||||
// Add soft span cost.
|
||||
if (optimize_costs && dimension_->HasSoftSpanUpperBounds()) {
|
||||
BoundCost bound_cost =
|
||||
const BoundCost bound_cost =
|
||||
dimension_->GetSoftSpanUpperBoundForVehicle(vehicle);
|
||||
if (bound_cost.bound < std::numeric_limits<int64_t>::max() &&
|
||||
bound_cost.cost > 0) {
|
||||
|
||||
Reference in New Issue
Block a user