Формулировка многоцелевой оптимизации нескольких пластов (NSGA II) в MATLAB - PullRequest
0 голосов
/ 27 мая 2020

Я хочу оптимизировать систему резервуаров с помощью NSGA II (gamultiobj) в MATLAB. Я просто стремился построить воображаемую систему резервуаров, которая работает со случайными значениями, чтобы понять систему. Но какое-то время я не мог продолжить. Поделюсь кодом ниже. У меня есть 4 резервуара на 3 временных шага . Я хотел бы максимизировать общий сброс воды для забора энергии и орошения (2 цель). Нужно ли мне писать символы c математика? Я рассмотрел примеры, но решить не смог. Буду рад, если поможете.

%%%%% 4 RESERVOIR EXAMPLE %%%%
%  
%                 |
%                 |
%                 v
%                ÆÆÆ
%     |         ÆÆÆÆÆ     
%     |          [2]
%     |           |
%     v           v
%    ÆÆÆ         ÆÆÆ
%   ÆÆÆÆÆ       ÆÆÆÆÆ
%    [1]         [3]
%     |__ __ __ __|
%           |
%           |  
%           v
%          ÆÆÆ
%         ÆÆÆÆÆ     
%          [4]
% 

% X (i,t) 
% i = RESERVOIR INDEX
% t = TIMESTEP

% EN: RELEASE FOR GENERATING ENERGY, IR: ABSTRACT FOR IRRIGATION DEMAND
% 4 RESERVOIR FOR 3 TIMESTEP:
% X  =[EN(1,1) EN(1,2) EN(1,3)
%      EN(2,1) EN(2,2) EN(2,3)
%      EN(3,1) EN(3,2) EN(3,3)
%      EN(4,1) EN(4,2) EN(4,3)
%      IR(1,1) IR(1,2) IR(1,3)
%      IR(2,1) IR(2,2) IR(2,3)
%      IR(3,1) IR(3,2) IR(3,3)
%      IR(4,1) IR(4,2) IR(4,3)]

% INFLOW FROM EACH SUBBASIN INTO RESERVOIR
INF =[40 40 40 ; ...
      20 20 20 ; ...
      20 20 20 ; ... 
      10 10 10 ]   

% M(J,K): RESERVOIR SYSTEM CONNECTIVITY MATRIX
%         (-1) FOR ABSTRACTION, (+1) RECEIVES WATER FROM UPSTREAM RESERVOIR
%         RESERVOIR(J) RECEIVES WATER FOM RESERVOIR(K)
M = [-1   0   0   0 ; ...
      0  -1   0   0 ; ...
      0   1  -1   0 ; ... 
      1   0   1  -1 ]

% N(J,K): IRRIGATION SYSTEM CONNECTIVITY MATRIX
%         (-1) FOR ABSTRACTION, (+1) RECEIVES RETURN WATER FROM UPSTREAM IRRIGATION
%         RESERVOIR(J) RECEIVES WATER FOM IRRIGATION(K)
N = [-1   0   0   0 ; ...
      0  -1   0   0 ; ...
      0   1  -1   0 ; ... 
      1   0   1  -1 ]

% MERGE CONNECTIVITY MATRCIES
CON_MAX = [M N]    

% MERGE RELEASES FOR ENERGY AND ABSTRACTIONS
% EN = ones(4,3)
% IR = ones(4,3)
X = [EN; IR]

% RELEASE FOR ENERGY AND IRRIGATION TOTAL MUST BE > 10 CMS
% A*x <= b
% -EN-IR <= -10 
A = [-1  0  0  0 -1  0  0  0; ...
      0 -1  0  0  0 -1  0  0; ...
      0  0 -1  0  0  0 -1  0; ... 
      0  0  0 -1  0  0  0 -1] 

b = [-10 -10 -10 ; ...
     -10 -10 -10 ; ...
     -10 -10 -10 ; ... 
     -10 -10 -10 ] 

% lb < x < ub
% 0 (FOR BOTH SECTOR) < x < 100 FOR ENERGY AND 95 FOR IRRIGATION
lb = [0 0 0 ; ...
      0 0 0 ; ...
      0 0 0 ; ... 
      0 0 0 ; ... 
      0 0 0 ; ...
      0 0 0 ; ...
      0 0 0 ; ... 
      0 0 0 ] 

ub = [100 100 100 ; ...
      100 100 100 ; ...
      100 100 100 ; ... 
      100 100 100 ; ... 
      95   95  95 ; ...
      95   95  95 ; ...
      95   95  95 ; ... 
      95   95  95 ] 

t         = 1 % START FROM TIMESTEP 1
T         = 3 % TIME HORIZON (t_END)
RES_COUNT = 4 % RESERVOIR COUNT
EN_COUNT  = 4 % ENERGY RELEASE COUNT
IR_COUNT  = 4 % IRRIGATION ABSTRACT COUNT
NVAR      = (EN_COUNT+IR_COUNT)*T %TOTAL NUMBER OF DECISION VARIABLE 

% INITIAL STORAGE VOLUMES
S_0 = [10 ; ...
       10 ; ...
       10 ; ... 
       10 ] 

