graph_process_manager_core/process/
config.rs

1/*
2Copyright 2020 Erwan Mahe (github.com/erwanM974)
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17
18use std::hash::Hash;
19
20use crate::queue::priorities::AbstractPriorities;
21
22use super::{handler::AbstractAlgorithmOperationHandler, persistent_state::AbstractProcessMutablePersistentState};
23
24
25
26/** 
27 * Configuration of an abstract process that performs a certain computation.
28 * This can be, for instance:
29 * - a term rewrite system
30 * - a runtime verification algorithm
31 * - ...
32 * 
33 * The main thing in common with the kinds of processes that can be modelled this way is
34 * that they can be represented as a search in a graph structure 
35 * (which may be finite or not, and which is not known in advance).
36 * 
37 * The graph structure is not known in advance. At the start of the process, we only know of a single node which is the initial node.
38 * From any given node, a number of distinct possible steps may be taken.
39 * Each such step may yield to the discovery of a new node.
40 * Thus, the graph structure is explored.
41 * 
42 * The overall process is characterized by:
43 * - the problem which it tries to solve, this problem being represented by:
44 *   + a "Context"
45 *   + and the initial node of the graph from which the search starts
46 * - the algorithm that solves this problem, this algorithm being represented by:
47 *   + a "Parameterization" which allows encoding variants of that algorithm without code duplication
48 *   + an "AlgorithmOperationHandler" that is tasked with performing the following operations:
49 *     * compute a child node from the evaluation of a step from a parent node
50 *     * collect all possible next steps that could be taken after reaching a given node
51 *     * etc
52 *     * see [AbstractAlgorithmOperationHandler](AbstractAlgorithmOperationHandler) for details
53 * 
54 * Because the "Context" and "Parameterization" are often entertwined in practice, we represent
55 * them together in the "ContextAndParameterization" associated type.
56 * 
57 * Both nodes and steps carry domain-specific information.
58 * This information is encoded via the associate types:
59 * - "DomainSpecificNode"
60 * - "DomainSpecificStep"
61 * 
62 * Priorities in the order of evaluations of the steps that may be taken from the same node
63 * can be configured via the "Priorities" associated type.
64 * 
65 * The process has a global state that may evolve as the graph structure is evolved.
66 * This is represented by the "MutablePersistentState" associated type.
67 * 
68 * We consider three kinds of filters:
69 * - NodesPreFilters, which evaluate newly encountered nodes
70 * - NodesPostFilters, which evalute the set of steps that may be taken from a newly encountered node
71 * - StepsFilters, which evalute individual steps
72 * 
73 * Any of these filters may be used to stop/prevent/preempt the exploration of parts of the graph structure.
74 * These filters return an Option<FiltrationResult>:
75 * - if is is None, then the node or step is evaluated normally
76 * - if is is Some(x), then the process do not explore the successors of the filtered node/step
77 *   and x is further used to change the global state and notify loggers
78 * **/
79pub trait AbstractProcessConfiguration : Sized {
80    // ***
81    type ContextAndParameterization;
82    type AlgorithmOperationHandler : AbstractAlgorithmOperationHandler<Self>;
83    // ***
84    type DomainSpecificNode : AbstractNodeKind;
85    type DomainSpecificStep;
86    type Priorities : AbstractPriorities<Self::DomainSpecificStep>;
87    // ***
88    type MutablePersistentState : AbstractProcessMutablePersistentState<Self>;
89    // ***
90    type FiltrationResult;
91    // ***
92}
93
94
95
96pub trait AbstractNodeKind : Sized + Clone + PartialEq + Eq + Hash {
97
98    fn is_included_for_memoization(&self, memoized_node : &Self) -> bool;
99
100}