# Constructing linear constraints

In this section, you will learn about The two essential components of linear constraints, are the definitions of the constraints and the right-hand side. Each row in a matrix denotes the coefficients of a linear constraint. If the jth variable does not appear in the ith constraint, the corresponding element of A, Aij is set to zero.

In the next section, we provide a brief tutorial on matrix initialization.

## Initializing a Matrix in OPT++

Storing elements in a matrix is a simple task which can be accomplished in various ways. You can load the elements of a matrix from an array:
```   Matrix A(10,12);
Real a[] = {11,12,....,61,62,63,.....,101,102,...,1012};
A << a;
```

Or, for small matrices you can enter the values as follows.

```    Matrix A(3,2);
A << 11 << 12
<< 21 << 22
<< 31 << 32;
```
Note: Matrices are stored by row.

Now, we show the necessary steps for creation of linear equations and inequalities.

## Creating Linear Equations

As customary, linear equations are written as

The LinearEquation constructor

```   LinearEquation(const Matrix& A, const ColumnVector& rhs);
```
requires two parameters, a Matrix, which consists of the constraints, and a ColumnVector that contains the elements of the right-hand side.

## Creating Linear Inequalities

In OPT++, the standard form for a linear inequality is

The corresponding constructor is

```   LinearInequality(const Matrix& A, const ColumnVector& rhs);
```

To define upper bounds on the constraints, such as

use the following constructor:

```   LinearInequality(const Matrix& A, const ColumnVector& rhs,
const bool rowFlag);
```

To create lower and upper bounds on the constraints, use

```   LinearInequality(const Matrix& A, const ColumnVector& lower,
const ColumnVector& upper);
```
which generates

OPT++ does not support sparse constraints. Therefore, a bound must be given for each constraint even if only a subset of the constraint have finite bounds. An infinite lower bound is specified by

Similarly, an infinite upper bound is specified by

Last revised July 13, 2006

Bug Reports    OPT++ Developers    Copyright Information    GNU Lesser General Public License
Documentation, generated by , last revised August 30, 2006.