% File "plan": Parallelizes plans for different RCSs
% First Release date: 10/15/00
%
% $Name:  $

%%%%%%%%%%%%%%%%%%%%    Planning Module    %%%%%%%%%%%%%%%%%%%%% 
% 
% This module establishes the search criteria used by the program 
% to find a plan, or, sequence of actions that if executed would  
% achieve the goal situation. 
%    
% The following rule expresses one possible search criteria. It 
% can be read as: "do exactly one action at each moment of time  
% until the goal is reached." 
% It also prohibits an action to occur on the last moment of time  
% because the effects of such action would be lost. Only results  
% achieved inside the time limits established for the computation  
% are considered. 

% action_of(A,R) is true iff action A is performed on switches
%                and commands from the RCS R system. 

action_of(flip(Sw,S),R) :- of_type(Sw,R,v_switch), 
                           state_of(S,v_switch).

action_of(CC,R) :- commands(CC,V,S),
                   of_type(V,R,valve),
                   not bad_circuitry(V).
                  
action_of(CC,R) :- basic_command(CC,V,S),
                   of_type(V,R,valve),
                   bad_circuitry(V).                   
                   
action_of(CC,R) :- commands(cc(CC,CC1),V,S),
                   of_type(V,R,valve),
                   type_cc(CC),
                   type_cc(CC1),
                   neq(CC,CC1),
                   bad_circuitry(V).
                   
action_of(CC,R) :- commands(cc(CC1,CC),V,S),
                   of_type(V,R,valve),
                   type_cc(CC),
                   type_cc(CC1),
                   neq(CC,CC1),
                   bad_circuitry(V).               
 
                                     

1{occurs(A,T):action_of(A,R)}1 :- time(T),                         
                                  T < lasttime,
                                  system(R),
                                  not goal(T,R),
                                  not done(R).    


%%%%% For Typing Purposes only

type_cc(closea_fi12).
type_cc(closeb_ffi12).
type_cc(closeb_foi12).

type_cc(closea_li12).
type_cc(closeb_lfi12).
type_cc(closeb_loi12).

type_cc(close_lx12).
type_cc(close_lfx12).
type_cc(close_lox12).

type_cc(closea_ri12).
type_cc(closeb_rfi12).
type_cc(closeb_roi12).

type_cc(close_rx12).
type_cc(close_rfx12).
type_cc(close_rox12).

type_cc(opena_ffm5).
type_cc(openb_ffm5).
type_cc(opena_lfm5).
type_cc(openb_lfm5).
type_cc(opena_rfm5).
type_cc(openb_rfm5).

type_cc(closea_ffm5).
type_cc(closeb_ffm5).
type_cc(closea_lfm5).
type_cc(closeb_lfm5).
type_cc(closea_rfm5).
type_cc(closeb_rfm5).

    


%%%%%%%%%%%%%%%%%%%%%%%%     Goal     %%%%%%%%%%%%%%%%%%%%%%%%%% 
 
goal :- time(T1),
        time(T2),
        time(T3), 
        goal(T1,left_rcs),
        goal(T2,right_rcs),
        goal(T3,fwd_rcs).

goal(T,S) :- time(T), done(S).

:- not goal.




%%%%%%%%%%%%%%%%%%%%%%%%   End: Goal   %%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%             Facts                %%%%%%%%%%%%%%%%%

% of_type(D,R,Dev) is true iff device D from RCS R is of type Dev. 

% Switches

of_type(fha,fwd_rcs,v_switch).       % fha   = forward helium a 
of_type(fhb,fwd_rcs,v_switch).       % fhb   = forward helium b 
of_type(fi12,fwd_rcs,v_switch).      % fi12  = forward isolation 12 
of_type(fi345,fwd_rcs,v_switch).     % fi345 = forward isolation 345 
of_type(fm1,fwd_rcs,v_switch).       % fm1   = forward manifold 1 
of_type(fm2,fwd_rcs,v_switch).       % fm2   = forward manifold 2 
of_type(fm3,fwd_rcs,v_switch).       % fm3   = forward manifold 3 
of_type(fm4,fwd_rcs,v_switch).       % fm4   = forward manifold 4 
of_type(fm5,fwd_rcs,v_switch).       % fm5   = forward manifold 5 

of_type(lha,left_rcs,v_switch).      % lha   = left helium a 
of_type(lhb,left_rcs,v_switch).      % lhb   = left helium b 
of_type(li12,left_rcs,v_switch).     % li12  = left isolation 12 
of_type(li345a,left_rcs,v_switch).   % li345a= left isolation 345a 
of_type(li345b,left_rcs,v_switch).   % li345b= left isolation 345b 
of_type(lm1,left_rcs,v_switch).      % lm1   = left manifold 1 
of_type(lm2,left_rcs,v_switch).      % lm2   = left manifold 2 
of_type(lm3,left_rcs,v_switch).      % lm3   = left manifold 3 
of_type(lm4,left_rcs,v_switch).      % lm4   = left manifold 4 
of_type(lm5,left_rcs,v_switch).      % lm5   = left manifold 5 
of_type(lx12,left_rcs,v_switch).     % lx12  = left cross-feed isolation 12  
of_type(lx345,left_rcs,v_switch).    % lx345 = left cross-feed isolation 345  

