<!DOCTYPE html>
<html lang="en-US">

  <head>
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,maximum-scale=2">
    <link rel="stylesheet" href="assets/css/style.css?v=">
    <script src="https://code.jquery.com/jquery-3.3.0.min.js" integrity="sha256-RTQy8VOmNlT6b2PIRur37p6JEBZUE7o8wPgMvu18MC4=" crossorigin="anonymous"></script>
    <script src="assets/js/main.js"></script>
<!-- Begin Jekyll SEO tag v2.6.1 -->
<title>BIRDS | Bidirectional Transformation for Relational View Update Datalog-based Strategies</title>
<meta name="generator" content="Jekyll v4.0.0" />
<meta property="og:title" content="BIRDS" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Bidirectional Transformation for Relational View Update Datalog-based Strategies" />
<meta property="og:description" content="Bidirectional Transformation for Relational View Update Datalog-based Strategies" />
<meta property="og:site_name" content="BIRDS" />
<script type="application/ld+json">
{"@type":"WebPage","url":"/ridesharing-tutorial.html","headline":"BIRDS","description":"Bidirectional Transformation for Relational View Update Datalog-based Strategies","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->

  </head>

  <body>

    <!-- HEADER -->
    <div id="header_wrap" class="outer">
        <header class="inner">
          
            <a id="forkme_banner" href="https://github.com/dangtv/BIRDS">View on GitHub</a>
          
          <a id="project_title" href="/BIRDS">BIRDS</a>
           <!-- <h1 id="project_title">  BIRDS </h1>  -->
          <h2 id="project_tagline">Bidirectional Transformation for Relational View Update Datalog-based Strategies</h2>

          
        </header>
    </div>

    <!-- MAIN CONTENT -->
    <div id="main_content_wrap" class="outer, wrapper">
      <div class="inner">
          <nav>
              <h3>Contents</h3>
              <ul></ul>
            </nav>
        <section id="main_content">
          <h1 id="examples-on-a-ride-sharing-schema">Examples on a ride-sharing schema</h1>

<p>The ride-sharing schema (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/schema.sql">schema.sql</a>) contains three tables:</p>

<p><code class="highlighter-rouge">area</code></p>

<table>
  <thead>
    <tr>
      <th>original_node</th>
      <th>area_node</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>50</td>
      <td>0</td>
    </tr>
    <tr>
      <td>100</td>
      <td>1</td>
    </tr>
    <tr>
      <td>200</td>
      <td>2</td>
    </tr>
    <tr>
      <td>300</td>
      <td>3</td>
    </tr>
    <tr>
      <td>400</td>
      <td>4</td>
    </tr>
    <tr>
      <td>500</td>
      <td>5</td>
    </tr>
    <tr>
      <td>600</td>
      <td>6</td>
    </tr>
    <tr>
      <td>700</td>
      <td>7</td>
    </tr>
    <tr>
      <td>800</td>
      <td>8</td>
    </tr>
  </tbody>
</table>

<p><code class="highlighter-rouge">peer1_vehicle</code></p>

<table>
  <thead>
    <tr>
      <th>vehicle_id</th>
      <th>current_location</th>
      <th>seat_count</th>
      <th>request_id</th>
      <th>pickup_location</th>
      <th>dropoff_location</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>200</td>
      <td>4</td>
      <td>3</td>
      <td>200</td>
      <td>300</td>
    </tr>
    <tr>
      <td>2</td>
      <td>50</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>3</td>
      <td>100</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>4</td>
      <td>300</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>5</td>
      <td>500</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>6</td>
      <td>600</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>7</td>
      <td>400</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
  </tbody>
</table>

<p><code class="highlighter-rouge">peer2_vehicle</code></p>

<table>
  <thead>
    <tr>
      <th>vehicle_id</th>
      <th>current_location</th>
      <th>seat_count</th>
      <th>request_id</th>
      <th>pickup_location</th>
      <th>dropoff_location</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>600</td>
      <td>4</td>
      <td>5</td>
      <td>600</td>
      <td>700</td>
    </tr>
    <tr>
      <td>3</td>
      <td>300</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>10</td>
      <td>400</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>2</td>
      <td>800</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>11</td>
      <td>100</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>12</td>
      <td>50</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>13</td>
      <td>700</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>23</td>
      <td>200</td>
      <td>4</td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
  </tbody>
</table>

<h2 id="view-peer1_public">View <code class="highlighter-rouge">peer1_public</code></h2>

<p>The following is an update strategy on the view <code class="highlighter-rouge">peer1_public</code> by using Datalog (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_peer1_public.dl">real_peer1_public.dl</a>):</p>

<div class="language-prolog highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ss">source</span> <span class="ss">peer1_vehicle</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">source</span> <span class="ss">area</span><span class="p">(</span><span class="ss">'ORIGINAL_NODE'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'AREA_NODE'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">view</span> <span class="ss">peer1_public</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_AREA'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>

<span class="c1">% view definition</span>
<span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">).</span>

<span class="c1">%constraints</span>
<span class="c1">% primary key VEHICLE_ID on peer1_vehicle</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">L1</span> <span class="o">=</span> <span class="nv">L2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">S1</span> <span class="o">=</span> <span class="nv">S2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">R1</span> <span class="o">=</span> <span class="nv">R2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">P1</span> <span class="o">=</span> <span class="nv">P2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">D1</span> <span class="o">=</span> <span class="nv">D2</span><span class="p">.</span>

<span class="c1">% primary key ORIGINAL_NODE</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">ORIGINAL_NODE</span><span class="p">,</span> <span class="nv">AREA_NODE1</span><span class="p">),</span>  <span class="ss">area</span> <span class="p">(</span><span class="nv">ORIGINAL_NODE</span><span class="p">,</span> <span class="nv">AREA_NODE2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">AREA_NODE1</span> <span class="o">=</span> <span class="nv">AREA_NODE2</span><span class="p">.</span>

<span class="c1">% primary key VEHICLE_ID on peer1_public</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">L1</span> <span class="o">=</span> <span class="nv">L2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">S1</span> <span class="o">=</span> <span class="nv">S2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">R1</span> <span class="o">=</span> <span class="nv">R2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">P1</span> <span class="o">=</span> <span class="nv">P2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">D1</span> <span class="o">=</span> <span class="nv">D2</span><span class="p">.</span>

<span class="c1">% prevent update on the column CURRENT_AREA</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span><span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A1</span><span class="p">),</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A2</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">A1</span> <span class="o">=</span> <span class="nv">A2</span><span class="p">.</span>
<span class="c1">% prevent insertion or deletion of a new vehicle id</span>
<span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">_</span><span class="p">).</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">),</span> <span class="nv">NOT</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">).</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span><span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="nv">NOT</span> <span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">).</span>

