Exemplo n.º 1
0
        public Constraint AddAutomaton(IEnumerable <IntVar> vars, long starting_state,
                                       IEnumerable <Tuple <long, long, long> > transitions, IEnumerable <long> final_states)
        {
            Constraint ct = new Constraint(model_);
            AutomatonConstraintProto aut = new AutomatonConstraintProto();

            foreach (IntVar var in vars)
            {
                aut.Vars.Add(var.Index);
            }
            aut.StartingState = starting_state;
            foreach (long f in final_states)
            {
                aut.FinalStates.Add(f);
            }
            foreach (Tuple <long, long, long> transition in transitions)
            {
                aut.TransitionHead.Add(transition.Item1);
                aut.TransitionLabel.Add(transition.Item2);
                aut.TransitionTail.Add(transition.Item3);
            }

            ct.Proto.Automaton = aut;
            return(ct);
        }
Exemplo n.º 2
0
        public Constraint AddAutomaton(IEnumerable <IntVar> vars, long starting_state, long[,] transitions,
                                       IEnumerable <long> final_states)
        {
            Constraint ct = new Constraint(model_);
            AutomatonConstraintProto aut = new AutomatonConstraintProto();

            foreach (IntVar var in vars)
            {
                aut.Vars.Add(var.Index);
            }
            aut.StartingState = starting_state;
            foreach (long f in final_states)
            {
                aut.FinalStates.Add(f);
            }
            for (int i = 0; i < transitions.GetLength(0); ++i)
            {
                aut.TransitionTail.Add(transitions[i, 0]);
                aut.TransitionLabel.Add(transitions[i, 1]);
                aut.TransitionHead.Add(transitions[i, 2]);
            }

            ct.Proto.Automaton = aut;
            return(ct);
        }
Exemplo n.º 3
0
        /*
         * <summary>
         * Adds a transitions to the automaton.
         * </summary>
         */
        public AutomatonConstraint AddTransition(int tail, int head, long label)
        {
            AutomatonConstraintProto aut = Proto.Automaton;

            aut.TransitionTail.Add(tail);
            aut.TransitionLabel.Add(label);
            aut.TransitionHead.Add(head);
            return(this);
        }
Exemplo n.º 4
0
        /**
         * <summary>
         * Adds an automaton constraint.
         * </summary>
         *
         * <remarks>
         * <para>An automaton constraint takes a list of variables (of size n), an initial state, a set of
         * final states, and a set of transitions that will be added incrementally directly on the
         * returned AutomatonConstraint instance. A transition is a triplet (<c>tail</c>, <c>transition</c>,
         * <c>head</c>), where <c>tail</c> and <c>head</c> are states, and <c>transition</c> is the label of an arc from
         * <c>head</c> to <c>tail</c>, corresponding to the value of one variable in the list of variables. </para>
         *
         * <para>This automaton will be unrolled into a flow with n + 1 phases. Each phase contains the
         * possible states of the automaton. The first state contains the initial state. The last phase
         * contains the final states. </para>
         *
         * <para>Between two consecutive phases i and i + 1, the automaton creates a set of arcs. For each
         * transition (<c>tail</c>, <c>label</c>, <c>head</c>), it will add an arc from the state <c>tail</c> of phase i and
         * the state <c>head</c> of phase i + 1. This arc labeled by the value <c>label</c> of the variables
         * <c>variables[i]</c>. That is, this arc can only be selected <c>variables[i]</c>a is assigned the value
         * <c>label</c>. </para>
         *
         * <para>A feasible solution of this constraint is an assignment of variables such that, starting
         * from the initial state in phase 0, there is a path labeled by the values of the variables that
         * ends in one of the final states in the final phase. </para>
         * </remarks>
         *
         * <param name="vars"> a non empty list of variables whose values correspond to the labels
         *     of the arcs traversed by the automaton</param>
         * <param name="starting_state"> the initial state of the automaton</param>
         * <param name="final_states"> a non empty list of admissible final states </param>
         * <returns> an instance of the AutomatonConstraint class </returns>
         */
        public AutomatonConstraint AddAutomaton(IEnumerable <IntVar> vars, long starting_state,
                                                IEnumerable <long> final_states)
        {
            AutomatonConstraintProto aut = new AutomatonConstraintProto();

            aut.Vars.TrySetCapacity(vars);
            foreach (IntVar var in vars)
            {
                aut.Vars.Add(var.Index);
            }

            aut.StartingState = starting_state;
            aut.FinalStates.AddRange(final_states);

            AutomatonConstraint ct = new AutomatonConstraint(model_);

            ct.Proto.Automaton = aut;
            return(ct);
        }