共有プールルートの作成

このドキュメントでは、共有プールルートを作成し、正しいフィールドを設定して、車両に割り当てて完了する方法について説明します。Fleet Engine を設定し、車両を作成し、ドライバー アプリが動作し、必要に応じてユーザーアプリが動作していることを前提としています。また、オンデマンド ルートで利用できるさまざまなルート シナリオについても理解している必要があります。関連するガイドは次のとおりです。

ルート作成の基本

このセクションでは、Fleet Engine でルートを作成するために必要なリクエストの詳細について説明します。作成リクエストは、gRPC または REST を使用して発行します。

  • CreateTrip() メソッド: gRPC または REST
  • CreateTripRequest メッセージ: gRPC のみ

ルート フィールド

Fleet Engine でルートを作成するには、次のフィールドを使用します。ルートの種類(単一または複数の目的地、連続、共有プール)に応じて、異なるフィールドを使用できます。省略可のフィールドは、ルートの作成時に指定することも、ルートの更新時に後で設定することもできます。

ルート フィールド
名前 必須かどうか 説明
parent プロジェクト ID を含む文字列。この ID は、Fleet Engine の統合全体で同じサービス アカウントのロールを使用して使用する必要があります。
trip_id このルートを一意に識別するために作成する文字列。ルート ID には 特定の制限があります。参照に示されているように。
trip_type 作成するルートタイプに応じて、TripType を次の値に設定します。
  • 単一の目的地: SHARED または EXCLUSIVE に設定します。
  • 複数の目的地: EXCLUSIVE に設定します。
  • 連続: EXCLUSIVE に設定します。
  • 共有プール: SHARED に設定します。
pickup_point ルートの出発地。
中間地点

複数の目的地ルートのみ: ドライバーが乗車地点と降車地点の間で立ち寄る中間地点のリスト。dropoff_point と同様に、このフィールドは UpdateTrip を呼び出して後で設定することもできますが、複数の目的地ルートには定義上、中間地点が含まれます。

vehicle_waypoints

共有プールルートのみ: このフィールドは、複数のルートの経由地をインターリーブすることをサポートしています。 割り当てられた車両の残りの経由地と、このルートの乗車地点と降車地点の経由地がすべて含まれます。このフィールドは、 CreateTrip または UpdateTrip を呼び出して設定できます。`UpdateVehicle` の呼び出しで `waypoints` フィールドを使用して、車両の経由地を更新することもできます。プライバシー上の理由から、この情報は GetTrip 呼び出しでは返されません 。

number_of_passengers いいえ ルートの乗客数。
dropoff_point いいえ ルートの目的地。
vehicle_id いいえ ルートに割り当てられた車両の ID。

例: 共有プールルートを作成する

次のバックエンド統合のサンプルは、ルートを作成して、共有プールルートとして車両に割り当てる方法を示しています。

// Vehicle with VEHICLE_ID ID is already created and it is assigned Trip A.

static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_ID = "shared-trip-A";
static final String VEHICLE_ID = "your-vehicle-id";
static final String TRIP_A_ID = "trip-a-id";
static final String TRIP_B_ID = "trip-b-id";

TripServiceBlockingStub tripService = TripService.newBlockingStub(channel);

String parent = "providers/" + PROJECT_ID;

LatLng tripBPickup =
    LatLng.newBuilder().setLatitude(-12.12314).setLongitude(88.142123).build();
LatLng tripBDropoff =
    LatLng.newBuilder().setLatitude(-14.12314).setLongitude(90.142123).build();

TerminalLocation tripBPickupTerminalLocation =
    TerminalLocation.newBuilder().setPoint(tripBPickup).build();
TerminalLocation tripBDropoffTerminalLocation =
    TerminalLocation.newBuilder().setPoint(tripBDropoff).build();

// TripA already exists and it's assigned to a vehicle with VEHICLE_ID ID.
Trip tripB = Trip.newBuilder()
    .setTripType(TripType.SHARED)
    .setVehicleId(VEHICLE_ID)
    .setPickupPoint(tripBPickupTerminalLocation)
    .setDropoffPoint(tripBDropoffTerminalLocation)
    .addAllVehicleWaypoints(
        // This is where you define the arrival order for unvisited waypoints.
        // If you don't specify an order, then the Fleet Engine adds Trip B's
        // waypoints to the end of Trip A's.
        ImmutableList.of(
            // Trip B's pickup point.
            TripWaypoint.newBuilder()
                .setLocation(tripBPickupTerminalLocation)
                .setTripId(TRIP_B_ID)
                .setWaypointType(WaypointType.PICKUP_WAYPOINT_TYPE)
                .build(),
            // Trip A's drop-off point.
            TripWaypoint.newBuilder()
                .setLocation(tripA.getDropoffPoint())
                .setTripId(TRIP_A_ID)
                .setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
                .build(),
            // Trip B's drop-off point.
            TripWaypoint.newBuilder()
                .setLocation(tripBDropoffTerminalLocation)
                .setTripId(TRIP_B_ID)
                .setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
                .build()))
    .build();

