# 概览

• 编程语言Julia：是一个由MIT学生开发的高性能动态编程语言，有很多包可以添加来扩充其功能。
• 优化库JuMP：是Julia的一个包，用于建立优化问题。
• solver：Jump支持很多开源与商业的solver，这些solver用于求解优化问题。常用的solver有COIN Clp, COIN Cbc, Gurobi等。

# 非线性条件线性化

## 绝对值约束

|x1+x2–x3–x4|≤5{x1+x2–x3–x4≥−5x1+x2–x3–x4≤5

|x1 +x2 –x3 –x4|≤5 \left\{\begin{aligned} x1 +x2 –x3 –x4 \ge -5\\ x1 +x2 –x3 –x4≤5 \end{aligned}\right.

## 最大最小约束

maxmin{50x1,25x2,20x3,15x4}⎧⎩⎨⎪⎪⎪⎪⎪⎪maxzz≤50x1z≤25x2z≤20x3z≤15x4

\max \min \{50x_1, 25x_2, 20x_3, 15x_4\} \left\{\begin{aligned} \max z \\ z \le 50x_1 \\ z \le 25x_2 \\ z \le 20x_3 \\ z \le 15x_4 \end{aligned}\right.

## 比例约束

• 分母如果是负数，必须得变化符号。
• 分母如果是0，那么新的约束同样满足条件，所以0的情况不用考虑。

x1(x1+x2+x3+x4)≥.2{.8x1−.2x2−.2x3−.2x4≥0

\frac{x1}{(x1 +x2 +x3 +x4)} ≥ .2 \left\{\begin{aligned} .8x1 -.2x2 -.2x3 -.2x4 ≥0 \end{aligned}\right.

• 绝对值约束
• 最大最小约束
• 比例约束

# Julia优化例子

## Knapsack

using JuMP, DataFrames
# Define model
m = Model()
# Define capacity
capacity = 11
# Read data from CSV file using readtable
# Weights from first column, weights = [1 2 15 6 28]
weights = data[:,1]
# Values from second column, values = [1 6 18 22 7]
values = data[:,2]
# Assign binary values to items
@variable(m, x[1:5], Bin)
# Constraint on total weight
@constraint(m, sum{weights[i]*x[i], i in 1:5} <= capacity)
# Maximize value from items
@objective(m, Max, sum{values[i]*x[i], i in 1:5})
# Solve model
solve(m)
# Determine which items to carry
println("Variable Values: ", getvalue(x))
# Determine value from items carried
println("Objetive value: ", getobjectivevalue(m))

## Diet

using JuMP
#Define model
m = Model()
#Food available
S = ["brownies","ice cream","cola","cheese cake"]
#Non-negativity
@defVar(m, x[S] >= 0)
#Minimum calories
@addConstraint(m, 400x["brownies"] + 200x["ice cream"] + 150x["cola"] + 500x["cheese cake"] >= 500)
#At least 6 grams of chocolate
@addConstraint(m, 3x["brownies"] + 2x["ice cream"] >= 6)
#At least 10 grams of sugar
@addConstraint(m, 2x["brownies"] + 2x["ice cream"] + 4x["cola"] + 4x["cheese cake"] >= 10)
#At least 8 grams of fat
@addConstraint(m, 2x["brownies"] + 4x["ice cream"] + 1x["cola"] + 5x["cheese cake"] >= 8)
#Minimize cost of consumption
@setObjective(m, Min, 0.5x["brownies"] + 0.2x["ice cream"] + 0.3x["cola"] + 0.8x["cheese cake"])
#Solve the optimization problem
solve(m)
#Determine consumption amounts
println("variable values: ", getValue(x))
#Determine optimal cost of consumption
println("Objetive value: ", getObjectiveValue(m))

99 篇文章32 人订阅

0 条评论

## 相关文章

2441

3695

3015

38811

1002

7008

6547

### 【论文推荐】最新七篇图像分类相关论文—条件标签空间、生成对抗胶囊网络、深度预测编码网络、生成对抗网络、数字病理图像、在线表示学习

【导读】专知内容组整理了最近七篇图像分类（Image Classification）相关文章，为大家进行介绍，欢迎查看! 1. Learning Image C...

3977

2768

733