zoukankan      html  css  js  c++  java
  • 分枝定界的matlab实现

    function [optSolution,optValue,exists]=BranchBound(c,A,b)
    % 分支定界法
    % 整数规划问题标准型
    % min c'*x
    % s.t.
    % A*x<=b
    
    upper = inf;
    lower = -inf;
    branchStack_A(1) = {A};
    branchStack_B(1) = {b};
    numOfVariable = length(c);
    
    while ~isempty(branchStack_A)
        len = length(branchStack_A);
        A = branchStack_A{len};
        b = branchStack_B{len};
        branchStack_A(len) = [];
        branchStack_B(len) = [];
        
    %     A
    %     b
        [x,opt,exist] = linprog(c,A,b);
        if 1 == exist && (opt - upper) <= 1e-7
            for iVar = [1:numOfVariable + 1]
                if iVar <= numOfVariable
                    if abs(x(iVar) - round(x(iVar))) > 1e-7
                        %进行分枝操作,就将子问题入栈
                        temp_A = zeros(1,numOfVariable);
                        
                        temp_A(iVar) = -1;
                        branchStack_A(len) = {[A;temp_A]};
                        branchStack_B(len) = {[b;-(floor(x(iVar) + 1))]};
                        
                        temp_A(iVar) = 1;
                        branchStack_A(len + 1) = {[A;temp_A]};
                        branchStack_B(len + 1) = {[b;floor(x(iVar))]};
                        break;
                    end
                else
                    %是个整数解.更新upper
                    if abs(upper - opt) < 1e-7
                        optSolution(:,end + 1) = x;
                    else
                        optSolution = x;
                        upper = opt;
                        optValue = opt;
                    end
                end
            end %for
        end %if
    end%while
       
    sizeOfSolution = size(optSolution);
    if sizeOfSolution(2) == 0
        exists = 0;
    else
        exists = 1;
    end
    end 
    

      

  • 相关阅读:
    Centos7新特性——systemd取代init管理服务
    Git初探
    Nginx内置变量
    Nginx初探
    PHP多进程初步
    golang消息队列nsq
    golang 的 go异步编程通道要注意的问题
    golang 连接池mysql
    golang centos运行方法
    golang go path和go mod的区别
  • 原文地址:https://www.cnblogs.com/li_shugan/p/3250818.html
Copyright © 2011-2022 走看看