Java Reference

Java Reference

ScalProd.java
Go to the documentation of this file.
1 // Copyright 2010-2018 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.sat;
15 
17 public final class ScalProd implements LinearExpr {
18  private final IntVar[] variables;
19  private final long[] coefficients;
20 
21  public ScalProd(IntVar[] variables, long[] coefficients) {
22  assert (variables.length == coefficients.length);
23  this.variables = variables;
24  this.coefficients = coefficients;
25  }
26 
27  @Override
28  public int numElements() {
29  return variables.length;
30  }
31 
32  @Override
33  public IntVar getVariable(int index) {
34  assert (index >= 0);
35  assert (index < variables.length);
36  return variables[index];
37  }
38 
39  @Override
40  public long getCoefficient(int index) {
41  assert (index >= 0);
42  assert (index < coefficients.length);
43  return coefficients[index];
44  }
45 }
int numElements()
Returns the number of elements in the interface.
Definition: ScalProd.java:28
A linear expression interface that can be parsed.
Definition: ScalProd.java:17
long getCoefficient(int index)
Returns the ith coefficient.
Definition: ScalProd.java:40
ScalProd(IntVar[] variables, long[] coefficients)
Definition: ScalProd.java:21
IntVar getVariable(int index)
Returns the ith variable.
Definition: ScalProd.java:33
An integer variable.
A linear expression interface that can be parsed.
Definition: LinearExpr.java:17