14package com.google.ortools.modelbuilder;
16import java.util.LinkedHashMap;
25 static class ModelBuilderException
extends RuntimeException {
26 public ModelBuilderException(String methodName, String msg) {
28 super(methodName +
": " + msg);
35 super(methodName, array1Name +
" and " + array2Name +
" have mismatched lengths");
40 public static class WrongLength extends ModelBuilderException {
42 super(methodName, msg);
49 constantMap =
new LinkedHashMap<>();
56 clonedModel.constantMap.putAll(constantMap);
63 public Variable newVar(
double lb,
double ub,
boolean isIntegral, String name) {
64 return new Variable(helper, lb, ub, isIntegral, name);
69 return new Variable(helper, lb, ub,
false, name);
74 return new Variable(helper, lb, ub,
true, name);
79 return new Variable(helper, 0, 1,
true, name);
84 if (constantMap.containsKey(value)) {
85 return new Variable(helper, constantMap.get(value));
88 constantMap.put(value, cste.
getIndex());
107 if (lb == Double.NEGATIVE_INFINITY || lb == Double.POSITIVE_INFINITY) {
112 if (ub == Double.NEGATIVE_INFINITY || ub == Double.POSITIVE_INFINITY) {
177 if (lb == Double.NEGATIVE_INFINITY || lb == Double.POSITIVE_INFINITY) {
182 if (ub == Double.NEGATIVE_INFINITY || ub == Double.POSITIVE_INFINITY) {
252 helper.clearObjective();
254 LinkedHashMap<Integer, Double> coeffMap =
new LinkedHashMap<>();
258 for (Map.Entry<Integer, Double> entry : coeffMap.entrySet()) {
259 if (entry.getValue() != 0) {
260 helper.setVarObjectiveCoefficient(entry.getKey(), entry.getValue());
263 helper.setObjectiveOffset(e.
getOffset());
268 double getObjectiveOffset() {
273 void setObjectiveOffset(
double offset) {
286 void addHint(Variable v,
double value) {
287 helper.
addHint(v.getIndex(), value);
294 return helper.numVariables();
299 return helper.numConstraints();
304 return helper.getName();
309 helper.setName(name);
320 return helper.writeModelToProtoFile(file);
330 return helper.readModelFromProtoFile(file);
334 return helper.exportToMpsString(obfuscate);
338 return helper.exportToLpString(obfuscate);
342 return helper.writeToMpsFile(filename, obfuscate);
346 return helper.importFromMpsString(mpsString);
350 return helper.importFromMpsString(mpsFile);
354 return helper.importFromLpString(lpString);
358 return helper.importFromMpsString(lpFile);
368 private final Map<Double, Integer> constantMap;