25 [Obsolete(
"This Sum method is deprecated, please use LinearExpr.Sum() instead.")]
30 [Obsolete(
"This ScalProd method is deprecated, please use LinearExpr.ScalProd() instead.")]
35 [Obsolete(
"This ScalProd method is deprecated, please use LinearExpr.ScalProd() instead.")]
78 throw new NotImplementedException();
230 Dictionary<IntVar, long> dict)
232 List<LinearExpr> exprs =
new List<LinearExpr>();
233 List<long> coeffs =
new List<long>();
234 if ((Object)e !=
null)
237 coeffs.Add(initial_coeff);
241 while (exprs.Count > 0)
245 long coeff = coeffs[0];
247 if (coeff == 0 || (Object)expr ==
null)
continue;
255 coeffs.Add(p.
Coeff * coeff);
267 if (dict.ContainsKey(i))
280 long sub_coeff = sub_prod.
Coeff;
282 if (dict.ContainsKey(i))
284 dict[i] += coeff * sub_coeff;
288 dict.Add(i, coeff * sub_coeff);
301 if (dict.ContainsKey(i))
313 if (dict.ContainsKey(i))
325 throw new ArgumentException(
"Cannot interpret '" + expr.ToString() +
326 "' in an integer expression");
343 get {
return expr_; }
348 get {
return coeff_; }
360 expressions_ =
new List<LinearExpr>();
368 expressions_ =
new List<LinearExpr>();
375 expressions_ =
new List<LinearExpr>(exprs);
381 expressions_ =
new List<LinearExpr>(vars);
387 expressions_ =
new List<LinearExpr>(vars.Length);
388 for (
int i = 0; i < vars.Length; ++i)
394 public SumArray(IEnumerable<IntVar> vars, IEnumerable<long> coeffs)
396 List<IntVar> tmp_vars =
new List<IntVar>();
397 foreach (
IntVar v
in vars)
401 List<long> tmp_coeffs =
new List<long>();
402 foreach (
long c
in coeffs)
406 if (tmp_vars.Count != tmp_coeffs.Count)
408 throw new ArgumentException(
409 "in SumArray(vars, coeffs), the two lists do not have the same length");
411 IntVar[] flat_vars = tmp_vars.ToArray();
412 long[] flat_coeffs = tmp_coeffs.ToArray();
413 expressions_ =
new List<LinearExpr>(flat_vars.Length);
414 for (
int i = 0; i < flat_vars.Length; ++i)
416 expressions_.Add(
Prod(flat_vars[i], flat_coeffs[i]));
421 public SumArray(IEnumerable<IntVar> vars, IEnumerable<int> coeffs)
423 List<IntVar> tmp_vars =
new List<IntVar>();
424 foreach (
IntVar v
in vars)
428 List<long> tmp_coeffs =
new List<long>();
429 foreach (
int c
in coeffs)
433 if (tmp_vars.Count != tmp_coeffs.Count)
435 throw new ArgumentException(
436 "in SumArray(vars, coeffs), the two lists do not have the same length");
438 IntVar[] flat_vars = tmp_vars.ToArray();
439 long[] flat_coeffs = tmp_coeffs.ToArray();
440 expressions_ =
new List<LinearExpr>(flat_vars.Length);
441 for (
int i = 0; i < flat_vars.Length; ++i)
443 expressions_.Add(
Prod(flat_vars[i], flat_coeffs[i]));
450 if ((Object)expr !=
null)
452 expressions_.Add(expr);
458 get {
return expressions_; }
463 get {
return constant_; }
468 return String.Format(
"({0})",
ToString());
476 if ((Object)expr ==
null)
continue;
477 if (!String.IsNullOrEmpty(result))
479 result += String.Format(
" + ");
487 private List<LinearExpr> expressions_;
488 private long constant_;
506 get {
return index_; }
517 set { var_ = value; }
527 if (var_.
Name !=
null)
544 foreach (
long b
in var_.
Domain)
548 throw new ArgumentException(
549 "Cannot call Not() on a non boolean variable");
552 if (negation_ ==
null)
562 private List<long> bounds_;
576 return -boolvar_.
Index - 1;
591 return String.Format(
"Not({0})", boolvar_.
ShortString());
614 type_ =
Type.BoundExpression;
624 type_ = equality ?
Type.VarEqVar :
Type.VarDiffVar;
633 type_ = equality ?
Type.VarEqCst :
Type.VarDiffCst;
638 if (type_ ==
Type.VarEqVar)
640 return (
object)left_ == (object)right_;
642 else if (type_ ==
Type.VarDiffVar)
644 return (
object)left_ != (object)right_;
656 return !bie.IsTrue();
663 case Type.BoundExpression:
664 return String.Format(
"{0} <= {1} <= {2}", lb_, left_, ub_);
666 return String.Format(
"{0} == {1}", left_, right_);
667 case Type.VarDiffVar:
668 return String.Format(
"{0} != {1}", left_, right_);
670 return String.Format(
"{0} == {1}", left_, lb_);
671 case Type.VarDiffCst:
672 return String.Format(
"{0} != {1}", left_, lb_);
674 throw new ArgumentException(
"Wrong mode in BoundedLinearExpression.");
681 if (a.
CtType !=
Type.BoundExpression || a.
Ub != Int64.MaxValue)
683 throw new ArgumentException(
684 "Operator <= not supported for this BoundedLinearExpression");
692 if (a.
CtType !=
Type.BoundExpression || a.
Ub != Int64.MaxValue)
694 throw new ArgumentException(
695 "Operator < not supported for this BoundedLinearExpression");
703 if (a.
CtType !=
Type.BoundExpression || a.
Lb != Int64.MinValue)
705 throw new ArgumentException(
706 "Operator >= not supported for this BoundedLinearExpression");
714 if (a.
CtType !=
Type.BoundExpression || a.
Lb != Int64.MinValue)
716 throw new ArgumentException(
717 "Operator < not supported for this BoundedLinearExpression");
724 get {
return left_; }
729 get {
return right_; }
744 get {
return type_; }
long [] FlattenedIntervals()