19using System.Collections;
20using System.Collections.Generic;
22using System.Runtime.CompilerServices;
23using Google.Protobuf.Collections;
38 constantMap_ =
new Dictionary<double, int>();
39 tmp_var_value_map_ =
new SortedDictionary<int, double>();
40 tmp_terms_ =
new Queue<Term>();
51 foreach (KeyValuePair<double, int> entry
in constantMap_)
53 clonedModel.constantMap_[entry.Key] = entry.Value;
68 public Variable NewVar(
double lb,
double ub,
bool isIntegral, String name)
70 return new Variable(helper_, lb, ub, isIntegral, name);
82 return new Variable(helper_, lb, ub,
false, name);
94 return new Variable(helper_, lb, ub,
true, name);
104 return new Variable(helper_, 0, 1,
true, name);
114 if (constantMap_.TryGetValue(value, out
int index))
116 return new Variable(helper_, index);
119 constantMap_.Add(value, cste.
Index);
126 return new Variable(helper_, index);
149 throw new ArgumentException(
"Cannot use '" + lin.
ToString() +
"' as a linear constraint.");
164 var dict = tmp_var_value_map_;
166 double offset =
LinearExpr.GetVarValueMap(expr, dict, tmp_terms_);
167 foreach (KeyValuePair<int, double> term
in dict)
171 if (lb == Double.NegativeInfinity || lb == Double.PositiveInfinity)
177 lin.LowerBound = lb - offset;
179 if (ub == Double.NegativeInfinity || ub == Double.PositiveInfinity)
185 lin.UpperBound = ub - offset;
218 throw new ArgumentException(
"Cannot use '" + lin.
ToString() +
"' as a linear constraint.");
236 lin.IndicatorVariable = iVar;
237 lin.IndicatorValue = iValue;
238 var dict = tmp_var_value_map_;
240 double offset =
LinearExpr.GetVarValueMap(expr, dict, tmp_terms_);
241 foreach (KeyValuePair<int, double> term
in dict)
245 if (lb == Double.NegativeInfinity || lb == Double.PositiveInfinity)
251 lin.LowerBound = lb - offset;
253 if (ub == Double.NegativeInfinity || ub == Double.PositiveInfinity)
259 lin.UpperBound = ub - offset;
298 var dict = tmp_var_value_map_;
300 double offset =
LinearExpr.GetVarValueMap(obj, dict, tmp_terms_);
301 foreach (KeyValuePair<int, double> term
in dict)
303 if (term.Value != 0.0)
364 return helper_.
Name();
438 private Dictionary<double, int> constantMap_;
441 private SortedDictionary<int, double> tmp_var_value_map_;
442 private Queue<Term> tmp_terms_;