for (int i = 0; i < n; i++) {
vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
}
IntVar cost = VariableFactory.bounded("z", 10, 10, solver);
CostAutomaton auto = new CostAutomaton();
int start = auto.addState();
int end = auto.addState();
auto.setInitialState(start);
auto.setFinal(start);
auto.setFinal(end);
auto.addTransition(start, start, 0, 1);
auto.addTransition(start, end, 2);
auto.addTransition(end, start, 2);
auto.addTransition(end, start, 0, 1);
int[][][] costs = new int[n][3][2];
for (int i = 0; i < costs.length; i++) {
for (int k = 0; k < 2; k++) {
costs[i][0][k] = 1;
costs[i][1][k] = 1;
}
}
auto.addCounter(new CounterState(costs, 10, 10));
solver.post(IntConstraintFactory.cost_regular(vars, cost, auto));
solver.set(IntStrategyFactory.lexico_LB(vars));
solver.findAllSolutions();