Effacer les filtres
Effacer les filtres

Conditional constraint matrix creation for intlinprog use

1 vue (au cours des 30 derniers jours)
Taner Cokyasar
Taner Cokyasar le 13 Juil 2016
Modifié(e) : Taner Cokyasar le 13 Juil 2016
I know, this question is a little bit complicated and may even be hard to tell in here. However, I really need this to be done. If you see anything unclear, please let me know. So, I can provide more information.
I have following conditional constraint I am using in my mathematical model:
I need to formulate an A and b matrices for this constraint. Sum(m*Zim), B and f(i) is my parameters. t and Beta can be obtained by using parameters. Y(it) is the only variable.
i=3; %Can be higher
m=3; %Can be higher
t=12; %Can be higher
A = 10; %Can be higher
B = 12; %Can be higher
Zim = [0; 0; 1; 0; 1; 0; 0; 1; 0]; %All 'Zim' values are binary variables. Their answers are obtained by solving another model. Depending on 'i' and 'm', the dimension of this vector can be higher.
fi = [6; 3; 5];
For matrix b (which is easier to express), I will only have a vector that is = [9; 7] (for this example) because Sum of mZ(im) values correspond to minimal numbers for the Second and Third 'i'.
For matrix A, I need to construct a matrix containing coefficients of Yit variables. Since i=3 and t=12, I have 36 Yit variables: Y11, Y12, Y13, ... ,Y1(12), Y21, Y22, ... ,Y2(12), Y31, Y32, ... , Y3(12). Thus, I will have a 2x36 matrix as following (for this example):
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 8 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 6 7 0 0 0 0 0
These consecutive number are coming from the equation's upper and lower bounds.
I have the following code already, however, it is not working correctly. If you may fix it or suggest a better code, I would highly appreciate it.
i = size(input,1); %This is basically saying i = 3 for this particular example
m = max(input(:,5)); %This is basically saying m = 3 for this particular example
Alb = 10; %I defined A as Alb here
Bub = 12; %I defined B as Bub here
k = input(:,7); %k corresponds to my f(i) shown in the constraint and takes the data from a file
ss = 1:12;
s = 12;
t = Alb-k;
beta = Bub-k;
Zvalues = [0; 0; 1; 0; 1; 0; 0; 1; 0]; %Zvalues are used instead of Zim. They are same.
si=1;
for ii=1:m:length(Zvalues)
scalar(si)=[1:m]*Zvalues(ii:ii+m-1);
si=si+1;
end
b = [];
A = [];
const6=find(scalar==min(scalar));
for ii=1:length(const6)
a2newrow5=zeros(1,i*12);
monthss=t(ii):beta(ii);
iiss=ones(1,length(monthss))*const6(ii);
yind7=sub2ind([12 i],monthss,iiss);
a2newrow5(yind7)=monthss;
A=[A;a2newrow5];
b=[b; Bub-k(ii)];
end

Réponses (0)

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by