17using System.Collections.Generic;
21 public virtual double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
31 public double Visit(Dictionary<Variable, double> coefficients)
33 return DoVisit(coefficients, 1.0);
98 throw new ArgumentException(
"Operator != not supported for LinearExpression");
103 throw new ArgumentException(
"Operator != not supported for LinearExpression");
177 return "(" + expr_.ToString() +
" * " + coeff_ +
")";
180 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
182 double current_multiplier = multiplier * coeff_;
183 if (current_multiplier != 0.0)
185 return expr_.
DoVisit(coefficients, current_multiplier);
199 private double coeff_;
212 return "(" + expr_.ToString() +
" + " + coeff_ +
")";
215 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
217 if (multiplier != 0.0)
219 return coeff_ * multiplier + expr_.
DoVisit(coefficients, multiplier);
233 private double coeff_;
248 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
250 if (multiplier != 0.0)
252 if (coefficients.ContainsKey(var_))
254 coefficients[var_] += multiplier;
258 coefficients[var_] = multiplier;
282 return "(" + left_.ToString() +
" + " + right_.ToString() +
")";
285 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
287 if (multiplier != 0.0)
289 return left_.
DoVisit(coefficients, multiplier) + right_.
DoVisit(coefficients, multiplier);
313 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
315 if (multiplier != 0.0)
317 double constant = 0.0;
320 constant += expr.
DoVisit(coefficients, multiplier);
350 public override double DoVisit(Dictionary<Variable, double> coefficients,
double multiplier)
352 if (multiplier != 0.0)
356 if (coefficients.ContainsKey(var))
358 coefficients[var] += multiplier;
362 coefficients[var] = multiplier;