Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

What technique does CPLEX use to solve Quadratic Assignment Problems?

  • 1.  What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Wed September 09, 2015 10:22 AM

    Originally posted by: maiklb2005


     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Wed September 16, 2015 06:21 AM

    Originally posted by: PierreBonami


    Hi,

    Your question is very open and hard to answer, but I'll do my best.

    The short answer is simple as CPLEX doesn't develop a specific algorithm for the Quadratic Assignment Problem.

    QAP may be formulated as an MIQP (keeping the products in the objective) or an MILP (linearizing them by adding variables) or stronger relaxations (RLT).

    In the first case it will be solved by our MIQP solver in the latter one by the MIP solver. The relevant sections of our manual are:

    http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.2/ilog.odms.cplex.help/CPLEX/UsrMan/topics/discr_optim/mip/01_mip_title_synopsis.html

    and

    http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.2/ilog.odms.cplex.help/CPLEX/UsrMan/topics/discr_optim/mip_quadratic/02_introMIQP.html

    I hope this helps. Sorry but I don't think we can't say much more.

    Best regards,

    Pierre


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Mon May 13, 2019 01:05 PM

    Originally posted by: Mambo12345


    I have the same question now !
    I have 12 persons and 15 offices and the cplexmiqp takes more than 5 minutes to solve it.
    How can I implement it in a fast way ?
    My solution x is a vector of 15*12=180 elements, right ?
    Or is it possible to formulate it in a different way ?
    All variables are binary and my matrix Aeq is of the form:
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0...  0 0 00

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 .... 0

    15 times 1 in each row that every person has to sit in one office. My vector beq is just a vector with 1 in it.
    I have absolutely no idea to make it faster.
    Can please somebody help me ?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Mon May 13, 2019 01:32 PM


  • 5.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Mon May 13, 2019 01:47 PM

    Originally posted by: Mambo12345


    Hey, thanks for the quick answer. This helps a bit to understand my problem.
    But when I want to solve it with matlab it takes 5 minutes. And I just have small matrices.
    Is it usual that Matlab takes so long to solve a problem with 12 people and 15 offices ?
    I already tried to make a linear program of my QAP and it is even slower.
    It is harder to implement that in Matlab, I guess.
    Because I am not able to use the function cplex.solve()

    I have never heard CPO before, but I will try to find it out.

    Best regards !
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Mon May 13, 2019 02:19 PM

    Hi,

    with CPLEX what takes time in your case is prove optimality, but you may set a time limit and then CPLEX will stop after x s.

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.cplex.help/CPLEX/Parameters/topics/TiLim.html

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Mon May 13, 2019 02:26 PM

    Originally posted by: Mambo12345


    Hey,

    but is it usual that it takes 5 minutes for such an QAP with 12 people and 15 offices ?
    A time limit would not guarantee to give the correct solution.

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue May 14, 2019 12:58 AM

    Whether this is unusual or not can only be answered if you show the full model/data. There can be many reasons why things take so long, including problems in the model formulation.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue May 14, 2019 01:44 AM

    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


  • 10.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue May 14, 2019 02:07 AM

    I am not sure but it seems the definition of Y is missing? It would be easier if you used options.exportmodel="model.sav" and then attach the generated SAV file here.

    Can you also attach the full log output?


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue May 14, 2019 02:30 AM

    Originally posted by: Mambo12345


    Y, T and c are my input parameters. I got them from a text file and copy the values to matlab.
    When I did this, the function is running.
    At the moment it is still running but as soon as it finished I will post all the data here.
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue May 14, 2019 01:34 PM

    Originally posted by: Mambo12345


    Elapsed time = 6410.86 sec. (807832.56 ticks, tree = 2.75 MB, solutions = 15)
     277891    16    infeasible           6777.0000     6773.0000  9241049    0.06%
     277892    19        cutoff           6777.0000     6773.0000  9241044    0.06
    Cover cuts applied:  2
    Zero-half cuts applied:  76
    Gomory fractional cuts applied:  4

    Root node processing (before b&c):
      Real time             =    3.97 sec. (897.48 ticks)
    Parallel b&c, 4 threads:
      Real time             = 6407.02 sec. (806940.21 ticks)
      Sync time (average)   =  440.90 sec.
      Wait time (average)   =    1.74 sec.
                              ------------
    Total (root+branch&cut) = 6410.98 sec. (807837.69 ticks)

     

    Exitflag is 1 and it gave me a good solution, but it takes to long. Do you know what could be the reason for the high time ?
    This is all information I got or what else do you mean ? I hope that you can see what is wrong. If you need some more data.
    I attached a file with my Workspace and all variables that are in my workspace.
    I hope you can find something


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Fri May 24, 2019 03:29 PM

    Hi,

    for QAP and CPO you may have a look at the example https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.ide.help/OPL_Studio/usroplexamples/topics/opl_cp_examples_syntax.html#usroplsamples.uss_opl_cpsamples.1024674__usroplsamples.uss_opl_cpsamples.1024514 in CPLEX

    and with the same data set, if you want to run MIP you may write

    int nbPerm = ...;
    range r = 1..nbPerm;
    int dist[r][r] = ...;
    int flow[r][r] =...;

    execute {
                      cplex.tilim=30;
    }

    range R1 = 1..nbPerm;

    dvar boolean perm[R1][R1];


    dexpr int cost[i in r][j in r] = dist[i][j]*sum(i2,j2 in r) (perm[j][j2]) * (perm[i][i2])*flow[i2][j2];

    minimize sum(i in r, j in r) cost[i][j];
    subject to {

     
    forall(i in R1) sum(j in R1) perm[i][j]==1;
    forall(j in R1) sum(i in R1) perm[i][j]==1;
    };

    tuple permSolutionT{
        int R1;
        int value;
    };
    {permSolutionT} permSolution = {<i0,i> | i0 in R1,i in R1 : perm[i0,i]==1};

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Wed June 12, 2019 08:31 PM

    Originally posted by: EdKlotz


    Please export a SAV or LP file from your MATLAB code and upload that to the forum if you want help on performance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: What technique does CPLEX use to solve Quadratic Assignment Problems?

    Posted Tue June 18, 2019 12:22 AM

    Originally posted by: EdKlotz


    Let me reiterate my request for an LP or SAV file.    I have some Python code that uses that DoCplex based on second half of the presentation attached below that specifically ties to tighten QAP formulations.   Results were mixed, with success on some models, but not much on others.    If you attached an LP file of one of your challenging models, I can try out my code and see if it helps.  It's not sufficiently developed to share it on this forum, but I'd like to try it on some more models.

     

     


    #CPLEXOptimizers
    #DecisionOptimization