-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregular.cpp
More file actions
47 lines (44 loc) · 1.46 KB
/
regular.cpp
File metadata and controls
47 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* mini-cp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3
* as published by the Free Software Foundation.
*
* mini-cp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mini-cp. If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
*
* Copyright (c) 2018. by Laurent Michel, Pierre Schaus, Pascal Van Hentenryck
*/
#include "regular.hpp"
#include "constraint.hpp"
#include "table.hpp"
std::vector<std::vector<int>> Automaton::transition() const
{
std::vector<std::vector<int>> table(_t.size());
int row = 0;
for(const auto& t : _t) {
table[row++] = std::vector<int> {t.from, t.symbol, t.to};
}
return table;
}
void Regular::post()
{
auto cp = _A->getSolver();
auto states = _A->getStates();
auto finals = _A->getFinals();
int start = _A->getStart();
int lb = 0,ub = _x.size();
Factory::Veci q = Factory::intVarArray(cp,ub - lb + 1, states.first(),states.to());
auto tr = _A->transition();
var<int>::Ptr first = q[0];
using namespace Factory;
cp->post(first == start);
for(int k=0;k < ub;k++)
cp->post(table(std::vector<var<int>::Ptr> {q[k],_x[k],q[k+1]},tr));
for(auto s : states)
if (finals.find(s) == finals.end())
cp->post(q[ub] != s);
}