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)
169 helper_.AddConstraintTerm(lin.Index, term.Key, term.Value);
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)
243 helper_.AddEnforcedConstraintTerm(lin.Index, term.Key, term.Value);
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;
297 helper_.ClearObjective();
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)
305 helper_.SetVarObjectiveCoefficient(term.Key, term.Value);
308 helper_.SetObjectiveOffset(offset);
309 helper_.SetMaximize(maximize);
318 return helper_.ObjectiveOffset();
321 helper_.SetObjectiveOffset(value);
330 helper_.ClearHints();
339 helper_.AddHint(var.
Index, value);
347 return helper_.VariablesCount();
355 return helper_.ConstraintsCount();
364 return helper_.Name();
367 helper_.SetName(value);
379 return helper_.WriteModelToProtoFile(file);
389 return helper_.ReadModelFromProtoFile(file);
394 return helper_.ExportToMpsString(obfuscate);
399 return helper_.ExportToLpString(obfuscate);
404 return helper_.WriteToMpsFile(filename, obfuscate);
409 return helper_.ImportFromMpsString(mpsString);
414 return helper_.ImportFromMpsString(mpsFile);
419 return helper_.ImportFromLpString(lpString);
424 return helper_.ImportFromMpsString(lpFile);
438 private Dictionary<double, int> constantMap_;
441 private SortedDictionary<int, double> tmp_var_value_map_;
442 private Queue<Term> tmp_terms_;