Esempio n. 1
0
        public Constraint AddModuloEquality <T, V, M>(T target, V v, M m)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            args.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(v)));
            args.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(m)));
            args.Target     = GetLinearExpressionProto(GetLinearExpr(target));
            ct.Proto.IntMod = args;
            return(ct);
        }
Esempio n. 2
0
        public Constraint AddDivisionEquality <T, N, D>(T target, N num, D denom)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            args.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(num)));
            args.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(denom)));
            args.Target     = GetLinearExpressionProto(GetLinearExpr(target));
            ct.Proto.IntDiv = args;
            return(ct);
        }
Esempio n. 3
0
        public Constraint AddAbsEquality(LinearExpr target, LinearExpr expr)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            args.Exprs.Add(GetLinearExpressionProto(expr));
            args.Exprs.Add(GetLinearExpressionProto(expr, /*negate=*/ true));
            args.Target     = GetLinearExpressionProto(target);
            ct.Proto.LinMax = args;
            return(ct);
        }
Esempio n. 4
0
        public Constraint AddMultiplicationEquality(LinearExpr target, IEnumerable <LinearExpr> exprs)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            args.Target = GetLinearExpressionProto(target);
            foreach (LinearExpr expr in exprs)
            {
                args.Exprs.Add(GetLinearExpressionProto(expr));
            }
            ct.Proto.IntProd = args;
            return(ct);
        }
Esempio n. 5
0
        public Constraint AddMinEquality(LinearExpr target, IEnumerable <LinearExpr> exprs)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            foreach (LinearExpr expr in exprs)
            {
                args.Exprs.Add(GetLinearExpressionProto(expr, /*negate=*/ true));
            }
            args.Target     = GetLinearExpressionProto(target, /*negate=*/ true);
            ct.Proto.LinMax = args;
            return(ct);
        }
Esempio n. 6
0
        public Constraint AddMaxEquality(IntVar target, IEnumerable <IntVar> vars)
        {
            Constraint          ct   = new Constraint(model_);
            LinearArgumentProto args = new LinearArgumentProto();

            foreach (IntVar var in vars)
            {
                args.Exprs.Add(GetLinearExpressionProto(var));
            }
            args.Target     = GetLinearExpressionProto(target);
            ct.Proto.LinMax = args;
            return(ct);
        }
Esempio n. 7
0
        /**
         * <summary>
         * Adds <c>target == left * right</c>.
         * </summary>
         */
        public Constraint AddMultiplicationEquality(LinearExpr target, LinearExpr left, LinearExpr right)
        {
            LinearArgumentProto prod = new LinearArgumentProto();

            prod.Target         = GetLinearExpressionProto(target);
            prod.Exprs.Capacity = 2;
            prod.Exprs.Add(GetLinearExpressionProto(left));
            prod.Exprs.Add(GetLinearExpressionProto(right));

            Constraint ct = new Constraint(model_);

            ct.Proto.IntProd = prod;
            return(ct);
        }
Esempio n. 8
0
        /**
         * <summary>
         * Adds <c>target == v % m</c>.
         * </summary>
         */
        public Constraint AddModuloEquality <T, V, M>(T target, V v, M m)
        {
            LinearArgumentProto mod = new LinearArgumentProto();

            mod.Exprs.Capacity = 2;
            mod.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(v)));
            mod.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(m)));
            mod.Target = GetLinearExpressionProto(GetLinearExpr(target));

            Constraint ct = new Constraint(model_);

            ct.Proto.IntMod = mod;
            return(ct);
        }
Esempio n. 9
0
        /**
         * <summary>
         * Adds <c>target == num / denom</c> (integer division rounded towards 0).
         * </summary>
         */
        public Constraint AddDivisionEquality <T, N, D>(T target, N num, D denom)
        {
            LinearArgumentProto div = new LinearArgumentProto();

            div.Exprs.Capacity = 2;
            div.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(num)));
            div.Exprs.Add(GetLinearExpressionProto(GetLinearExpr(denom)));
            div.Target = GetLinearExpressionProto(GetLinearExpr(target));

            Constraint ct = new Constraint(model_);

            ct.Proto.IntDiv = div;
            return(ct);
        }
Esempio n. 10
0
        /**
         * <summary>
         * Adds <c>target == ∏(exprs)</c>.
         * </summary>
         */
        public Constraint AddMultiplicationEquality(LinearExpr target, IEnumerable <LinearExpr> exprs)
        {
            LinearArgumentProto prod = new LinearArgumentProto();

            prod.Target = GetLinearExpressionProto(target);
            prod.Exprs.TrySetCapacity(exprs);
            foreach (LinearExpr expr in exprs)
            {
                prod.Exprs.Add(GetLinearExpressionProto(expr));
            }

            Constraint ct = new Constraint(model_);

            ct.Proto.IntProd = prod;
            return(ct);
        }
Esempio n. 11
0
        /**
         * <summary>
         * Adds <c>target == Max(exprs)</c>.
         * </summary>
         */
        public Constraint AddMaxEquality(LinearExpr target, IEnumerable <LinearExpr> exprs)
        {
            LinearArgumentProto lin = new LinearArgumentProto();

            lin.Exprs.TrySetCapacity(exprs);
            foreach (LinearExpr expr in exprs)
            {
                lin.Exprs.Add(GetLinearExpressionProto(expr));
            }
            lin.Target = GetLinearExpressionProto(target);

            Constraint ct = new Constraint(model_);

            ct.Proto.LinMax = lin;
            return(ct);
        }