Skip to content

Commit b9a5027

Browse files
feat: added the route modifiers (googleapis#11804)
- [ ] Regenerate this pull request now. Users can now set optional conditions when calculating vehicle routes. PiperOrigin-RevId: 572934958 Source-Link: googleapis/googleapis@d1ed9b8 Source-Link: https://github.com/googleapis/googleapis-gen/commit/797754860db7e2fea109f855062523e063e57603 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLW9wdGltaXphdGlvbi8uT3dsQm90LnlhbWwiLCJoIjoiNzk3NzU0ODYwZGI3ZTJmZWExMDlmODU1MDYyNTIzZTA2M2U1NzYwMyJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2f5b709 commit b9a5027

13 files changed

Lines changed: 626 additions & 28 deletions

packages/google-cloud-optimization/CONTRIBUTING.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ Running System Tests
143143
$ nox -s system
144144

145145
# Run a single system test
146-
$ nox -s system- -- -k <name of test>
146+
$ nox -s system-3.11 -- -k <name of test>
147147

148148

149149
.. note::
150150

151-
System tests are only configured to run under Python.
151+
System tests are only configured to run under Python 3.8, 3.9, 3.10 and 3.11.
152152
For expediency, we do not run them in older versions of Python 3.
153153

154154
This alone will not run the tests. You'll need to change some local

packages/google-cloud-optimization/google/cloud/optimization/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
OptimizeToursRequest,
4646
OptimizeToursResponse,
4747
OptimizeToursValidationError,
48+
RouteModifiers,
4849
Shipment,
4950
ShipmentModel,
5051
ShipmentRoute,
@@ -78,6 +79,7 @@
7879
"OptimizeToursRequest",
7980
"OptimizeToursResponse",
8081
"OptimizeToursValidationError",
82+
"RouteModifiers",
8183
"Shipment",
8284
"ShipmentModel",
8385
"ShipmentRoute",

packages/google-cloud-optimization/google/cloud/optimization/gapic_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright 2022 Google LLC
2+
# Copyright 2023 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.5.0" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-optimization/google/cloud/optimization_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
OptimizeToursRequest,
4141
OptimizeToursResponse,
4242
OptimizeToursValidationError,
43+
RouteModifiers,
4344
Shipment,
4445
ShipmentModel,
4546
ShipmentRoute,
@@ -73,6 +74,7 @@
7374
"OptimizeToursResponse",
7475
"OptimizeToursValidationError",
7576
"OutputConfig",
77+
"RouteModifiers",
7678
"Shipment",
7779
"ShipmentModel",
7880
"ShipmentRoute",

packages/google-cloud-optimization/google/cloud/optimization_v1/gapic_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright 2022 Google LLC
2+
# Copyright 2023 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.5.0" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-optimization/google/cloud/optimization_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
OptimizeToursRequest,
3535
OptimizeToursResponse,
3636
OptimizeToursValidationError,
37+
RouteModifiers,
3738
Shipment,
3839
ShipmentModel,
3940
ShipmentRoute,
@@ -65,6 +66,7 @@
6566
"OptimizeToursRequest",
6667
"OptimizeToursResponse",
6768
"OptimizeToursValidationError",
69+
"RouteModifiers",
6870
"Shipment",
6971
"ShipmentModel",
7072
"ShipmentRoute",

packages/google-cloud-optimization/google/cloud/optimization_v1/types/fleet_routing.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"Shipment",
3636
"ShipmentTypeIncompatibility",
3737
"ShipmentTypeRequirement",
38+
"RouteModifiers",
3839
"Vehicle",
3940
"TimeWindow",
4041
"CapacityQuantity",
@@ -1689,6 +1690,53 @@ class RequirementMode(proto.Enum):
16891690
)
16901691

16911692

1693+
class RouteModifiers(proto.Message):
1694+
r"""Encapsulates a set of optional conditions to satisfy when
1695+
calculating vehicle routes. This is similar to ``RouteModifiers`` in
1696+
the Google Maps Platform API; see:
1697+
https://developers.google.com/maps/documentation/routes/reference/rest/v2/RouteModifiers.
1698+
1699+
Attributes:
1700+
avoid_tolls (bool):
1701+
Specifies whether to avoid toll roads where
1702+
reasonable. Preference will be given to routes
1703+
not containing toll roads. Applies only to
1704+
motorized travel modes.
1705+
avoid_highways (bool):
1706+
Specifies whether to avoid highways where
1707+
reasonable. Preference will be given to routes
1708+
not containing highways. Applies only to
1709+
motorized travel modes.
1710+
avoid_ferries (bool):
1711+
Specifies whether to avoid ferries where
1712+
reasonable. Preference will be given to routes
1713+
not containing travel by ferries. Applies only
1714+
to motorized travel modes.
1715+
avoid_indoor (bool):
1716+
Optional. Specifies whether to avoid navigating indoors
1717+
where reasonable. Preference will be given to routes not
1718+
containing indoor navigation. Applies only to the
1719+
``WALKING`` travel mode.
1720+
"""
1721+
1722+
avoid_tolls: bool = proto.Field(
1723+
proto.BOOL,
1724+
number=2,
1725+
)
1726+
avoid_highways: bool = proto.Field(
1727+
proto.BOOL,
1728+
number=3,
1729+
)
1730+
avoid_ferries: bool = proto.Field(
1731+
proto.BOOL,
1732+
number=4,
1733+
)
1734+
avoid_indoor: bool = proto.Field(
1735+
proto.BOOL,
1736+
number=5,
1737+
)
1738+
1739+
16921740
class Vehicle(proto.Message):
16931741
r"""Models a vehicle in a shipment problem. Solving a shipment problem
16941742
will build a route starting from ``start_location`` and ending at
@@ -1703,6 +1751,10 @@ class Vehicle(proto.Message):
17031751
The travel mode which affects the roads usable by the
17041752
vehicle and its speed. See also
17051753
``travel_duration_multiple``.
1754+
route_modifiers (google.cloud.optimization_v1.types.RouteModifiers):
1755+
Optional. A set of conditions to satisfy that
1756+
affect the way routes are calculated for the
1757+
given vehicle.
17061758
start_location (google.type.latlng_pb2.LatLng):
17071759
Geographic location where the vehicle starts before picking
17081760
up any shipments. If not specified, the vehicle starts at
@@ -2141,6 +2193,11 @@ class DurationLimit(proto.Message):
21412193
number=1,
21422194
enum=TravelMode,
21432195
)
2196+
route_modifiers: "RouteModifiers" = proto.Field(
2197+
proto.MESSAGE,
2198+
number=2,
2199+
message="RouteModifiers",
2200+
)
21442201
start_location: latlng_pb2.LatLng = proto.Field(
21452202
proto.MESSAGE,
21462203
number=3,
@@ -4219,6 +4276,15 @@ class OptimizeToursValidationError(proto.Message):
42194276
42204277
- PRECEDENCE_ERROR = 46;
42214278
4279+
- PRECEDENCE_RULE_MISSING_FIRST_INDEX = 4600;
4280+
- PRECEDENCE_RULE_MISSING_SECOND_INDEX = 4601;
4281+
- PRECEDENCE_RULE_FIRST_INDEX_OUT_OF_BOUNDS = 4602;
4282+
- PRECEDENCE_RULE_SECOND_INDEX_OUT_OF_BOUNDS = 4603;
4283+
- PRECEDENCE_RULE_DUPLICATE_INDEX = 4604;
4284+
- PRECEDENCE_RULE_INEXISTENT_FIRST_VISIT_REQUEST = 4605;
4285+
- PRECEDENCE_RULE_INEXISTENT_SECOND_VISIT_REQUEST =
4286+
4606;
4287+
42224288
- BREAK_ERROR = 48;
42234289
42244290
- BREAK_RULE_EMPTY = 4800;

packages/google-cloud-optimization/noxfile.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
UNIT_TEST_EXTRAS = []
4747
UNIT_TEST_EXTRAS_BY_PYTHON = {}
4848

49-
SYSTEM_TEST_PYTHON_VERSIONS = []
49+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
5050
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
5151
"mock",
5252
"pytest",
@@ -405,24 +405,3 @@ def prerelease_deps(session):
405405
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
406406

407407
session.run("py.test", "tests/unit")
408-
409-
system_test_path = os.path.join("tests", "system.py")
410-
system_test_folder_path = os.path.join("tests", "system")
411-
412-
# Only run system tests if found.
413-
if os.path.exists(system_test_path):
414-
session.run(
415-
"py.test",
416-
"--verbose",
417-
f"--junitxml=system_{session.python}_sponge_log.xml",
418-
system_test_path,
419-
*session.posargs,
420-
)
421-
if os.path.exists(system_test_folder_path):
422-
session.run(
423-
"py.test",
424-
"--verbose",
425-
f"--junitxml=system_{session.python}_sponge_log.xml",
426-
system_test_folder_path,
427-
*session.posargs,
428-
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2023 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for BatchOptimizeTours
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-optimization
24+
25+
26+
# [START cloudoptimization_v1_generated_FleetRouting_BatchOptimizeTours_async]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import optimization_v1
35+
36+
37+
async def sample_batch_optimize_tours():
38+
# Create a client
39+
client = optimization_v1.FleetRoutingAsyncClient()
40+
41+
# Initialize request argument(s)
42+
model_configs = optimization_v1.AsyncModelConfig()
43+
model_configs.input_config.gcs_source.uri = "uri_value"
44+
model_configs.output_config.gcs_destination.uri = "uri_value"
45+
46+
request = optimization_v1.BatchOptimizeToursRequest(
47+
parent="parent_value",
48+
model_configs=model_configs,
49+
)
50+
51+
# Make the request
52+
operation = client.batch_optimize_tours(request=request)
53+
54+
print("Waiting for operation to complete...")
55+
56+
response = (await operation).result()
57+
58+
# Handle the response
59+
print(response)
60+
61+
# [END cloudoptimization_v1_generated_FleetRouting_BatchOptimizeTours_async]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2023 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for BatchOptimizeTours
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-optimization
24+
25+
26+
# [START cloudoptimization_v1_generated_FleetRouting_BatchOptimizeTours_sync]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import optimization_v1
35+
36+
37+
def sample_batch_optimize_tours():
38+
# Create a client
39+
client = optimization_v1.FleetRoutingClient()
40+
41+
# Initialize request argument(s)
42+
model_configs = optimization_v1.AsyncModelConfig()
43+
model_configs.input_config.gcs_source.uri = "uri_value"
44+
model_configs.output_config.gcs_destination.uri = "uri_value"
45+
46+
request = optimization_v1.BatchOptimizeToursRequest(
47+
parent="parent_value",
48+
model_configs=model_configs,
49+
)
50+
51+
# Make the request
52+
operation = client.batch_optimize_tours(request=request)
53+
54+
print("Waiting for operation to complete...")
55+
56+
response = operation.result()
57+
58+
# Handle the response
59+
print(response)
60+
61+
# [END cloudoptimization_v1_generated_FleetRouting_BatchOptimizeTours_sync]

0 commit comments

Comments
 (0)