Java Reference

Java Reference

LinearConstraint.java
Go to the documentation of this file.
1 // Copyright 2010-2022 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 
14 package com.google.ortools.modelbuilder;
15 
17 public class LinearConstraint {
18  public LinearConstraint(ModelBuilderHelper helper) {
19  this.helper = helper;
20  this.index = helper.addLinearConstraint();
21  }
22 
24  public int getIndex() {
25  return index;
26  }
27 
29  public ModelBuilderHelper getHelper() {
30  return helper;
31  }
32 
34  public double getLowerBound() {
35  return helper.getConstraintLowerBound(index);
36  }
37 
39  public void setLowerBound(double lb) {
40  helper.setConstraintLowerBound(index, lb);
41  }
42 
44  public double getUpperBound() {
45  return helper.getConstraintUpperBound(index);
46  }
47 
49  public void setUpperBound(double ub) {
50  helper.setConstraintUpperBound(index, ub);
51  }
52 
54  public String getName() {
55  return helper.getConstraintName(index);
56  }
57 
58  // Sets the name of the variable. */
59  public void setName(String name) {
60  helper.setConstraintName(index, name);
61  }
62 
63  // Adds var * coeff to the constraint.
64  public void addTerm(Variable var, double coeff) {
65  helper.addConstraintTerm(index, var.getIndex(), coeff);
66  }
67 
69  public LinearConstraint withName(String name) {
70  setName(name);
71  return this;
72  }
73 
74  private final ModelBuilderHelper helper;
75  private final int index;
76 }
Wrapper around a linear constraint stored in the ModelBuilderHelper instance.
LinearConstraint withName(String name)
Inline setter.
int getIndex()
Returns the index of the constraint in the model.
double getLowerBound()
Returns the lower bound of the variable.
ModelBuilderHelper getHelper()
Returns the constraint builder.
double getUpperBound()
Returns the upper bound of the variable.
void setUpperBound(double ub)
Returns the upper bound of the variable.
String getName()
Returns the name of the variable given upon creation.
void setLowerBound(double lb)
Returns the lower bound of the variable.
int getIndex()
Returns the index of the variable in the underlying ModelBuilderHelper.
Definition: Variable.java:33