hoa: add support for controllable-AP

* doc/spot.bib (perez.19.hoa): New entry.
* spot/parseaut/public.hh: Mention it.
* spot/parseaut/parseaut.yy, spot/parseaut/scanaut.ll: Learn to parse
the controllable-AP header.
* spot/twaalgos/hoa.cc: Print it.
* tests/core/ltlsynt.test, tests/core/parseaut.test,
tests/core/readsave.test, tests/python/_synthesis.ipynb,
tests/python/except.py, tests/python/games.ipynb,
tests/python/mealy.py, tests/python/synthesis.py: Adjust or augment
test cases.
This commit is contained in:
Alexandre Duret-Lutz 2022-01-03 18:04:29 +01:00
parent 7cefe30d97
commit 8c33f959a3
14 changed files with 134 additions and 15 deletions

View file

@ -1,5 +1,5 @@
/* -*- coding: utf-8 -*-
** Copyright (C) 2014-2021 Laboratoire de Recherche et Développement
** Copyright (C) 2014-2022 Laboratoire de Recherche et Développement
** de l'Epita (LRDE).
**
** This file is part of Spot, a model checking library.
@ -97,6 +97,10 @@ extern "C" int strverscmp(const char *s1, const char *s2);
named_tgba_t* namer = nullptr;
spot::acc_mapper_int* acc_mapper = nullptr;
std::vector<int> ap;
std::vector<int> controllable_ap;
bool has_controllable_ap = false;
std::vector<spot::location> controllable_ap_loc;
spot::location controllable_aps_loc;
std::vector<bdd> guards;
std::vector<bdd>::const_iterator cur_guard;
// If "Alias: ..." occurs before "AP: ..." in the HOA format we
@ -233,6 +237,7 @@ extern "C" int strverscmp(const char *s1, const char *s2);
%token ALIAS "Alias:"
%token ACCEPTANCE "Acceptance:"
%token ACCNAME "acc-name:"
%token CONTROLLABLE_AP "controllable-AP:"
%token TOOL "tool:"
%token NAME "name:"
%token PROPERTIES "properties:"
@ -404,6 +409,37 @@ header: format-version header-items
for (auto& p: res.alias)
p.second = bddtrue;
}
if (res.has_controllable_ap)
{
if (!res.ignore_more_ap && !res.controllable_ap.empty())
{
error(res.controllable_aps_loc,
"controllable-AP without AP declaration");
}
else
{
bdd cont = bddtrue;
unsigned n = res.controllable_ap.size();
unsigned maxap = res.ap.size();
for (unsigned i = 0; i < n; ++i)
{
unsigned c = res.controllable_ap[i];
if (c >= maxap)
{
error(res.controllable_ap_loc[i],
"controllable AP number is larger than"
" the number of APs...");
error(res.ap_loc, "... declared here.");
}
else
{
cont &= bdd_ithvar(res.ap[c]);
}
}
res.aut_or_ks->set_named_prop("synthesis-outputs",
new bdd(cont));
}
}
// Process properties.
{
auto explicit_labels = res.prop_is_true("explicit-labels");
@ -683,6 +719,13 @@ version: IDENTIFIER
format-version: "HOA:" { res.h->loc = @1; } version
controllable-aps: %empty
| controllable-aps INT
{
res.controllable_ap.push_back($2);
res.controllable_ap_loc.push_back(@2);
}
aps: "AP:" INT
{
if (res.ignore_more_ap)
@ -766,6 +809,11 @@ header-item: "States:" INT
res.start.emplace_back(@$, std::vector<unsigned>{$2});
}
| aps
| "controllable-AP:" controllable-aps
{
res.controllable_aps_loc = @1;
res.has_controllable_ap = true;
}
| "Alias:" ANAME { res.in_alias=true; } label-expr
{
res.in_alias = false;

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014, 2015, 2016, 2017 Laboratoire de Recherche et
// Copyright (C) 2013, 2014, 2015, 2016, 2017, 2022 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -117,6 +117,12 @@ namespace spot
/// tool that produce Büchi automata in the form of a neverclaim,
/// but is not understood by this parser, please report it to
/// spot@lrde.epita.fr.
///
/// The parser for HOA recognize a few extensions. It maps the
/// `controlled-AP:` header \cite perez.19.hoa to the
/// `synthesis-output` property of Spot. It also maps
/// `spot.highlight.edges:`, `spot.highlight.states:`, and
/// `spot.state-player:` to the associated automata properties.
class SPOT_API automaton_stream_parser final
{
spot::location last_loc;

View file

@ -1,5 +1,5 @@
/* -*- coding: utf-8 -*-
** Copyright (C) 2014-2018, 2020, 2021 Laboratoire de Recherche et Développement
** Copyright (C) 2014-2018, 2020, 2021, 2022 Laboratoire de Recherche et Développement
** de l'Epita (LRDE).
**
** This file is part of Spot, a model checking library.
@ -145,6 +145,7 @@ identifier [[:alpha:]_][[:alnum:]_.-]*
"Alias:" return token::ALIAS;
"Acceptance:" return token::ACCEPTANCE;
"acc-name:" return token::ACCNAME;
"controllable-AP:" return token::CONTROLLABLE_AP;
"tool:" return token::TOOL;
"name:" return token::NAME;
"properties:" return token::PROPERTIES;

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014-2021 Laboratoire de Recherche et
// Copyright (C) 2014-2022 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -627,6 +627,22 @@ namespace spot
}
os << nl;
}
if (auto synout = aut->get_named_prop<bdd>("synthesis-outputs"))
{
bdd vars = bdd_support(*synout);
os << "controllable-AP:";
while (vars != bddtrue)
{
int v = bdd_var(vars);
vars = bdd_high(vars);
if (auto p = md.ap.find(v); p != md.ap.end())
os << ' ' << p->second;
else
throw std::runtime_error("print_hoa(): synthesis-outputs has "
"unregistered proposition");
}
os << nl;
}
// If we want to output implicit labels, we have to
// fill a vector with all destinations in order.