%% CONTINUITY CONSTRAINTS
%  STORAGE(t+1) = STORAGE(t) + INFLOW(t) + M*ENERGY(t) + N*IRRIGATION(t)
%  STO = S0 + INF + M*EN + N*IR
%  STO = S0 + INF + CON_MAX * X
STO = zeros(RES_COUNT,T);

    t = 1           % ONLY FOR TIMESTEP = 1  
    for i = 1:4     % EACH RESERVOIR 
        STO(i,t) = S_0(i,t) + INF(i,t) + CON_MAX(i,t) * X(i,t)  ;
    end

% LOOP
for t = 2:3         % EACH TIMESTEP    
    for i = 1:4     % EACH RESERVOIR  
        STO(i,t) = STO(i,(t-1)) + INF(i,t) + CON_MAX(i,t) * X(i,t) ; 

    % PENALTY FUNCTIONS:
    % TO OVERCOME THE GA LIMITATIONS ON HANDLING THE HIGHLY CONSTRAINED SYSTEM, THE NONLINEAR CONSTRAINTS
    % ARE SATISFIED IN DIFFERENT WAYS TO TRANSFORM THE CONSTRAINED OPTIMIZATION INTO THE UNCONSTRAINED ONE.
    % THE COMPUTATION OF RESERVOIR STORAGE IS BASED ON THE CONTINUITY EQUATION SO IT IS SATISFIED.
    % STORAGE AND END-STORAGE CONSTRAINTS ARE INCLUDED INTO THE OBJECTIVE FUNCTION IN FORM OF PENALTY FUNCTIONS. 
    % THE DEVIATION FROM THE MIN AND MAX STORAGE AND END-STORAGE ARE PENALIZED BY SQUARE DIFFERENCES FROM CONSTRAINTS.

    % PENALTY 1, 3 AND 3
    P_1 = zeros(4,3)
    P_2 = zeros(4,3)
    P_3 = zeros(4,3)

    % MIN AND MAX STORAGE FOR EACH RESERVOIR EACH TIMESTEP
    S_MIN=[ 1 1 1 ; ...
            1 1 1 ; ...
            1 1 1 ; ... 
            1 1 1 ]

    S_MAX=[ 50 50 50 ; ...
            50 50 50 ; ...
            50 50 50 ; ... 
            50 50 50 ]

    % PENALTY WEIGHTED FACTOR ASSUMPTION
    K_1=60
    K_2=40
    K_3=40     

    P_1 (i,t)= K_1*(S_MIN(i,t)-STO(i,t)).^2
    P_2 (i,t)= K_2*(STO(i,t)-S_MAX(i,t)).^2
    P_3 (i,t)= K_3*(STO(i,T)-STO(i,1)).^2
    % P_1, P_2 AND P_3 WILL INSERT TO OBJECTIVE FUNCTIONS 

    end
end

%% SYMBOLIC MATH ??
XX   = sym('x',[RES_COUNT*2,T]);              % WATER RELEASE AND IRRIGATION
FF   = sym('F',[RES_COUNT,T]);                % FLOW INTO RESERVOIR
SS00 = sym('S0',[RES_COUNT,T]);               % INITIAL STORAGE
CC   = sym({'c1','c2','c3','c4'}.','real');   % CONSTANT

for t = 1:T 
    TOTFLOW(1:RES_COUNT,t) = M*XX(1:RES_COUNT,t) + N*XX(RES_COUNT+1:end,t);
end

t = 1
SS = cell(RES_COUNT,T);

for i = 1:RES_COUNT 
    SS{i,t} = SS00(i,t) + CC(1)*(FF(i,t)-TOTFLOW(i,t));
end

for t = 2:T 
    for ii = 1:RES_COUNT
        SS{ii,t} = SS{ii,t-1} + CC(1)*(FF(ii,t)-TOTFLOW(ii,t));
    end
end
%celldisp(SS)

% TOTAL EN AND IR (MINUS FOR MAX TO MIN)
for t = 1:T 
    for i = 1:RES_COUNT    
        OBJ1T(i,t) = XX(i,t);
        OBJ1 = -sum(OBJ1T);

        OBJ2T(i,t) = XX(RES_COUNT+i,t);
        OBJ2 = -sum(OBJ2T);
    end
end

% GENERATE A MATLAB FILE
matlabFunction(OBJ1,'vars',{XX},'file','OBJI1');
matlabFunction(OBJ2,'vars',{XX},'file','OBJI2');

%%
% HOW CAN I SETUP THIS FUNCTION?
% TWO OBJECTIVE FUNCTION, FOR EACH TIMESTEP:
% 1) MAXIMIZE TOTAL RELEASE FOR ENERGY
% 2) MAXIMIZE TOTAL ABSTRACTION FOR IRRIGATION
% 
% fitnessfcn = @(EN,IR)[OBJ_1, OBJ_2]
% 
% OBJ_1 =sum(NN*EN - (P_1 + P_2 + P_3) ) 
% OBJ_2 =sum(N*IR  - (P_1 + P_2 + P_3) ) 
%  
% [x,fval] = gamultiobj(@OBJ1,1,[],[],[],[],lb,ub,options)?
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...