LydiaSyft
base.hpp
1 //
2 // Created by marcofavorito on 23/01/24.
3 //
4 
5 #ifndef LYDIASYFT_CLI_BASE_HPP
6 #define LYDIASYFT_CLI_BASE_HPP
7 
8 #include <optional>
9 #include <string>
10 #include <CLI/CLI.hpp>
11 #include "lydia/types.hpp"
12 #include "lydia/parser/ltlf/driver.hpp"
13 #include "Player.h"
14 #include "VarMgr.h"
15 #include "game/InputOutputPartition.h"
16 #include "game/Transducer.h"
17 #include "Stopwatch.h"
18 #include "Synthesizer.h"
19 #include "synthesizer/LTLfMaxSetSynthesizer.h"
20 #include "Utils.h"
21 
22 
23 namespace Syft {
24 
25  class Printer {
26  private:
27  const bool print_strategy_;
28  const bool print_times_;
29 
30  // for output messages
31  std::ostream &out_;
32 
33  public:
34  Printer(bool print_strategy, bool print_times, std::ostream &out) :
35  print_strategy_(print_strategy), print_times_(print_times), out_(out) {}
36 
37  void
38  dump_transducer_if_enabled(const Transducer &transducer, const std::string &output_file = "strategy.dot") const;
39 
40  void dump_add_if_enabled(const std::shared_ptr<VarMgr> &var_mgr, const CUDD::ADD &add,
41  const std::string &output_file) const;
42 
43  void
44  dump_maxset_if_enabled(const LTLfMaxSetSynthesizer &maxset_synthesizer,
45  const MaxSetSynthesisResult &maxset_strategy,
46  const std::string &def_strategy_output_file = "def_strategy.dot",
47  const std::string &nondef_strategy_output_file = "nondef_strategy.dot") const;
48 
49  void print_times_if_enabled(const std::string &message, std::chrono::milliseconds time) const;
50 
51  void print_realizable() const { out_ << Syft::REALIZABLE_STR << std::endl; }
52 
53  void print_unrealizable() const { out_ << Syft::UNREALIZABLE_STR << std::endl; }
54 
55  };
56 
57 
58  void add_assumption_file_option(CLI::App *, std::string &);
59 
60  void add_gr1_file_option(CLI::App *, std::string &);
61 
62  void add_env_safety_file_option(CLI::App *, std::optional<std::string> &);
63 
64  void add_agent_safety_file_option(CLI::App *, std::optional<std::string> &);
65 
66  void add_spec_file_option(CLI::App *, std::string &);
67 
68  void add_syfco_option(CLI::App *, std::optional<std::string> &);
69 
70  void add_slugs_option(CLI::App *, std::string &);
71 
75  class BaseRunner {
76  protected:
77  const std::string formula_file_;
78  const std::string path_to_syfco_;
79 
80  const TLSFArgs args_;
81  const std::shared_ptr<Syft::VarMgr> var_mgr_;
82 
83  const Printer printer_;
84 
85  std::shared_ptr<whitemech::lydia::parsers::ltlf::LTLfDriver> driver_;
86 
87  bool handle_preprocessing_result_(const OneStepSynthesisResult &one_step_result,
88  Stopwatch &total_time_stopwatch) const;
89 
90  void handle_synthesis_result_(const DfaGameSynthesizer &synthesizer, const SynthesisResult &result) const;
91 
92  void handle_synthesis_result_(const SynthesisResult &result) const;
93 
94  SymbolicStateDfa do_dfa_construction_() const;
95 
96  public:
97  BaseRunner(const std::shared_ptr<whitemech::lydia::parsers::ltlf::LTLfDriver> &driver,
98  const std::string &formula_file, const std::string &path_to_syfco, bool print_strategy,
99  bool print_times) :
100  driver_(driver),
101  formula_file_(formula_file), path_to_syfco_(path_to_syfco),
102  printer_(print_strategy, print_times, std::cout),
103  args_(parse_tlsf(driver, formula_file, path_to_syfco)),
104  var_mgr_(build_var_mgr(args_.partition)) {}
105  };
106 
107 }
108 
109 #endif //LYDIASYFT_CLI_BASE_HPP
Base class for running a synthesis algorithm.
Definition: base.hpp:75
A synthesizer for a game whose arena is a symbolic-state DFA.
Definition: DfaGameSynthesizer.h:15
A maxset-synthesizer for a reachability game given as a symbolic-state DFA.
Definition: LTLfMaxSetSynthesizer.h:19
Definition: base.hpp:25
Stopwatch for timing executions.
Definition: Stopwatch.h:11
A DFA with symbolic states and transitions.
Definition: SymbolicStateDfa.h:18
A symbolic tranducer representing a winning strategy for a game.
Definition: Transducer.h:20
Definition: Synthesizer.h:24
Definition: Synthesizer.h:30
Definition: Synthesizer.h:16
Definition: Utils.h:25