// Copyright 2010-2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.ortools.sat;

/** A linear expression interface that can be parsed. */
public interface LinearExpr {
  /** Returns the number of elements in the interface. */
  int numElements();

  /** Returns the ith variable. */
  IntVar getVariable(int index);

  /** Returns the ith coefficient. */
  long getCoefficient(int index);

  /** Creates a sum expression. */
  static LinearExpr sum(IntVar[] variables) {
    return new SumOfVariables(variables);
  }

  /** Creates a scalar product. */
  static LinearExpr scalProd(IntVar[] variables, long[] coefficients) {
    return new ScalProd(variables, coefficients);
  }

  /** Creates a scalar product. */
  static LinearExpr scalProd(IntVar[] variables, int[] coefficients) {
    long[] tmp = new long[coefficients.length];
    for (int i = 0; i < coefficients.length; ++i) {
      tmp[i] = coefficients[i];
    }
    return new ScalProd(variables, tmp);
  }
}

@@ -1503,11 +1503,206 @@
 mp);%0A  %7D
+%0A%0A  /** Creates a linear term (var * coefficient). */%0A  static LinearExpr term(IntVar variable, long coefficient) %7B%0A    return new ScalProd(new IntVar%5B%5D %7Bvariable%7D, new long%5B%5D %7Bcoefficient%7D);%0A  %7D
 %0A%7D%0A

add LinearExpr.Term() API; improve internals