1
/* Copyright (C) 2021 Nikolaj J. Ulrik <nikolaj@njulrik.dk>,
2
* Simon M. Virenfeldt <simon@simwir.dk>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "LTL/SuccessorGeneration/AutomatonHeuristic.h"
19
#include "LTL/Simplification/SpotToPQL.h"
21
#include <spot/twa/formula2bdd.hh>
22
#include <spot/tl/formula.hh>
26
AutomatonHeuristic::AutomatonHeuristic(const PetriEngine::PetriNet *net, const Structures::BuchiAutomaton &aut)
27
: _net(net), _aut(aut)
29
std::vector<AtomicProposition> aps(_aut.ap_info.size());
30
std::transform(std::begin(_aut.ap_info), std::end(_aut.ap_info), std::begin(aps),
31
[](const std::pair<int, AtomicProposition> &pair) { return pair.second; });
32
for (unsigned state = 0; state < _aut._buchi->num_states(); ++state) {
33
_state_guards.emplace_back(state, _aut._buchi->state_is_accepting(state));
34
for (auto &e : _aut._buchi->out(state)) {
35
auto formula = spot::bdd_to_formula(e.cond, _aut.dict);
37
_state_guards.back().retarding = toPQL(formula, aps);
39
_state_guards.back().progressing.push_back(toPQL(formula, aps));
42
if (!_state_guards.back().retarding) {
43
_state_guards.back().retarding = std::make_shared<BooleanCondition>(false);
48
bool AutomatonHeuristic::has_heuristic(const Structures::ProductState &state)
50
assert(state.getBuchiState() < _state_guards.size());
51
return !_state_guards[state.getBuchiState()].is_accepting;
54
uint32_t AutomatonHeuristic::eval(const Structures::ProductState &state, uint32_t)
56
assert(state.getBuchiState() < _state_guards.size());
57
const auto &guardInfo = _state_guards[state.getBuchiState()];
58
if (guardInfo.is_accepting) return 0;
59
uint32_t min_dist = std::numeric_limits<uint32_t>::max();
60
PetriEngine::PQL::DistanceContext context{_net, state.marking()};
61
for (const auto &condition : guardInfo.progressing) {
62
uint32_t dist = condition->distance(context);
63
if (dist < min_dist) min_dist = dist;
b'\\ No newline at end of file'