<?xml version="1.0" encoding="UTF-8"?>
<semantic:definitions xmlns="https://www.drools.org/kie-dmn"
                      xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
                      xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
                      xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/"
                      xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/"
                      xmlns:kie="https://www.drools.org/kie-dmn"
                      xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/"
                      id="_0019_flight_rebooking"
                      name="0019-flight-rebooking"
                      namespace="https://www.drools.org/kie-dmn">
   <semantic:itemDefinition id="_tFlight" name="tFlight">
      <semantic:itemComponent id="_tFlight_Flight" name="Flight Number">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_From" name="From">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_To" name="To">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_Dep" name="Departure">
         <semantic:typeRef>dateTime</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_Arr" name="Arrival">
         <semantic:typeRef>dateTime</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_Capacity" name="Capacity">
         <semantic:typeRef>number</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tFlight_Status" name="Status">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
   </semantic:itemDefinition>
   <semantic:itemDefinition id="_tFlightTable" isCollection="true" name="tFlightTable">
      <semantic:typeRef>tFlight</semantic:typeRef>
   </semantic:itemDefinition>
   <semantic:itemDefinition id="_tPassenger" name="tPassenger">
      <semantic:itemComponent id="_tPassenger_Name" name="Name">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tPassenger_Status" name="Status">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tPassenger_Miles" name="Miles">
         <semantic:typeRef>number</semantic:typeRef>
      </semantic:itemComponent>
      <semantic:itemComponent id="_tPassenger_Flight" name="Flight Number">
         <semantic:typeRef>string</semantic:typeRef>
      </semantic:itemComponent>
   </semantic:itemDefinition>
   <semantic:itemDefinition id="_tPassengerTable" isCollection="true" name="tPassengerTable">
      <semantic:typeRef>tPassenger</semantic:typeRef>
   </semantic:itemDefinition>
   <semantic:itemDefinition id="_tFlightNumberList"
                            isCollection="true"
                            name="tFlightNumberList">
      <semantic:typeRef>string</semantic:typeRef>
   </semantic:itemDefinition>
   <semantic:inputData id="i_Flight_List" name="Flight List">
      <semantic:variable name="Flight List" typeRef="tFlightTable"/>
   </semantic:inputData>
   <semantic:inputData id="i_Passenger_List" name="Passenger List">
      <semantic:variable name="Passenger List" typeRef="tPassengerTable"/>
   </semantic:inputData>
   <semantic:decision name="Prioritized Waiting List" id="d_PrioritizedWaitingList">
      <semantic:variable name="Prioritized Waiting List" typeRef="tPassengerTable"/>
      <semantic:informationRequirement>
         <semantic:requiredInput href="#i_Passenger_List"/>
      </semantic:informationRequirement>
      <semantic:informationRequirement>
         <semantic:requiredInput href="#i_Flight_List"/>
      </semantic:informationRequirement>
      <semantic:knowledgeRequirement>
         <semantic:requiredKnowledge href="#b_PassengerPriority"/>
      </semantic:knowledgeRequirement>
      <semantic:context>
         <semantic:contextEntry>
            <semantic:variable name="Cancelled Flights" typeRef="tFlightNumberList"/>
            <semantic:literalExpression>
               <semantic:text>Flight List[ Status = "cancelled" ].Flight Number</semantic:text>
            </semantic:literalExpression>
         </semantic:contextEntry>
         <semantic:contextEntry>
            <semantic:variable name="Waiting List" typeRef="tPassengerTable"/>
            <semantic:literalExpression>
               <semantic:text>Passenger List[ list contains( Cancelled Flights, Flight Number ) ]</semantic:text>
            </semantic:literalExpression>
         </semantic:contextEntry>
         <semantic:contextEntry>
            <semantic:literalExpression>
               <semantic:text>sort( Waiting List, passenger priority )</semantic:text>
            </semantic:literalExpression>
         </semantic:contextEntry>
      </semantic:context>
   </semantic:decision>
   <semantic:decision name="Rebooked Passengers" id="d_RebookedPassengers">
      <semantic:variable name="Rebooked Passengers" typeRef="tPassengerTable"/>
      <semantic:informationRequirement>
         <semantic:requiredDecision href="#d_PrioritizedWaitingList"/>
      </semantic:informationRequirement>
      <semantic:informationRequirement>
         <semantic:requiredInput href="#i_Flight_List"/>
      </semantic:informationRequirement>
      <semantic:knowledgeRequirement>
         <semantic:requiredKnowledge href="#b_ReassignNextPassenger"/>
      </semantic:knowledgeRequirement>
      <semantic:invocation>
         <semantic:literalExpression>
            <semantic:text>reassign next passenger</semantic:text>
         </semantic:literalExpression>
         <semantic:binding>
            <semantic:parameter name="Waiting List"/>
            <semantic:literalExpression>
               <semantic:text>Prioritized Waiting List</semantic:text>
            </semantic:literalExpression>
         </semantic:binding>
         <semantic:binding>
            <semantic:parameter name="Reassigned Passengers List"/>
            <semantic:literalExpression>
               <semantic:text>[]</semantic:text>
            </semantic:literalExpression>
         </semantic:binding>
         <semantic:binding>
            <semantic:parameter name="Flights"/>
            <semantic:literalExpression>
               <semantic:text>Flight List</semantic:text>
            </semantic:literalExpression>
         </semantic:binding>
      </semantic:invocation>
   </semantic:decision>
   <semantic:businessKnowledgeModel id="b_PassengerPriority" name="passenger priority">
      <semantic:variable name="passenger priority" typeRef="boolean"/>
      <semantic:encapsulatedLogic>
         <semantic:formalParameter name="Passenger1" typeRef="tPassenger"/>
         <semantic:formalParameter name="Passenger2" typeRef="tPassenger"/>
         <semantic:decisionTable hitPolicy="UNIQUE">
            <semantic:input id="b_Passenger_Priority_dt_i_P1_Status" label="Passenger1.Status">
               <semantic:inputExpression typeRef="string">
                  <semantic:text>Passenger1.Status</semantic:text>
               </semantic:inputExpression>
               <semantic:inputValues>
                  <semantic:text>"gold", "silver", "bronze"</semantic:text>
               </semantic:inputValues>
            </semantic:input>
            <semantic:input id="b_Passenger_Priority_dt_i_P2_Status" label="Passenger2.Status">
               <semantic:inputExpression typeRef="string">
                  <semantic:text>Passenger2.Status</semantic:text>
               </semantic:inputExpression>
               <semantic:inputValues>
                  <semantic:text>"gold", "silver", "bronze"</semantic:text>
               </semantic:inputValues>
            </semantic:input>
            <semantic:input id="b_Passenger_Priority_dt_i_P1_Miles" label="Passenger1.Miles">
               <semantic:inputExpression typeRef="string">
                  <semantic:text>Passenger1.Miles</semantic:text>
               </semantic:inputExpression>
            </semantic:input>
            <semantic:output id="b_Status_Priority_dt_o" label="Passenger1 has priority">
               <semantic:outputValues>
                  <semantic:text>true, false</semantic:text>
               </semantic:outputValues>
               <semantic:defaultOutputEntry>
                  <semantic:text>false</semantic:text>
               </semantic:defaultOutputEntry>
            </semantic:output>
            <semantic:rule id="b_Passenger_Priority_dt_r1">
               <semantic:inputEntry id="b_Passenger_Priority_dt_r1_i1">
                  <semantic:text>"gold"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r1_i2">
                  <semantic:text>"gold"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r1_i3">
                  <semantic:text>&gt;= Passenger2.Miles</semantic:text>
               </semantic:inputEntry>
               <semantic:outputEntry id="b_Passenger_Priority_dt_r1_o1">
                  <semantic:text>true</semantic:text>
               </semantic:outputEntry>
            </semantic:rule>
            <semantic:rule id="b_Passenger_Priority_dt_r2">
               <semantic:inputEntry id="b_Passenger_Priority_dt_r2_i1">
                  <semantic:text>"gold"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r2_i2">
                  <semantic:text>"silver","bronze"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r2_i3">
                  <semantic:text>-</semantic:text>
               </semantic:inputEntry>
               <semantic:outputEntry id="b_Passenger_Priority_dt_r2_o1">
                  <semantic:text>true</semantic:text>
               </semantic:outputEntry>
            </semantic:rule>
            <semantic:rule id="b_Passenger_Priority_dt_r3">
               <semantic:inputEntry id="b_Passenger_Priority_dt_r3_i1">
                  <semantic:text>"silver"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r3_i2">
                  <semantic:text>"silver"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r3_i3">
                  <semantic:text>&gt;= Passenger2.Miles</semantic:text>
               </semantic:inputEntry>
               <semantic:outputEntry id="b_Passenger_Priority_dt_r3_o1">
                  <semantic:text>true</semantic:text>
               </semantic:outputEntry>
            </semantic:rule>
            <semantic:rule id="b_Passenger_Priority_dt_r4">
               <semantic:inputEntry id="b_Passenger_Priority_dt_r4_i1">
                  <semantic:text>"silver"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r4_i2">
                  <semantic:text>"bronze"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r4_i3">
                  <semantic:text>-</semantic:text>
               </semantic:inputEntry>
               <semantic:outputEntry id="b_Passenger_Priority_dt_r4_o1">
                  <semantic:text>true</semantic:text>
               </semantic:outputEntry>
            </semantic:rule>
            <semantic:rule id="b_Passenger_Priority_dt_r5">
               <semantic:inputEntry id="b_Passenger_Priority_dt_r5_i1">
                  <semantic:text>"bronze"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r5_i2">
                  <semantic:text>"bronze"</semantic:text>
               </semantic:inputEntry>
               <semantic:inputEntry id="b_Passenger_Priority_dt_r5_i3">
                  <semantic:text>&gt;= Passenger2.Miles</semantic:text>
               </semantic:inputEntry>
               <semantic:outputEntry id="b_Passenger_Priority_dt_r5_o1">
                  <semantic:text>true</semantic:text>
               </semantic:outputEntry>
            </semantic:rule>
         </semantic:decisionTable>
      </semantic:encapsulatedLogic>
   </semantic:businessKnowledgeModel>
   <semantic:businessKnowledgeModel id="b_ReassignNextPassenger" name="reassign next passenger">
      <semantic:variable name="reassign next passenger" typeRef="tPassengerTable"/>
      <semantic:encapsulatedLogic>
         <semantic:formalParameter name="Waiting List" typeRef="tPassengerTable"/>
         <semantic:formalParameter name="Reassigned Passengers List" typeRef="tPassengerTable"/>
         <semantic:formalParameter name="Flights" typeRef="tFlightTable"/>
         <semantic:context>
            <semantic:contextEntry>
               <semantic:variable name="Next Passenger" typeRef="tPassenger"/>
               <semantic:literalExpression>
                  <semantic:text>Waiting List[1]</semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:variable name="Original Flight" typeRef="tFlight"/>
               <semantic:literalExpression>
                  <semantic:text>Flights[ Flight Number = Next Passenger.Flight Number ][1]</semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:variable name="Best Alternate Flight" typeRef="tFlight"/>
               <semantic:literalExpression>
                  <semantic:text>Flights[ From = Original Flight.From and 
                                       To = Original Flight.To and
                                       Departure &gt; Original Flight.Departure and
                                       Status = "scheduled" and
                                       has capacity( item, Reassigned Passengers List ) ][1]</semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:variable name="Reassigned Passenger" typeRef="tPassenger"/>
               <semantic:context>
                  <semantic:contextEntry>
                     <semantic:variable name="Name" typeRef="string"/>
                     <semantic:literalExpression>
                        <semantic:text>Next Passenger.Name</semantic:text>
                     </semantic:literalExpression>
                  </semantic:contextEntry>
                  <semantic:contextEntry>
                     <semantic:variable name="Status" typeRef="string"/>
                     <semantic:literalExpression>
                        <semantic:text>Next Passenger.Status</semantic:text>
                     </semantic:literalExpression>
                  </semantic:contextEntry>
                  <semantic:contextEntry>
                     <semantic:variable name="Miles" typeRef="number"/>
                     <semantic:literalExpression>
                        <semantic:text>Next Passenger.Miles</semantic:text>
                     </semantic:literalExpression>
                  </semantic:contextEntry>
                  <semantic:contextEntry>
                     <semantic:variable name="Flight Number" typeRef="string"/>
                     <semantic:literalExpression>
                        <semantic:text>Best Alternate Flight.Flight Number</semantic:text>
                     </semantic:literalExpression>
                  </semantic:contextEntry>
               </semantic:context>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:variable name="Remaining Waiting List" typeRef="tPassengerTable"/>
               <semantic:literalExpression>
                  <semantic:text>remove( Waiting List, 1 )</semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:variable name="Updated Reassigned Passengers List" typeRef="tPassengerTable"/>
               <semantic:literalExpression>
                  <semantic:text>append( Reassigned Passengers List, Reassigned Passenger )</semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
            <semantic:contextEntry>
               <semantic:literalExpression>
                  <semantic:text>if count( Remaining Waiting List ) &gt; 0 
                              then
                                   reassign next passenger( Remaining Waiting List,
                                                            Updated Reassigned Passengers List,
                                                            Flights )
                              else 
                                   Updated Reassigned Passengers List
                        </semantic:text>
               </semantic:literalExpression>
            </semantic:contextEntry>
         </semantic:context>
      </semantic:encapsulatedLogic>
      <semantic:knowledgeRequirement>
         <semantic:requiredKnowledge href="#b_HasCapacity"/>
      </semantic:knowledgeRequirement>
   </semantic:businessKnowledgeModel>
   <semantic:businessKnowledgeModel id="b_HasCapacity" name="has capacity">
      <semantic:variable name="has capacity" typeRef="boolean"/>
      <semantic:encapsulatedLogic>
         <semantic:formalParameter name="flight" typeRef="tFlight"/>
         <semantic:formalParameter name="rebooked list" typeRef="tPassengerTable"/>
         <semantic:literalExpression>
            <semantic:text> flight.Capacity &gt; count( rebooked list[ Flight Number = flight.Flight Number ] ) </semantic:text>
         </semantic:literalExpression>
      </semantic:encapsulatedLogic>
   </semantic:businessKnowledgeModel>
</semantic:definitions>
