Package solver.constraints.nary.automata.FA

Examples of solver.constraints.nary.automata.FA.FiniteAutomaton


    @Test(groups = "1s")
    public void testcost_regular() {
        Solver solver = new Solver();
        IntVar[] VARS = VF.enumeratedArray("VARS", 5, 0, 2, solver);
        IntVar COST = VF.enumerated("COST", 0, 10, solver);
        FiniteAutomaton fauto = new FiniteAutomaton();
        int start = fauto.addState();
        int end = fauto.addState();
        fauto.setInitialState(start);
        fauto.setFinal(start, end);

        fauto.addTransition(start, start, 0, 1);
        fauto.addTransition(start, end, 2);

        fauto.addTransition(end, end, 1);
        fauto.addTransition(end, start, 0, 2);

        int[][] costs = new int[5][3];
        costs[0] = new int[]{1, 2, 3};
        costs[1] = new int[]{2, 3, 1};
        costs[2] = new int[]{3, 1, 2};
View Full Code Here


    @Test(groups = "1s")
    public void testmulticost_regular() {
        Solver solver = new Solver();
        IntVar[] VARS = VF.enumeratedArray("VARS", 5, 0, 2, solver);
        IntVar[] CVARS = VF.enumeratedArray("CVARS", 5, 0, 10, solver);
        FiniteAutomaton fauto = new FiniteAutomaton();
        int start = fauto.addState();
        int end = fauto.addState();
        fauto.setInitialState(start);
        fauto.setFinal(start, end);

        fauto.addTransition(start, start, 0, 1);
        fauto.addTransition(start, end, 2);

        fauto.addTransition(end, end, 1);
        fauto.addTransition(end, start, 0, 2);

        int[][][] costs = new int[5][3][];
//        costs[0] = new int[]{1, 2, 3};
//        costs[1] = new int[]{2, 3, 1};
//        costs[2] = new int[]{3, 1, 2};
View Full Code Here

    @Test(groups = "1s")
    public void testregular() {
        Solver solver = new Solver();
        IntVar[] CS = VF.enumeratedArray("CS", 4, 1, 5, solver);
        solver.post(ICF.regular(CS,
                new FiniteAutomaton("(1|2)(3*)(4|5)")));
        SMF.log(solver, true, false);
        solver.findAllSolutions();
    }
View Full Code Here

//      AUTOMATON Constraints
//**************************************************


    private FiniteAutomaton makeForbiddenPatternsAsAutomaton() {
        FiniteAutomaton automaton = new FiniteAutomaton();
        for (String reg : data.forbiddenRegExps()) {
            FiniteAutomaton a = new FiniteAutomaton(reg);
            automaton = automaton.union(a);
            automaton.minimize();
        }
        for (int a = 0; a < data.nbActivities(); a++) {
            automaton.addToAlphabet(a);
View Full Code Here

        automaton.minimize();
        return automaton;
    }

    private void makeForbiddenPatternsWithRegular(Solver solver) {
        FiniteAutomaton automaton = this.makeForbiddenPatternsAsAutomaton();
        description += "pat[regular/" + automaton.getNbStates() + "] ";
        for (int e = 0; e < data.nbEmployees(); e++) {
            solver.post(IntConstraintFactory.regular(shifts[e], automaton));
        }
    }
View Full Code Here

            solver.post(IntConstraintFactory.regular(shifts[e], automaton));
        }
    }

    private void makeForbiddenPatternsAndMonthlyCountersWithMultiCostRegular(Solver solver) {
        FiniteAutomaton automaton = this.makeForbiddenPatternsAsAutomaton();
        int[][][] costs = new int[data.nbDays()][data.nbActivities()][data.nbActivities()];
        for (int a = 0; a < data.nbActivities(); a++) {
            for (int t = 0; t < data.nbDays(); t++) {
                costs[t][a][a] = 1;
            }
        }
        description += "pat[MCRegular/" + automaton.getNbStates() + "/" + costs[0][0].length + "] ";
        for (int e = 0; e < data.nbEmployees(); e++) {
            solver.post(IntConstraintFactory.multicost_regular(shifts[e], occurrences[e], CostAutomaton.makeMultiResources(automaton, costs, occurrences[e])));
        }
    }
View Full Code Here

        }
    }


    private void makeForbiddenPatternsAndMonthlyAndRestWeeklyCountersWithMultiCostRegular(Solver solver) {
        FiniteAutomaton automaton = this.makeForbiddenPatternsAsAutomaton();

        int[][][] costs = new int[data.nbDays()][data.nbActivities()][data.nbActivities() + data.nbWeeks()];
        for (int a = 0; a < data.nbActivities(); a++) {
            for (int t = 0; t < data.nbDays(); t++) {
                costs[t][a][a] = 1;
            }
        }
        description += "pat[MCRegular/" + automaton.getNbStates() + "/" + costs[0][0].length + "] ";

        int r = data.getValue("REST");
        for (int w = 0; w < data.nbWeeks(); w++) {
            for (int t = 0; t < 7; t++) {
                costs[7 * w + t][r][data.nbActivities() + w] = 1;
View Full Code Here

        for (int i = 0; i < n; i++) {
            vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
        }


        FiniteAutomaton auto = new FiniteAutomaton();
        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);

        solver.post(IntConstraintFactory.regular(vars, auto));
        solver.set(IntStrategyFactory.lexico_LB(vars));

        solver.findAllSolutions();
View Full Code Here

        forbiddenRegExps.add("(0|1|2)*01(0|1)(0|1|2)*");
        // at most three 2 on consecutive even positions
        forbiddenRegExps.add("(0|1|2)((0|1|2)(0|1|2))*2(0|1|2)2(0|1|2)2(0|1|2)*");

        // a unique automaton is built as the complement language composed of all the forbidden patterns
        FiniteAutomaton auto = new FiniteAutomaton();
        for (String reg : forbiddenRegExps) {
            FiniteAutomaton a = new FiniteAutomaton(reg);
            auto = auto.union(a);
            auto.minimize();
        }
        auto = auto.complement();
        auto.minimize();
View Full Code Here

        IntVar[] vars = new IntVar[n];
        for (int i = 0; i < n; i++) {
            vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
        }

        FiniteAutomaton auto = new FiniteAutomaton();
        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);

        solver.post(IntConstraintFactory.regular(vars, auto));
        solver.set(IntStrategyFactory.lexico_LB(vars));

        solver.findAllSolutions();
View Full Code Here

TOP

Related Classes of solver.constraints.nary.automata.FA.FiniteAutomaton

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.