// Create Trip request
CreateTripRequest createTripRequest = CreateTripRequest.newBuilder()
    .setParent(parent)
    .setTripId(TRIP_B_ID)
    .setTrip(tripB)
    .build();

try {
  // createdTrip.remainingWaypoints will contain shared-pool waypoints.
  // [tripB.pickup, tripA.dropoff, tripB.dropoff]
  Trip createdTrip = tripService.createTrip(createTripRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case ALREADY_EXISTS:
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}

共有プールルートを更新する

Fleet Engine で作成されたルートは、Fleet Engine がルートの ETA を計算して追跡できるように、車両に割り当てる必要があります。これは、ルートの作成時またはルートの更新時に行うことができます。

共有プールルートの場合は、ルートの車両の経由地のコレクション(Trip.vehicle_waypoints)で、未訪問の経由地の順序を指定する必要があります。Fleet Engine はこのリストを使用して、共有プール内のすべてのルートのルート経由地を自動的に更新します。

たとえば、2 つの共有プールルート、ルート Aルート B があるとします。

  • ルート A は降車地点に向かっています。
  • ルート B が同じ車両に追加されます。

ルート B の 1 つの UpdateTripRequest で、ルート B vehicleId を設定し、Trip.vehicle_waypoints を最適な 経由地の順序(B 乗車地点A 降車地点B 降車地点)に設定します。

  • getVehicle() を呼び出すと、remainingWaypoints が返されます。これには、
    B 乗車地点A 降車地点B 降車地点が含まれます。
  • ルート A の getTrip() または onTripRemainingWaypointsUpdated コールバックは、remainingWaypoints を返します。これには、
    B 乗車地点A 降車地点が含まれます。
  • ルート B の Trip BgetTrip() または onTripRemainingWaypointsUpdated コールバックは、remainingWaypoints 以下を含む
    を返します。 B 乗車地点A 降車地点B 降車地点

次のバックエンド統合のサンプルは、2 つの共有プールルートの車両 ID と経由地を使用してルートを更新する方法を示しています。

static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_A_ID = "share-trip-A";
static final String TRIP_B_ID = "share-trip-B";
static final String VEHICLE_ID = "Vehicle";

String tripName = "providers/" + PROJECT_ID + "/trips/" + TRIP_B_ID;

// Get Trip A and Trip B objects from either the Fleet Engine or storage.
Trip tripA = ;
Trip tripB = ;

TripServiceBlockingStub tripService = TripService.newBlockingStub(channel);

// The trip settings to update.
Trip trip = Trip.newBuilder()
    .setVehicleId(VEHICLE_ID)
    .addAllVehicleWaypoints(
        // This is where you define the arrival order for unvisited waypoints.
        // If you don't specify an order, then the Fleet Engine adds Trip B's
        // waypoints to the end of Trip A's.
        ImmutableList.of(
            // Trip B's pickup point.
            TripWaypoint.newBuilder()
                .setLocation(tripB.getPickupPoint())
                .setTripId(TRIP_B_ID)
                .setWaypointType(WaypointType.PICKUP_WAYPOINT_TYPE)
                .build(),
            // Trip A's drop-off point.
            TripWaypoint.newBuilder()
                .setLocation(tripA.getDropoffPoint())
                .setTripId(TRIP_A_ID)
                .setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
                .build(),
            // Trip B's drop-off point.
            TripWaypoint.newBuilder()
                .setLocation(tripB.getDropoffPoint())
                .setTripId(TRIP_B_ID)
                .setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
                .build()))
    .build();

// The trip update request.
UpdateTripRequest updateTripRequest = UpdateTripRequest.newBuilder()
    .setName(tripName)
    .setTrip(trip)
    .setUpdateMask(FieldMask.newBuilder()
        .addPaths("vehicle_id")
        .addPaths("vehicle_waypoints"))
    .build();

// Error handling. If Fleet Engine has both a trip and vehicle with the IDs,
// and if the credentials validate, and if the given vehicle_waypoints list
// is valid, then the service updates the trip.
try {
  Trip updatedTrip = tripService.updateTrip(updateTripRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case NOT_FOUND:          // Either the trip or vehicle does not exist.
      break;
    case PERMISSION_DENIED:
      break;
    case INVALID_REQUEST:    // vehicle_waypoints is invalid.
      break;
  }
  return;
}

次のステップ