google-cloud-optimization-v1 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,719 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/cloud/optimization/v1/fleet_routing_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module Optimization
25
+ module V1
26
+ module FleetRouting
27
+ ##
28
+ # Client for the FleetRouting service.
29
+ #
30
+ # A service for optimizing vehicle tours.
31
+ #
32
+ # Validity of certain types of fields:
33
+ #
34
+ # * `google.protobuf.Timestamp`
35
+ # * Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00.
36
+ # * seconds must be in [0, 253402300799],
37
+ # i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
38
+ # * nanos must be unset or set to 0.
39
+ # * `google.protobuf.Duration`
40
+ # * seconds must be in [0, 253402300799],
41
+ # i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
42
+ # * nanos must be unset or set to 0.
43
+ # * `google.type.LatLng`
44
+ # * latitude must be in [-90.0, 90.0].
45
+ # * longitude must be in [-180.0, 180.0].
46
+ # * at least one of latitude and longitude must be non-zero.
47
+ #
48
+ class Client
49
+ # @private
50
+ attr_reader :fleet_routing_stub
51
+
52
+ ##
53
+ # Configure the FleetRouting Client class.
54
+ #
55
+ # See {::Google::Cloud::Optimization::V1::FleetRouting::Client::Configuration}
56
+ # for a description of the configuration fields.
57
+ #
58
+ # @example
59
+ #
60
+ # # Modify the configuration for all FleetRouting clients
61
+ # ::Google::Cloud::Optimization::V1::FleetRouting::Client.configure do |config|
62
+ # config.timeout = 10.0
63
+ # end
64
+ #
65
+ # @yield [config] Configure the Client client.
66
+ # @yieldparam config [Client::Configuration]
67
+ #
68
+ # @return [Client::Configuration]
69
+ #
70
+ def self.configure
71
+ @configure ||= begin
72
+ namespace = ["Google", "Cloud", "Optimization", "V1"]
73
+ parent_config = while namespace.any?
74
+ parent_name = namespace.join "::"
75
+ parent_const = const_get parent_name
76
+ break parent_const.configure if parent_const.respond_to? :configure
77
+ namespace.pop
78
+ end
79
+ default_config = Client::Configuration.new parent_config
80
+
81
+ default_config.rpcs.optimize_tours.timeout = 3600.0
82
+ default_config.rpcs.optimize_tours.retry_policy = {
83
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
84
+ }
85
+
86
+ default_config.rpcs.batch_optimize_tours.timeout = 60.0
87
+ default_config.rpcs.batch_optimize_tours.retry_policy = {
88
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
89
+ }
90
+
91
+ default_config
92
+ end
93
+ yield @configure if block_given?
94
+ @configure
95
+ end
96
+
97
+ ##
98
+ # Configure the FleetRouting Client instance.
99
+ #
100
+ # The configuration is set to the derived mode, meaning that values can be changed,
101
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
102
+ # should be made on {Client.configure}.
103
+ #
104
+ # See {::Google::Cloud::Optimization::V1::FleetRouting::Client::Configuration}
105
+ # for a description of the configuration fields.
106
+ #
107
+ # @yield [config] Configure the Client client.
108
+ # @yieldparam config [Client::Configuration]
109
+ #
110
+ # @return [Client::Configuration]
111
+ #
112
+ def configure
113
+ yield @config if block_given?
114
+ @config
115
+ end
116
+
117
+ ##
118
+ # Create a new FleetRouting client object.
119
+ #
120
+ # @example
121
+ #
122
+ # # Create a client using the default configuration
123
+ # client = ::Google::Cloud::Optimization::V1::FleetRouting::Client.new
124
+ #
125
+ # # Create a client using a custom configuration
126
+ # client = ::Google::Cloud::Optimization::V1::FleetRouting::Client.new do |config|
127
+ # config.timeout = 10.0
128
+ # end
129
+ #
130
+ # @yield [config] Configure the FleetRouting client.
131
+ # @yieldparam config [Client::Configuration]
132
+ #
133
+ def initialize
134
+ # These require statements are intentionally placed here to initialize
135
+ # the gRPC module only when it's required.
136
+ # See https://github.com/googleapis/toolkit/issues/446
137
+ require "gapic/grpc"
138
+ require "google/cloud/optimization/v1/fleet_routing_services_pb"
139
+
140
+ # Create the configuration object
141
+ @config = Configuration.new Client.configure
142
+
143
+ # Yield the configuration if needed
144
+ yield @config if block_given?
145
+
146
+ # Create credentials
147
+ credentials = @config.credentials
148
+ # Use self-signed JWT if the endpoint is unchanged from default,
149
+ # but only if the default endpoint does not have a region prefix.
150
+ enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
151
+ !@config.endpoint.split(".").first.include?("-")
152
+ credentials ||= Credentials.default scope: @config.scope,
153
+ enable_self_signed_jwt: enable_self_signed_jwt
154
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
155
+ credentials = Credentials.new credentials, scope: @config.scope
156
+ end
157
+ @quota_project_id = @config.quota_project
158
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
159
+
160
+ @operations_client = Operations.new do |config|
161
+ config.credentials = credentials
162
+ config.quota_project = @quota_project_id
163
+ config.endpoint = @config.endpoint
164
+ end
165
+
166
+ @fleet_routing_stub = ::Gapic::ServiceStub.new(
167
+ ::Google::Cloud::Optimization::V1::FleetRouting::Stub,
168
+ credentials: credentials,
169
+ endpoint: @config.endpoint,
170
+ channel_args: @config.channel_args,
171
+ interceptors: @config.interceptors
172
+ )
173
+ end
174
+
175
+ ##
176
+ # Get the associated client for long-running operations.
177
+ #
178
+ # @return [::Google::Cloud::Optimization::V1::FleetRouting::Operations]
179
+ #
180
+ attr_reader :operations_client
181
+
182
+ # Service calls
183
+
184
+ ##
185
+ # Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
186
+ # `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
187
+ # routes to be performed by vehicles minimizing the overall cost.
188
+ #
189
+ # A `ShipmentModel` model consists mainly of `Shipment`s that need to be
190
+ # carried out and `Vehicle`s that can be used to transport the `Shipment`s.
191
+ # The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
192
+ # they assign a series of `Visit`s to each vehicle, where a `Visit`
193
+ # corresponds to a `VisitRequest`, which is a pickup or delivery for a
194
+ # `Shipment`.
195
+ #
196
+ # The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
197
+ # minimizes the total cost where cost has many components defined in the
198
+ # `ShipmentModel`.
199
+ #
200
+ # @overload optimize_tours(request, options = nil)
201
+ # Pass arguments to `optimize_tours` via a request object, either of type
202
+ # {::Google::Cloud::Optimization::V1::OptimizeToursRequest} or an equivalent Hash.
203
+ #
204
+ # @param request [::Google::Cloud::Optimization::V1::OptimizeToursRequest, ::Hash]
205
+ # A request object representing the call parameters. Required. To specify no
206
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
207
+ # @param options [::Gapic::CallOptions, ::Hash]
208
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
209
+ #
210
+ # @overload optimize_tours(parent: nil, timeout: nil, model: nil, solving_mode: nil, max_validation_errors: nil, search_mode: nil, injected_first_solution_routes: nil, injected_solution_constraint: nil, refresh_details_routes: nil, interpret_injected_solutions_using_labels: nil, consider_road_traffic: nil, populate_polylines: nil, populate_transition_polylines: nil, allow_large_deadline_despite_interruption_risk: nil, use_geodesic_distances: nil, geodesic_meters_per_second: nil, label: nil, populate_travel_step_polylines: nil)
211
+ # Pass arguments to `optimize_tours` via keyword arguments. Note that at
212
+ # least one keyword argument is required. To specify no parameters, or to keep all
213
+ # the default parameter values, pass an empty Hash as a request object (see above).
214
+ #
215
+ # @param parent [::String]
216
+ # Required. Target project and location to make a call.
217
+ #
218
+ # Format: `projects/{project-id}/locations/{location-id}`.
219
+ #
220
+ # If no location is specified, a region will be chosen automatically.
221
+ # @param timeout [::Google::Protobuf::Duration, ::Hash]
222
+ # If this timeout is set, the server returns a response before the timeout
223
+ # period has elapsed or the server deadline for synchronous requests is
224
+ # reached, whichever is sooner.
225
+ #
226
+ # For asynchronous requests, the server will generate a solution (if
227
+ # possible) before the timeout has elapsed.
228
+ # @param model [::Google::Cloud::Optimization::V1::ShipmentModel, ::Hash]
229
+ # Shipment model to solve.
230
+ # @param solving_mode [::Google::Cloud::Optimization::V1::OptimizeToursRequest::SolvingMode]
231
+ # By default, the solving mode is `DEFAULT_SOLVE` (0).
232
+ # @param max_validation_errors [::Integer]
233
+ # Truncates the number of validation errors returned. Those errors are
234
+ # typically attached to an INVALID_ARGUMENT error payload as a BadRequest
235
+ # error detail (https://cloud.google.com/apis/design/errors#error_details),
236
+ # unless solving_mode=VALIDATE_ONLY: see the
237
+ # {::Google::Cloud::Optimization::V1::OptimizeToursResponse#validation_errors OptimizeToursResponse.validation_errors}
238
+ # field.
239
+ # This defaults to 100 and is capped at 10,000.
240
+ # @param search_mode [::Google::Cloud::Optimization::V1::OptimizeToursRequest::SearchMode]
241
+ # Search mode used to solve the request.
242
+ # @param injected_first_solution_routes [::Array<::Google::Cloud::Optimization::V1::ShipmentRoute, ::Hash>]
243
+ # Guide the optimization algorithm in finding a first solution that is
244
+ # similar to a previous solution.
245
+ #
246
+ # The model is constrained when the first solution is built.
247
+ # Any shipments not performed on a route are implicitly skipped in the first
248
+ # solution, but they may be performed in successive solutions.
249
+ #
250
+ # The solution must satisfy some basic validity assumptions:
251
+ #
252
+ # * for all routes, `vehicle_index` must be in range and not be duplicated.
253
+ # * for all visits, `shipment_index` and `visit_request_index` must be
254
+ # in range.
255
+ # * a shipment may only be referenced on one route.
256
+ # * the pickup of a pickup-delivery shipment must be performed before
257
+ # the delivery.
258
+ # * no more than one pickup alternative or delivery alternative of
259
+ # a shipment may be performed.
260
+ # * for all routes, times are increasing (i.e., `vehicle_start_time
261
+ # <= visits[0].start_time <= visits[1].start_time ...
262
+ # <= vehicle_end_time`).
263
+ # * a shipment may only be performed on a vehicle that is allowed. A
264
+ # vehicle is allowed if {::Google::Cloud::Optimization::V1::Shipment#allowed_vehicle_indices Shipment.allowed_vehicle_indices} is empty or
265
+ # its `vehicle_index` is included in
266
+ # {::Google::Cloud::Optimization::V1::Shipment#allowed_vehicle_indices Shipment.allowed_vehicle_indices}.
267
+ #
268
+ # If the injected solution is not feasible, a validation error is not
269
+ # necessarily returned and an error indicating infeasibility may be returned
270
+ # instead.
271
+ # @param injected_solution_constraint [::Google::Cloud::Optimization::V1::InjectedSolutionConstraint, ::Hash]
272
+ # Constrain the optimization algorithm to find a final solution that is
273
+ # similar to a previous solution. For example, this may be used to freeze
274
+ # portions of routes which have already been completed or which are to be
275
+ # completed but must not be modified.
276
+ #
277
+ # If the injected solution is not feasible, a validation error is not
278
+ # necessarily returned and an error indicating infeasibility may be returned
279
+ # instead.
280
+ # @param refresh_details_routes [::Array<::Google::Cloud::Optimization::V1::ShipmentRoute, ::Hash>]
281
+ # If non-empty, the given routes will be refreshed, without modifying their
282
+ # underlying sequence of visits or travel times: only other details will be
283
+ # updated. This does not solve the model.
284
+ #
285
+ # As of 2020/11, this only populates the polylines of non-empty routes and
286
+ # requires that `populate_polylines` is true.
287
+ #
288
+ # The `route_polyline` fields of the passed-in routes may be inconsistent
289
+ # with route `transitions`.
290
+ #
291
+ # This field must not be used together with `injected_first_solution_routes`
292
+ # or `injected_solution_constraint`.
293
+ #
294
+ # `Shipment.ignore` and `Vehicle.ignore` have no effect on the behavior.
295
+ # Polylines are still populated between all visits in all non-empty routes
296
+ # regardless of whether the related shipments or vehicles are ignored.
297
+ # @param interpret_injected_solutions_using_labels [::Boolean]
298
+ # If true:
299
+ #
300
+ # * uses {::Google::Cloud::Optimization::V1::ShipmentRoute#vehicle_label ShipmentRoute.vehicle_label} instead of `vehicle_index` to
301
+ # match routes in an injected solution with vehicles in the request;
302
+ # reuses the mapping of original {::Google::Cloud::Optimization::V1::ShipmentRoute#vehicle_index ShipmentRoute.vehicle_index} to new
303
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute#vehicle_index ShipmentRoute.vehicle_index} to update
304
+ # {::Google::Cloud::Optimization::V1::InjectedSolutionConstraint::ConstraintRelaxation#vehicle_indices ConstraintRelaxation.vehicle_indices}
305
+ # if non-empty, but the mapping must be unambiguous (i.e., multiple
306
+ # `ShipmentRoute`s must not share the same original `vehicle_index`).
307
+ # * uses {::Google::Cloud::Optimization::V1::ShipmentRoute::Visit#shipment_label ShipmentRoute.Visit.shipment_label} instead of `shipment_index`
308
+ # to match visits in an injected solution with shipments in the request;
309
+ # * uses {::Google::Cloud::Optimization::V1::SkippedShipment#label SkippedShipment.label} instead of {::Google::Cloud::Optimization::V1::SkippedShipment#index SkippedShipment.index} to
310
+ # match skipped shipments in the injected solution with request
311
+ # shipments.
312
+ #
313
+ # This interpretation applies to the `injected_first_solution_routes`,
314
+ # `injected_solution_constraint`, and `refresh_details_routes` fields.
315
+ # It can be used when shipment or vehicle indices in the request have
316
+ # changed since the solution was created, perhaps because shipments or
317
+ # vehicles have been removed from or added to the request.
318
+ #
319
+ # If true, labels in the following categories must appear at most once in
320
+ # their category:
321
+ #
322
+ # * {::Google::Cloud::Optimization::V1::Vehicle#label Vehicle.label} in the request;
323
+ # * {::Google::Cloud::Optimization::V1::Shipment#label Shipment.label} in the request;
324
+ # * {::Google::Cloud::Optimization::V1::ShipmentRoute#vehicle_label ShipmentRoute.vehicle_label} in the injected solution;
325
+ # * {::Google::Cloud::Optimization::V1::SkippedShipment#label SkippedShipment.label} and {::Google::Cloud::Optimization::V1::ShipmentRoute::Visit#shipment_label ShipmentRoute.Visit.shipment_label} in
326
+ # the injected solution (except pickup/delivery visit pairs, whose
327
+ # `shipment_label` must appear twice).
328
+ #
329
+ # If a `vehicle_label` in the injected solution does not correspond to a
330
+ # request vehicle, the corresponding route is removed from the solution
331
+ # along with its visits. If a `shipment_label` in the injected solution does
332
+ # not correspond to a request shipment, the corresponding visit is removed
333
+ # from the solution. If a {::Google::Cloud::Optimization::V1::SkippedShipment#label SkippedShipment.label} in the injected solution
334
+ # does not correspond to a request shipment, the `SkippedShipment` is removed
335
+ # from the solution.
336
+ #
337
+ # Removing route visits or entire routes from an injected solution may
338
+ # have an effect on the implied constraints, which may lead to change in
339
+ # solution, validation errors, or infeasibility.
340
+ #
341
+ # NOTE: The caller must ensure that each {::Google::Cloud::Optimization::V1::Vehicle#label Vehicle.label}
342
+ # (resp. {::Google::Cloud::Optimization::V1::Shipment#label Shipment.label}) uniquely identifies a vehicle (resp. shipment)
343
+ # entity used across the two relevant requests: the past request that
344
+ # produced the `OptimizeToursResponse` used in the injected solution and the
345
+ # current request that includes the injected solution. The uniqueness checks
346
+ # described above are not enough to guarantee this requirement.
347
+ # @param consider_road_traffic [::Boolean]
348
+ # Consider traffic estimation in calculating `ShipmentRoute` fields
349
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute::Transition#travel_duration Transition.travel_duration},
350
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute::Visit#start_time Visit.start_time},
351
+ # and `vehicle_end_time`; in setting the
352
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute#has_traffic_infeasibilities ShipmentRoute.has_traffic_infeasibilities} field, and in calculating the
353
+ # {::Google::Cloud::Optimization::V1::OptimizeToursResponse#total_cost OptimizeToursResponse.total_cost} field.
354
+ # @param populate_polylines [::Boolean]
355
+ # If true, polylines will be populated in response `ShipmentRoute`s.
356
+ # @param populate_transition_polylines [::Boolean]
357
+ # If true, polylines will be populated in response
358
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute#transitions ShipmentRoute.transitions}.
359
+ # Note that in this case, the polylines will also be populated in the
360
+ # deprecated `travel_steps`.
361
+ # @param allow_large_deadline_despite_interruption_risk [::Boolean]
362
+ # If this is set, then the request can have a deadline
363
+ # (see https://grpc.io/blog/deadlines) of up to 60 minutes.
364
+ # Otherwise, the maximum deadline is only 30 minutes.
365
+ # Note that long-lived requests have a significantly larger (but still small)
366
+ # risk of interruption.
367
+ # @param use_geodesic_distances [::Boolean]
368
+ # If true, travel distances will be computed using geodesic distances instead
369
+ # of Google Maps distances, and travel times will be computed using geodesic
370
+ # distances with a speed defined by `geodesic_meters_per_second`.
371
+ # @param geodesic_meters_per_second [::Float]
372
+ # When `use_geodesic_distances` is true, this field must be set and defines
373
+ # the speed applied to compute travel times. Its value must be at least 1.0
374
+ # meters/seconds.
375
+ # @param label [::String]
376
+ # Label that may be used to identify this request, reported back in the
377
+ # {::Google::Cloud::Optimization::V1::OptimizeToursResponse#request_label OptimizeToursResponse.request_label}.
378
+ # @param populate_travel_step_polylines [::Boolean]
379
+ # Deprecated: Use [OptimizeToursRequest.populate_transition_polylines][] instead.
380
+ # If true, polylines will be populated in response
381
+ # {::Google::Cloud::Optimization::V1::ShipmentRoute#transitions ShipmentRoute.transitions}. Note that in this case, the polylines will
382
+ # also be populated in the deprecated `travel_steps`.
383
+ #
384
+ # @yield [response, operation] Access the result along with the RPC operation
385
+ # @yieldparam response [::Google::Cloud::Optimization::V1::OptimizeToursResponse]
386
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
387
+ #
388
+ # @return [::Google::Cloud::Optimization::V1::OptimizeToursResponse]
389
+ #
390
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
391
+ #
392
+ # @example Basic example
393
+ # require "google/cloud/optimization/v1"
394
+ #
395
+ # # Create a client object. The client can be reused for multiple calls.
396
+ # client = Google::Cloud::Optimization::V1::FleetRouting::Client.new
397
+ #
398
+ # # Create a request. To set request fields, pass in keyword arguments.
399
+ # request = Google::Cloud::Optimization::V1::OptimizeToursRequest.new
400
+ #
401
+ # # Call the optimize_tours method.
402
+ # result = client.optimize_tours request
403
+ #
404
+ # # The returned object is of type Google::Cloud::Optimization::V1::OptimizeToursResponse.
405
+ # p result
406
+ #
407
+ def optimize_tours request, options = nil
408
+ raise ::ArgumentError, "request must be provided" if request.nil?
409
+
410
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Optimization::V1::OptimizeToursRequest
411
+
412
+ # Converts hash and nil to an options object
413
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
414
+
415
+ # Customize the options with defaults
416
+ metadata = @config.rpcs.optimize_tours.metadata.to_h
417
+
418
+ # Set x-goog-api-client and x-goog-user-project headers
419
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
420
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
421
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
422
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
423
+
424
+ header_params = {}
425
+ if request.parent
426
+ header_params["parent"] = request.parent
427
+ end
428
+
429
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
430
+ metadata[:"x-goog-request-params"] ||= request_params_header
431
+
432
+ options.apply_defaults timeout: @config.rpcs.optimize_tours.timeout,
433
+ metadata: metadata,
434
+ retry_policy: @config.rpcs.optimize_tours.retry_policy
435
+
436
+ options.apply_defaults timeout: @config.timeout,
437
+ metadata: @config.metadata,
438
+ retry_policy: @config.retry_policy
439
+
440
+ @fleet_routing_stub.call_rpc :optimize_tours, request, options: options do |response, operation|
441
+ yield response, operation if block_given?
442
+ return response
443
+ end
444
+ rescue ::GRPC::BadStatus => e
445
+ raise ::Google::Cloud::Error.from_error(e)
446
+ end
447
+
448
+ ##
449
+ # Optimizes vehicle tours for one or more `OptimizeToursRequest`
450
+ # messages as a batch.
451
+ #
452
+ # This method is a Long Running Operation (LRO). The inputs for optimization
453
+ # (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
454
+ # messages) are read/written from/to Cloud Storage in user-specified
455
+ # format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
456
+ # contains a `ShipmentModel` and returns an `OptimizeToursResponse`
457
+ # containing `ShipmentRoute`s, which are a set of routes to be performed by
458
+ # vehicles minimizing the overall cost.
459
+ #
460
+ # @overload batch_optimize_tours(request, options = nil)
461
+ # Pass arguments to `batch_optimize_tours` via a request object, either of type
462
+ # {::Google::Cloud::Optimization::V1::BatchOptimizeToursRequest} or an equivalent Hash.
463
+ #
464
+ # @param request [::Google::Cloud::Optimization::V1::BatchOptimizeToursRequest, ::Hash]
465
+ # A request object representing the call parameters. Required. To specify no
466
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
467
+ # @param options [::Gapic::CallOptions, ::Hash]
468
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
469
+ #
470
+ # @overload batch_optimize_tours(parent: nil, model_configs: nil)
471
+ # Pass arguments to `batch_optimize_tours` via keyword arguments. Note that at
472
+ # least one keyword argument is required. To specify no parameters, or to keep all
473
+ # the default parameter values, pass an empty Hash as a request object (see above).
474
+ #
475
+ # @param parent [::String]
476
+ # Required. Target project and location to make a call.
477
+ #
478
+ # Format: `projects/{project-id}/locations/{location-id}`.
479
+ #
480
+ # If no location is specified, a region will be chosen automatically.
481
+ # @param model_configs [::Array<::Google::Cloud::Optimization::V1::BatchOptimizeToursRequest::AsyncModelConfig, ::Hash>]
482
+ # Required. Input/Output information each purchase model, such as file paths and data
483
+ # formats.
484
+ #
485
+ # @yield [response, operation] Access the result along with the RPC operation
486
+ # @yieldparam response [::Gapic::Operation]
487
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
488
+ #
489
+ # @return [::Gapic::Operation]
490
+ #
491
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
492
+ #
493
+ # @example Basic example
494
+ # require "google/cloud/optimization/v1"
495
+ #
496
+ # # Create a client object. The client can be reused for multiple calls.
497
+ # client = Google::Cloud::Optimization::V1::FleetRouting::Client.new
498
+ #
499
+ # # Create a request. To set request fields, pass in keyword arguments.
500
+ # request = Google::Cloud::Optimization::V1::BatchOptimizeToursRequest.new
501
+ #
502
+ # # Call the batch_optimize_tours method.
503
+ # result = client.batch_optimize_tours request
504
+ #
505
+ # # The returned object is of type Gapic::Operation. You can use this
506
+ # # object to check the status of an operation, cancel it, or wait
507
+ # # for results. Here is how to block until completion:
508
+ # result.wait_until_done! timeout: 60
509
+ # if result.response?
510
+ # p result.response
511
+ # else
512
+ # puts "Error!"
513
+ # end
514
+ #
515
+ def batch_optimize_tours request, options = nil
516
+ raise ::ArgumentError, "request must be provided" if request.nil?
517
+
518
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Optimization::V1::BatchOptimizeToursRequest
519
+
520
+ # Converts hash and nil to an options object
521
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
522
+
523
+ # Customize the options with defaults
524
+ metadata = @config.rpcs.batch_optimize_tours.metadata.to_h
525
+
526
+ # Set x-goog-api-client and x-goog-user-project headers
527
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
528
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
529
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
530
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
531
+
532
+ header_params = {}
533
+ if request.parent
534
+ header_params["parent"] = request.parent
535
+ end
536
+
537
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
538
+ metadata[:"x-goog-request-params"] ||= request_params_header
539
+
540
+ options.apply_defaults timeout: @config.rpcs.batch_optimize_tours.timeout,
541
+ metadata: metadata,
542
+ retry_policy: @config.rpcs.batch_optimize_tours.retry_policy
543
+
544
+ options.apply_defaults timeout: @config.timeout,
545
+ metadata: @config.metadata,
546
+ retry_policy: @config.retry_policy
547
+
548
+ @fleet_routing_stub.call_rpc :batch_optimize_tours, request, options: options do |response, operation|
549
+ response = ::Gapic::Operation.new response, @operations_client, options: options
550
+ yield response, operation if block_given?
551
+ return response
552
+ end
553
+ rescue ::GRPC::BadStatus => e
554
+ raise ::Google::Cloud::Error.from_error(e)
555
+ end
556
+
557
+ ##
558
+ # Configuration class for the FleetRouting API.
559
+ #
560
+ # This class represents the configuration for FleetRouting,
561
+ # providing control over timeouts, retry behavior, logging, transport
562
+ # parameters, and other low-level controls. Certain parameters can also be
563
+ # applied individually to specific RPCs. See
564
+ # {::Google::Cloud::Optimization::V1::FleetRouting::Client::Configuration::Rpcs}
565
+ # for a list of RPCs that can be configured independently.
566
+ #
567
+ # Configuration can be applied globally to all clients, or to a single client
568
+ # on construction.
569
+ #
570
+ # @example
571
+ #
572
+ # # Modify the global config, setting the timeout for
573
+ # # optimize_tours to 20 seconds,
574
+ # # and all remaining timeouts to 10 seconds.
575
+ # ::Google::Cloud::Optimization::V1::FleetRouting::Client.configure do |config|
576
+ # config.timeout = 10.0
577
+ # config.rpcs.optimize_tours.timeout = 20.0
578
+ # end
579
+ #
580
+ # # Apply the above configuration only to a new client.
581
+ # client = ::Google::Cloud::Optimization::V1::FleetRouting::Client.new do |config|
582
+ # config.timeout = 10.0
583
+ # config.rpcs.optimize_tours.timeout = 20.0
584
+ # end
585
+ #
586
+ # @!attribute [rw] endpoint
587
+ # The hostname or hostname:port of the service endpoint.
588
+ # Defaults to `"cloudoptimization.googleapis.com"`.
589
+ # @return [::String]
590
+ # @!attribute [rw] credentials
591
+ # Credentials to send with calls. You may provide any of the following types:
592
+ # * (`String`) The path to a service account key file in JSON format
593
+ # * (`Hash`) A service account key as a Hash
594
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
595
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
596
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
597
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
598
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
599
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
600
+ # * (`nil`) indicating no credentials
601
+ # @return [::Object]
602
+ # @!attribute [rw] scope
603
+ # The OAuth scopes
604
+ # @return [::Array<::String>]
605
+ # @!attribute [rw] lib_name
606
+ # The library name as recorded in instrumentation and logging
607
+ # @return [::String]
608
+ # @!attribute [rw] lib_version
609
+ # The library version as recorded in instrumentation and logging
610
+ # @return [::String]
611
+ # @!attribute [rw] channel_args
612
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
613
+ # `GRPC::Core::Channel` object is provided as the credential.
614
+ # @return [::Hash]
615
+ # @!attribute [rw] interceptors
616
+ # An array of interceptors that are run before calls are executed.
617
+ # @return [::Array<::GRPC::ClientInterceptor>]
618
+ # @!attribute [rw] timeout
619
+ # The call timeout in seconds.
620
+ # @return [::Numeric]
621
+ # @!attribute [rw] metadata
622
+ # Additional gRPC headers to be sent with the call.
623
+ # @return [::Hash{::Symbol=>::String}]
624
+ # @!attribute [rw] retry_policy
625
+ # The retry policy. The value is a hash with the following keys:
626
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
627
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
628
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
629
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
630
+ # trigger a retry.
631
+ # @return [::Hash]
632
+ # @!attribute [rw] quota_project
633
+ # A separate project against which to charge quota.
634
+ # @return [::String]
635
+ #
636
+ class Configuration
637
+ extend ::Gapic::Config
638
+
639
+ config_attr :endpoint, "cloudoptimization.googleapis.com", ::String
640
+ config_attr :credentials, nil do |value|
641
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
642
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
643
+ allowed.any? { |klass| klass === value }
644
+ end
645
+ config_attr :scope, nil, ::String, ::Array, nil
646
+ config_attr :lib_name, nil, ::String, nil
647
+ config_attr :lib_version, nil, ::String, nil
648
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
649
+ config_attr :interceptors, nil, ::Array, nil
650
+ config_attr :timeout, nil, ::Numeric, nil
651
+ config_attr :metadata, nil, ::Hash, nil
652
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
653
+ config_attr :quota_project, nil, ::String, nil
654
+
655
+ # @private
656
+ def initialize parent_config = nil
657
+ @parent_config = parent_config unless parent_config.nil?
658
+
659
+ yield self if block_given?
660
+ end
661
+
662
+ ##
663
+ # Configurations for individual RPCs
664
+ # @return [Rpcs]
665
+ #
666
+ def rpcs
667
+ @rpcs ||= begin
668
+ parent_rpcs = nil
669
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
670
+ Rpcs.new parent_rpcs
671
+ end
672
+ end
673
+
674
+ ##
675
+ # Configuration RPC class for the FleetRouting API.
676
+ #
677
+ # Includes fields providing the configuration for each RPC in this service.
678
+ # Each configuration object is of type `Gapic::Config::Method` and includes
679
+ # the following configuration fields:
680
+ #
681
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
682
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
683
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
684
+ # include the following keys:
685
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
686
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
687
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
688
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
689
+ # trigger a retry.
690
+ #
691
+ class Rpcs
692
+ ##
693
+ # RPC-specific configuration for `optimize_tours`
694
+ # @return [::Gapic::Config::Method]
695
+ #
696
+ attr_reader :optimize_tours
697
+ ##
698
+ # RPC-specific configuration for `batch_optimize_tours`
699
+ # @return [::Gapic::Config::Method]
700
+ #
701
+ attr_reader :batch_optimize_tours
702
+
703
+ # @private
704
+ def initialize parent_rpcs = nil
705
+ optimize_tours_config = parent_rpcs.optimize_tours if parent_rpcs.respond_to? :optimize_tours
706
+ @optimize_tours = ::Gapic::Config::Method.new optimize_tours_config
707
+ batch_optimize_tours_config = parent_rpcs.batch_optimize_tours if parent_rpcs.respond_to? :batch_optimize_tours
708
+ @batch_optimize_tours = ::Gapic::Config::Method.new batch_optimize_tours_config
709
+
710
+ yield self if block_given?
711
+ end
712
+ end
713
+ end
714
+ end
715
+ end
716
+ end
717
+ end
718
+ end
719
+ end