<span class="c1">% update strategy</span>
<span class="o">-</span><span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">),</span> <span class="ss">not</span> <span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
<span class="o">+</span><span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer1_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">peer1_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span><span class="nv">L</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">),</span> <span class="ss">not</span> <span class="ss">peer1_vehicle</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
</code></pre></div></div>

<p>Verifying and compiling the update strategy to SQL statements saved in the file (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_peer1_public.sql">real_peer1_public.sql</a>):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>birds <span class="nt">-v</span> <span class="nt">-f</span> real_peer1_public.dl <span class="nt">-o</span> real_peer1_public.sql
</code></pre></div></div>

<p><img src="assets/images/peer1-public-compilation.png" alt="peer1-public-compile" /></p>

<h2 id="view-peer2_public">View <code class="highlighter-rouge">peer2_public</code></h2>

<p>The following is an update strategy on the view <code class="highlighter-rouge">peer2_public</code> by using Datalog (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_peer2_public.dl">real_peer2_public.dl</a>):</p>

<div class="language-prolog highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ss">source</span> <span class="ss">peer2_vehicle</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">source</span> <span class="ss">area</span><span class="p">(</span><span class="ss">'ORIGINAL_NODE'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'AREA_NODE'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">view</span> <span class="ss">peer2_public</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_AREA'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>

<span class="c1">% view definition</span>
<span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">).</span>

<span class="c1">%constraints</span>
<span class="c1">% primary key VEHICLE_ID on peer2_vehicle</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">L1</span> <span class="o">=</span> <span class="nv">L2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">S1</span> <span class="o">=</span> <span class="nv">S2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">R1</span> <span class="o">=</span> <span class="nv">R2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">P1</span> <span class="o">=</span> <span class="nv">P2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">D1</span> <span class="o">=</span> <span class="nv">D2</span><span class="p">.</span>

<span class="c1">% primary key ORIGINAL_NODE</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">ORIGINAL_NODE</span><span class="p">,</span> <span class="nv">AREA_NODE1</span><span class="p">),</span>  <span class="ss">area</span> <span class="p">(</span><span class="nv">ORIGINAL_NODE</span><span class="p">,</span> <span class="nv">AREA_NODE2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">AREA_NODE1</span> <span class="o">=</span> <span class="nv">AREA_NODE2</span><span class="p">.</span>

<span class="c1">% primary key VEHICLE_ID on peer2_public</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">L1</span> <span class="o">=</span> <span class="nv">L2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">S1</span> <span class="o">=</span> <span class="nv">S2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">R1</span> <span class="o">=</span> <span class="nv">R2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">P1</span> <span class="o">=</span> <span class="nv">P2</span><span class="p">.</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L1</span><span class="p">,</span> <span class="nv">S1</span><span class="p">,</span> <span class="nv">R1</span><span class="p">,</span> <span class="nv">P1</span><span class="p">,</span> <span class="nv">D1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L2</span><span class="p">,</span> <span class="nv">S2</span><span class="p">,</span> <span class="nv">R2</span><span class="p">,</span> <span class="nv">P2</span><span class="p">,</span> <span class="nv">D2</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">D1</span> <span class="o">=</span> <span class="nv">D2</span><span class="p">.</span>

<span class="c1">% prevent updates on the column CURRENT_AREA</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span><span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A1</span><span class="p">),</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A2</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">A1</span> <span class="o">=</span> <span class="nv">A2</span><span class="p">.</span>
<span class="c1">% prevent insertion or deletion of a new vehicle id</span>
<span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">_</span><span class="p">).</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">),</span> <span class="nv">NOT</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">).</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span><span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="nv">NOT</span> <span class="ss">all_id</span><span class="p">(</span><span class="nv">V</span><span class="p">).</span>

