Example #1
0
        public IntervalVar NewOptionalIntervalVar <S, D, E>(S start, D duration, E end, ILiteral is_present, string name)
        {
            int i = is_present.GetIndex();

            return(new IntervalVar(model_, GetOrCreateIndex(start), GetOrCreateIndex(duration), GetOrCreateIndex(end),
                                   i, name));
        }
Example #2
0
 public Constraint AddImplication(ILiteral a, ILiteral b)
 {
   Constraint ct = new Constraint(model_);
   BoolArgumentProto or = new BoolArgumentProto();
   or.Literals.Add(a.Not().GetIndex());
   or.Literals.Add(b.GetIndex());
   ct.Proto.BoolOr = or;
   return ct;
 }
Example #3
0
        /**
         * <summary>
         * Add an arc to the graph of the circuit constraint.
         * </summary>
         *
         * <param name="tail"> the index of the tail node</param>
         * <param name="head"> the index of the head node</param>
         * <param name="literal"> it will be set to true if the arc is selected</param>
         */
        public CircuitConstraint AddArc(int tail, int head, ILiteral literal)
        {
            CircuitConstraintProto circuit = Proto.Circuit;

            circuit.Tails.Add(tail);
            circuit.Heads.Add(head);
            circuit.Literals.Add(literal.GetIndex());
            return(this);
        }
Example #4
0
        /**
         * <summary>
         * Adds an optional event.
         * </summary>
         *
         * <remarks>
         * If `is_active` is true, It will increase the used capacity by `level_change` at time `time`.
         * `time` must be an affine expression.
         * </remarks>
         */
        public ReservoirConstraint AddOptionalEvent <T, L>(T time, L level_change, ILiteral literal)
        {
            ReservoirConstraintProto res = Proto.Reservoir;

            res.TimeExprs.Add(cp_model_.GetLinearExpressionProto(cp_model_.GetLinearExpr(time)));
            res.LevelChanges.Add(Convert.ToInt64(level_change));
            res.ActiveLiterals.Add(literal.GetIndex());
            return(this);
        }
Example #5
0
        /**
         * <summary>
         * Add an arc to the graph of the multiple circuit constraint.
         * </summary>
         *
         * <param name="tail"> the index of the tail node</param>
         * <param name="head"> the index of the head node</param>
         * <param name="literal"> it will be set to true if the arc is selected</param>
         */
        public MultipleCircuitConstraint AddArc(int tail, int head, ILiteral literal)
        {
            RoutesConstraintProto routes = Proto.Routes;

            routes.Tails.Add(tail);
            routes.Heads.Add(head);
            routes.Literals.Add(literal.GetIndex());
            return(this);
        }
Example #6
0
 public IntervalVar NewOptionalIntervalVar<S, D, E>(
     S start, D duration, E end, ILiteral is_present, string name) {
   int i = is_present.GetIndex();
   return new IntervalVar(model_,
                          GetOrCreateOptionalIndex(start, i),
                          // Size is currently not optional.
                          GetOrCreateIndex(duration),
                          GetOrCreateOptionalIndex(end, i),
                          i,
                          name);
 }
Example #7
0
        public IntervalVar NewOptionalFixedSizeIntervalVar <S>(S start, long duration, ILiteral is_present, string name)
        {
            LinearExpr startExpr    = GetLinearExpr(start);
            LinearExpr durationExpr = GetLinearExpr(duration);
            LinearExpr endExpr      = LinearExpr.Sum(new LinearExpr[] { startExpr, durationExpr });

            LinearExpressionProto startProto    = GetLinearExpressionProto(startExpr);
            LinearExpressionProto durationProto = GetLinearExpressionProto(durationExpr);
            LinearExpressionProto endProto      = GetLinearExpressionProto(endExpr);

            return(new IntervalVar(model_, startProto, durationProto, endProto, is_present.GetIndex(), name));
        }
Example #8
0
 public Boolean BooleanValue(ILiteral literal)
 {
     if (literal is IntVar || literal is NotBooleanVariable)
     {
         int index = literal.GetIndex();
         return(SolutionBooleanValue(index));
     }
     else
     {
         throw new ArgumentException("Cannot evaluate '" + literal.ToString() + "' as a boolean literal");
     }
 }
Example #9
0
        public IntervalVar NewOptionalIntervalVar <S, D, E>(S start, D duration, E end, ILiteral is_present, string name)
        {
            LinearExpr startExpr    = GetLinearExpr(start);
            LinearExpr durationExpr = GetLinearExpr(duration);
            LinearExpr endExpr      = GetLinearExpr(end);

            Add(startExpr + durationExpr == endExpr).OnlyEnforceIf(is_present);

            LinearExpressionProto startProto    = GetLinearExpressionProto(startExpr);
            LinearExpressionProto durationProto = GetLinearExpressionProto(durationExpr);
            LinearExpressionProto endProto      = GetLinearExpressionProto(endExpr);

            return(new IntervalVar(model_, startProto, durationProto, endProto, is_present.GetIndex(), name));
        }
Example #10
0
 public Boolean BooleanValue(ILiteral literal)
 {
     if (literal is IntVar || literal is NotBooleanVariable)
     {
         int index = literal.GetIndex();
         if (index >= 0)
         {
             return(response_.Solution[index] != 0);
         }
         else
         {
             return(response_.Solution[-index - 1] == 0);
         }
     }
     else
     {
         throw new ArgumentException("Cannot evaluate '" + literal.ToString() + "' as a boolean literal");
     }
 }
Example #11
0
 public void AddAssumption(ILiteral lit)
 {
     model_.Assumptions.Add(lit.GetIndex());
 }
Example #12
0
 public void OnlyEnforceIf(ILiteral lit)
 {
     constraint_.EnforcementLiteral.Add(lit.GetIndex());
 }
Example #13
0
 public IntVar NewOptionalConstant(
     long value, ILiteral is_present, string name)
 {
     long[] bounds = { value, value };
     return(new IntVar(model_, bounds, is_present.GetIndex(), name));
 }
Example #14
0
 public IntVar NewOptionalEnumeratedIntVar(
     IEnumerable <long> bounds, ILiteral is_present, string name)
 {
     return(new IntVar(model_, bounds, is_present.GetIndex(), name));
 }
Example #15
0
 public IntVar NewOptionalIntVar(
     long lb, long ub, ILiteral is_present, string name)
 {
     long[] bounds = { lb, ub };
     return(new IntVar(model_, bounds, is_present.GetIndex(), name));
 }