⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panmip.m

📁 由matlab开发的hybrid系统的描述语言
💻 M
📖 第 1 页 / 共 5 页
字号:
            flag = 7;
         case {3}   % unbounded
            flag = -1;
         case {4}        % Objective limit exceeded in Phase II
            flag = 7;    %% MUST BE CORRECTED / CHECKED
         case {5}        % Iteration limit exceeded in Phase II
            flag = 7;    %% MUST BE CORRECTED / CHECKED
         case {6}        % Iteration limit exceeded in Phase I
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {7}        % Time limit exceeded in Phase II
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {8}        % Time limit exceeded in Phase I
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {9}        % Problem non-optimal,singularities in Phase II
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {10}       % Problem non-optimal,singularities in Phase I
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {11}       % Optimal solution found, unscaled infeasibilities
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {12}       % Aborted in Phase II
            flag = 7;    %% MUST BE CORRECTED / CHECKED       
         case {13}       % Aborted in Phase I
            flag = 7;    %% MUST BE CORRECTED / CHECKED       
         case {14}       % Aborted in barrier, dual infeasible
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {15}       % Aborted in barrier, primal infeasible
            flag = 7;         
         case {16}       % Aborted in barrier,primal and dual infeasible
            flag = 7;  
         case {17}       % Aborted in barrier, primal and dual feasible 
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {18}       % Aborted in crossover
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {19}       % Infeasible or unbounded
            flag = 7;  
         case {32}       % Converged, dual feasible, primal infeasible
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {33}       %  Converged, primal feasible, dual infeasible 
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {34}       % Converged, primal and dual infeasible
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {35}       % Primal objective limit reached
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {36}       % Dual objective limit reached  
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {37}       % Primal has unbounded optimal face
            flag = -1;   %% MUST BE CORRECTED / CHECKED        
         case {38}       % Non-optimal solution found, primal-dual feasible
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {39}       % Non-optimal solution found, primal infeasible
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {40}       % Non-optimal solution found, dual infeasible  
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {41}       % Non-optimal solution found, primal-dual infeasible
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {42}       % Non-optimal solution found, numerical difficulties
            flag = 7;    %% MUST BE CORRECTED / CHECKED        
         case {43}       % Barrier found inconsistent constraints
            flag = 7;    %% MUST BE CORRECTED / CHECKED
         case {101}      % cpxmip_optimal: Optimal integer solution found 
            flag = 1;
         case {102}      % Optimal sol. within epgap or epagap tolerance found
            flag = 1;
         case {103}      % Integer infeasible  
            flag = 5;    %% MUST BE CORRECTED / CHECKED        
         case {104}      % Mixed integer solutions limit exceeded  
            flag = 7;    %% MUST BE CORRECTED / CHECKED
         case {105}      % Node limit exceeded, integer solution exists  
            flag = 11;   %% MUST BE CORRECTED / CHECKED        
         case {106}      % Node limit exceeded, no integer solution  
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         case {107}      % Time limit exceeded, integer solution exists  
            flag = 11;   %% MUST BE CORRECTED / CHECKED        
         case {108}      % Time limit exceeded, no integer solution  
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         case {109}      % Error termination, integer solution exists  
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {110}      % Error termination, no integer solution  
            flag = 5;    %% MUST BE CORRECTED / CHECKED
         case {111}      % Treememory limit, integer solution exists  
            flag = 11;   %% MUST BE CORRECTED / CHECKED        
         case {112}      % Treememory limit, no integer solution exists  
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         case {113}      % Aborted, integer solution exists  
            flag = 11;   %% MUST BE CORRECTED / CHECKED        
         case {114}      % Aborted, no integer solution  
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         case {115}      % Problem optimal with unscaled infeasibilities  
            flag = 1;    %% MUST BE CORRECTED / CHECKED        
         case {116}      % Out of memory, no tree, integer solution exists  
            flag = 11;   %% MUST BE CORRECTED / CHECKED        
         case {117}      % Out of memory, no tree, no integer solution  
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         case {118}      % Node file size limit, integer solution exists
            flag = 11;   %% MUST BE CORRECTED / CHECKED  
         case {119}      % Node file size limit, no integer solution          
            flag = 15;   %% MUST BE CORRECTED / CHECKED        
         otherwise
            error('other error code from CPLEX')
      end  
      
      if (flag == 7) | (flag == -1)
         xopt = x_opt_init;
         fopt = f_opt_init;
      end                         
             
   case {'cplex_file'}
   %------------------  
      
      if ~isunix
         if ~exist('cplex2.bat')
            % create the batch file used for calling cplex
            fid = fopen('cplex2.bat','wt');
            fprintf(fid,'@echo off\n');
            fprintf(fid,'set ILOG_LICENSE_FILE=%s\n',IlogLicense);
            fprintf(fid,'set PATH=%%PATH%%;%s\n',CplexPath);
            fprintf(fid,'cplex.exe < %%1 > %%2');
            fclose(fid)
            cplex2onthefly = 1;  % this variable is used later to determine
                                 % whether cplex2.bat has been generated
                                 % on the fly and will have to be deleted
                                 % before laving the function panmip
         else
            cplex2onthefly = 0;
         end 
      else
         cplex2onthefly = 0;      
      end
         
      if ~isfield(Options,'cplex_file')
         Options.cplex_file = [];
      end
      
      if isfield(Options.cplex_file,'extractbox')
         extractbox = Options.cplex_file.extractbox;
      else
         extractbox = 0;         
      end
      
      if isfield(Options.cplex_file,'infinity')
         infty  = Options.cplex_file.infinity;
      else
         infty  = 1e8;
      end
      
      if isfield(Options.cplex_file,'deletefile')
         deletefile  = Options.cplex_file.deletefile;
      else
         deletefile  = 1;
      end
      
      if isfield(Options.cplex_file,'suppresserr')
         suppresserr  = Options.cplex_file.suppresserr;
      else
         suppresserr  = 0;
      end  

      if isfield(Options.cplex_file,'quality')
         quality  = Options.cplex_file.quality;
      else
         quality  = 0;
      end  
               
      if isfield(Options.cplex_file,'presolve')
         presolve  = Options.cplex_file.presolve;
      else
         presolve  = 1;
      end           
      
      if isfield(Options.cplex_file,'mpsfile')
         mpsfile  = Options.cplex_file.mpsfile;
      else
         mpsfile  = 'ravioli_cplex_prob_298.mps';
      end
      
      if isfield(Options.cplex_file,'runfile')
         runfile  = Options.cplex_file.runfile;
      else
         runfile  = 'basilicoVerde_run_file_563';
      end
      
      if isfield(Options.cplex_file,'solutionfile')
         solutionfile  = Options.cplex_file.solutionfile;
      else
         solutionfile  = 'solution_stracciatella_6329';
      end
      
      if isfield(Options.cplex_file,'initialsolutionfile')
         initialsolutionfile  = Options.cplex_file.initialsolutionfile;
      else
         initialsolutionfile  = 'initial_solution_malaga_1245';
      end
      
      if isfield(Options.cplex_file,'treefile')
         treefile = Options.cplex_file.treefile;
      else
         treefile = 'tree_file_prosciutto_e_funghi_54386';
      end
      oldtreefile = [treefile, '_old'];
                   
      if (norm(H,inf) > 1e-4) 
         if ( ~isempty(find(vartype=='B')) | ~isempty(find(vartype=='I')) )
            if ~suppresserr
               error('This is an MIQP, this solver option allows only MILPs')
            else
               warning('Will set Hessian to 0 and solve an MILP')
               QPflag   = 0;  
               MILPflag = 1;
               LPflag   = 0;
            end
         else
            QPflag   = 1;  
            MILPflag = 0;
            LPflag   = 0;
         end   
      else % no quadratic coefficients
         if ( ~isempty(find(vartype=='B')) | ~isempty(find(vartype=='I')) )
            QPflag   = 0;  
            MILPflag = 1;
            LPflag   = 0;
         else
            QPflag   = 0;  
            MILPflag = 0;
            LPflag   = 1;
         end 
      end        

      Options2                = [];
      Options2.solver         = 'mps';
      Options2.mps.outname    = mpsfile;
      Options2.mps.infinity   = infty;
      Options2.mps.extractbox = extractbox;
      Options2.mps.format     = 'cplex'; 
      Options2.mps.QPflag     = QPflag;
      Options2.mps.MILPflag   = MILPflag;
      Options2.mps.LPflag     = LPflag;
      Options2.mps.suppresserr= suppresserr;
      
      swarn = warning;  % Saves current warning state
      warning off;      
       
      [xopt, fopt, flag, Extendedflag] = ...
         panmip(H, f, C, d, ctype, rangevar, vartype, lb, ub, x0, Options2); 

      warning(swarn); 
      
      % if we are solving an MILP and x0 was provided write it to a MST file
      useinitialsolution = 0; % runfile should write the instructions to use 
                              % initial solution
      if (x0_was_provided)
         if (MILPflag)
            writeMST(x0, x0ii, vartype, initialsolutionfile);
            useinitialsolution  = 1;
            initialsolutiontype = 'mst';
         else
            warning('Initial solution will be ignored');
         end
      end      
     
      % writing the file defining the actions to run with cplex 
            
      fid = fopen(runfile,'w');        % open file                
      
      fprintf(fid,'re %s\n',mpsfile);  % read problem
      
      if (useinitialsolution)
         if strcmp(initialsolutiontype,'mst');
            fprintf(fid, 're %s mst\n', initialsolutionfile);
            fprintf(fid, 'set mip strategy mipstart 1\n');
         end
      end
            
      if isfield(Options.cplex_file,'absmipgap')
         absmipgap = Options.cplex_file.absmipgap;
         if absmipgap <= 0
            error('a negative absmipgap is not allowed')
         end   
         fprintf(fid,['set mip tolerances absmipgap ',num2str(absmipgap),'\n']);
      end
      
      if isfield(Options.cplex_file,'mipgap')
         mipgap = Options.cplex_file.mipgap;
         if mipgap <= 0
            error('a negative mipgap is not allowed')
         end   
         fprintf(fid,['set mip tolerances mipgap ',num2str(mipgap),'\n']);
      end      
      
      if isfield(Options.cplex_file,'itolerance') & ...
        ~isfield(Options.cplex_file,'integrality')
         inttol = Options.cplex_file.itolerance;
         if inttol <= 0
            error('negative integer tolerances are not allowed')
         end   
         fprintf(fid,['set mip tolerances integrality ',num2str(inttol),'\n']);
      end 
      
      if isfield(Options.cplex_file,'nodeselect')
         switch Options.cplex_file.nodeselect
         case 'depth'
            ndsl = 0;
         case 'best-bound'   
            ndsl = 1;
         case 'best-est'   
            ndsl = 2;
         case 'a-best-est'  
            ndsl = 3;
         otherwise
            warning('node selection strategy not implemented,choose best-bound')
            ndsl = 1;
         end        
         fprintf(fid,['set mip strategy nodeselect ',num2str(ndsl),'\n']);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -