14package com.google.ortools.modelbuilder;
16import java.util.LinkedHashMap;
24public final class ModelBuilder {
25 static class ModelBuilderException
extends RuntimeException {
26 public ModelBuilderException(String methodName, String msg) {
28 super(methodName +
": " + msg);
33 public static class MismatchedArrayLengths
extends ModelBuilderException {
35 super(methodName, array1Name +
" and " + array2Name +
" have mismatched lengths");
40 public static class WrongLength
extends ModelBuilderException {
42 super(methodName, msg);
49 constantMap =
new LinkedHashMap<>();
55 clonedModel.getHelper().overwriteModel(helper);
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) {
254 LinkedHashMap<Integer, Double> coeffMap =
new LinkedHashMap<>();
258 for (Map.Entry<Integer, Double> entry : coeffMap.entrySet()) {
259 if (entry.getValue() != 0) {
268 double getObjectiveOffset() {
273 void setObjectiveOffset(
double offset) {
286 void addHint(Variable v,
double value) {
287 helper.
addHint(v.getIndex(), value);
368 private final Map<Double, Integer> constantMap;