// 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);
  }
}

// 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);
  }

  /** Creates a linear term (var * coefficient). */
  static LinearExpr term(IntVar variable, long coefficient) {
    return new ScalProd(new IntVar[] {variable}, new long[] {coefficient});
  }
}

add LinearExpr.Term() API; improve internals