<span class="c1">% update strategy</span>
<span class="o">-</span><span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">),</span> <span class="ss">not</span> <span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
<span class="o">+</span><span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer2_public</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="ss">peer2_vehicle</span> <span class="p">(</span><span class="nv">V</span><span class="p">,</span><span class="nv">L</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">,</span> <span class="nv">_</span><span class="p">),</span> <span class="ss">area</span> <span class="p">(</span><span class="nv">L</span><span class="p">,</span><span class="nv">A</span><span class="p">),</span> <span class="ss">not</span> <span class="ss">peer2_vehicle</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">L</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
</code></pre></div></div>

<p>Verifying and compiling the update strategy to SQL statements saved in the file (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_peer2_public.sql">real_peer2_public.sql</a>):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>birds <span class="nt">-v</span> <span class="nt">-f</span> real_peer2_public.dl <span class="nt">-o</span> real_peer2_public.sql
</code></pre></div></div>

<p><img src="assets/images/peer2-public-compilation.png" alt="peer2-public-compile" /></p>

<h2 id="view-all_vehicles">View <code class="highlighter-rouge">all_vehicles</code></h2>

<p>Since <code class="highlighter-rouge">peer1_public</code> and <code class="highlighter-rouge">peer2_public</code> are both updatable, we can use them as the base relations for other views.</p>

<p>The following is an update strategy for the view <code class="highlighter-rouge">all_vehicles</code> over <code class="highlighter-rouge">peer1_public</code> and <code class="highlighter-rouge">peer2_public</code> by using Datalog (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_all_vehicles.dl">real_all_vehicles.dl</a>):</p>

<div class="language-prolog highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ss">source</span> <span class="ss">peer1_public</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_AREA'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">source</span> <span class="ss">peer2_public</span><span class="p">(</span><span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_AREA'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">view</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="ss">'COMPANY_ID'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span> <span class="ss">'VEHICLE_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'CURRENT_AREA'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'SEAT_COUNT'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'REQUEST_ID'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'PICKUP_LOCATION'</span><span class="o">:</span><span class="ss">int</span> <span class="p">,</span> <span class="ss">'DROPOFF_LOCATION'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>

<span class="c1">% constraint</span>
<span class="c1">% ensure that the company_id in all_vehicles is 1 or 2</span>
<span class="nv">_</span><span class="p">|</span><span class="nv">_</span> <span class="p">:-</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="nv">C</span><span class="p">,</span> <span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">C</span><span class="o">=</span><span class="m">1</span><span class="p">,</span> <span class="nv">NOT</span> <span class="nv">C</span><span class="o">=</span><span class="m">2</span><span class="p">.</span>

<span class="o">+</span><span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="nv">C</span><span class="p">,</span> <span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span><span class="nv">C</span> <span class="o">=</span> <span class="m">1</span><span class="p">,</span> <span class="nv">NOT</span> <span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
<span class="o">-</span><span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer1_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="nv">C</span> <span class="o">=</span> <span class="m">1</span><span class="p">,</span> <span class="nv">NOT</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="nv">C</span><span class="p">,</span> <span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
<span class="o">+</span><span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="nv">C</span><span class="p">,</span> <span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="nv">C</span> <span class="o">=</span> <span class="m">2</span><span class="p">,</span> <span class="nv">NOT</span> <span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
<span class="o">-</span><span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">peer2_public</span><span class="p">(</span><span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">),</span> <span class="nv">C</span> <span class="o">=</span> <span class="m">2</span><span class="p">,</span> <span class="nv">NOT</span> <span class="ss">all_vehicles</span><span class="p">(</span><span class="nv">C</span><span class="p">,</span> <span class="nv">V</span><span class="p">,</span> <span class="nv">A</span><span class="p">,</span> <span class="nv">S</span><span class="p">,</span> <span class="nv">R</span><span class="p">,</span> <span class="nv">P</span><span class="p">,</span> <span class="nv">D</span><span class="p">).</span>
</code></pre></div></div>

<p>Verifying and compiling the update strategy to SQL statements saved in the file (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/ride_sharing/real_all_vehicles.sql">real_all_vehicles.sql</a>):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>birds <span class="nt">-v</span> <span class="nt">-f</span> real_all_vehicles.dl <span class="nt">-o</span> real_all_vehicles.sql
</code></pre></div></div>

<p><img src="assets/images/all-vehicle-compilation.png" alt="all-vehicle-compile" /></p>

        </section>
      </div>
    </div>
    
    <!-- FOOTER  -->
    <div id="footer_wrap" class="outer">
      <footer class="inner">
        <p style="margin-bottom:0em"><small>
          
          Maintained by <a href="https://dangtv.github.io">Vandang Tran</a>, Hiroyuki Kato, Zhenjiang Hu</small>.
        
        <small>Theme based on <a href="https://github.com/pages-themes/slate">Slate</a></small>.
        <small>Last updated on 2 Dec 2020</small></p>
      </footer>
    </div>

    
  </body>
</html>