├── LectureNotes ├── 第10章 │ ├── 第10.1节 最速下降法.png │ ├── 第10.2节 牛顿法.png │ ├── 第10.3节 共轭方向法.png │ └── 第10.4节 拟牛顿法.png ├── 第11章 │ ├── 第11.1节 交替方向法.png │ ├── 第11.2节 单纯形法.png │ └── 第11.3节 差分拟牛顿法.png ├── 第12章 │ ├── 第12.1节 Zoutendijk可行方向法.png │ ├── 第12.2节 Rosen投影梯度法.png │ └── 第12.4节 Frank-Wolfe方法.png ├── 第13章 │ ├── 第13.1节 外点罚函数法.png │ └── 第13.2节 内点罚函数法.png ├── 第1章 │ ├── 第1.1节 课程介绍.pptx │ ├── 第1.2节 最优化问题举例.png │ ├── 第1.3节 最优化问题的模型及分类.png │ ├── 第1.4节 凸集和凸函数.png │ └── 第1.5节 数学预备知识.png ├── 第2章 │ ├── 第2.1节 标准形式及图解法.png │ └── 第2.2节 基本性质.png ├── 第3章 │ └── 第3.1节 单纯形方法原理.png ├── 第4章 │ ├── 第4.0节 线性规划对偶之通俗解释.png │ └── 第4.1节 线性规划中的对偶理论.png ├── 第7章 │ ├── 第7.1节 无约束优化问题的极值条件.png │ ├── 第7.2节 约束极值问题的最优性条件.png │ └── 第7.3节 对偶及鞍点问题.png └── 第9章 │ ├── 第9.0节 无约束优化问题的算法结构.png │ ├── 第9.1节 一维搜索的概念.png │ ├── 第9.2节 试探法.png │ ├── 第9.3节 函数逼近法.png │ └── 第9.4节 非精确线搜索.png ├── README.md └── code ├── 1 ├── 10_1SteepDesecntDirection+BisectionMethod ├── Bisection.m ├── SteepestDescentDirctionMehtod.m ├── objfun.m ├── objfun_grad.m └── phi.m ├── 10_1SteepestDescentDirectionMethod ├── SteepestDesDirMethod.asv ├── SteepestDesDirMethod.m ├── grad_obj.m ├── obj.m ├── phi.m └── test.m ├── 10_2NewtonMethod ├── H_obj.m ├── NewtonMethod.m ├── grad_obj.m ├── handel.wav ├── obj.m ├── phi.m └── test.m ├── 10_3ConjugateGradientMethod ├── ConjugateGradientMethod.asv ├── ConjugateGradientMethod.m ├── grad_obj.m ├── obj.m ├── phi.m └── test.m ├── 10_4QuasiNewtonMethod ├── QuasiNewtonMethod.asv ├── QuasiNewtonMethod.m ├── grad_obj.m ├── obj.m ├── phi.m └── test.m ├── 11_1Cyclic coordinate method ├── Cyclic_Coordinate_Method.m ├── objective_fun.m └── theta.m ├── 11_2Hooke Jeeves mathod ├── Hooke_Jeeves_Method.m ├── objective_fun.m └── theta.m ├── 11_3Risenbriock method ├── Gram_Schmidt_Procedure.m ├── Risenbriock_Method.m ├── objective_fun.m └── theta.m ├── 11_4Simplex method ├── Simplex_Method.m ├── objective_fun.m └── test.m ├── 11_5Trust region method ├── Hessian.m ├── Trust_Region_Method.m ├── gradient.m ├── mk.m └── objective_fun.m ├── 12_1ZoutendijkMethodforLinearConstraints ├── main.m ├── objfun.m └── zoutendijk.m ├── 12_2RosenGradientProjectMethod ├── main.m ├── objfun.m └── rosen.m ├── 12_4Frank-WolfeMethod ├── frank_wolfe.m ├── main.m └── objfun.m ├── 13_1ExteriorPenaltyFunctionMethod ├── conFun.m ├── exteriorPenalty.m ├── main.m └── objFun.m ├── 13_2BarrierFunctionMethod ├── barrierFunctionMethod.m ├── conFun.m ├── main.m └── objFun.m ├── 3_1SimplexMethod ├── linProg.m └── main.m ├── 9_1ExactLineSearch ├── Bisection.m ├── Fibonaccimethod.m ├── Goldenmethod.asv ├── Goldenmethod.m ├── P2_fibonacci.m └── obj1.m └── 9_2InexactLineSearch ├── figure1.m ├── figure2.m ├── grad_obj2.m ├── inexactlinesearch_AG.m ├── inexactlinesearch_WP.m ├── obj2.m ├── phi.m ├── test.m └── test2.m /LectureNotes/第10章/第10.1节 最速下降法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第10章/第10.1节 最速下降法.png -------------------------------------------------------------------------------- /LectureNotes/第10章/第10.2节 牛顿法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第10章/第10.2节 牛顿法.png -------------------------------------------------------------------------------- /LectureNotes/第10章/第10.3节 共轭方向法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第10章/第10.3节 共轭方向法.png -------------------------------------------------------------------------------- /LectureNotes/第10章/第10.4节 拟牛顿法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第10章/第10.4节 拟牛顿法.png -------------------------------------------------------------------------------- /LectureNotes/第11章/第11.1节 交替方向法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第11章/第11.1节 交替方向法.png -------------------------------------------------------------------------------- /LectureNotes/第11章/第11.2节 单纯形法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第11章/第11.2节 单纯形法.png -------------------------------------------------------------------------------- /LectureNotes/第11章/第11.3节 差分拟牛顿法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第11章/第11.3节 差分拟牛顿法.png -------------------------------------------------------------------------------- /LectureNotes/第12章/第12.1节 Zoutendijk可行方向法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第12章/第12.1节 Zoutendijk可行方向法.png -------------------------------------------------------------------------------- /LectureNotes/第12章/第12.2节 Rosen投影梯度法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第12章/第12.2节 Rosen投影梯度法.png -------------------------------------------------------------------------------- /LectureNotes/第12章/第12.4节 Frank-Wolfe方法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第12章/第12.4节 Frank-Wolfe方法.png -------------------------------------------------------------------------------- /LectureNotes/第13章/第13.1节 外点罚函数法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第13章/第13.1节 外点罚函数法.png -------------------------------------------------------------------------------- /LectureNotes/第13章/第13.2节 内点罚函数法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第13章/第13.2节 内点罚函数法.png -------------------------------------------------------------------------------- /LectureNotes/第1章/第1.1节 课程介绍.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第1章/第1.1节 课程介绍.pptx -------------------------------------------------------------------------------- /LectureNotes/第1章/第1.2节 最优化问题举例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第1章/第1.2节 最优化问题举例.png -------------------------------------------------------------------------------- /LectureNotes/第1章/第1.3节 最优化问题的模型及分类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第1章/第1.3节 最优化问题的模型及分类.png -------------------------------------------------------------------------------- /LectureNotes/第1章/第1.4节 凸集和凸函数.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第1章/第1.4节 凸集和凸函数.png -------------------------------------------------------------------------------- /LectureNotes/第1章/第1.5节 数学预备知识.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第1章/第1.5节 数学预备知识.png -------------------------------------------------------------------------------- /LectureNotes/第2章/第2.1节 标准形式及图解法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第2章/第2.1节 标准形式及图解法.png -------------------------------------------------------------------------------- /LectureNotes/第2章/第2.2节 基本性质.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第2章/第2.2节 基本性质.png -------------------------------------------------------------------------------- /LectureNotes/第3章/第3.1节 单纯形方法原理.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第3章/第3.1节 单纯形方法原理.png -------------------------------------------------------------------------------- /LectureNotes/第4章/第4.0节 线性规划对偶之通俗解释.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第4章/第4.0节 线性规划对偶之通俗解释.png -------------------------------------------------------------------------------- /LectureNotes/第4章/第4.1节 线性规划中的对偶理论.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第4章/第4.1节 线性规划中的对偶理论.png -------------------------------------------------------------------------------- /LectureNotes/第7章/第7.1节 无约束优化问题的极值条件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第7章/第7.1节 无约束优化问题的极值条件.png -------------------------------------------------------------------------------- /LectureNotes/第7章/第7.2节 约束极值问题的最优性条件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第7章/第7.2节 约束极值问题的最优性条件.png -------------------------------------------------------------------------------- /LectureNotes/第7章/第7.3节 对偶及鞍点问题.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第7章/第7.3节 对偶及鞍点问题.png -------------------------------------------------------------------------------- /LectureNotes/第9章/第9.0节 无约束优化问题的算法结构.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第9章/第9.0节 无约束优化问题的算法结构.png -------------------------------------------------------------------------------- /LectureNotes/第9章/第9.1节 一维搜索的概念.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第9章/第9.1节 一维搜索的概念.png -------------------------------------------------------------------------------- /LectureNotes/第9章/第9.2节 试探法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第9章/第9.2节 试探法.png -------------------------------------------------------------------------------- /LectureNotes/第9章/第9.3节 函数逼近法.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第9章/第9.3节 函数逼近法.png -------------------------------------------------------------------------------- /LectureNotes/第9章/第9.4节 非精确线搜索.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/LectureNotes/第9章/第9.4节 非精确线搜索.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Optimization-Theory-and-Algorithm 2 | 用于存放《最优化理论与算法》代码与课件 3 | 代码:code 4 | 课件:LectureNotes 5 | -------------------------------------------------------------------------------- /code/1: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /code/10_1SteepDesecntDirection+BisectionMethod/Bisection.m: -------------------------------------------------------------------------------- 1 | function y = Bisection(xk,dk,ak,bk) 2 | 3 | % parameters 4 | epsilon = 1e-1; 5 | eta = 0.001; 6 | 7 | % main program 8 | while 1 9 | if bk-ak <= epsilon 10 | y = (bk+ak)/2; 11 | return; 12 | else 13 | mid = (bk+ak)/2; 14 | lambdak = mid-eta; 15 | muk = mid+eta; 16 | flambdak = phi(xk,dk,lambdak); 17 | fmuk = phi(xk,dk,muk); 18 | if flambdak > fmuk 19 | ak = lambdak; 20 | else 21 | bk = muk; 22 | end 23 | end 24 | end 25 | 26 | -------------------------------------------------------------------------------- /code/10_1SteepDesecntDirection+BisectionMethod/SteepestDescentDirctionMehtod.m: -------------------------------------------------------------------------------- 1 | function [fstar, xstar] = SteepestDescentDirctionMehtod(x0) 2 | % parameters 3 | epsilon = 1e-4; 4 | xk = x0; 5 | 6 | % stop checking 7 | Dk = []; 8 | while 1 9 | gk = objfun_grad(xk); 10 | Dk =[Dk -gk]; 11 | if norm(gk) <= epsilon 12 | fstar = objfun(xk); 13 | xstar = xk; 14 | plot(Dk(1,:),Dk(2,:)) 15 | return; 16 | else 17 | dk = -gk; % search direction 18 | alphak = Bisection(xk,dk,0,2); % line search for step size 19 | xk = xk+alphak*dk; 20 | end 21 | end 22 | 23 | -------------------------------------------------------------------------------- /code/10_1SteepDesecntDirection+BisectionMethod/objfun.m: -------------------------------------------------------------------------------- 1 | function y = objfun(x) 2 | 3 | y = (1/3)*x(1)^2+(1/2)*x(2)^2; -------------------------------------------------------------------------------- /code/10_1SteepDesecntDirection+BisectionMethod/objfun_grad.m: -------------------------------------------------------------------------------- 1 | function y = objfun_grad(x) 2 | 3 | y = [(2/3)*x(1);x(2)]; -------------------------------------------------------------------------------- /code/10_1SteepDesecntDirection+BisectionMethod/phi.m: -------------------------------------------------------------------------------- 1 | function y = phi(xk,dk,alpha) 2 | 3 | y = objfun(xk+alpha*dk); -------------------------------------------------------------------------------- /code/10_1SteepestDescentDirectionMethod/SteepestDesDirMethod.asv: -------------------------------------------------------------------------------- 1 | function [fmin,xmin]=SteepestDesDirMethod(x0) 2 | 3 | % initialization 4 | epsilon=1.0e-4; 5 | fmin=inf; 6 | xmin=x0; 7 | xk=x0; 8 | 9 | % iteration 10 | while 1 11 | % stop criterion 12 | gk=grad_obj(xk); 13 | if norm(gk)=fs && f1=fm && f1=fs && f3=fm && f3=Deltak 37 | % dk=-(Deltak/norm(gk))*gk; 38 | % elseif norm(dku)=eta2 && (norm(dk)<=Deltak+epsilon && norm(dk)>=Deltak-epsilon) 56 | Deltak=min(gamma2*Deltak,Delta_bar); 57 | end 58 | 59 | % update iteration point 60 | if rhok>eta1 61 | xk=xk+dk; 62 | end 63 | k=k+1; 64 | end -------------------------------------------------------------------------------- /code/11_5Trust region method/gradient.m: -------------------------------------------------------------------------------- 1 | function y=gradient(x) 2 | 3 | y=zeros(length(x),1); 4 | y(1)=4*(x(1)-2)^3+2*(x(1)-2*x(2)); 5 | y(2)=-4*(x(1)-2*x(2)); -------------------------------------------------------------------------------- /code/11_5Trust region method/mk.m: -------------------------------------------------------------------------------- 1 | function y=mk(x,xk) 2 | 3 | fk=objective_fun(xk); 4 | gk=gradient(xk); 5 | Bk=Hessian(xk); 6 | 7 | y=fk+gk'*x+0.5*x'*Bk*x; -------------------------------------------------------------------------------- /code/11_5Trust region method/objective_fun.m: -------------------------------------------------------------------------------- 1 | function y=objective_fun(x) 2 | 3 | y=(x(1)-2)^4+(x(1)-2*x(2))^2; -------------------------------------------------------------------------------- /code/12_1ZoutendijkMethodforLinearConstraints/main.m: -------------------------------------------------------------------------------- 1 | f = @(x) objfun(x); 2 | A = [-2 1;-1 -1;1 0;0 1]; 3 | b = [-1;-2;0;0]; 4 | E = []; 5 | e = []; 6 | 7 | [xstar,ystar] = zoutendijk(f,A,b,E,e) -------------------------------------------------------------------------------- /code/12_1ZoutendijkMethodforLinearConstraints/objfun.m: -------------------------------------------------------------------------------- 1 | function [y,g] = objfun(x) 2 | y = x(1)^2+x(2)^2-2*x(1)-4*x(2)+6; 3 | g = [2*x(1)-2;2*x(2)-4]; -------------------------------------------------------------------------------- /code/12_1ZoutendijkMethodforLinearConstraints/zoutendijk.m: -------------------------------------------------------------------------------- 1 | %------------------------------------- 2 | % Zoutendijk feasible direction method 3 | %------------------------------------- 4 | function [xstar,ystar] = zoutendijk(fun,A,b,E,e) 5 | 6 | epsilon = 0.01; 7 | 8 | % Initial feasible point 9 | x = inifeapoi(A,b,E,e); 10 | 11 | % Iteration 12 | while 1 13 | % Feasible descent direction 14 | [d,grad] = feadesdir(fun,A,b,E,e,x); 15 | 16 | % If it is a K-T point 17 | if abs(grad'*d) <= epsilon 18 | xstar = x; 19 | ystar = fun(xstar); 20 | return; 21 | end 22 | 23 | % Line search 24 | lambda = linesearch(fun,A,b,x,d); 25 | 26 | % Update 27 | x = x+lambda*d; 28 | end 29 | 30 | %------------------------------------- 31 | % Initial feasible point 32 | %------------------------------------- 33 | function x = inifeapoi(A,b,E,e) 34 | f = @(x) 0.5*(norm(E*x-e))^2; 35 | while 1 36 | [~,n] = size(A); 37 | x = -5+10*rand(n,1); 38 | if ~isempty(E) 39 | x = fminsearch(f,x); 40 | end 41 | if all(A*x >= b) 42 | break 43 | end 44 | end 45 | 46 | %------------------------------------- 47 | % Feasible descent direction 48 | %------------------------------------- 49 | function [d,grad] = feadesdir(fun,A,b,E,e,x) 50 | epsilon = 0.01; 51 | [~,grad] = fun(x); 52 | temp = A*x; 53 | A1 = A(temp<=b+epsilon,:); 54 | f = grad'; 55 | Aineq = -A1; 56 | bineq = zeros(length(Aineq(:,1)),1); 57 | if isempty(E) 58 | Aeq = E; 59 | beq = e; 60 | else 61 | Aeq = E; 62 | beq = zeros(length(Aeq(:,1)),1); 63 | end 64 | lb = -1*ones(length(x),1); 65 | ub = ones(length(x),1); 66 | d = linprog(f,Aineq,bineq,Aeq,beq,lb,ub); 67 | 68 | %------------------------------------- 69 | % Line search 70 | %------------------------------------- 71 | function lambda = linesearch(fun,A,b,x,d) 72 | epsilon = 0.01; 73 | temp = A*x; 74 | A1 = A(temp<=b+epsilon,:); 75 | A2 = A(temp>b+epsilon,:); 76 | b1 = b(temp<=b+epsilon); 77 | b2 = b(temp>b+epsilon); 78 | b_hat = b2-A2*x; 79 | d_hat = A2*d; 80 | if all(d_hat>=0) 81 | lambda_max = 10; 82 | else 83 | lambda_max = min(b_hat(d_hat<0)./d_hat(d_hat<0)); 84 | end 85 | lineobjfun = @(lambda) fun(x+lambda*d); 86 | lambda = fminbnd(lineobjfun,0,lambda_max); 87 | 88 | 89 | -------------------------------------------------------------------------------- /code/12_2RosenGradientProjectMethod/main.m: -------------------------------------------------------------------------------- 1 | f = @(x) objfun(x); 2 | A = [-1 -1;-1 -5;1 0;0 1]; 3 | b = [-2;-5;0;0]; 4 | E = []; 5 | e = []; 6 | 7 | [xstar,ystar] = rosen(f,A,b,E,e) -------------------------------------------------------------------------------- /code/12_2RosenGradientProjectMethod/objfun.m: -------------------------------------------------------------------------------- 1 | function [y,g] = objfun(x) 2 | y = 2*x(1)^2+2*x(2)^2-2*x(1)*x(2)-4*x(1)-6*x(2); 3 | g = [4*x(1)-2*x(2)-4;4*x(2)-2*x(1)-6]; -------------------------------------------------------------------------------- /code/12_2RosenGradientProjectMethod/rosen.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/code/12_2RosenGradientProjectMethod/rosen.m -------------------------------------------------------------------------------- /code/12_4Frank-WolfeMethod/frank_wolfe.m: -------------------------------------------------------------------------------- 1 | %------------------------------------- 2 | % Frank&Wolfe method 3 | %------------------------------------- 4 | function [xstar,ystar] = frank_wolfe(fun,A,b,E,e) 5 | 6 | epsilon = 0.01; 7 | 8 | % Initial feasible point 9 | x = iniFeaPoi(A,b,E,e); 10 | 11 | % Iteration 12 | while 1 13 | % Solve linear programming problem 14 | [~,grad] = fun(x); 15 | f = grad'; 16 | Aineq = -A; 17 | bineq = -b; 18 | Aeq = E; 19 | beq = e; 20 | y = linprog(f,Aineq,bineq,Aeq,beq); 21 | 22 | % Direction 23 | d = y-x; 24 | 25 | if grad'*d >= -epsilon 26 | % x is a K-T point 27 | xstar = x; 28 | ystar = fun(x); 29 | return; 30 | else 31 | % Line search 32 | lambda = linesearch(fun,x,d); 33 | end 34 | 35 | % Update 36 | x = x+lambda*d; 37 | end 38 | 39 | %------------------------------------- 40 | % Initial feasible point 41 | %------------------------------------- 42 | function x = iniFeaPoi(A,b,E,e) 43 | f = @(x) 0.5*(norm(E*x-e))^2; 44 | while 1 45 | [~,n] = size(A); 46 | x = -5+10*rand(n,1); 47 | if ~isempty(E) 48 | x = fminsearch(f,x); 49 | end 50 | if all(A*x >= b) 51 | break 52 | end 53 | end 54 | x = [0,0]'; 55 | 56 | %------------------------------------- 57 | % Line search 58 | %------------------------------------- 59 | function lambda = linesearch(fun,x,d) 60 | lineobjfun = @(lambda) fun(x+lambda*d); 61 | lambda = fminbnd(lineobjfun,0,1); 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /code/12_4Frank-WolfeMethod/main.m: -------------------------------------------------------------------------------- 1 | f = @(x) objfun(x); 2 | A = [-1 -1;-1 -5;1 0;0 1]; 3 | b = [-2;-5;0;0]; 4 | E = []; 5 | e = []; 6 | 7 | [xstar,ystar] = frank_wolfe(f,A,b,E,e) -------------------------------------------------------------------------------- /code/12_4Frank-WolfeMethod/objfun.m: -------------------------------------------------------------------------------- 1 | function [y,g] = objfun(x) 2 | y = 2*x(1)^2+2*x(2)^2-2*x(1)*x(2)-4*x(1)-6*x(2); 3 | g = [4*x(1)-2*x(2)-4;4*x(2)-2*x(1)-6]; -------------------------------------------------------------------------------- /code/13_1ExteriorPenaltyFunctionMethod/conFun.m: -------------------------------------------------------------------------------- 1 | function y = conFun(x) 2 | y = x(2)-1; -------------------------------------------------------------------------------- /code/13_1ExteriorPenaltyFunctionMethod/exteriorPenalty.m: -------------------------------------------------------------------------------- 1 | %------------------------------------- 2 | % Exterior penality function method 3 | %------------------------------------- 4 | function [xstar,ystar] = exteriorPenalty(funObj,funCon,x0) 5 | 6 | sigma = 1; 7 | c = 2; 8 | epsilon = 0.01; 9 | x = x0; 10 | 11 | while 1 12 | % Constrate the penality term as a function 13 | penTerm = penalityTerm(funCon,sigma); 14 | 15 | % Constrate the exterior penality function 16 | penFun = penalityFunction(funObj,penTerm); 17 | 18 | % Solve auxiliary problem 19 | x = fminsearch(penFun,x); 20 | 21 | if penTerm(x) < epsilon 22 | % x is a K-T point 23 | xstar = x; 24 | ystar = funObj(x); 25 | fprintf('sigma = %f',sigma) 26 | return 27 | else 28 | % Increase penality factor 29 | sigma = c*sigma; 30 | end 31 | end 32 | 33 | %------------------------------------- 34 | % Constrate the penality term as a function 35 | %------------------------------------- 36 | function penTerm = penalityTerm(funCon,sigma) 37 | y = @(x) funCon(x); 38 | penTerm = @(x) sigma*(sum(max(0,-y(x)).^2)); 39 | 40 | %------------------------------------- 41 | % Constrate the exterior penality function 42 | %------------------------------------- 43 | function penFun = penalityFunction(funObj,penTerm) 44 | penFun = @(x) funObj(x)+penTerm(x); 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /code/13_1ExteriorPenaltyFunctionMethod/main.m: -------------------------------------------------------------------------------- 1 | x0 = [0;0]; 2 | funObj = @(x) objFun(x); 3 | funCon = @(x) conFun(x); 4 | [xstar,ystar] = exteriorPenalty(funObj,funCon,x0) -------------------------------------------------------------------------------- /code/13_1ExteriorPenaltyFunctionMethod/objFun.m: -------------------------------------------------------------------------------- 1 | function [y,g] = objFun(x) 2 | y = (x(1)-1)^2+x(2)^2; 3 | g = [2*(x(1)-1);2*x(2)]; -------------------------------------------------------------------------------- /code/13_2BarrierFunctionMethod/barrierFunctionMethod.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QiangLong2017/Optimization-Theory-and-Algorithm/13becd67be377356c221367ffbc7c90a1aabd917/code/13_2BarrierFunctionMethod/barrierFunctionMethod.m -------------------------------------------------------------------------------- /code/13_2BarrierFunctionMethod/conFun.m: -------------------------------------------------------------------------------- 1 | function y = conFun(x) 2 | y = [x(1)-1;x(2)]; -------------------------------------------------------------------------------- /code/13_2BarrierFunctionMethod/main.m: -------------------------------------------------------------------------------- 1 | funObj = @(x) objFun(x); 2 | funCon = @(x) conFun(x); 3 | lb = [-10;-10]; 4 | ub = [10;10]; 5 | [xstar,ystar] = barrierFunctionMethod(funObj,funCon,lb,ub) -------------------------------------------------------------------------------- /code/13_2BarrierFunctionMethod/objFun.m: -------------------------------------------------------------------------------- 1 | function [y,g] = objFun(x) 2 | y = (1/12)*(x(1)+1)^3+x(2); 3 | g = [(1/4)*(x(1)+1)^2;1]; -------------------------------------------------------------------------------- /code/3_1SimplexMethod/linProg.m: -------------------------------------------------------------------------------- 1 | function [xstar,fstar] = linProg(c,A,b) 2 | [m,n] = size(A); 3 | x = zeros(n,1); 4 | [B_idx,N_idx] = baseMat(A); % Initial base and non-base matrix 5 | % B_idx = [3 4 5]; 6 | % N_idx = [1 2]; 7 | 8 | while 1 9 | B_idx 10 | N_idx 11 | x_B = ((A(:,B_idx))^-1)*b; % Base variables 12 | x(B_idx) = x_B; % Initial solution 13 | f = c'*x; % Initial objective function value 14 | w = c(B_idx)'*((A(:,B_idx))^-1);% Simplex multiplier 15 | z_c = w*A(:,N_idx)-c(N_idx)'; % Discrimination number 16 | [zk_ck,k] = max(z_c); % out-bese variable 17 | k = N_idx(k); 18 | if zk_ck <= 0 % optimal solution founded 19 | xstar = x; 20 | fstar = f; 21 | return 22 | else 23 | yk = ((A(:,B_idx))^-1)*A(:,k); 24 | if all(yk<=0) % No finite solution 25 | disp('No finite solution') 26 | xstar = x; 27 | fstar = f; 28 | else 29 | yk0_idx = find(yk>0); % entry-base variable 30 | [x(k),r] = min(x_B(yk0_idx)./yk(yk0_idx)); % enter base 31 | r = B_idx(yk0_idx(r)); 32 | x(r) = 0; % out base 33 | B_idx(B_idx==r) = []; 34 | B_idx = [B_idx k]; 35 | N_idx(N_idx==k) = []; 36 | N_idx = [N_idx r]; 37 | end 38 | end 39 | end 40 | 41 | function [B_idx,N_idx] = baseMat(A) 42 | [m,n] = size(A); 43 | combs = combntns(1:1:n,m); 44 | for comb = combs' 45 | B = A(:,comb); 46 | if abs(det(B)) >= 0.01 47 | B_idx = comb; 48 | N_idx = setdiff(1:1:n,B_idx); 49 | return 50 | end 51 | end -------------------------------------------------------------------------------- /code/3_1SimplexMethod/main.m: -------------------------------------------------------------------------------- 1 | c = [-4 -1 0 0 0]'; 2 | b = [4 12 3]'; 3 | A = [-1 2 1 0 0;2 3 0 1 0;1 -1 0 0 1]; 4 | [xstar,fstar] = linProg(c,A,b) -------------------------------------------------------------------------------- /code/9_1ExactLineSearch/Bisection.m: -------------------------------------------------------------------------------- 1 | function [xstar,fstar]=Bisection(a0,b0) 2 | 3 | global counterf 4 | counterf=0; 5 | 6 | % initialization 7 | epsilon=0.00001; 8 | L=1e-4; 9 | 10 | ak=a0; 11 | bk=b0; 12 | 13 | % iteration 14 | while 1 15 | % stop criteria 16 | len=bk-ak; 17 | if lenfmuk 31 | ak=lambdak; 32 | else 33 | bk=muk; 34 | end 35 | end 36 | 37 | counterf -------------------------------------------------------------------------------- /code/9_1ExactLineSearch/Fibonaccimethod.m: -------------------------------------------------------------------------------- 1 | function [xmin,fmin]=Fibonaccimethod(a,b) 2 | 3 | global counterf 4 | counterf=0; 5 | 6 | % set parameters 7 | L=1e-4; 8 | temp1=(b-a)/L; 9 | 10 | % input Fibonacci sequence 11 | k=3; 12 | while 1 13 | Fibo=P2_fibonacci(k+1); 14 | if Fibo(k)>=temp1; 15 | break; 16 | end 17 | k=k+1; 18 | end 19 | n=k+1; 20 | 21 | ak=a; 22 | bk=b; 23 | for k=1:n-2 24 | % check stop criterion 25 | % lengths=(bk-ak)/2; 26 | % if lengths=fxk+(1-pho)*gradfxk'*dk*alpha); 12 | y=alpha; 13 | break; 14 | elseif fxkplus1>fxk+pho*gradfxk'*dk*alpha 15 | alpha=0.5*alpha; 16 | elseif fxkplus1=sigma*gradfxk'*dk); 14 | y=alpha; 15 | break; 16 | elseif fxkplus1>fxk+pho*gradfxk'*dk*alpha 17 | alpha=0.5*alpha; 18 | elseif gradxkplus1'*dk