The same problem but different results

72 views
Skip to first unread message

haliaetos

unread,
Mar 7, 2014, 9:06:42 AM3/7/14
to yal...@googlegroups.com
hi Johan, I use the the data in cplex to solve the problem,but the matlab says the errors" Infeasible problem (CPLEX-IBM)",however I can solve the problem directly useing the cplex .whether my following code has errors or the yalmip has errors!

clc;clear all;
nbCities = 30;
build_limit = 8;
send = [19 13 20 18 23 25 22 28 18 16 17 14 22 13 18 20 15 23 25 19 18 19 22 22 21 19 17 21 15 25]';
request = [4 1 2 7 9 9 3 9 5 2 4 1 9 3 1 7 5 9 2 4 9 6 5 4 5 6 8 9 5 6];
ship_cost = [  0   61  35   35  53  16  11   58  28  34   43  18   48  30   68   15  27   53  26   32  13  41  54  36  51   68  29  20   49   48;
    61    0  96   88  29  77  50   92  57  75   48  47   76  32   77   74  34   75  87   68  70  38   8  87  71   82  39  78  104  106;
    35   96   0   18  88  21  45   72  58  53   65  49   51  66   93   22  61   76  14   40  33  76  88  43  76   91  64  17   43   33;
    35   88  18    0  87  27  42   84  62  62   51  42   33  62  100   20  55   85  26   25  39  76  81  55  83  100  63  16   59   51;
    53   29  88   87   0  67  45   66  37  54   62  47   85  26   49   68  35   48  77   73  57  14  27  67  44   54  24  73   85   90;
    16   77  21   27  67   0  27   57  36  34   55  32   51  46   73   10  43   57  10   37  12  54  69  29  57   73  43  12   38   34;
    11   50  45   42  45  27   0   64  29  40   35   8   46  20   68   24  16   55  37   31  23  35  43  44  52   69  22  29   60   59;
    58   92  72   84  66  57  64    0  37  24   99  72  106  65   31   67  72   19  60   90  47  54  87  30  23   26  56  69   38   49;
    28   57  58   62  37  36  29   37   0  18   62  36   74  28   40   41  34   26  45   59  24  23  51  30  24   41  19  46   48   54;
    34   75  53   62  54  34  40   24  18   0   75  48   81  45   41   43  50   24  39   66  23  40  69  15  24   39  37  46   32   39;
    43   48  65   51  62  55  35   99  62  75    0  27   29  39   99   46  30   88  63   27  57  59  41  79  85  101  48  49   92   89;
    18   47  49   42  47  32   8   72  36  48   27   0   40  21   74   27  13   62  42   27  31  39  39  52  60   77  26  31   67   65;
    48   76  51   33  85  51  46  106  74  81   29  40    0  60  114   41  51  100  55   15  59  79  69  80  98  115  66  40   89   82;
    30   32  66   62  26  46  20   65  28  45   39  21   60   0   60   44  10   51  56   48  38  19  25  55  48   63  10  49   72   74;
    68   77  93  100  49  73  68   31  40  41   99  74  114  60    0   80  69   17  79   99  61  42  75  53  17    6  51  85   67   77;
    15   74  22   20  68  10  24   67  41  43   46  27   41  44   80    0  39   65  17   26  20  56  66  39  63   80  44   5   48   43;
    27   34  61   55  35  43  16   72  34  50   30  13   51  10   69   39   0   59  53   39  38  29  27  58  56   72  18  44   74   74;
    53   75  76   85  48  57  55   19  26  24   88  62  100  51   17   65  59    0  63   85  45  37  70  37   4   15  42  69   51   60;
    26   87  14   26  77  10  37   60  45  39   63  42   55  56   79   17  53   63   0   42  21  64  80  30  63   78  53  15   34   27;
    32   68  40   25  73  37  31   90  59  66   27  27   15  48   99   26  39   85  42    0  44  65  61  65  83  100  52  27   75   69;
    13   70  33   39  57  12  23   47  24  23   57  31   59  38   61   20  38  45  21   44   0  44  63  22  44   61  34  24   36   36;
    41   38  76   76  14  54  35   54  23  40   59  39   79  19   42   56  29   37  64   65  44   0  34  53  33   46  13  61   71   76;
    54    8  88   81  27  69  43   87  51  69   41  39   69  25   75   66  27   70  80   61  63  34   0  80  67   79  32  71   97   99;
    36   87  43   55  67  29  44   30  30  15   79  52   80  55   53   39  58   37  30   65  22  53  80   0  38   51  48  41   18   25;
    51   71  76   83  44  57  52   23  24  24   85  60   98  48   17   63  56    4  63   83  44  33  67  38   0   17  38  68   53   62;
    68   82  91  100  54  73  69   26  41  39  101  77  115  63    6   80  72   15  78  100  61  46  79  51  17    0  54  84   63   73;
    29   39  64   63  24  43  22   56  19  37   48  26   66  10   51   44  18   42  53   52  34  13  32  48  38   54   0  49   66   69;
    20   78  17   16  73  12  29   69  46  46   49  31   40  49   85    5  44   69  15   27  24  61  71  41  68   84  49   0   48   42;
    49  104  43   59  85  38  60   38  48  32   92  67   89  72   67   48  74   51  34   75  36  71  97  18  53   63  66  48    0   12;
    48  106  33   51  90  34  59   49  54  39   89  65   82  74   77   43  74   60  27   69  36  76  99  25  62   73  69  42   12    0 ];
