Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
EnforcedLinearConstraint.java
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package com.google.ortools.modelbuilder;
15
17public class EnforcedLinearConstraint {
19 this.helper = helper;
20 this.index = helper.addEnforcedLinearConstraint();
21 }
22
24 if (!helper.isEnforcedConstraint(index)) {
25 throw new IllegalArgumentException(
26 "the given index does not refer to an enforced linear constraint");
27 }
28 this.helper = helper;
29 this.index = index;
30 }
31
33 public int getIndex() {
34 return index;
35 }
36
39 return helper;
40 }
41
43 public double getLowerBound() {
44 return helper.getEnforcedConstraintLowerBound(index);
45 }
46
48 public void setLowerBound(double lb) {
49 helper.setEnforcedConstraintLowerBound(index, lb);
50 }
51
53 public double getUpperBound() {
54 return helper.getEnforcedConstraintUpperBound(index);
55 }
56
58 public void setUpperBound(double ub) {
59 helper.setEnforcedConstraintUpperBound(index, ub);
60 }
61
63 public String getName() {
64 return helper.getEnforcedConstraintName(index);
65 }
66
67 // Sets the name of the constraint. */
68 public void setName(String name) {
69 helper.setEnforcedConstraintName(index, name);
70 }
71
73 public void addTerm(Variable v, double coeff) {
74 helper.safeAddEnforcedConstraintTerm(index, v.getIndex(), coeff);
75 }
76
78 public void setCoefficient(Variable v, double coeff) {
79 helper.setEnforcedConstraintCoefficient(index, v.getIndex(), coeff);
80 }
81
83 public void clearTerms() {
84 helper.clearEnforcedConstraintTerms(index);
85 }
86
89 return new Variable(helper, helper.getEnforcedIndicatorVariableIndex(index));
90 }
91
95 }
96
98 public boolean getIndicatorValue() {
99 return helper.getEnforcedIndicatorValue(index);
100 }
101
103 public void setIndicatorValue(boolean b) {
104 helper.setEnforcedIndicatorValue(index, b);
105 }
106
108 public EnforcedLinearConstraint withName(String name) {
109 setName(name);
110 return this;
111 }
112
113 private final ModelBuilderHelper helper;
114 private final int index;
115}
void setName(String name)
Sets the name of the constraint. *‍/.
void setEnforcedConstraintCoefficient(int ct_index, int var_index, double coeff)
void safeAddEnforcedConstraintTerm(int ct_index, int var_index, double coeff)
void setEnforcedIndicatorVariableIndex(int ct_index, int var_index)
void setEnforcedIndicatorValue(int ct_index, boolean positive)