~tapaal-ltl/verifypn/fire-count-heuristic

« back to all changes in this revision

Viewing changes to src/LTL/SuccessorGeneration/AutomatonHeuristic.cpp

  • Committer: Nikolaj Jensen Ulrik
  • Date: 2021-03-24 07:31:53 UTC
  • Revision ID: nikolaj@njulrik.dk-20210324073153-5b3dr8bey6ik9psb
WIP Büchi guided search

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2021  Nikolaj J. Ulrik <nikolaj@njulrik.dk>,
 
2
 *                     Simon M. Virenfeldt <simon@simwir.dk>
 
3
 * 
 
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.
 
8
 * 
 
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.
 
13
 * 
 
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/>.
 
16
 */
 
17
 
 
18
#include "LTL/SuccessorGeneration/AutomatonHeuristic.h"
 
19
#include "LTL/Simplification/SpotToPQL.h"
 
20
 
 
21
#include <spot/twa/formula2bdd.hh>
 
22
#include <spot/tl/formula.hh>
 
23
 
 
24
 
 
25
namespace LTL {
 
26
    AutomatonHeuristic::AutomatonHeuristic(const PetriEngine::PetriNet *net, const Structures::BuchiAutomaton &aut)
 
27
            : _net(net), _aut(aut)
 
28
    {
 
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);
 
36
                if (e.dst == state) {
 
37
                    _state_guards.back().retarding = toPQL(formula, aps);
 
38
                } else {
 
39
                    _state_guards.back().progressing.push_back(toPQL(formula, aps));
 
40
                }
 
41
            }
 
42
            if (!_state_guards.back().retarding) {
 
43
                _state_guards.back().retarding = std::make_shared<BooleanCondition>(false);
 
44
            }
 
45
        }
 
46
    }
 
47
 
 
48
    bool AutomatonHeuristic::has_heuristic(const Structures::ProductState &state)
 
49
    {
 
50
        assert(state.getBuchiState() < _state_guards.size());
 
51
        return !_state_guards[state.getBuchiState()].is_accepting;
 
52
    }
 
53
 
 
54
    uint32_t AutomatonHeuristic::eval(const Structures::ProductState &state, uint32_t)
 
55
    {
 
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;
 
64
        }
 
65
        return min_dist;
 
66
    }
 
67
}
 
 
b'\\ No newline at end of file'