[m,n]=size(ship_cost);
Ship=sdpvar(m,n);
Build=binvar(1,m);
Constraints=[];
for i=1:m
    Constraints=Constraints+[sum(Ship(i,:))<=Build(i).*send(i)];
end
for j=1:n
    Constraints=Constraints+[sum(Ship(:,j))>=request(j)];
end
Constraints=Constraints+[sum(Build)<=build_limit];
% objective
 Objective=0;
 for i=1:m
     for j=1:n
          Objective =Objective+ ship_cost(i,j)*Ship(i,j);
     end
 end
% Objective =sum(sum(ship_cost.*Ship));
options = sdpsettings('verbose',1,'solver','cplex','cplex.mip',1);
sol = solvesdp(Constraints,Objective,options);
if sol.problem == 0
    solution = double(Build);
else
    display('Hmm, something went wrong!');
    sol.info
    yalmiperror(sol.problem)
end
模型1.jpg

Johan Löfberg

unread,
Mar 7, 2014, 9:28:03 AM3/7/14
to yal...@googlegroups.com
n=m so you've defined Ship to be symmetric

haliaetos

unread,
Mar 8, 2014, 5:58:20 AM3/8/14
to yal...@googlegroups.com
so what ?My m=n,but my Ship isn't the symmetric, Ship(1,2) may not equal the Ship(2,1),how to solve the problem ?

Johan Löfberg

unread,
Mar 8, 2014, 6:18:56 AM3/8/14
to yal...@googlegroups.com

haliaetos

unread,
Mar 8, 2014, 6:48:51 AM3/8/14
to yal...@googlegroups.com
Ship=sdpvar(m,n,'full')?Should I change it? Unbounded objective function (CPLEX-IBM),

Johan Löfberg

unread,
Mar 8, 2014, 10:03:51 AM3/8/14
to yal...@googlegroups.com
Yes, since you don't want to enforce Ship to be symmetric you should use sdpvar(n,m,'full')

The problem is trivially unbounded though. You can achive arbitrarily low objective. You are missing some constraint

sol = solvesdp([Constraints,Objective >= -100000],Objective)
sol
=

    yalmiptime
: 0.2650
    solvertime
: 0.0070
          info
: 'Successfully solved (GUROBI-GUROBI)'
       problem
: 0

>> Objective
Linear scalar (real, 870 variables, current value : -100000)
double(Ship(1:5,1:5))

ans
=

 
815.5246 -796.5246         0         0         0
 
-811.5246  806.5246         0         0         0
         
0   -2.0000    2.0000         0         0
         
0   -7.0000         0    7.0000         0
         
0   -9.0000         0         0    9.0000




Johan Löfberg

unread,
Mar 8, 2014, 10:09:21 AM3/8/14
to yal...@googlegroups.com
FYI, the following compact model is possible. I've added the constraint you most likely missed

 Constraints = [sum(Ship,2) <= Build(:).*send(:),
                sum
(Ship,1) >= request,
                sum
(Build)<=build_limit,Ship >= 0];
 
Objective = sum(sum(ship_cost.*Ship));


haliaetos

unread,
Mar 9, 2014, 3:48:11 AM3/9/14
to yal...@googlegroups.com
oh,yes,I am really missing the Constraints:Ship>=0;And your Constraints and Objective is sure simple,Yalmip is worth to leraning,but I have another question whether the solution is the best value,?I am coding the example LagrangianRelaxation in Cplex,if the solution is the best value ,need i to calculate the other value!

haliaetos

unread,
Mar 9, 2014, 3:58:46 AM3/9/14
to yal...@googlegroups.com
And why  the Matlab output the information with the Cplex when I solve the problem!How to control it ! And " options = sdpsettings('verbose',1,'solver','cplex','cplex.mip',1); Whether  he " cplex.mip',1"  is as the default,if not code it ,the solvertime whether is not increasing
information.png

haliaetos

unread,
Mar 9, 2014, 3:58:57 AM3/9/14
to yal...@googlegroups.com
information.png

Johan Löfberg

unread,
Mar 9, 2014, 2:36:28 PM3/9/14
to yal...@googlegroups.com
Yes, it is optimal. The problem is trivial to solve for CPLEX, finishes already in the first node.

Johan Löfberg

unread,
Mar 9, 2014, 2:40:34 PM3/9/14
to yal...@googlegroups.com
Are you really using the latest version of YALMIP? It should essentially be impossible for anything to be seen from cplex if you set verbose to 0, as YALMIP places the call to cplex in a evalc call, to take care of some bugs in the display logic in cplex.

Note, you cannot control any cplex options at the moment. There is a severe bug in the CPLEX MATLAB interface. Any option you try to use will be completely disregarded by cplex.
https://www.ibm.com/developerworks/community/forums/html/topic?id=7dce2826-4858-4136-bbd4-a31fb7fadd90&ps=50
Reply all
Reply to author
Forward
0 new messages