Example #1
0
        /**
         * <summary>
         * Adds <c> AllowedAssignments(variables)</c>.
         * </summary>
         *
         * <remarks>An AllowedAssignments constraint is a constraint on an array of variables that forces, when
         * all variables are fixed to a single value, that the corresponding list of values is equal to
         * one of the tuples of the tupleList.
         * </remarks>
         *
         * <param name="vars"> a list of variables</param>
         * <returns> an instance of the TableConstraint class without any tuples. Tuples can be added
         * directly to the table constraint
         * </returns>
         */
        public TableConstraint AddAllowedAssignments(IEnumerable <IntVar> vars)
        {
            TableConstraintProto table = new TableConstraintProto();

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

            TableConstraint ct = new TableConstraint(model_);

            ct.Proto.Table = table;
            return(ct);
        }
Example #2
0
        /**
         * <summary>
         * Adds a tuple of possible/forbidden values to the constraint.
         * </summary>
         *
         * <param name="tuple"> the tuple to add to the constraint</param>
         * <exception cref="ArgumentException"> if the tuple does not have the same length as the array of
         *     variables of the constraint</exception>
         */
        public TableConstraint AddTuple(IEnumerable <long> tuple)
        {
            TableConstraintProto table = Proto.Table;

            int count = 0;

            foreach (long value in tuple)
            {
                table.Values.Add(value);
                count++;
            }
            if (count != table.Vars.Count)
            {
                throw new ArgumentException("addTuple", "tuple does not have the same length as the variables");
            }
            return(this);
        }
Example #3
0
        /**
         * <summary>
         * Adds a set of tuples of possible/forbidden values to the constraint.
         * </summary>
         *
         * <param name="tuples"> the set of tuple to add to the constraint</param>
         * <exception cref="ArgumentException"> if the tuple does not have the same length as the array of
         *     variables of the constraint</exception>
         */
        public TableConstraint AddTuples(long[,] tuples)
        {
            TableConstraintProto table = Proto.Table;

            if (tuples.GetLength(1) != table.Vars.Count)
            {
                throw new ArgumentException("addTuples", "tuples does not have the same length as the variables");
            }

            for (int i = 0; i < tuples.GetLength(0); ++i)
            {
                for (int j = 0; j < tuples.GetLength(1); ++j)
                {
                    table.Values.Add(tuples[i, j]);
                }
            }
            return(this);
        }
Example #4
0
        public Constraint AddAllowedAssignments(IEnumerable <IntVar> vars, long[,] tuples)
        {
            Constraint           ct    = new Constraint(model_);
            TableConstraintProto table = new TableConstraintProto();

            foreach (IntVar var in vars)
            {
                table.Vars.Add(var.Index);
            }
            for (int i = 0; i < tuples.GetLength(0); ++i)
            {
                for (int j = 0; j < tuples.GetLength(1); ++j)
                {
                    table.Values.Add(tuples[i, j]);
                }
            }
            ct.Proto.Table = table;
            return(ct);
        }