Originally posted by: Mambo12345
Thanks for the quick answer. I will post the code and all my functions to the model:
[Aeq, A, beq, b] = Constraints(T,Y,c'); %this generates my constraints
H=quadraticmatrix(T,Y); %this generates my matrix
opt = cplexoptimset('cplex');
options.Display = 'iter';
Cplex.Param.mip.cuts.bqp = 3;
Cplex.Param.emphasis.numerical = 1;
Cplex.Param.mip.cuts.gomory =2
f = zeros(1,size(Y,1)*size(T,1))
ctype = [];
for i=1:length(A),
ctype = [ctype;'B'];
end
ctype = ctype';
[x,fval,exitflag,output] = cplexmiqp(H, f, A, b', Aeq, beq', [], [], [], [], [], ctype ,[],options); %this solves my problem
lsg2= reshape(x,[size(T,1),size(Y,1)]); %this is to see my solution as a matrix
lsg2=lsg2'
min2=fval
__________________________________
Now my functions:
function H =quadraticmatrix(T,Y)
merge = cell(size(Y));
for k1 = 1:size(Y,1)
for k2 = 1:size(Y,1)
merge{k1,k2} = Y(k1,k2) * T;
end
end
merge = cell2mat(merge);
H=merge+merge' % this is to get a symmetric matrix
end
_________________________
This is my other function to generate the constraints:
function [Aeq, A, beq, b] = Constraints(T,Y,c)
b = ones(1,size(T,1));
beq = ones(1,size(Y,1));
Aeq = zeros(size(Y,1),size(Y,1)*size(T,1));
A = zeros(size(T,1),size(Y,1)*size(T,1));
counter=0;
counter2=0;
counter3=0;
grenze1 = 8;
grenze2 = 14;
grenze3 = 20;
grenze4 = 26;
%this is to generate Aeq
%the people are just allowed to sit in some areas, that depends on the vector c
%if Y is a 10x10 matrix than c hast do be a vector with 10 elements
for j = 0:size(Y,1) - 1
if c(j+1) == 0
Aeq(j+1,size(T,1)*j+1:size(T,1)*j+grenze1)=1;
Aeq(j+1,size(T,1)*j+grenze2+1:size(T,1)*j+grenze3)=1;
else if c(j+1) == 1
Aeq(j+1,size(T,1)*j+1:size(T,1)*j+grenze1)=1;
Aeq(j+1,size(T,1)*j+grenze2+1:size(T,1)*j+grenze3)=1;
Aeq(j+1,size(T,1)*j+grenze3+1:size(T,1)*j+grenze4)=1;
else
Aeq(j+1,size(T,1)*j+grenze1+1:size(T,1)*j+grenze2)=1;
Aeq(j+1,size(T,1)*j+grenze3+1:size(T,1)*j+grenze4)=1;
end
end
end
%this is to generate my matrix A:
for j = 0:size(T,1)-1
for i = 1:size(T,1):size(Y,1)*size(T,1)
A(j+1,i+j) = 1;
end
end
end
In my example now my matrix T is of size 26x26 (I have 26 offices) and I have 10 people, so Y is 10x10 and c is 10x1 with the information in which area the people are allowed to sit.
This is running since 35 minutes and there are more than 47% left.
I dont know what to do.
Thanks for your attention !
#CPLEXOptimizers#DecisionOptimization