-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: add p05_api_example_ltlf_synthesis_maximally_permissive
- Loading branch information
1 parent
5347261
commit d26a1b2
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions
76
docs/api/p05_api_example_ltlf_synthesis_maximally_permissive.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# LTLf Synthesis with Maximally Permissive Strategy {#p05_api_example_ltlf_synthesis_maximally_permissive} | ||
|
||
In this example, we will show how to use the LydiaSyft C++ APIs to solve LTLf synthesis with maximally permissive strategies. | ||
|
||
The code for this example can be found in `examples/05_ltlf_synthesis_maximally_permissive/ltlf_synthesis.cpp`. | ||
To build this example, you can run `make ltlf_synthesis_maximally_permissive_example`. | ||
|
||
|
||
```cpp | ||
#include <filesystem> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <lydia/parser/ltlf/driver.hpp> | ||
|
||
#include "automata/SymbolicStateDfa.h" | ||
#include "Player.h" | ||
#include "VarMgr.h" | ||
#include "Utils.h" | ||
#include "Preprocessing.h" | ||
|
||
|
||
int main(int argc, char ** argv) { | ||
|
||
// parse TLSF file | ||
std::filesystem::path ROOT_DIRECTORY = __ROOT_DIRECTORY; | ||
std::filesystem::path tlsf_file_test = ROOT_DIRECTORY / "examples" / "test1.tlsf"; | ||
auto driver = std::make_shared<whitemech::lydia::parsers::ltlf::LTLfDriver>(); | ||
Syft::TLSFArgs args = Syft::parse_tlsf(driver, tlsf_file_test.string()); | ||
std::cout << "TLSF file parsed: " << tlsf_file_test.string() << std::endl; | ||
std::cout << "Starting Player: " << (args.protagonist_player == Syft::Player::Agent? "Agent" : "Environment") << std::endl; | ||
std::cout << "Protagonist Player: " << (args.starting_player == Syft::Player::Agent? "Agent" : "Environment") << std::endl; | ||
std::cout << "Input variables: "; | ||
for (const auto& var : args.partition.input_variables){ | ||
std::cout << var << ", "; | ||
} | ||
std::cout << std::endl; | ||
std::cout << "Output variables: "; | ||
for (const auto& var : args.partition.output_variables){ | ||
std::cout << var << ", "; | ||
} | ||
std::cout << std::endl; | ||
|
||
// build variable manager | ||
auto var_mgr = Syft::build_var_mgr(args.partition); | ||
|
||
std::cout << "Building DFA of the formula..." << std::endl; | ||
Syft::SymbolicStateDfa dfa = Syft::do_dfa_construction(*args.formula, var_mgr); | ||
|
||
std::cout << "Solving the DFA game (with maximally permissive strategies)..." << std::endl; | ||
var_mgr->partition_variables(args.partition.input_variables, args.partition.output_variables); | ||
|
||
Syft::LTLfMaxSetSynthesizer synthesizer(dfa, args.starting_player, | ||
args.protagonist_player, dfa.final_states(), | ||
var_mgr->cudd_mgr()->bddOne()); | ||
Syft::MaxSetSynthesisResult result = synthesizer.run(); | ||
if (result.realizability) { | ||
std::cout << "Specification is realizable!" << std::endl; | ||
std::cout << "Printing the (maximally permissive) strategy in DOT format..." << std::endl; | ||
var_mgr->dump_dot(result.deferring_strategy.Add(), "deferring_strategy.dot"); | ||
var_mgr->dump_dot(result.nondeferring_strategy.Add(), "nondeferring_strategy.dot"); | ||
} | ||
else { | ||
std::cout << "Specification is unrealizable!" << std::endl; | ||
} | ||
|
||
} | ||
``` | ||
The code is similar to the classical setting, except that: | ||
- the class `Syft::LTLfMaxSetSynthesizer` is used; | ||
- the result is an instance of the class `Syft::MaxSetSynthesisResult`; | ||
- we have two strategies: the _deferring_ strategy and the _nondeferring_ strategy | ||
The header file is named `synthesizer/LTLfMaxSetSynthesizer.h`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
examples/05_ltlf_synthesis_maximally_permissive/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_executable(ltlf_synthesis_maximally_permissive_example ltlf_synthesis_maximally_permissive.cpp) | ||
|
||
target_include_directories(ltlf_synthesis_maximally_permissive_example PRIVATE ${UTILS_INCLUDE_PATH} ${PARSER_INCLUDE_PATH} ${SYNTHESIS_INCLUDE_PATH} ${EXT_INCLUDE_PATH}) | ||
target_link_libraries(ltlf_synthesis_maximally_permissive_example ${PARSER_LIB_NAME} ${SYNTHESIS_LIB_NAME} ${UTILS_LIB_NAME} ${LYDIA_LIBRARIES}) |
59 changes: 59 additions & 0 deletions
59
examples/05_ltlf_synthesis_maximally_permissive/ltlf_synthesis_maximally_permissive.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <filesystem> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <lydia/parser/ltlf/driver.hpp> | ||
|
||
#include "automata/SymbolicStateDfa.h" | ||
#include "Player.h" | ||
#include "VarMgr.h" | ||
#include "Utils.h" | ||
#include "Preprocessing.h" | ||
|
||
|
||
int main(int argc, char ** argv) { | ||
|
||
// parse TLSF file | ||
std::filesystem::path ROOT_DIRECTORY = __ROOT_DIRECTORY; | ||
std::filesystem::path tlsf_file_test = ROOT_DIRECTORY / "examples" / "test1.tlsf"; | ||
auto driver = std::make_shared<whitemech::lydia::parsers::ltlf::LTLfDriver>(); | ||
Syft::TLSFArgs args = Syft::parse_tlsf(driver, tlsf_file_test.string()); | ||
std::cout << "TLSF file parsed: " << tlsf_file_test.string() << std::endl; | ||
std::cout << "Starting Player: " << (args.protagonist_player == Syft::Player::Agent? "Agent" : "Environment") << std::endl; | ||
std::cout << "Protagonist Player: " << (args.starting_player == Syft::Player::Agent? "Agent" : "Environment") << std::endl; | ||
std::cout << "Input variables: "; | ||
for (const auto& var : args.partition.input_variables){ | ||
std::cout << var << ", "; | ||
} | ||
std::cout << std::endl; | ||
std::cout << "Output variables: "; | ||
for (const auto& var : args.partition.output_variables){ | ||
std::cout << var << ", "; | ||
} | ||
std::cout << std::endl; | ||
|
||
// build variable manager | ||
auto var_mgr = Syft::build_var_mgr(args.partition); | ||
|
||
std::cout << "Building DFA of the formula..." << std::endl; | ||
Syft::SymbolicStateDfa dfa = Syft::do_dfa_construction(*args.formula, var_mgr); | ||
|
||
std::cout << "Solving the DFA game (with maximally permissive strategies)..." << std::endl; | ||
var_mgr->partition_variables(args.partition.input_variables, args.partition.output_variables); | ||
|
||
Syft::LTLfMaxSetSynthesizer synthesizer(dfa, args.starting_player, | ||
args.protagonist_player, dfa.final_states(), | ||
var_mgr->cudd_mgr()->bddOne()); | ||
Syft::MaxSetSynthesisResult result = synthesizer.run(); | ||
if (result.realizability) { | ||
std::cout << "Specification is realizable!" << std::endl; | ||
std::cout << "Printing the (maximally permissive) strategy in DOT format..." << std::endl; | ||
var_mgr->dump_dot(result.deferring_strategy.Add(), "deferring_strategy.dot"); | ||
var_mgr->dump_dot(result.nondeferring_strategy.Add(), "nondeferring_strategy.dot"); | ||
} | ||
else { | ||
std::cout << "Specification is unrealizable!" << std::endl; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters