Design · Rule-Based Behavior Graph Abstraction

Sep 4, 2023 | Tech Software

Graph : public Node

  • properties
    • name
    • type
    • enabled
  • states
    • current iteration
    • total iteration
    • time
    • terminated
  • <Node*>
  • <Var*>
    • scope: graph, nodes
    • category: tool, AI, device, robot, peripheral
Requirements
  • start (only 1), end (automatic if a node has no next), transit, branch, merge, loop, subgraph
  • can find from a lookup table any variable in the graph

Canvas : public Graph

  • <Var*>
    • scope: graph, subgraphs, nodes
        %% https://github.com/JakeSteam/Mermaid
        graph LR

        Start((Start)):::start --> N0
        classDef start fill:#ffd8a7, color:#000, stroke:#919191

        N0 --> N1 --> | branch | N2
        N1 --> N3
        N2 --> | merge | N4
        N3 --> N4 --> N5

        N5 --> N6 --> N7 --> | loop | N5
        N7 --> Subgraph

        subgraph Subgraph[N8 - Subgraph]
        S-Start((Start)):::start --> S-N1 --> S-N2
        end

        Subgraph --> N9 & N10
        N10 --> N11 --> Parallel --> N13

        subgraph Parallel[N12 - Parallel]
        P-N1([P-N1]) -.- P-N2([P-N2])
        end

    

Node

  • properties
    • name
    • type
    • enabled
  • states
    • time
    • terminated
  • variables
    • <Input Var>
    • <State Var>
    • <Output Var>
  • <Transition>
    • target
    • Condition*
    • <Expression*>
      • Var = Operate(TYPE, Var, ...)
      • var = Operate(ASSIGN, var1)
      • var = Operate(ADD, var1, var2)
      • var = Operate(MULTIPLY, var1, var2, var3, ...)
      • ...
  • Controller
    • <Task*>
      • goals, constraints, specifications from <Input Var> or other <Var>
  • functions
    • OnStart()
      • update Controller
      • update <Input Var>
    • OnRunning()
      • update Controller
      • update <State Var>
      • check <Transition>
    • OnFinish()
      • update Controller
      • update <Output Var>
      • evaluate <Expression>
namespace utility {

enum class Type {
    kEqual,
    kLess, kGreater,
    kLessOrEqual, kGreaterOrEqual,
    kAnd, kOr,
};

} // namespace utility

class Condition
{
public:
    virtual bool Triggered() = 0;
    Type type_;
    Var* left_var_, right_var_;
};

class ConditionEqual : public Condition {};
class ConditionLess : public Condition {};
class ConditionGreater : public Condition {};
class ConditionLessOrEqual : public Condition {};
class ConditionGreaterOrEqual : public Condition {};

class ConditionNested : public Condition
{
public:
    // https://en.cppreference.com/w/cpp/language/abstract_class
    virtual bool Triggered() override = 0;
protected:
    std::vector<Condition*> conditions_;
};

class ConditionAnd : public ConditionNested {};
class ConditionOr : public ConditionNested {};