Skip to content

Commit

Permalink
Fix bug for prestar on weighted PDA.
Browse files Browse the repository at this point in the history
Reorder rule


reorder
  • Loading branch information
MortenSchou committed Mar 23, 2020
1 parent 34c75d7 commit 481c16e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/pdaaal/PDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ namespace pdaaal {
template<typename W, typename C>
struct rule_t<W, C, std::enable_if_t<!is_weighted<W>>> {
size_t _to = 0;
op_t _operation = NOOP;
uint32_t _op_label = uint32_t{};
op_t _operation = PUSH;
uint32_t _op_label = 0;
labels_t _labels;
bool operator<(const rule_t<W,C>& other) const {
if (_to != other._to)
Expand All @@ -108,9 +108,9 @@ namespace pdaaal {
template<typename W, typename C>
struct rule_t<W, C, std::enable_if_t<is_weighted<W>>> {
size_t _to = 0;
op_t _operation = NOOP;
W _weight;
uint32_t _op_label = uint32_t{};
op_t _operation = PUSH;
W _weight = zero<W>()();
uint32_t _op_label = 0;
labels_t _labels;
bool operator<(const rule_t<W,C>& other) const {
if (_to != other._to)
Expand Down
2 changes: 1 addition & 1 deletion src/pdaaal/Solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace pdaaal {
if (t._from >= n_pda_states) { continue; }
for (auto pre_state : pda_states[t._from]._pre_states) {
const auto &rules = pda_states[pre_state]._rules;
rule_t<W,C> dummy_rule{t._from, PUSH, 0}; // PUSH and 0 are the smallest w.r.t. PDA::rule_t::operator<
rule_t<W,C> dummy_rule{t._from};
auto lb = std::lower_bound(rules.begin(), rules.end(), dummy_rule);
while (lb != rules.end() && lb->_to == t._from) {
auto &rule = *lb;
Expand Down
13 changes: 7 additions & 6 deletions test/PAutomaton_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ BOOST_AUTO_TEST_CASE(WeightedPreStar)
// This is pretty much the rules from the example in Figure 3.1 (Schwoon-php02)
// However r_2 requires a swap and a push, which is done through auxiliary state 3.
std::unordered_set<char> labels{'A', 'B', 'C'};
TypedPDA<char, int> pda(labels);
pda.add_rule(0, 1, PUSH, 'B', false, 'A', 1);
pda.add_rule(0, 0, POP , '*', false, 'B', 1);
pda.add_rule(1, 3, SWAP, 'A', false, 'B', 1);
pda.add_rule(2, 0, SWAP, 'B', false, 'C', 1);
pda.add_rule(3, 2, PUSH, 'C', false, 'A', 1);
TypedPDA<char, std::vector<int>> pda(labels);
std::vector<int> w{1};
pda.add_rule(0, 1, PUSH, 'B', false, 'A', w);
pda.add_rule(0, 0, POP , '*', false, 'B', w);
pda.add_rule(1, 3, SWAP, 'A', false, 'B', w);
pda.add_rule(2, 0, SWAP, 'B', false, 'C', w);
pda.add_rule(3, 2, PUSH, 'C', false, 'A', w);

std::vector<char> init_stack{'A', 'A'};
PAutomaton automaton(pda, 0, pda.encode_pre(init_stack));
Expand Down

0 comments on commit 481c16e

Please sign in to comment.