public static LinearExpr Term(IntVar var, long coeff) { return(Prod(var, coeff)); }
public NotBooleanVariable(IntVar boolvar) { boolvar_ = boolvar; }
public static long GetVarValueMap(IntegerExpression e, long initial_coeff, Dictionary <IntVar, long> dict) { List <IntegerExpression> exprs = new List <IntegerExpression>(); List <long> coeffs = new List <long>(); exprs.Add(e); coeffs.Add(initial_coeff); long constant = 0; while (exprs.Count > 0) { IntegerExpression expr = exprs[0]; exprs.RemoveAt(0); long coeff = coeffs[0]; coeffs.RemoveAt(0); if (coeff == 0) { 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 (IntegerExpression sub in a.Expressions) { 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) { throw new ArgumentException( "Cannot interpret a literal in an integer expression."); } else { throw new ArgumentException("Cannot interpret '" + expr.ToString() + "' in an integer expression"); } } return(constant); }
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); }
/** * <summary> * Returns the value of an integer variable in the current solution. * </summary> */ public long Value(IntVar intVar) { return(SolutionIntegerValue(intVar.GetIndex())); }