Class Expression

All Implemented Interfaces:
Comparable<Expression>, Optimisation, Optimisation.Constraint, Optimisation.Objective

public final class Expression extends ModelEntity<Expression>
Expression represents a mathematical expression in the optimization model that can serve as either a constraint or a component of the objective function.

An Expression can be:

  • Linear: Contains only linear terms (variable coefficients)
  • Quadratic: Contains quadratic terms (products of variables)
  • Compound: Contains both linear and quadratic terms

Basic usage:

Advanced features include:

  • Integer expression handling with automatic detection and constraint tightening
  • Support for binary variables with specialized methods for detecting binary constraints
  • Expression evaluation at specific variable values using evaluate(Access1D)
  • Compensation for fixed variables to simplify expressions during solving
  • Numerical scaling for improved solver stability
  • Convenient methods for creating common expression types (sums, distances, etc.)
  • Conversion to various function types for integration with different solvers

The Expression class provides a fluent interface for building expressions with method chaining. It also supports automatic handling of numerical stability issues through scaling adjustments.

Note that while the Expression class supports quadratic terms in constraints, some solvers may only support linear constraints. Quadratic, linear, or compound expressions can typically be used in the objective function depending on the solver capabilities.