Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

optimproblem

Create optimization problem

Syntax

``prob = optimproblem``
``prob = optimproblem(Name,Value)``

Description

example

````prob = optimproblem` creates an optimization problem with default properties.```

example

````prob = optimproblem(Name,Value)` uses additional options specified by one or more `Name,Value` pair arguments. For example, to specify a maximization problem instead of a minimization problem, use ```prob = optimproblem('ObjectiveSense','maximize')```.```

Examples

collapse all

Create an optimization problem with default properties.

`prob = optimproblem`
```prob = OptimizationProblem with properties: Description: '' ObjectiveSense: 'minimize' Variables: [0x0 struct] containing 0 OptimizationVariables Objective: [0x0 OptimizationExpression] Constraints: [0x0 struct] containing 0 OptimizationConstraints No problem defined. ```

Create a linear programming problem for maximization. The problem has two positive variables and three linear inequality constraints.

`prob = optimproblem('ObjectiveSense','max');`

Create positive variables. Include an objective function in the problem.

```x = optimvar('x',2,1,'LowerBound',0); prob.Objective = x(1) + 2*x(2);```

Create linear inequality constraints in the problem.

```cons1 = x(1) + 5*x(2) <= 100; cons2 = x(1) + x(2) <= 40; cons3 = 2*x(1) + x(2)/2 <= 60; prob.Constraints.cons1 = cons1; prob.Constraints.cons2 = cons2; prob.Constraints.cons3 = cons3;```

Review the problem.

`showproblem(prob)`
``` OptimizationProblem : max : x(1, 1) + 2*x(2, 1) subject to cons1: x(1, 1) + 5*x(2, 1) <= 100 subject to cons2: x(1, 1) + x(2, 1) <= 40 subject to cons3: 2*x(1, 1) + 0.5*x(2, 1) <= 60 variable bounds: 0 <= x(1, 1) 0 <= x(2, 1) ```

Solve the problem.

`sol = solve(prob);`
```Optimal solution found. ```
`sol.x`
```ans = 2×1 25.0000 15.0000 ```

Input Arguments

collapse all

Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: To specify a maximization problem, use ```prob = optimproblem('ObjectiveSense','maximize')```.

Problem constraints, specified as an `OptimizationConstraint` array or a structure with `OptimizationConstraint` arrays as fields.

Example: ```prob = optimproblem('Constraints',sum(x,2) == 1)```

Problem label, specified as a string or character vector. The software does not use `Description` for computation. `Description` is an arbitrary label that you can use for any reason. For example, you can share, archive, or present a model or problem, and store descriptive information about the model or problem in the `Description` property.

Example: ```prob = optimproblem('Description',"An iterative approach to the Traveling Salesman problem")```

Data Types: `char` | `string`

Objective function, specified as a scalar `OptimizationExpression` object.

Example: ```prob = optimproblem('Objective',sum(sum(x)))``` for a 2-D variable `x`

Sense of optimization, specified as `'minimize'` or `'maximize'`. You can also specify `'min'` to obtain `'minimize'` or `'max'` to obtain `'maximize'`. The `solve` function minimizes the objective when `ObjectiveSense` is `'minimize'` and maximizes the objective when `ObjectiveSense` is `'maximize'`.

Example: ```prob = optimproblem('ObjectiveSense','max')```

Data Types: `char` | `string`

Output Arguments

collapse all

Optimization problem, returned as an `OptimizationProblem` object. Typically, to complete the problem description, you specify an objective function and linear constraints. However, you can have a feasibility problem, which has no objective function, or you can have a problem with no linear constraints. Solve a complete problem by calling `solve`.

Watch now