of_type(rha,right_rcs,v_switch).     % rha   = right helium a 
of_type(rhb,right_rcs,v_switch).     % rhb   = right helium b 
of_type(ri12,right_rcs,v_switch).    % ri12  = right isolation 12 
of_type(ri345a,right_rcs,v_switch).  % ri345a= right isolation 345a 
of_type(ri345b,right_rcs,v_switch).  % ri345b= right isolation 345b 
of_type(rm1,right_rcs,v_switch).     % rm1   = right manifold 1 
of_type(rm2,right_rcs,v_switch).     % rm2   = right manifold 2 
of_type(rm3,right_rcs,v_switch).     % rm3   = right manifold 3 
of_type(rm4,right_rcs,v_switch).     % rm4   = right manifold 4 
of_type(rm5,right_rcs,v_switch).     % rm5   = right manifold 5 
of_type(rx12,right_rcs,v_switch).    % rx12  = right cross-feed isolation 12  
of_type(rx345,right_rcs,v_switch).   % rx345 = right cross-feed isolation 345 
 
% Valves
 
of_type(ffha,fwd_rcs,valve). 
of_type(foha,fwd_rcs,valve).
of_type(ffhb,fwd_rcs,valve).
of_type(fohb,fwd_rcs,valve).
of_type(ffi12,fwd_rcs,valve).
of_type(foi12,fwd_rcs,valve).
of_type(ffi345,fwd_rcs,valve).
of_type(foi345,fwd_rcs,valve).
of_type(ffm1,fwd_rcs,valve).
of_type(fom1,fwd_rcs,valve).
of_type(ffm2,fwd_rcs,valve).
of_type(fom2,fwd_rcs,valve).
of_type(ffm3,fwd_rcs,valve).
of_type(fom3,fwd_rcs,valve).
of_type(ffm4,fwd_rcs,valve).
of_type(fom4,fwd_rcs,valve).
of_type(ffm5,fwd_rcs,valve).
of_type(fom5,fwd_rcs,valve).

of_type(lfha,left_rcs,valve). 
of_type(loha,left_rcs,valve).
of_type(lfhb,left_rcs,valve).
of_type(lohb,left_rcs,valve).
of_type(lfi12,left_rcs,valve).
of_type(loi12,left_rcs,valve).
of_type(lfi345a,left_rcs,valve).
of_type(loi345a,left_rcs,valve).
of_type(lfi345b,left_rcs,valve).
of_type(loi345b,left_rcs,valve).
of_type(lfm1,left_rcs,valve).
of_type(lom1,left_rcs,valve).
of_type(lfm2,left_rcs,valve).
of_type(lom2,left_rcs,valve).
of_type(lfm3,left_rcs,valve).
of_type(lom3,left_rcs,valve).
of_type(lfm4,left_rcs,valve).
of_type(lom4,left_rcs,valve).
of_type(lfm5,left_rcs,valve).
of_type(lom5,left_rcs,valve).
of_type(lfx12,left_rcs,valve).
of_type(lox12,left_rcs,valve).
of_type(lfx345,left_rcs,valve).
of_type(lox345,left_rcs,valve).

of_type(rfha,right_rcs,valve). 
of_type(roha,right_rcs,valve).
of_type(rfhb,right_rcs,valve).
of_type(rohb,right_rcs,valve).
of_type(rfi12,right_rcs,valve).
of_type(roi12,right_rcs,valve).
of_type(rfi345a,right_rcs,valve).
of_type(roi345a,right_rcs,valve).
of_type(rfi345b,right_rcs,valve).
of_type(roi345b,right_rcs,valve).
of_type(rfm1,right_rcs,valve).
of_type(rom1,right_rcs,valve).
of_type(rfm2,right_rcs,valve).
of_type(rom2,right_rcs,valve).
of_type(rfm3,right_rcs,valve).
of_type(rom3,right_rcs,valve).
of_type(rfm4,right_rcs,valve).
of_type(rom4,right_rcs,valve).
of_type(rfm5,right_rcs,valve).
of_type(rom5,right_rcs,valve).
of_type(rfx12,right_rcs,valve).
of_type(rox12,right_rcs,valve).
of_type(rfx345,right_rcs,valve).
of_type(rox345,right_rcs,valve).


of_type(V,R,valve) :- dummy_valve(V,R).


% Dummy valves have been added between fuel/oxidizer tanks
% and the following junction node in order to correctly
% determine when the junction node is leaking.
 
dummy_valve(ffdummy,fwd_rcs).
dummy_valve(fodummy,fwd_rcs).
dummy_valve(lfdummy,left_rcs).
dummy_valve(lodummy,left_rcs).
dummy_valve(rfdummy,right_rcs).
dummy_valve(rodummy,right_rcs).



 
%%%%%%%%%%%%%%%%%%%%%%%%   End: Control Module   %%%%%%%%%%%%%%%%%%%%%%%%% 

hide dummy_valve(X,Y).
hide action_of(X,Y).
hide of_type(X,Y,Z).
hide command_between(X,Y,Z). 
hide issued_commands(X,Y). 
hide prev(X,Y). 
hide open_prev(X,Y). 
hide perf(X,Y).
hide type_cc(X).
hide is_pressurized_by(X,Y). 
