Java Reference

Java Reference

modelbuilder/LinearExpr.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 interface LinearExpr extends LinearArgument {
19  int numElements();
20 
22  int getVariableIndex(int index);
23 
25  double getCoefficient(int index);
26 
28  double getOffset();
29 
32  return new LinearExprBuilder();
33  }
34 
36  static LinearExpr constant(double value) {
37  return newBuilder().add(value).build();
38  }
39 
41  static LinearExpr term(LinearArgument expr, double coeff) {
42  return newBuilder().addTerm(expr, coeff).build();
43  }
44 
46  static LinearExpr affine(LinearArgument expr, double coeff, double offset) {
47  return newBuilder().addTerm(expr, coeff).add(offset).build();
48  }
49 
51  static LinearExpr sum(LinearArgument[] exprs) {
52  return newBuilder().addSum(exprs).build();
53  }
54 
56  static LinearExpr weightedSum(LinearArgument[] exprs, double[] coeffs) {
57  return newBuilder().addWeightedSum(exprs, coeffs).build();
58  }
59 }
LinearExprBuilder addTerm(LinearArgument expr, double coeff)
LinearExprBuilder addWeightedSum(LinearArgument[] exprs, double[] coeffs)
A object that can build a LinearExpr object.
A linear expression (sum (ai * xi) + b).
static LinearExpr term(LinearArgument expr, double coeff)
Shortcut for newBuilder().addTerm(expr, coeff).build()
static LinearExpr weightedSum(LinearArgument[] exprs, double[] coeffs)
Shortcut for newBuilder().addWeightedSum(exprs, coeffs).build()
static LinearExpr affine(LinearArgument expr, double coeff, double offset)
Shortcut for newBuilder().addTerm(expr, coeff).add(offset).build()
int numElements()
Returns the number of terms (excluding the constant one) in this expression.
double getCoefficient(int index)
Returns the ith coefficient.
static LinearExpr constant(double value)
Shortcut for newBuilder().add(value).build()
static LinearExprBuilder newBuilder()
Returns a builder.
double getOffset()
Returns the constant part of the expression.
int getVariableIndex(int index)
Returns the index of the ith variable.
static LinearExpr sum(LinearArgument[] exprs)
Shortcut for newBuilder().addSum(exprs).build()