`from ortools.linear_solver import pywraplp`

`solver = pywraplp.Solver.CreateSolver('linear_programming_examples', 'GLOP')`

```＃声明变量x，下限为0，无上限
x = Solver.NumVar（0，Solver.Infinity（），“ x”）
＃声明变量y，下限为0，无上限
y = Solver.NumVar（0，Solver.infinity（），“ y”）
＃声明变量z，下限为0，无上限
z = Solver.NumVar（0，Solver.infinity（），“ z”）```

```＃将目标添加到求解器
objective = solver.Objective()
＃为目标添加条件，从而使目标函数产生结果
objective.SetCoefficient(x, 1)
objective.SetCoefficient(y, 2)
objective.SetCoefficient(z, 3)
＃将问题声明为最大化问题
objective.SetMaximization()```

```＃添加约束：2x + y + z <= 20
constraint = solver.Constraint(-solver.infinity(), 20)
constraint.SetCoefficient(x, 2)
constraint.SetCoefficient(y, 1)
constraint.SetCoefficient(z, 1)
＃添加约束：x + y + z <= 15
constraint = solver.Constraint(-solver.infinity(),15)
constraint.SetCoefficient(x, 1)
constraint.SetCoefficient(y, 1)
constraint.SetCoefficient(z, 1)
＃添加约束：x-y-z> = 0
constraint = solver.Constraint(0,solver.infinity())
constraint.SetCoefficient(x, 1)
constraint.SetCoefficient(y, -1)
constraint.SetCoefficient(z, -1)```

```solver.Solve()
```
```0
```

x的最佳解决方案输出如下：

```print("x_opt: ", x.solution_value())
```
`x_opt:  6.666666666666667`

y的最优解输出如下：

```print("y_opt: ", y.solution_value())
```
`y_opt:  0.0`

z的最优解输出如下：

```print("z_opt: ", z.solution_value())
```
```z_opt:  6.666666666666667
```

```print("optimal value: " + str(x.solution_value()+2*y.solution_value()+3*z.solution_value()))
```
`optimal value: 26.666666666666668`