public ProductCst(LinearExpr e, long v) { expr_ = e; coeff_ = v; }
public static long GetVarValueMap(LinearExpr e, long initial_coeff, Dictionary <IntVar, long> dict) { List <LinearExpr> exprs = new List <LinearExpr>(); List <long> coeffs = new List <long>(); if ((Object)e != null) { exprs.Add(e); coeffs.Add(initial_coeff); } long constant = 0; while (exprs.Count > 0) { LinearExpr expr = exprs[0]; exprs.RemoveAt(0); long coeff = coeffs[0]; coeffs.RemoveAt(0); if (coeff == 0 || (Object)expr == null) { continue; } if (expr is ProductCst) { ProductCst p = (ProductCst)expr; if (p.Coeff != 0) { exprs.Add(p.Expr); coeffs.Add(p.Coeff * coeff); } } else if (expr is SumArray) { SumArray a = (SumArray)expr; constant += coeff * a.Constant; foreach (LinearExpr sub in a.Expressions) { if (sub is IntVar) { IntVar i = (IntVar)sub; if (dict.ContainsKey(i)) { dict[i] += coeff; } else { dict.Add(i, coeff); } } else if (sub is ProductCst && ((ProductCst)sub).Expr is IntVar) { ProductCst sub_prod = (ProductCst)sub; IntVar i = (IntVar)sub_prod.Expr; long sub_coeff = sub_prod.Coeff; if (dict.ContainsKey(i)) { dict[i] += coeff * sub_coeff; } else { dict.Add(i, coeff * sub_coeff); } } else { exprs.Add(sub); coeffs.Add(coeff); } } } else if (expr is IntVar) { IntVar i = (IntVar)expr; if (dict.ContainsKey(i)) { dict[i] += coeff; } else { dict.Add(i, coeff); } } else if (expr is NotBooleanVariable) { IntVar i = ((NotBooleanVariable)expr).NotVar(); if (dict.ContainsKey(i)) { dict[i] -= coeff; } else { dict.Add(i, -coeff); } constant += coeff; } else { throw new ArgumentException("Cannot interpret '" + expr.ToString() + "' in an integer expression"); } } return(constant); }
public static LinearExpr Sum(this IntVar[] vars) { return(LinearExpr.Sum(vars)); }
public void Maximize(LinearExpr obj) { SetObjective(obj, false); }
public Constraint AddLinearConstraint(LinearExpr linear_expr, long lb, long ub) { return(AddLinearExpressionInDomain(linear_expr, new Domain(lb, ub))); }
public LinearExpr StartExpr() { return(LinearExpr.RebuildLinearExprFromLinearExpressionProto(interval_.StartView, model_)); }
/** <summary> Adds <c>expr</c> to the builder.</summary> */ public LinearExprBuilder Add(LinearExpr expr) { return(AddTerm(expr, 1)); }
public SumArray(LinearExpr a, LinearExpr b) { AddExpr(a); AddExpr(b); constant_ = 0L; }
public SumArray(LinearExpr a, long b) { AddExpr(a); constant_ = b; }
void Init(int size) { expressions_ = new LinearExpr[size]; coefficients_ = new long[size]; }
/** * <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); }
public SumArray(LinearExpr a, long b) { Init(1); AddExpr(a, 0); constant_ = b; }
public Term(LinearExpr e, long c) { this.expr = e; this.coefficient = c; }
/** <summary> Adds <c>expr * coefficient</c> to the builder.</summary> */ public LinearExprBuilder AddTerm(LinearExpr expr, long coefficient) { terms_.Add(new Term(expr, coefficient)); return(this); }
public static LinearExpr ScalProd(this IntVar[] vars, long[] coeffs) { return(LinearExpr.ScalProd(vars, coeffs)); }
public void AddExpr(LinearExpr expr) { expressions_.Add(expr); }
public SumArray(LinearExpr a, long b) { expressions_ = new List <LinearExpr>(); AddExpr(a); constant_ = b; }
// Objective. public void Minimize(LinearExpr obj) { SetObjective(obj, true); }
public LinearExpr EndExpr() { return(LinearExpr.RebuildLinearExprFromLinearExpressionProto(interval_.EndView, model_)); }
/** <summary> Creates <c>expr * coeff</c>.</summary> */ public static LinearExpr Term(LinearExpr expr, long coeff) { return(Prod(expr, coeff)); }