linprog

linprog

Solve linear programming problems

解决线性规划问题

Linear programming solver

线性规划求解

Finds the minimum of a problem specified by

fxbbeqlb, and ub are vectors, and A and Aeq are matrices.

fxbbeqlb 和 ub 为列向量;AAeq 为矩阵。

 

Examples

例子

1. Linear Program, Linear Inequality Constraints

线性规划,线性不等式约束

For this example, use these linear inequality constraints:

在这个例子中,使用这些线性不等式约束:

x(1)+x(2)≤2

x(1)+x(2)/4≤1

x(1)-x(2)≤2

-x(1)-x(2)≤-1

-x(1)+x(2)≤2.

1 A=[1 1
2 1 1/4
3 1 -1
4 -1/4 -1
5 -1 -1
6 -1 1];
7 b=[2 1 2 1 -1 2];

Use the objective function -x(1)-x(2)/3.

使用目标函数 -x(1)-x(2)/3。

1 f=[-1 -1/3];

Solve the linear program.

求解线性规划。

1 x=linprog(f,A,b)
2 Optimization terminated.
3 
4 x =
5 
6     0.6667
7     1.3333

 

2. Linear Program with Linear Inequalities and Equalities

线性规划与线性不等式和等式

Solve a simple linear program defined by linear inequalities and linear equalities.

通过求解线性不等式和线性等式定义的简单线性规划。

 

For this example, use these linear inequality constraints:

在这个例子中,使用这些线性不等式约束:

x(1)+x(2)≤2

x(1)+x(2)≤1

x(1)-x(2)≤2

-x(1)/4-x(2)≤1

-x(1)-x(2)≤-1

-x(1)+x(2)≤2.

1 A=[1 1
2 1 1/4
3 1 -1
4 -1/4 -1
5 -1 -1
6 -1 1];
7 b=[2 1 2 1 -1 2];

Use the linear equality constraint x(1)+x(2)/4=1/2.

使用线性等式约束 x(1)+x(2)/4=1/2。

1 Aeq=[1 1/4];
2 beq=1/2;

Use the objective function -x(1)-x(2)/3.

使用目标函数 -x(1)-x(2)/3。

1 f=[-1 -1/3];

Solve the linear program.

求解线性规划。

1 x=linprog(f,A,b,Aeq,beq)
2 Optimization terminated.
3 
4 x =
5 
6     0.0000
7     2.0000

 

3. Linear Program with All Constraint Types

线性规划与所有约束类型

Solve a simple linear program with linear inequalities, linear equalities, and bounds.

求解线性不等式,线性等式和边界简单的线性程序。

 

For this example, use these linear inequality constraints:

在这个例子中,使用这些线性不等式约束:

x(1)+x(2)≤2

x(1)+x(2)/4≤1

x(1)-x(2)≤2

-x(1)/4-x(2)≤1

-x(1)-x(2)≤-1

-x(1)+x(2)≤2.

1 A = [1 1
2     1 1/4
3     1 -1
4     -1/4 -1
5     -1 -1
6     -1 1];
7 
8 b = [2 1 2 1 -1 2];

Use the linear equality constraint x(1)+x(2)/4=1/2.

使用线性等式约束 x(1)+x(2)/4=1/2。

1 Aeq = [1 1/4];
2 beq = 1/2;

Set these bounds:

设置这些界限:

-1≤x(1)≤1.5

-0.5≤x(2)≤1.25

lb = [-1,-0.5];
ub = [1.5,1.25];

Use the objective function -x(1)-x(2)/3.

1 f = [-1 -1/3];

Solve the linear program.

求解线性规划。

1 x = linprog(f,A,b,Aeq,beq,lb,ub)
2 Optimization terminated.
3 
4 x =
5 
6     0.1875
7     1.2500

 

4. Linear Program Using the Dual-Simplex Algorithm

线性规划采用双单纯形算法

Solve a linear program using the 'dual-simplex' algorithm.

解决了使用'双单“算法,线性规划。

 

For this example, use these linear inequality constraints:

在这个例子中,使用这些线性不等式约束:

x(1)+x(2)≤2

x(1)+x(2)/4≤1

x(1)-x(2)≤2

-x(1)/4-x(2)≤1

-x(1)-x(2)≤-1

-x(1)+x(2)≤2.

A = [1 1
    1 1/4
    1 -1
    -1/4 -1
    -1 -1
    -1 1];

b = [2 1 2 1 -1 2];

Use the linear equality constraint x(1)+x(2)/4=1/2.

使用线性等式约束 x(1)+x(2)/4=1/2。

Aeq = [1 1/4];
beq = 1/2;

Set these bounds:

设置这些界限:

1≤x(1)≤1.5

-0.5≤x(2)≤1.25.

lb = [-1,-0.5];
ub = [1.5,1.25];

Use the objective function -x(1)-x(2)/3.

使用目标函数 -x(1)-x(2)/3。

f = [-1 -1/3];

Set options to use the 'dual-simplex' algorithm.

设置选项使用'双单“算法。

options = optimoptions('linprog','Algorithm','dual-simplex');

Set the initial point to [], because the dual-simplex algorithm does not accept an initial point x0.

设置初始点为[],因为双单工算法不接受一个初始点X0。

x0 = [];

Solve the linear program using the 'dual-simplex' algorithm.

解决了使用'双单“算法线性程序。

x = linprog(f,A,b,Aeq,beq,lb,ub,x0,options)

Optimal solution found.


x =

    0.1875
    1.2500

 

posted @ 2016-04-02 21:07  u539f  阅读(737)  评论(0编辑  收藏  举报