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

📄 sga_consfunc_function.m

📁 一个matlab环境下编制的使用很方便的多目标程序
💻 M
字号:
function [ constraint_value ,error_status ] = SGA_CONSFUNC_function( x1 , x2 ,x3)

% /*M-FILE FUNCTION SGA_CONSFUNC_function MMM SGALAB */
% /*==================================================================================================
%  Simple Genetic Algorithm Laboratory Toolbox for Matlab 7.x
%
%  Copyright 2007 The SxLAB Family - Yi Chen - chenyi2005@gmail.com
% ====================================================================================================
%File description:
%
%      SGA_CONSFUNC_function contains the constraint (fitness) functions 
%      this function is an example of a constraint fitness function
%      
%
%Input:
%            x1,x2,x3,... -- are input varialbes
% 
%Output:
%            constraint_value   -- is the constraint (fitness) functions' result
%                                  if 'constraint_value' = NaN , that is to say, the 
%                                  the xi is not fit the constraint functions
%            error_status =    0 -- ok
%                             !0 -- fail
% 
%Appendix comments:
%                     
% 
%Usage:
%[ subjected_decimal_value ] = SGA_CONSFUNC_function(x1,x2,x3)
%
% 
%  See Also:         SGA_ENCODING ,
%                    SGA_DECODING ,
%                    SGA_SELECTION ,
%                    SGA_CROSSOVER,
%                    SGA_MUTATION,
%                    SGA_FITNESS_FUNCTION, 
%                    SGA_FITNESS_EVALUATING, 
%                    SGA_BENCHMARK_FUNCS,
%                    		
%
%===================================================================================================
% 
%===================================================================================================
%Revision -
%Date          Name     Description of Change  email                 where
%27-Jun-2003   Chen Yi  Initial version        chen_yi2000@sina.com  Chongqing
%14-May-2007   Chen Yi  update 1003            chenyi2005@gmail.com  Glasgow
%HISTORY$
%==================================================================================================*/

% SGA_CONSFUNC_function Begin
                             
error_status = 1 ;
eq_flag      = 0;
ineq_flag    = 0;

%check Equation constraint 
if ( ( eq_consfunc1( x1,x2,x3 ) == 0 )&&...
     ( eq_consfunc2( x1,x2,x3 ) == 0 )&&...
     ( eq_consfunc3( x1,x2,x3 ) == 0 )...
   )

   eq_flag = 1 ;
   
end


%check in-Equation constraint 
if  ( ineq_consfunc1( x1,x2,x3 ) <= 0 ) 
    
   ineq_flag = 1 ;
   
end

% check x fit constraint or not
if( eq_flag == 1 && ineq_flag == 1 )
    
   constraint_value = [ x1,x2,x3 ];
   
   error_status = 0 ;
   
else
    
    constraint_value = [ 0,0,0 ];
 
end

% SGA_CONSFUNC_function End



%%Here to define constrait functions : Subject to target functions
% to take constrait function this this way :

% Part I
%=================================================================
%%%  Equation :
%                EQ_CONSFUNC_NUM = 1 ;  f1(x1,x2,x3,...)= 0
%                EQ_CONSFUNC_NUM = 2 ;  f2(x1,x2,x3,...)= 0
%                EQ_CONSFUNC_NUM = 3 ;  f3(x1,x2,x3,...)= 0
%                ...
%==================================================================
% equation 1
function  [ eq_consfunc_value1 ] = eq_consfunc1(x1,x2,x3)
           
           eq_consfunc_value1 = 10.5*x1^2 + 100.334*x2^7+sin(exp( x3 ) );
% equation 2          
function  [ eq_consfunc_value2 ] = eq_consfunc2(x1,x2,x3)
            
           eq_consfunc_value1 = x1/x2+exp( x3 ) ;
% equation 3         
function  [ eq_consfunc_value3 ] = eq_consfunc3(x1,x2,x3)
            
           eq_consfunc_value3 = x1 + x2*sin(exp( x3 ) );

           
% Part II
%=================================================================
%%%  InEquation: :
%                INEQ_CONSFUNC_NUM = 1 ;  g1(x1,x2,x3,...)<= 0
%                INEQ_CONSFUNC_NUM = 2 ;  g2(x1,x2,x3,...)<= 0
%                INEQ_CONSFUNC_NUM = 3 ;  g3(x1,x2,x3,...)<= 0
%                ...
%==================================================================
function [ineq_consfunc_value1]=ineq_consfunc1(x1,x2,x3)

          ineq_consfunc_value1=x1*x2*x3;
      


⌨️ 快捷键说明

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