google-maps-routeoptimization 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/maps/routeoptimization/__init__.py +85 -0
- google/maps/routeoptimization/gapic_version.py +16 -0
- google/maps/routeoptimization/py.typed +2 -0
- google/maps/routeoptimization_v1/__init__.py +83 -0
- google/maps/routeoptimization_v1/gapic_metadata.json +58 -0
- google/maps/routeoptimization_v1/gapic_version.py +16 -0
- google/maps/routeoptimization_v1/py.typed +2 -0
- google/maps/routeoptimization_v1/services/__init__.py +15 -0
- google/maps/routeoptimization_v1/services/route_optimization/__init__.py +22 -0
- google/maps/routeoptimization_v1/services/route_optimization/async_client.py +588 -0
- google/maps/routeoptimization_v1/services/route_optimization/client.py +992 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/__init__.py +36 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/base.py +200 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc.py +381 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc_asyncio.py +408 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/rest.py +631 -0
- google/maps/routeoptimization_v1/types/__init__.py +72 -0
- google/maps/routeoptimization_v1/types/route_optimization_service.py +4029 -0
- google_maps_routeoptimization-0.1.0.dist-info/LICENSE +202 -0
- google_maps_routeoptimization-0.1.0.dist-info/METADATA +137 -0
- google_maps_routeoptimization-0.1.0.dist-info/RECORD +23 -0
- google_maps_routeoptimization-0.1.0.dist-info/WHEEL +5 -0
- google_maps_routeoptimization-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 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
|
+
|
|
17
|
+
import dataclasses
|
|
18
|
+
import json # type: ignore
|
|
19
|
+
import re
|
|
20
|
+
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
|
|
21
|
+
import warnings
|
|
22
|
+
|
|
23
|
+
from google.api_core import (
|
|
24
|
+
gapic_v1,
|
|
25
|
+
operations_v1,
|
|
26
|
+
path_template,
|
|
27
|
+
rest_helpers,
|
|
28
|
+
rest_streaming,
|
|
29
|
+
)
|
|
30
|
+
from google.api_core import exceptions as core_exceptions
|
|
31
|
+
from google.api_core import retry as retries
|
|
32
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
33
|
+
from google.auth.transport.grpc import SslCredentials # type: ignore
|
|
34
|
+
from google.auth.transport.requests import AuthorizedSession # type: ignore
|
|
35
|
+
from google.protobuf import json_format
|
|
36
|
+
import grpc # type: ignore
|
|
37
|
+
from requests import __version__ as requests_version
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
|
|
41
|
+
except AttributeError: # pragma: NO COVER
|
|
42
|
+
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
from google.longrunning import operations_pb2 # type: ignore
|
|
46
|
+
|
|
47
|
+
from google.maps.routeoptimization_v1.types import route_optimization_service
|
|
48
|
+
|
|
49
|
+
from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
|
|
50
|
+
from .base import RouteOptimizationTransport
|
|
51
|
+
|
|
52
|
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
|
53
|
+
gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
|
|
54
|
+
grpc_version=None,
|
|
55
|
+
rest_version=requests_version,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class RouteOptimizationRestInterceptor:
|
|
60
|
+
"""Interceptor for RouteOptimization.
|
|
61
|
+
|
|
62
|
+
Interceptors are used to manipulate requests, request metadata, and responses
|
|
63
|
+
in arbitrary ways.
|
|
64
|
+
Example use cases include:
|
|
65
|
+
* Logging
|
|
66
|
+
* Verifying requests according to service or custom semantics
|
|
67
|
+
* Stripping extraneous information from responses
|
|
68
|
+
|
|
69
|
+
These use cases and more can be enabled by injecting an
|
|
70
|
+
instance of a custom subclass when constructing the RouteOptimizationRestTransport.
|
|
71
|
+
|
|
72
|
+
.. code-block:: python
|
|
73
|
+
class MyCustomRouteOptimizationInterceptor(RouteOptimizationRestInterceptor):
|
|
74
|
+
def pre_batch_optimize_tours(self, request, metadata):
|
|
75
|
+
logging.log(f"Received request: {request}")
|
|
76
|
+
return request, metadata
|
|
77
|
+
|
|
78
|
+
def post_batch_optimize_tours(self, response):
|
|
79
|
+
logging.log(f"Received response: {response}")
|
|
80
|
+
return response
|
|
81
|
+
|
|
82
|
+
def pre_optimize_tours(self, request, metadata):
|
|
83
|
+
logging.log(f"Received request: {request}")
|
|
84
|
+
return request, metadata
|
|
85
|
+
|
|
86
|
+
def post_optimize_tours(self, response):
|
|
87
|
+
logging.log(f"Received response: {response}")
|
|
88
|
+
return response
|
|
89
|
+
|
|
90
|
+
transport = RouteOptimizationRestTransport(interceptor=MyCustomRouteOptimizationInterceptor())
|
|
91
|
+
client = RouteOptimizationClient(transport=transport)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
def pre_batch_optimize_tours(
|
|
97
|
+
self,
|
|
98
|
+
request: route_optimization_service.BatchOptimizeToursRequest,
|
|
99
|
+
metadata: Sequence[Tuple[str, str]],
|
|
100
|
+
) -> Tuple[
|
|
101
|
+
route_optimization_service.BatchOptimizeToursRequest, Sequence[Tuple[str, str]]
|
|
102
|
+
]:
|
|
103
|
+
"""Pre-rpc interceptor for batch_optimize_tours
|
|
104
|
+
|
|
105
|
+
Override in a subclass to manipulate the request or metadata
|
|
106
|
+
before they are sent to the RouteOptimization server.
|
|
107
|
+
"""
|
|
108
|
+
return request, metadata
|
|
109
|
+
|
|
110
|
+
def post_batch_optimize_tours(
|
|
111
|
+
self, response: operations_pb2.Operation
|
|
112
|
+
) -> operations_pb2.Operation:
|
|
113
|
+
"""Post-rpc interceptor for batch_optimize_tours
|
|
114
|
+
|
|
115
|
+
Override in a subclass to manipulate the response
|
|
116
|
+
after it is returned by the RouteOptimization server but before
|
|
117
|
+
it is returned to user code.
|
|
118
|
+
"""
|
|
119
|
+
return response
|
|
120
|
+
|
|
121
|
+
def pre_optimize_tours(
|
|
122
|
+
self,
|
|
123
|
+
request: route_optimization_service.OptimizeToursRequest,
|
|
124
|
+
metadata: Sequence[Tuple[str, str]],
|
|
125
|
+
) -> Tuple[
|
|
126
|
+
route_optimization_service.OptimizeToursRequest, Sequence[Tuple[str, str]]
|
|
127
|
+
]:
|
|
128
|
+
"""Pre-rpc interceptor for optimize_tours
|
|
129
|
+
|
|
130
|
+
Override in a subclass to manipulate the request or metadata
|
|
131
|
+
before they are sent to the RouteOptimization server.
|
|
132
|
+
"""
|
|
133
|
+
return request, metadata
|
|
134
|
+
|
|
135
|
+
def post_optimize_tours(
|
|
136
|
+
self, response: route_optimization_service.OptimizeToursResponse
|
|
137
|
+
) -> route_optimization_service.OptimizeToursResponse:
|
|
138
|
+
"""Post-rpc interceptor for optimize_tours
|
|
139
|
+
|
|
140
|
+
Override in a subclass to manipulate the response
|
|
141
|
+
after it is returned by the RouteOptimization server but before
|
|
142
|
+
it is returned to user code.
|
|
143
|
+
"""
|
|
144
|
+
return response
|
|
145
|
+
|
|
146
|
+
def pre_get_operation(
|
|
147
|
+
self,
|
|
148
|
+
request: operations_pb2.GetOperationRequest,
|
|
149
|
+
metadata: Sequence[Tuple[str, str]],
|
|
150
|
+
) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]:
|
|
151
|
+
"""Pre-rpc interceptor for get_operation
|
|
152
|
+
|
|
153
|
+
Override in a subclass to manipulate the request or metadata
|
|
154
|
+
before they are sent to the RouteOptimization server.
|
|
155
|
+
"""
|
|
156
|
+
return request, metadata
|
|
157
|
+
|
|
158
|
+
def post_get_operation(
|
|
159
|
+
self, response: operations_pb2.Operation
|
|
160
|
+
) -> operations_pb2.Operation:
|
|
161
|
+
"""Post-rpc interceptor for get_operation
|
|
162
|
+
|
|
163
|
+
Override in a subclass to manipulate the response
|
|
164
|
+
after it is returned by the RouteOptimization server but before
|
|
165
|
+
it is returned to user code.
|
|
166
|
+
"""
|
|
167
|
+
return response
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@dataclasses.dataclass
|
|
171
|
+
class RouteOptimizationRestStub:
|
|
172
|
+
_session: AuthorizedSession
|
|
173
|
+
_host: str
|
|
174
|
+
_interceptor: RouteOptimizationRestInterceptor
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class RouteOptimizationRestTransport(RouteOptimizationTransport):
|
|
178
|
+
"""REST backend transport for RouteOptimization.
|
|
179
|
+
|
|
180
|
+
A service for optimizing vehicle tours.
|
|
181
|
+
|
|
182
|
+
Validity of certain types of fields:
|
|
183
|
+
|
|
184
|
+
- ``google.protobuf.Timestamp``
|
|
185
|
+
|
|
186
|
+
- Times are in Unix time: seconds since
|
|
187
|
+
1970-01-01T00:00:00+00:00.
|
|
188
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
189
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
190
|
+
- nanos must be unset or set to 0.
|
|
191
|
+
|
|
192
|
+
- ``google.protobuf.Duration``
|
|
193
|
+
|
|
194
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
195
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
196
|
+
- nanos must be unset or set to 0.
|
|
197
|
+
|
|
198
|
+
- ``google.type.LatLng``
|
|
199
|
+
|
|
200
|
+
- latitude must be in [-90.0, 90.0].
|
|
201
|
+
- longitude must be in [-180.0, 180.0].
|
|
202
|
+
- at least one of latitude and longitude must be non-zero.
|
|
203
|
+
|
|
204
|
+
This class defines the same methods as the primary client, so the
|
|
205
|
+
primary client can load the underlying transport implementation
|
|
206
|
+
and call it.
|
|
207
|
+
|
|
208
|
+
It sends JSON representations of protocol buffers over HTTP/1.1
|
|
209
|
+
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
def __init__(
|
|
213
|
+
self,
|
|
214
|
+
*,
|
|
215
|
+
host: str = "routeoptimization.googleapis.com",
|
|
216
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
217
|
+
credentials_file: Optional[str] = None,
|
|
218
|
+
scopes: Optional[Sequence[str]] = None,
|
|
219
|
+
client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
|
|
220
|
+
quota_project_id: Optional[str] = None,
|
|
221
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
222
|
+
always_use_jwt_access: Optional[bool] = False,
|
|
223
|
+
url_scheme: str = "https",
|
|
224
|
+
interceptor: Optional[RouteOptimizationRestInterceptor] = None,
|
|
225
|
+
api_audience: Optional[str] = None,
|
|
226
|
+
) -> None:
|
|
227
|
+
"""Instantiate the transport.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
host (Optional[str]):
|
|
231
|
+
The hostname to connect to (default: 'routeoptimization.googleapis.com').
|
|
232
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
233
|
+
authorization credentials to attach to requests. These
|
|
234
|
+
credentials identify the application to the service; if none
|
|
235
|
+
are specified, the client will attempt to ascertain the
|
|
236
|
+
credentials from the environment.
|
|
237
|
+
|
|
238
|
+
credentials_file (Optional[str]): A file with credentials that can
|
|
239
|
+
be loaded with :func:`google.auth.load_credentials_from_file`.
|
|
240
|
+
This argument is ignored if ``channel`` is provided.
|
|
241
|
+
scopes (Optional(Sequence[str])): A list of scopes. This argument is
|
|
242
|
+
ignored if ``channel`` is provided.
|
|
243
|
+
client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
|
|
244
|
+
certificate to configure mutual TLS HTTP channel. It is ignored
|
|
245
|
+
if ``channel`` is provided.
|
|
246
|
+
quota_project_id (Optional[str]): An optional project to use for billing
|
|
247
|
+
and quota.
|
|
248
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
249
|
+
The client info used to send a user-agent string along with
|
|
250
|
+
API requests. If ``None``, then default info will be used.
|
|
251
|
+
Generally, you only need to set this if you are developing
|
|
252
|
+
your own client library.
|
|
253
|
+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
|
|
254
|
+
be used for service account credentials.
|
|
255
|
+
url_scheme: the protocol scheme for the API endpoint. Normally
|
|
256
|
+
"https", but for testing or local servers,
|
|
257
|
+
"http" can be specified.
|
|
258
|
+
"""
|
|
259
|
+
# Run the base constructor
|
|
260
|
+
# TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
|
|
261
|
+
# TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
|
|
262
|
+
# credentials object
|
|
263
|
+
maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host)
|
|
264
|
+
if maybe_url_match is None:
|
|
265
|
+
raise ValueError(
|
|
266
|
+
f"Unexpected hostname structure: {host}"
|
|
267
|
+
) # pragma: NO COVER
|
|
268
|
+
|
|
269
|
+
url_match_items = maybe_url_match.groupdict()
|
|
270
|
+
|
|
271
|
+
host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host
|
|
272
|
+
|
|
273
|
+
super().__init__(
|
|
274
|
+
host=host,
|
|
275
|
+
credentials=credentials,
|
|
276
|
+
client_info=client_info,
|
|
277
|
+
always_use_jwt_access=always_use_jwt_access,
|
|
278
|
+
api_audience=api_audience,
|
|
279
|
+
)
|
|
280
|
+
self._session = AuthorizedSession(
|
|
281
|
+
self._credentials, default_host=self.DEFAULT_HOST
|
|
282
|
+
)
|
|
283
|
+
self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None
|
|
284
|
+
if client_cert_source_for_mtls:
|
|
285
|
+
self._session.configure_mtls_channel(client_cert_source_for_mtls)
|
|
286
|
+
self._interceptor = interceptor or RouteOptimizationRestInterceptor()
|
|
287
|
+
self._prep_wrapped_messages(client_info)
|
|
288
|
+
|
|
289
|
+
@property
|
|
290
|
+
def operations_client(self) -> operations_v1.AbstractOperationsClient:
|
|
291
|
+
"""Create the client designed to process long-running operations.
|
|
292
|
+
|
|
293
|
+
This property caches on the instance; repeated calls return the same
|
|
294
|
+
client.
|
|
295
|
+
"""
|
|
296
|
+
# Only create a new client if we do not already have one.
|
|
297
|
+
if self._operations_client is None:
|
|
298
|
+
http_options: Dict[str, List[Dict[str, str]]] = {
|
|
299
|
+
"google.longrunning.Operations.GetOperation": [
|
|
300
|
+
{
|
|
301
|
+
"method": "get",
|
|
302
|
+
"uri": "/v1/{name=projects/*/locations/*/operations/*}",
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
rest_transport = operations_v1.OperationsRestTransport(
|
|
308
|
+
host=self._host,
|
|
309
|
+
# use the credentials which are saved
|
|
310
|
+
credentials=self._credentials,
|
|
311
|
+
scopes=self._scopes,
|
|
312
|
+
http_options=http_options,
|
|
313
|
+
path_prefix="v1",
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
self._operations_client = operations_v1.AbstractOperationsClient(
|
|
317
|
+
transport=rest_transport
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
# Return the client from cache.
|
|
321
|
+
return self._operations_client
|
|
322
|
+
|
|
323
|
+
class _BatchOptimizeTours(RouteOptimizationRestStub):
|
|
324
|
+
def __hash__(self):
|
|
325
|
+
return hash("BatchOptimizeTours")
|
|
326
|
+
|
|
327
|
+
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
|
|
328
|
+
|
|
329
|
+
@classmethod
|
|
330
|
+
def _get_unset_required_fields(cls, message_dict):
|
|
331
|
+
return {
|
|
332
|
+
k: v
|
|
333
|
+
for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
|
|
334
|
+
if k not in message_dict
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
def __call__(
|
|
338
|
+
self,
|
|
339
|
+
request: route_optimization_service.BatchOptimizeToursRequest,
|
|
340
|
+
*,
|
|
341
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
342
|
+
timeout: Optional[float] = None,
|
|
343
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
344
|
+
) -> operations_pb2.Operation:
|
|
345
|
+
r"""Call the batch optimize tours method over HTTP.
|
|
346
|
+
|
|
347
|
+
Args:
|
|
348
|
+
request (~.route_optimization_service.BatchOptimizeToursRequest):
|
|
349
|
+
The request object. Request to batch optimize tours as an asynchronous
|
|
350
|
+
operation. Each input file should contain one
|
|
351
|
+
``OptimizeToursRequest``, and each output file will
|
|
352
|
+
contain one ``OptimizeToursResponse``. The request
|
|
353
|
+
contains information to read/write and parse the files.
|
|
354
|
+
All the input and output files should be under the same
|
|
355
|
+
project.
|
|
356
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
357
|
+
should be retried.
|
|
358
|
+
timeout (float): The timeout for this request.
|
|
359
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
360
|
+
sent along with the request as metadata.
|
|
361
|
+
|
|
362
|
+
Returns:
|
|
363
|
+
~.operations_pb2.Operation:
|
|
364
|
+
This resource represents a
|
|
365
|
+
long-running operation that is the
|
|
366
|
+
result of a network API call.
|
|
367
|
+
|
|
368
|
+
"""
|
|
369
|
+
|
|
370
|
+
http_options: List[Dict[str, str]] = [
|
|
371
|
+
{
|
|
372
|
+
"method": "post",
|
|
373
|
+
"uri": "/v1/{parent=projects/*/locations/*}:batchOptimizeTours",
|
|
374
|
+
"body": "*",
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"method": "post",
|
|
378
|
+
"uri": "/v1/{parent=projects/*}:batchOptimizeTours",
|
|
379
|
+
"body": "*",
|
|
380
|
+
},
|
|
381
|
+
]
|
|
382
|
+
request, metadata = self._interceptor.pre_batch_optimize_tours(
|
|
383
|
+
request, metadata
|
|
384
|
+
)
|
|
385
|
+
pb_request = route_optimization_service.BatchOptimizeToursRequest.pb(
|
|
386
|
+
request
|
|
387
|
+
)
|
|
388
|
+
transcoded_request = path_template.transcode(http_options, pb_request)
|
|
389
|
+
|
|
390
|
+
# Jsonify the request body
|
|
391
|
+
|
|
392
|
+
body = json_format.MessageToJson(
|
|
393
|
+
transcoded_request["body"], use_integers_for_enums=True
|
|
394
|
+
)
|
|
395
|
+
uri = transcoded_request["uri"]
|
|
396
|
+
method = transcoded_request["method"]
|
|
397
|
+
|
|
398
|
+
# Jsonify the query params
|
|
399
|
+
query_params = json.loads(
|
|
400
|
+
json_format.MessageToJson(
|
|
401
|
+
transcoded_request["query_params"],
|
|
402
|
+
use_integers_for_enums=True,
|
|
403
|
+
)
|
|
404
|
+
)
|
|
405
|
+
query_params.update(self._get_unset_required_fields(query_params))
|
|
406
|
+
|
|
407
|
+
query_params["$alt"] = "json;enum-encoding=int"
|
|
408
|
+
|
|
409
|
+
# Send the request
|
|
410
|
+
headers = dict(metadata)
|
|
411
|
+
headers["Content-Type"] = "application/json"
|
|
412
|
+
response = getattr(self._session, method)(
|
|
413
|
+
"{host}{uri}".format(host=self._host, uri=uri),
|
|
414
|
+
timeout=timeout,
|
|
415
|
+
headers=headers,
|
|
416
|
+
params=rest_helpers.flatten_query_params(query_params, strict=True),
|
|
417
|
+
data=body,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
|
|
421
|
+
# subclass.
|
|
422
|
+
if response.status_code >= 400:
|
|
423
|
+
raise core_exceptions.from_http_response(response)
|
|
424
|
+
|
|
425
|
+
# Return the response
|
|
426
|
+
resp = operations_pb2.Operation()
|
|
427
|
+
json_format.Parse(response.content, resp, ignore_unknown_fields=True)
|
|
428
|
+
resp = self._interceptor.post_batch_optimize_tours(resp)
|
|
429
|
+
return resp
|
|
430
|
+
|
|
431
|
+
class _OptimizeTours(RouteOptimizationRestStub):
|
|
432
|
+
def __hash__(self):
|
|
433
|
+
return hash("OptimizeTours")
|
|
434
|
+
|
|
435
|
+
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}
|
|
436
|
+
|
|
437
|
+
@classmethod
|
|
438
|
+
def _get_unset_required_fields(cls, message_dict):
|
|
439
|
+
return {
|
|
440
|
+
k: v
|
|
441
|
+
for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items()
|
|
442
|
+
if k not in message_dict
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
def __call__(
|
|
446
|
+
self,
|
|
447
|
+
request: route_optimization_service.OptimizeToursRequest,
|
|
448
|
+
*,
|
|
449
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
450
|
+
timeout: Optional[float] = None,
|
|
451
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
452
|
+
) -> route_optimization_service.OptimizeToursResponse:
|
|
453
|
+
r"""Call the optimize tours method over HTTP.
|
|
454
|
+
|
|
455
|
+
Args:
|
|
456
|
+
request (~.route_optimization_service.OptimizeToursRequest):
|
|
457
|
+
The request object. Request to be given to a tour
|
|
458
|
+
optimization solver which defines the
|
|
459
|
+
shipment model to solve as well as
|
|
460
|
+
optimization parameters.
|
|
461
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
462
|
+
should be retried.
|
|
463
|
+
timeout (float): The timeout for this request.
|
|
464
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
465
|
+
sent along with the request as metadata.
|
|
466
|
+
|
|
467
|
+
Returns:
|
|
468
|
+
~.route_optimization_service.OptimizeToursResponse:
|
|
469
|
+
Response after solving a tour
|
|
470
|
+
optimization problem containing the
|
|
471
|
+
routes followed by each vehicle, the
|
|
472
|
+
shipments which have been skipped and
|
|
473
|
+
the overall cost of the solution.
|
|
474
|
+
|
|
475
|
+
"""
|
|
476
|
+
|
|
477
|
+
http_options: List[Dict[str, str]] = [
|
|
478
|
+
{
|
|
479
|
+
"method": "post",
|
|
480
|
+
"uri": "/v1/{parent=projects/*/locations/*}:optimizeTours",
|
|
481
|
+
"body": "*",
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"method": "post",
|
|
485
|
+
"uri": "/v1/{parent=projects/*}:optimizeTours",
|
|
486
|
+
"body": "*",
|
|
487
|
+
},
|
|
488
|
+
]
|
|
489
|
+
request, metadata = self._interceptor.pre_optimize_tours(request, metadata)
|
|
490
|
+
pb_request = route_optimization_service.OptimizeToursRequest.pb(request)
|
|
491
|
+
transcoded_request = path_template.transcode(http_options, pb_request)
|
|
492
|
+
|
|
493
|
+
# Jsonify the request body
|
|
494
|
+
|
|
495
|
+
body = json_format.MessageToJson(
|
|
496
|
+
transcoded_request["body"], use_integers_for_enums=True
|
|
497
|
+
)
|
|
498
|
+
uri = transcoded_request["uri"]
|
|
499
|
+
method = transcoded_request["method"]
|
|
500
|
+
|
|
501
|
+
# Jsonify the query params
|
|
502
|
+
query_params = json.loads(
|
|
503
|
+
json_format.MessageToJson(
|
|
504
|
+
transcoded_request["query_params"],
|
|
505
|
+
use_integers_for_enums=True,
|
|
506
|
+
)
|
|
507
|
+
)
|
|
508
|
+
query_params.update(self._get_unset_required_fields(query_params))
|
|
509
|
+
|
|
510
|
+
query_params["$alt"] = "json;enum-encoding=int"
|
|
511
|
+
|
|
512
|
+
# Send the request
|
|
513
|
+
headers = dict(metadata)
|
|
514
|
+
headers["Content-Type"] = "application/json"
|
|
515
|
+
response = getattr(self._session, method)(
|
|
516
|
+
"{host}{uri}".format(host=self._host, uri=uri),
|
|
517
|
+
timeout=timeout,
|
|
518
|
+
headers=headers,
|
|
519
|
+
params=rest_helpers.flatten_query_params(query_params, strict=True),
|
|
520
|
+
data=body,
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
|
|
524
|
+
# subclass.
|
|
525
|
+
if response.status_code >= 400:
|
|
526
|
+
raise core_exceptions.from_http_response(response)
|
|
527
|
+
|
|
528
|
+
# Return the response
|
|
529
|
+
resp = route_optimization_service.OptimizeToursResponse()
|
|
530
|
+
pb_resp = route_optimization_service.OptimizeToursResponse.pb(resp)
|
|
531
|
+
|
|
532
|
+
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
|
|
533
|
+
resp = self._interceptor.post_optimize_tours(resp)
|
|
534
|
+
return resp
|
|
535
|
+
|
|
536
|
+
@property
|
|
537
|
+
def batch_optimize_tours(
|
|
538
|
+
self,
|
|
539
|
+
) -> Callable[
|
|
540
|
+
[route_optimization_service.BatchOptimizeToursRequest], operations_pb2.Operation
|
|
541
|
+
]:
|
|
542
|
+
# The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
|
|
543
|
+
# In C++ this would require a dynamic_cast
|
|
544
|
+
return self._BatchOptimizeTours(self._session, self._host, self._interceptor) # type: ignore
|
|
545
|
+
|
|
546
|
+
@property
|
|
547
|
+
def optimize_tours(
|
|
548
|
+
self,
|
|
549
|
+
) -> Callable[
|
|
550
|
+
[route_optimization_service.OptimizeToursRequest],
|
|
551
|
+
route_optimization_service.OptimizeToursResponse,
|
|
552
|
+
]:
|
|
553
|
+
# The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
|
|
554
|
+
# In C++ this would require a dynamic_cast
|
|
555
|
+
return self._OptimizeTours(self._session, self._host, self._interceptor) # type: ignore
|
|
556
|
+
|
|
557
|
+
@property
|
|
558
|
+
def get_operation(self):
|
|
559
|
+
return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore
|
|
560
|
+
|
|
561
|
+
class _GetOperation(RouteOptimizationRestStub):
|
|
562
|
+
def __call__(
|
|
563
|
+
self,
|
|
564
|
+
request: operations_pb2.GetOperationRequest,
|
|
565
|
+
*,
|
|
566
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
567
|
+
timeout: Optional[float] = None,
|
|
568
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
569
|
+
) -> operations_pb2.Operation:
|
|
570
|
+
r"""Call the get operation method over HTTP.
|
|
571
|
+
|
|
572
|
+
Args:
|
|
573
|
+
request (operations_pb2.GetOperationRequest):
|
|
574
|
+
The request object for GetOperation method.
|
|
575
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
576
|
+
should be retried.
|
|
577
|
+
timeout (float): The timeout for this request.
|
|
578
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
579
|
+
sent along with the request as metadata.
|
|
580
|
+
|
|
581
|
+
Returns:
|
|
582
|
+
operations_pb2.Operation: Response from GetOperation method.
|
|
583
|
+
"""
|
|
584
|
+
|
|
585
|
+
http_options: List[Dict[str, str]] = [
|
|
586
|
+
{
|
|
587
|
+
"method": "get",
|
|
588
|
+
"uri": "/v1/{name=projects/*/locations/*/operations/*}",
|
|
589
|
+
},
|
|
590
|
+
]
|
|
591
|
+
|
|
592
|
+
request, metadata = self._interceptor.pre_get_operation(request, metadata)
|
|
593
|
+
request_kwargs = json_format.MessageToDict(request)
|
|
594
|
+
transcoded_request = path_template.transcode(http_options, **request_kwargs)
|
|
595
|
+
|
|
596
|
+
uri = transcoded_request["uri"]
|
|
597
|
+
method = transcoded_request["method"]
|
|
598
|
+
|
|
599
|
+
# Jsonify the query params
|
|
600
|
+
query_params = json.loads(json.dumps(transcoded_request["query_params"]))
|
|
601
|
+
|
|
602
|
+
# Send the request
|
|
603
|
+
headers = dict(metadata)
|
|
604
|
+
headers["Content-Type"] = "application/json"
|
|
605
|
+
|
|
606
|
+
response = getattr(self._session, method)(
|
|
607
|
+
"{host}{uri}".format(host=self._host, uri=uri),
|
|
608
|
+
timeout=timeout,
|
|
609
|
+
headers=headers,
|
|
610
|
+
params=rest_helpers.flatten_query_params(query_params),
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
|
|
614
|
+
# subclass.
|
|
615
|
+
if response.status_code >= 400:
|
|
616
|
+
raise core_exceptions.from_http_response(response)
|
|
617
|
+
|
|
618
|
+
resp = operations_pb2.Operation()
|
|
619
|
+
resp = json_format.Parse(response.content.decode("utf-8"), resp)
|
|
620
|
+
resp = self._interceptor.post_get_operation(resp)
|
|
621
|
+
return resp
|
|
622
|
+
|
|
623
|
+
@property
|
|
624
|
+
def kind(self) -> str:
|
|
625
|
+
return "rest"
|
|
626
|
+
|
|
627
|
+
def close(self):
|
|
628
|
+
self._session.close()
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
__all__ = ("RouteOptimizationRestTransport",)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 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
|
+
from .route_optimization_service import (
|
|
17
|
+
AggregatedMetrics,
|
|
18
|
+
BatchOptimizeToursMetadata,
|
|
19
|
+
BatchOptimizeToursRequest,
|
|
20
|
+
BatchOptimizeToursResponse,
|
|
21
|
+
BreakRule,
|
|
22
|
+
DataFormat,
|
|
23
|
+
DistanceLimit,
|
|
24
|
+
GcsDestination,
|
|
25
|
+
GcsSource,
|
|
26
|
+
InjectedSolutionConstraint,
|
|
27
|
+
InputConfig,
|
|
28
|
+
Location,
|
|
29
|
+
OptimizeToursRequest,
|
|
30
|
+
OptimizeToursResponse,
|
|
31
|
+
OptimizeToursValidationError,
|
|
32
|
+
OutputConfig,
|
|
33
|
+
Shipment,
|
|
34
|
+
ShipmentModel,
|
|
35
|
+
ShipmentRoute,
|
|
36
|
+
ShipmentTypeIncompatibility,
|
|
37
|
+
ShipmentTypeRequirement,
|
|
38
|
+
SkippedShipment,
|
|
39
|
+
TimeWindow,
|
|
40
|
+
TransitionAttributes,
|
|
41
|
+
Vehicle,
|
|
42
|
+
Waypoint,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
__all__ = (
|
|
46
|
+
"AggregatedMetrics",
|
|
47
|
+
"BatchOptimizeToursMetadata",
|
|
48
|
+
"BatchOptimizeToursRequest",
|
|
49
|
+
"BatchOptimizeToursResponse",
|
|
50
|
+
"BreakRule",
|
|
51
|
+
"DistanceLimit",
|
|
52
|
+
"GcsDestination",
|
|
53
|
+
"GcsSource",
|
|
54
|
+
"InjectedSolutionConstraint",
|
|
55
|
+
"InputConfig",
|
|
56
|
+
"Location",
|
|
57
|
+
"OptimizeToursRequest",
|
|
58
|
+
"OptimizeToursResponse",
|
|
59
|
+
"OptimizeToursValidationError",
|
|
60
|
+
"OutputConfig",
|
|
61
|
+
"Shipment",
|
|
62
|
+
"ShipmentModel",
|
|
63
|
+
"ShipmentRoute",
|
|
64
|
+
"ShipmentTypeIncompatibility",
|
|
65
|
+
"ShipmentTypeRequirement",
|
|
66
|
+
"SkippedShipment",
|
|
67
|
+
"TimeWindow",
|
|
68
|
+
"TransitionAttributes",
|
|
69
|
+
"Vehicle",
|
|
70
|
+
"Waypoint",
|
|
71
|
+
"DataFormat",
|
|
72
|
+
)
|