Can yalmip toolbox solve problems like this (my target function involves set operations)?thx!

503 views
Skip to first unread message

李汇熙

unread,
Feb 18, 2015, 4:42:20 AM2/18/15
to yal...@googlegroups.com

As you guys can see in the above pic, my target function involves set operations(Vi and Cj here are sets). Hence I was wondering whether the yalmip could solve such type of problems.

sorry for this question if you guys thought it's stupid...cause I've worked with Matlab just a few days ago.

Thank you very much and best regards!


Johan Löfberg

unread,
Feb 18, 2015, 4:47:48 AM2/18/15
to yal...@googlegroups.com
You notation is very unclear. What are decision varaibles and what are constants. What does it mean to minimize a sum of sets?.What do your substractions and aditions mean? Minkowsky difference? Intersection? How does the set V relate to the (assumed) variable v. Is vc_j a variable, or the product of the variable v and c_j?...

李汇熙

unread,
Feb 18, 2015, 5:15:32 AM2/18/15
to yal...@googlegroups.com
Thank you very much for your reply.
Well, I mean I want to mimize the number of element of a set. So could I call functions of set operations, which are coded by myself, when I define the objective?
For instance, in the basic example you give for the beginner, you said:

% Define constraints and objective
Constraints = [sum(x) <= 1, x(1)==0, x(2) >= 0.5];
Objective = x'*x+norm(x);

and I want to modify the right side of the "Objective = x'*x+norm(x);" as "Objective = No_of_SET_Elm(X)", where X is a set and the No_of_SET_Elm() is a function of getting the element number of certain set. 





Johan Löfberg

unread,
Feb 18, 2015, 5:23:12 AM2/18/15
to yal...@googlegroups.com
Sounds like you say set when you simply mean a vector/matrix of variables.

One interpretation of what your description looks like is

% Decision variable
X
= binvar(m,n,'full')
% Constants
vc
= randn(1,m);
pc
= randn(1,n);
v
= randn(n,1)
c
= randn(m,1)
Constraints = [sum(X,2) == 1, vc*X <= pc];
Objective = norm(X*v - c,1)


李汇熙

unread,
Feb 18, 2015, 6:13:25 AM2/18/15
to yal...@googlegroups.com
Thanks!
And yes I use a 0-1 matrix to describe the relationship between elements and sets. For example, if element a belongs to set A, the corrsponding value is 1 in the matrix;otherwise it's 0.
I've written several functions in Matlab to implement those basic set operations, and I wanna use them in Yalmip.
BTW, today is the Chinese New Years' Eve(除夕),  and happy Chinese Spring Festival (春节) to you!

Johan Löfberg

unread,
Feb 18, 2015, 6:14:57 AM2/18/15
to yal...@googlegroups.com
You are not going to be able to use those functions, unless they are simple linear operators

Give an example of what you are trying to do

李汇熙

unread,
Feb 18, 2015, 8:04:53 AM2/18/15
to yal...@googlegroups.com

Thanks!

The matrix M is below. For example, b belongs to set v2, hence m_22=1.

v1=[0 1 0 1 0 1 1]', v2, v3, v4, c1, c2 has property value vc1=3, vc2=4, vc3=2, vc4=4, pc1=6 and pc2=7 respectively.

My objective and constraints are shown in the figure below.


if X_ij=1, vi has certain type of relationship with cj. 


李汇熙

unread,
Feb 18, 2015, 8:06:04 AM2/18/15
to yal...@googlegroups.com
if X_ij=1, vi has certain type of relationship with cj; otherwise, X_ij=0.

Johan Löfberg

unread,
Feb 18, 2015, 8:10:09 AM2/18/15
to yal...@googlegroups.com
I don't see where the complication is. Sounds like you only have your own functions to define data , not to define any desired properties of the decision variable X. As I did before, the model you have is easily described as a simple MILP

李汇熙

unread,
Feb 18, 2015, 8:56:16 AM2/18/15
to yal...@googlegroups.com
yes, what I want to do is use my own defined functions in the objective, and I did not know whether this was feasible until I posted my question here and you answered it.  
Thank you very much for your help and time!

Johan Löfberg

unread,
Feb 18, 2015, 9:02:38 AM2/18/15
to yal...@googlegroups.com
You are not using any functions in your model. You are only using data created using your function, which of course is allowed (YALMIP does care how data was generated)

李汇熙

unread,
Feb 18, 2015, 9:42:18 AM2/18/15
to yal...@googlegroups.com
sorry sir, I don't understand precisely what do mean by "You are not using any functions in your model"... actually, I do make some operations of matrices in my objective (to obtain the unions and deferences of some sets), and I don't analyze whether these operations/functions are linear yet (but I think they are linear).

Johan Löfberg

unread,
Feb 18, 2015, 9:47:04 AM2/18/15
to yal...@googlegroups.com
What I am saying is that the YALMIP model I created based on your description, does not reference any of your strange functions. As long as your functions have created the data (c,v,pc,vc etc), everything is just standard MATLAB operations in the decision variable X.

Note, I interpret you U operation as a simple summation, i.e., the sum of all V(i) such that X(i,j)=1, which simplifies to a simple linear sum. If your U means something else, you have to clarify the notation (since if it is a set, i.e., a collection of something, it is really strange to take absolute value (if that is what | | means ) etc

李汇熙

unread,
Feb 18, 2015, 10:03:43 AM2/18/15
to yal...@googlegroups.com
Thx.
In my model, || is to obtain the number of element of a set (to count the number of 1 in an array) and U operation is to get the union of some sets.
For example, if x(1,2)=1 and x(2,2)=1, I will do (v1 U v2) - c2, and then obain the number of element of that set. There are many combinations of above operations, and I wish to find out which on could give me the smallest number of element.

Johan Löfberg

unread,
Feb 18, 2015, 10:17:22 AM2/18/15
to yal...@googlegroups.com
if v1 [0 1 0 1 0 1 1] and v2 is [1 1 0 1 0 0 0] and c1 = [1 0 0 1 1 0 0] , what is (v1 U v2)-c1?  The logic expression  v1 && v2 && (~c1)?

李汇熙

unread,
Feb 18, 2015, 10:40:31 AM2/18/15
to yal...@googlegroups.com
No sir, union operation is not && but ||(logic OR), and there is not logic expresssion for difference operation.

Johan Löfberg

unread,
Feb 18, 2015, 11:18:51 AM2/18/15
to yal...@googlegroups.com
Sorry, meant ||

So what is the result of (v1 U v2)-c1 with the given data


李汇熙

unread,
Feb 18, 2015, 10:45:03 PM2/18/15
to yal...@googlegroups.com
it's a set, and |v1| is the number of element of v1.
For instance, let the universal set = {a,b,c,d,e,f}, v1 = {a,b,c}, v2={b,c,d}, v3={d,e,f}, v4={a,c,e},c1={c}, c2={e,f}. so v1 U v2 ={a,b,c,d}, (v1 U v2)-c1={a,b,d}, and |(v1 U v2)-c1|=3.
In Matlab, I define the universal set = [1 1 1 1 1 1]', and v1= [1 1 1 0 0 0 ]', etc.
Actually, my trouble here is: in common, the objective of a MILP is like ∑c_i*x_i, it's a numerical plus operation (e.g.1+2=3), but my requirement here is more complicated. 
I  apply the 0-1 operators to choose which  sets could do the U operation, and then count the summation of total munber of all these union sets. 
In the example above, for |(v1 U v2)-c1|, I actually applied the 0-1 operator to remove v3 and v3 before I did the || operation(count the number of element).
Thx!

Johan Löfberg

unread,
Feb 19, 2015, 2:28:06 AM2/19/15
to
So it is (v1 || v2 ) && (~c1) then, when everything simply is interpreted as binary vectors

Johan Löfberg

unread,
Feb 19, 2015, 3:17:19 AM2/19/15
to yal...@googlegroups.com
and the summary is simply that you have to write everything in terms of standard algebra on binary vectors (with a 1 representing that a particular item is in set, and picking out some element from e.g. the binary vector V would be X(i,j)*V(i,j) etc).

If you have a binary vector z, the cardinality is trivially given by sum(z)

If you have binaries a b c, and you want to compute d = a || b && ~c, you have

[d <= 1-c, d >= a-c, d >= b-c, d <= a + b]

or with auxilliary variable w  to hold the ||

[d <= 1-c, d >= w - c, d <= w, w >= a, w >= b, w <= a + b]

It is actually possible to let YALMIP do the binary modelling, but I would be careful, as I've seen a couple of bugs. I hope I've sorted them all out, but no promises
>> binvar a b c
>> true((a | b) & ~(c))

There are also high-level operators such as ismember  and nnz etc, but that will very likely give you overly complicated models. You model is naturally written as a simple 0/1 problem

李汇熙

unread,
Feb 19, 2015, 3:54:35 AM2/19/15
to yal...@googlegroups.com
Thank you very much for your help!
I'm gonna do some tests on my computer.

李汇熙

unread,
Feb 19, 2015, 8:51:36 AM2/19/15
to yal...@googlegroups.com
Sir, there are some errors after I run my test. I'm not sure whether these errors were caused by my source code or not because it said that there is an error of sdpvar.or.
Plz help me to fix them, thank you very much!

Error in sdpvar.or (line 22)
switch class(varargin{1})

Output argument "varargout" (and maybe others) not assigned during call to "D:\Program
Files\MATLAB\R2012a\toolbox\yalmip\@sdpvar\or.m>or".

Error in Sum_of_U (line 12)
        T = T | V;

Error in test1 (line 7)
Obj = Sum_of_U(X, M, C);

And here is my source code:
Sum_of_U.m
function [ s ] = Sum_of_U( X, M , C)
% matrix X is m*n, M is No_of_element*m, C is No_of_element*n 
%   m is the number of VM, n is the number of C 
[m, n] = size(X);
l = size(M, 1);
s1 = 0;
s2 = 0;
for j = 1:n
    T = zeros(l,1);
    for i = 1:m
        V = X(i, j) * M(:, i);
        T = T | V;
        if i == m
            T = T & (~C(:, n));
            s1 = sum(T);
        end        
    end
    s2 = s2 +s1; 
end
s = s2;
end

this Sum_of_U() function works well if I implemnt it independently.

then the test1.m script:

M=[1,0,0,1;1,1,1,1;1,1,0,0;0,1,1,0;0,0,0,1;0,0,1,0];
C=[0,0;0,0;1,0;0,1;0,0;0,0];
vc = [4 5 4 4];
pm = [10 10];
X = binvar(4,2);
F = [sum(X,2)==1, vc*X<=pm];
Obj = Sum_of_U(X, M, C);
optimize(F, Obj);
sol = value(X);

Johan Löfberg

unread,
Feb 19, 2015, 9:08:23 AM2/19/15
to yal...@googlegroups.com
As I said, there are likely bugs in the high-level framework (doesn't like constant T). You should implement them using standard low-level MILP logic

李汇熙

unread,
Feb 19, 2015, 10:21:06 AM2/19/15
to yal...@googlegroups.com
Thx for your advice!
Actually, what I want to minimize is this 

X_ij is the binvar, M= [v_1;v_2;...;v_m].

So as you can see, I don'y think my problem is exactly a LP.



Johan Löfberg

unread,
Feb 19, 2015, 11:25:38 AM2/19/15
to
Not an LP but an MILP

All those operations can be written using standard MILP logic

z = x1 && x2 && .. xn is written as z <= x1, z <= x2,...,z<= xn, z >= x1+...+xn- (n-1)
z = x1 || x2 || ... ...xn  is written as    z <= x1+x2+..+xn, z >= x1, z >= x2,...

All your expressions can be unrolled to that, using a bunch of auxilliary variables. That is precisely what YALMIP (is supposed to do) does when you use high-level logics on binary variables (the code currently doesn't support vector arguments, and then you found that bug also)

Johan Löfberg

unread,
Feb 20, 2015, 3:11:18 AM2/20/15
to yal...@googlegroups.com
The next version of YALMIP will be fixed to support this vectorized logic code

李汇熙

unread,
Feb 20, 2015, 4:48:28 AM2/20/15
to yal...@googlegroups.com
Thank you very much!
Now, I'm using the method of exhaustion to solve this problem.
Although it's very very time-comsuming, obtaining an outcome is more importance for me.
I'm gonna improve my solution by applying your suggestion.
Thx again!

Johan Löfberg

unread,
Feb 20, 2015, 4:56:49 AM2/20/15
to yal...@googlegroups.com
What do you mean with exhaustion?

The MILP model is exhaustive search in the worst-case, but with the MILP model, cplex solves the problem in the root node in 0s, i.e., the model is trivial

李汇熙

unread,
Feb 20, 2015, 7:06:56 AM2/20/15
to yal...@googlegroups.com
I use "for" and "circshift" to list all possible X_ij matrix.
Take a 2*3 X_ij matrix for example, I begain with
1 0 0      
1 0 0  
to
0 1 0
1 0 0
to
0 0 1
1 0 0
to
1 0 0
0 1 0
.
.
.
finally to 
0 0 1
0 0 1
and there are 3^2 X_ij.
Someone has just told me that the implementation of "for" in matlab is inefficiency
And unfortunately, my problems are with large scale (the worst case could be 100^100 X_ij level).

Johan Löfberg

unread,
Feb 20, 2015, 7:08:38 AM2/20/15
to yal...@googlegroups.com
Ok, brute-forcing. No you don't want to do that. Use the YALMIP version I sent you per email and let me know if it works (via email correspondence to avoid any side-discussion here)

李汇熙

unread,
Feb 21, 2015, 8:23:43 PM2/21/15
to yal...@googlegroups.com
Hi Johan
There are two more questions.
1. As you can see below, why did it display so many "Maximum iterations or time limit exceeded "?
2. The 1st line of my code is "tic;" and the last line is "toc;" I spent nearly 20 hours to obtain an answer, but "Elapsed time is 136.338764 seconds." So how should I time the implementation precisely in Yalmip?
Thx1

* Starting YALMIP integer branch & bound.
* Lower solver   : LINPROG
* Upper solver   : rounder
* Max iterations : 300
 Node       Upper       Gap(%)      Lower    Open
    1 :          Inf      Inf      4.770E+02   2  Successfully solved 
    2 :          Inf      Inf      4.770E+02   3  Successfully solved 
    3 :          Inf      Inf      4.770E+02   4  Maximum iterations or time limit exceeded 
    4 :          Inf      Inf      4.770E+02   5  Maximum iterations or time limit exceeded 
    5 :          Inf      Inf      4.770E+02   6  Maximum iterations or time limit exceeded 
    6 :          Inf      Inf      4.770E+02   7  Maximum iterations or time limit exceeded 
    7 :          Inf      Inf      4.770E+02   8  Maximum iterations or time limit exceeded 
    8 :          Inf      Inf      4.770E+02   9  Successfully solved 
    9 :          Inf      Inf      4.770E+02  10  Maximum iterations or time limit exceeded 
   10 :          Inf      Inf      4.770E+02  11  Successfully solved 
   11 :          Inf      Inf      4.770E+02  12  Successfully solved 
   12 :          Inf      Inf      4.770E+02  13  Successfully solved 
   13 :          Inf      Inf      4.770E+02  14  Successfully solved 
   14 :          Inf      Inf      4.770E+02  15  Successfully solved 
   15 :          Inf      Inf      4.770E+02  16  Successfully solved 
   16 :          Inf      Inf      4.770E+02  17  Successfully solved 
   17 :          Inf      Inf      4.770E+02  18  Successfully solved 
   18 :          Inf      Inf      4.770E+02  19  Successfully solved 
   19 :          Inf      Inf      4.770E+02  20  Successfully solved 
   20 :          Inf      Inf      4.770E+02  21  Successfully solved 
   21 :    1.508E+03    51.94      4.770E+02  20  Successfully solved 
   22 :    1.508E+03    51.79      4.790E+02  21  Maximum iterations or time limit exceeded 
   23 :    1.508E+03    51.79      4.790E+02  22  Successfully solved 
   24 :    1.508E+03    51.79      4.790E+02  23  Successfully solved 
   25 :    1.508E+03    51.71      4.800E+02  24  Successfully solved 
   26 :    1.508E+03    51.71      4.800E+02  25  Successfully solved 
   27 :    1.508E+03    51.71      4.800E+02  26  Maximum iterations or time limit exceeded 
   28 :    1.508E+03    51.71      4.800E+02  27  Successfully solved 
   29 :    1.508E+03    51.71      4.800E+02  28  Maximum iterations or time limit exceeded 
   30 :    1.508E+03    51.71      4.800E+02  29  Successfully solved 
   31 :    1.508E+03    51.71      4.800E+02  30  Successfully solved 
   32 :    1.508E+03    51.71      4.800E+02  31  Successfully solved 
   33 :    1.508E+03    51.63      4.810E+02  32  Successfully solved 
   34 :    1.508E+03    51.63      4.810E+02  33  Successfully solved 
   35 :    1.508E+03    51.63      4.810E+02  34  Successfully solved 
   36 :    1.508E+03    51.63      4.810E+02  35  Successfully solved 
   37 :    1.508E+03    51.63      4.810E+02  36  Successfully solved 
   38 :    1.508E+03    51.63      4.810E+02  37  Successfully solved 
   39 :    1.508E+03    51.63      4.810E+02  38  Maximum iterations or time limit exceeded 
   40 :    1.508E+03    51.63      4.810E+02  39  Successfully solved 
   41 :    1.508E+03    51.56      4.820E+02  40  Successfully solved 
   42 :    1.508E+03    51.56      4.820E+02  41  Maximum iterations or time limit exceeded 
   43 :    1.508E+03    51.56      4.820E+02  42  Successfully solved 
   44 :    1.508E+03    51.56      4.820E+02  43  Maximum iterations or time limit exceeded 
   45 :    1.508E+03    51.48      4.830E+02  44  Successfully solved 
   46 :    1.508E+03    51.48      4.830E+02  45  Successfully solved 
   47 :    1.508E+03    51.48      4.830E+02  46  Successfully solved 
   48 :    1.508E+03    51.48      4.830E+02  47  Successfully solved 
   49 :    1.508E+03    51.48      4.830E+02  48  Successfully solved 
   50 :    1.508E+03    51.48      4.830E+02  49  Successfully solved 
   51 :    1.508E+03    51.48      4.830E+02  50  Successfully solved 
   52 :    1.508E+03    51.48      4.830E+02  51  Successfully solved 
   53 :    1.508E+03    51.48      4.830E+02  52  Successfully solved 
   54 :    1.508E+03    51.48      4.830E+02  53  Successfully solved 
   55 :    1.508E+03    51.48      4.830E+02  54  Successfully solved 
   56 :    1.508E+03    51.48      4.830E+02  55  Successfully solved 
   57 :    1.508E+03    51.48      4.830E+02  56  Successfully solved 
   58 :    1.508E+03    51.48      4.830E+02  57  Successfully solved 
   59 :    1.508E+03    51.48      4.830E+02  58  Successfully solved 
   60 :    1.508E+03    51.48      4.830E+02  59  Successfully solved 
   61 :    1.508E+03    51.41      4.840E+02  60  Maximum iterations or time limit exceeded 
   62 :    1.508E+03    51.41      4.840E+02  61  Maximum iterations or time limit exceeded 
   63 :    1.508E+03    51.41      4.840E+02  62  Maximum iterations or time limit exceeded 
   64 :    1.508E+03    51.41      4.840E+02  63  Successfully solved 
   65 :    1.508E+03    51.41      4.840E+02  64  Successfully solved 
   66 :    1.508E+03    51.41      4.840E+02  65  Successfully solved 
   67 :    1.508E+03    51.41      4.840E+02  66  Successfully solved 
   68 :    1.508E+03    51.41      4.840E+02  67  Maximum iterations or time limit exceeded 
   69 :    1.508E+03    51.41      4.840E+02  68  Successfully solved 
   70 :    1.508E+03    51.41      4.840E+02  69  Maximum iterations or time limit exceeded 
   71 :    1.508E+03    51.41      4.840E+02  70  Successfully solved 
   72 :    1.508E+03    51.41      4.840E+02  71  Successfully solved 
   73 :    1.508E+03    51.41      4.840E+02  72  Maximum iterations or time limit exceeded 
   74 :    1.508E+03    51.41      4.840E+02  73  Successfully solved 
   75 :    1.508E+03    51.41      4.840E+02  74  Successfully solved 
   76 :    1.508E+03    51.41      4.840E+02  75  Successfully solved 
   77 :    1.508E+03    51.41      4.840E+02  76  Successfully solved 
   78 :    1.508E+03    51.41      4.840E+02  77  Successfully solved 
   79 :    1.508E+03    51.33      4.850E+02  78  Maximum iterations or time limit exceeded 
   80 :    1.508E+03    51.33      4.850E+02  79  Successfully solved 
   81 :    1.508E+03    51.33      4.850E+02  80  Maximum iterations or time limit exceeded 
   82 :    1.508E+03    51.33      4.850E+02  81  Successfully solved 
   83 :    1.508E+03    51.33      4.850E+02  82  Successfully solved 
   84 :    1.508E+03    51.33      4.850E+02  83  Maximum iterations or time limit exceeded 
   85 :    1.508E+03    51.33      4.850E+02  84  Successfully solved 
   86 :    1.508E+03    51.33      4.850E+02  85  Successfully solved 
   87 :    1.508E+03    51.33      4.850E+02  86  Maximum iterations or time limit exceeded 
   88 :    1.508E+03    51.33      4.850E+02  87  Maximum iterations or time limit exceeded 
   89 :    1.508E+03    51.33      4.850E+02  88  Maximum iterations or time limit exceeded 
   90 :    1.508E+03    51.33      4.850E+02  89  Successfully solved 
   91 :    1.508E+03    51.25      4.860E+02  90  Successfully solved 
   92 :    1.508E+03    51.25      4.860E+02  91  Successfully solved 
   93 :    1.508E+03    51.25      4.860E+02  92  Successfully solved 
   94 :    1.508E+03    51.25      4.860E+02  93  Successfully solved 
   95 :    1.508E+03    51.25      4.860E+02  94  Successfully solved 
   96 :    1.508E+03    51.25      4.860E+02  95  Successfully solved 
   97 :    1.508E+03    51.25      4.860E+02  96  Maximum iterations or time limit exceeded 
   98 :    1.508E+03    51.25      4.860E+02  97  Successfully solved 
   99 :    1.508E+03    51.18      4.870E+02  98  Successfully solved 
  100 :    1.508E+03    51.18      4.870E+02  99  Successfully solved 
  101 :    1.508E+03    51.18      4.870E+02  100  Maximum iterations or time limit exceeded 
  102 :    1.508E+03    51.18      4.870E+02  101  Successfully solved 
  103 :    1.508E+03    51.18      4.870E+02  102  Successfully solved 
  104 :    1.508E+03    51.18      4.870E+02  103  Maximum iterations or time limit exceeded 
  105 :    1.508E+03    51.18      4.870E+02  104  Successfully solved 
  106 :    1.508E+03    51.18      4.870E+02  105  Maximum iterations or time limit exceeded 
  107 :    1.508E+03    51.10      4.880E+02  106  Successfully solved 
  108 :    1.508E+03    51.10      4.880E+02  107  Successfully solved 
  109 :    1.508E+03    51.10      4.880E+02  108  Successfully solved 
  110 :    1.508E+03    51.10      4.880E+02  109  Successfully solved 
  111 :    1.508E+03    51.10      4.880E+02  110  Successfully solved 
  112 :    1.508E+03    51.10      4.880E+02  111  Successfully solved 
  113 :    1.508E+03    51.10      4.880E+02  112  Successfully solved 
  114 :    1.508E+03    51.10      4.880E+02  113  Maximum iterations or time limit exceeded 
  115 :    1.508E+03    51.10      4.880E+02  114  Successfully solved 
  116 :    1.508E+03    51.10      4.880E+02  115  Maximum iterations or time limit exceeded 
  117 :    1.508E+03    51.03      4.890E+02  116  Successfully solved 
  118 :    1.508E+03    51.03      4.890E+02  117  Maximum iterations or time limit exceeded 
  119 :    1.508E+03    51.03      4.890E+02  118  Successfully solved 
  120 :    1.508E+03    51.03      4.890E+02  119  Maximum iterations or time limit exceeded 
  121 :    1.508E+03    51.03      4.890E+02  120  Successfully solved 
  122 :    1.508E+03    51.03      4.890E+02  121  Successfully solved 
  123 :    1.508E+03    51.03      4.890E+02  122  Successfully solved 
  124 :    1.508E+03    51.03      4.890E+02  123  Maximum iterations or time limit exceeded 
  125 :    1.508E+03    51.03      4.890E+02  124  Successfully solved 
  126 :    1.508E+03    51.03      4.890E+02  125  Successfully solved 
  127 :    1.508E+03    51.03      4.890E+02  126  Maximum iterations or time limit exceeded 
  128 :    1.508E+03    51.03      4.890E+02  127  Successfully solved 
  129 :    1.508E+03    50.95      4.900E+02  128  Maximum iterations or time limit exceeded 
  130 :    1.508E+03    50.95      4.900E+02  129  Maximum iterations or time limit exceeded 
  131 :    1.508E+03    50.95      4.900E+02  130  Successfully solved 
  132 :    1.508E+03    50.95      4.900E+02  131  Successfully solved 
  133 :    1.508E+03    50.95      4.900E+02  132  Maximum iterations or time limit exceeded 
  134 :    1.508E+03    50.95      4.900E+02  133  Maximum iterations or time limit exceeded 
  135 :    1.508E+03    50.95      4.900E+02  134  Successfully solved 
  136 :    1.508E+03    50.95      4.900E+02  135  Successfully solved 
  137 :    1.508E+03    50.95      4.900E+02  136  Successfully solved 
  138 :    1.508E+03    50.95      4.900E+02  137  Successfully solved 
  139 :    1.508E+03    50.88      4.910E+02  138  Successfully solved 
  140 :    1.508E+03    50.88      4.910E+02  139  Successfully solved 
  141 :    1.508E+03    50.88      4.910E+02  140  Successfully solved 
  142 :    1.508E+03    50.88      4.910E+02  141  Successfully solved 
  143 :    1.508E+03    50.88      4.910E+02  142  Successfully solved 
  144 :    1.508E+03    50.88      4.910E+02  143  Successfully solved 
  145 :    1.508E+03    50.88      4.910E+02  144  Successfully solved 
  146 :    1.508E+03    50.88      4.910E+02  145  Successfully solved 
  147 :    1.508E+03    50.88      4.910E+02  146  Successfully solved 
  148 :    1.508E+03    50.88      4.910E+02  147  Successfully solved 
  149 :    1.508E+03    50.88      4.910E+02  148  Successfully solved 
  150 :    1.508E+03    50.88      4.910E+02  149  Successfully solved 
  151 :    1.508E+03    50.88      4.910E+02  150  Successfully solved 
  152 :    1.508E+03    50.88      4.910E+02  151  Successfully solved 
  153 :    1.508E+03    50.88      4.910E+02  152  Successfully solved 
  154 :    1.508E+03    50.88      4.910E+02  153  Maximum iterations or time limit exceeded 
  155 :    1.508E+03    50.88      4.910E+02  154  Successfully solved 
  156 :    1.508E+03    50.88      4.910E+02  155  Maximum iterations or time limit exceeded 
  157 :    1.508E+03    50.80      4.920E+02  156  Maximum iterations or time limit exceeded 
  158 :    1.508E+03    50.80      4.920E+02  157  Maximum iterations or time limit exceeded 
  159 :    1.508E+03    50.80      4.920E+02  158  Successfully solved 
  160 :    1.508E+03    50.80      4.920E+02  159  Maximum iterations or time limit exceeded 
  161 :    1.508E+03    50.80      4.920E+02  160  Successfully solved 
  162 :    1.508E+03    50.80      4.920E+02  161  Successfully solved 
  163 :    1.508E+03    50.80      4.920E+02  162  Successfully solved 
  164 :    1.508E+03    50.80      4.920E+02  163  Successfully solved 
  165 :    1.508E+03    50.80      4.920E+02  164  Maximum iterations or time limit exceeded 
  166 :    1.508E+03    50.80      4.920E+02  165  Maximum iterations or time limit exceeded 
  167 :    1.508E+03    50.80      4.920E+02  166  Successfully solved 
  168 :    1.508E+03    50.80      4.920E+02  167  Maximum iterations or time limit exceeded 
  169 :    1.508E+03    50.80      4.920E+02  168  Maximum iterations or time limit exceeded 
  170 :    1.508E+03    50.80      4.920E+02  169  Successfully solved 
  171 :    1.508E+03    50.80      4.920E+02  170  Successfully solved 
  172 :    1.508E+03    50.80      4.920E+02  171  Maximum iterations or time limit exceeded 
  173 :    1.508E+03    50.72      4.930E+02  172  Successfully solved 
  174 :    1.508E+03    50.72      4.930E+02  173  Maximum iterations or time limit exceeded 
  175 :    1.508E+03    50.72      4.930E+02  174  Successfully solved 
  176 :    1.508E+03    50.72      4.930E+02  175  Successfully solved 
  177 :    1.508E+03    50.72      4.930E+02  176  Successfully solved 
  178 :    1.508E+03    50.72      4.930E+02  177  Successfully solved 
  179 :    1.508E+03    50.72      4.930E+02  178  Successfully solved 
  180 :    1.508E+03    50.72      4.930E+02  179  Successfully solved 
  181 :    1.508E+03    50.65      4.940E+02  180  Maximum iterations or time limit exceeded 
  182 :    1.508E+03    50.65      4.940E+02  181  Maximum iterations or time limit exceeded 
  183 :    1.508E+03    50.65      4.940E+02  182  Maximum iterations or time limit exceeded 
  184 :    1.508E+03    50.65      4.940E+02  183  Maximum iterations or time limit exceeded 
  185 :    1.508E+03    50.65      4.940E+02  184  Successfully solved 
  186 :    1.508E+03    50.65      4.940E+02  185  Successfully solved 
  187 :    1.508E+03    50.65      4.940E+02  186  Successfully solved 
  188 :    1.508E+03    50.65      4.940E+02  187  Successfully solved 
  189 :    1.508E+03    50.65      4.940E+02  188  Maximum iterations or time limit exceeded 
  190 :    1.508E+03    50.65      4.940E+02  189  Successfully solved 
  191 :    1.508E+03    50.65      4.940E+02  190  Successfully solved 
  192 :    1.508E+03    50.65      4.940E+02  191  Successfully solved 
  193 :    1.508E+03    50.57      4.950E+02  192  Successfully solved 
  194 :    1.508E+03    50.57      4.950E+02  193  Maximum iterations or time limit exceeded 
  195 :    1.508E+03    50.57      4.950E+02  194  Successfully solved 
  196 :    1.508E+03    50.57      4.950E+02  195  Successfully solved 
  197 :    1.508E+03    50.57      4.950E+02  196  Maximum iterations or time limit exceeded 
  198 :    1.508E+03    50.57      4.950E+02  197  Successfully solved 
  199 :    1.508E+03    50.57      4.950E+02  198  Successfully solved 
  200 :    1.508E+03    50.57      4.950E+02  199  Successfully solved 
  201 :    1.508E+03    50.57      4.950E+02  200  Successfully solved 
  202 :    1.508E+03    50.57      4.950E+02  201  Successfully solved 
  203 :    1.508E+03    50.57      4.950E+02  202  Successfully solved 
  204 :    1.508E+03    50.57      4.950E+02  203  Successfully solved 
  205 :    1.508E+03    50.57      4.950E+02  204  Successfully solved 
  206 :    1.508E+03    50.57      4.950E+02  205  Successfully solved 
  207 :    1.508E+03    50.57      4.950E+02  206  Successfully solved 
  208 :    1.508E+03    50.57      4.950E+02  207  Successfully solved 
  209 :    1.508E+03    50.57      4.950E+02  208  Successfully solved 
  210 :    1.508E+03    50.57      4.950E+02  209  Successfully solved 
  211 :    1.508E+03    50.57      4.950E+02  210  Successfully solved 
  212 :    1.508E+03    50.57      4.950E+02  211  Successfully solved 
  213 :    1.508E+03    50.57      4.950E+02  212  Maximum iterations or time limit exceeded 
  214 :    1.508E+03    50.57      4.950E+02  213  Successfully solved 
  215 :    1.508E+03    50.50      4.960E+02  214  Successfully solved 
  216 :    1.508E+03    50.50      4.960E+02  215  Maximum iterations or time limit exceeded 
  217 :    1.508E+03    50.50      4.960E+02  216  Maximum iterations or time limit exceeded 
  218 :    1.508E+03    50.50      4.960E+02  217  Successfully solved 
  219 :    1.508E+03    50.50      4.960E+02  218  Successfully solved 
  220 :    1.508E+03    50.50      4.960E+02  219  Maximum iterations or time limit exceeded 
  221 :    1.508E+03    50.50      4.960E+02  220  Successfully solved 
  222 :    1.508E+03    50.50      4.960E+02  221  Successfully solved 
  223 :    1.508E+03    50.50      4.960E+02  222  Successfully solved 
  224 :    1.508E+03    50.50      4.960E+02  223  Maximum iterations or time limit exceeded 
  225 :    1.508E+03    50.50      4.960E+02  224  Successfully solved 
  226 :    1.508E+03    50.50      4.960E+02  225  Successfully solved 
  227 :    1.508E+03    50.50      4.960E+02  226  Successfully solved 
  228 :    1.508E+03    50.50      4.960E+02  227  Maximum iterations or time limit exceeded 
  229 :    1.508E+03    50.50      4.960E+02  228  Successfully solved 
  230 :    1.508E+03    50.50      4.960E+02  229  Maximum iterations or time limit exceeded 
  231 :    1.508E+03    50.50      4.960E+02  230  Maximum iterations or time limit exceeded 
  232 :    1.508E+03    50.50      4.960E+02  231  Successfully solved 
  233 :    1.508E+03    50.50      4.960E+02  232  Successfully solved 
  234 :    1.508E+03    50.50      4.960E+02  233  Successfully solved 
  235 :    1.508E+03    50.42      4.970E+02  234  Maximum iterations or time limit exceeded 
  236 :    1.508E+03    50.42      4.970E+02  235  Maximum iterations or time limit exceeded 
  237 :    1.508E+03    50.42      4.970E+02  236  Successfully solved 
  238 :    1.508E+03    50.42      4.970E+02  237  Successfully solved 
  239 :    1.508E+03    50.42      4.970E+02  238  Successfully solved 
  240 :    1.508E+03    50.42      4.970E+02  239  Successfully solved 
  241 :    1.508E+03    50.42      4.970E+02  240  Maximum iterations or time limit exceeded 
  242 :    1.508E+03    50.42      4.970E+02  241  Successfully solved 
  243 :    1.508E+03    50.35      4.980E+02  242  Maximum iterations or time limit exceeded 
  244 :    1.508E+03    50.35      4.980E+02  243  Successfully solved 
  245 :    1.508E+03    50.35      4.980E+02  244  Maximum iterations or time limit exceeded 
  246 :    1.508E+03    50.35      4.980E+02  245  Successfully solved 
  247 :    1.508E+03    50.35      4.980E+02  246  Maximum iterations or time limit exceeded 
  248 :    1.508E+03    50.35      4.980E+02  247  Successfully solved 
  249 :    1.508E+03    50.35      4.980E+02  248  Successfully solved 
  250 :    1.508E+03    50.35      4.980E+02  249  Successfully solved 
  251 :    1.508E+03    50.35      4.980E+02  250  Successfully solved 
  252 :    1.508E+03    50.35      4.980E+02  251  Maximum iterations or time limit exceeded 
  253 :    1.508E+03    50.35      4.980E+02  252  Successfully solved 
  254 :    1.508E+03    50.35      4.980E+02  253  Maximum iterations or time limit exceeded 
  255 :    1.508E+03    50.27      4.990E+02  254  Successfully solved 
  256 :    1.508E+03    50.27      4.990E+02  255  Successfully solved 
  257 :    1.508E+03    50.27      4.990E+02  256  Successfully solved 
  258 :    1.508E+03    50.27      4.990E+02  257  Successfully solved 
  259 :    1.508E+03    50.27      4.990E+02  258  Successfully solved 
  260 :    1.508E+03    50.27      4.990E+02  259  Successfully solved 
  261 :    1.508E+03    50.27      4.990E+02  260  Successfully solved 
  262 :    1.508E+03    50.27      4.990E+02  261  Successfully solved 
  263 :    1.508E+03    50.27      4.990E+02  262  Successfully solved 
  264 :    1.508E+03    50.27      4.990E+02  263  Successfully solved 
  265 :    1.508E+03    50.20      5.000E+02  264  Successfully solved 
  266 :    1.508E+03    50.20      5.000E+02  265  Maximum iterations or time limit exceeded 
  267 :    1.508E+03    50.20      5.000E+02  266  Successfully solved 
  268 :    1.508E+03    50.20      5.000E+02  267  Successfully solved 
  269 :    1.508E+03    50.20      5.000E+02  268  Successfully solved 
  270 :    1.508E+03    50.20      5.000E+02  269  Successfully solved 
  271 :    1.508E+03    50.12      5.010E+02  270  Maximum iterations or time limit exceeded 
  272 :    1.508E+03    50.12      5.010E+02  271  Successfully solved 
  273 :    1.508E+03    50.12      5.010E+02  272  Successfully solved 
  274 :    1.508E+03    50.12      5.010E+02  273  Maximum iterations or time limit exceeded 
  275 :    1.508E+03    50.12      5.010E+02  274  Successfully solved 
  276 :    1.508E+03    50.12      5.010E+02  275  Successfully solved 
  277 :    1.508E+03    50.12      5.010E+02  276  Successfully solved 
  278 :    1.508E+03    50.12      5.010E+02  277  Successfully solved 
  279 :    1.508E+03    50.12      5.010E+02  278  Successfully solved 
  280 :    1.508E+03    50.12      5.010E+02  279  Successfully solved 
  281 :    1.508E+03    50.12      5.010E+02  280  Maximum iterations or time limit exceeded 
  282 :    1.508E+03    50.12      5.010E+02  281  Maximum iterations or time limit exceeded 
  283 :    1.508E+03    50.12      5.010E+02  282  Successfully solved 
  284 :    1.508E+03    50.12      5.010E+02  283  Successfully solved 
  285 :    1.508E+03    50.12      5.010E+02  284  Successfully solved 
  286 :    1.508E+03    50.12      5.010E+02  285  Maximum iterations or time limit exceeded 
  287 :    1.508E+03    50.12      5.010E+02  286  Successfully solved 
  288 :    1.508E+03    50.12      5.010E+02  287  Successfully solved 
  289 :    1.508E+03    50.12      5.010E+02  288  Successfully solved 
  290 :    1.508E+03    50.12      5.010E+02  289  Successfully solved 
  291 :    1.508E+03    50.05      5.020E+02  290  Successfully solved 
  292 :    1.508E+03    50.05      5.020E+02  291  Maximum iterations or time limit exceeded 
  293 :    1.508E+03    50.05      5.020E+02  292  Maximum iterations or time limit exceeded 
  294 :    1.508E+03    50.05      5.020E+02  293  Maximum iterations or time limit exceeded 
  295 :    1.508E+03    50.05      5.020E+02  294  Successfully solved 
  296 :    1.508E+03    50.05      5.020E+02  295  Successfully solved 
  297 :    1.508E+03    50.05      5.020E+02  296  Successfully solved 
  298 :    1.508E+03    50.05      5.020E+02  297  Successfully solved 
  299 :    1.508E+03    50.05      5.020E+02  298  Successfully solved 
  300 :    1.508E+03    50.05      5.020E+02  299  Successfully solved 
+ 300 Finishing.  Cost: 1508

ans =

        1508


ans =

  Columns 1 through 17

     0     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     0     1     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     0     0     0     0     0     0
     0     1     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     1     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     1     0     0     0
     0     1     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

  Columns 18 through 20

     0     0     0
     0     0     0
     0     0     1
     0     0     1
     0     0     0
     0     1     0
     0     0     0
     0     0     0
     0     0     0
     0     1     0

Elapsed time is 136.338764 seconds.

李汇熙

unread,
Feb 21, 2015, 9:14:06 PM2/21/15
to yal...@googlegroups.com
now I know "Maximum iterations or time limit exceeded " is caused by the solver...

Johan Löfberg

unread,
Feb 22, 2015, 3:17:25 AM2/22/15
to yal...@googlegroups.com
As I said, you have to install a MILP solver. I will not answer any MILP-relaed questions until you have done so.

Regarding tic-toc, YALMIP currently destroys tic-toc, known bug. Use clock/etime instead until fixed (hopefully that works

Johan Löfberg

unread,
Feb 22, 2015, 3:21:43 AM2/22/15
to yal...@googlegroups.com
Another way to code around tictoc bug

s=tic;
blabla
toc(s);

李汇熙

unread,
Mar 12, 2015, 11:33:22 PM3/12/15
to yal...@googlegroups.com
hi Johan
I wrote z=x1&&x2||x3 as constraints:
z1 <= x1,  z1 <= x2, z1 >= x1 + x2 - 1,  z <= z1 + x3,  z >= z1, z >= x3 (z1 had been initialized before)
And yalmip showed "Error using lmi/horzcat (line 21), One of the constraints evaluates to a FALSE LOGICAL variable" for "z <= z1 + x3,  z >= z1, z >= x3".
Does this mean that I cannot create z1 to help me to express these constraints?

Johan Löfberg

unread,
Mar 13, 2015, 3:51:43 AM3/13/15
to yal...@googlegroups.com
No, it means you are defining a trivially infeasible model. Some of those constraints evaluates to something like 0 >= 1. Similar to

sdpvar z1 x3
z
= z1+x3+1
[z <= z1+x3, z >= z1, z >= x3]


Johan Löfberg

unread,
Mar 13, 2015, 5:08:19 AM3/13/15
to yal...@googlegroups.com
and I doubt your code actually runs as you have stated it. Short-circuit logic is not allowed on variables

>> binvar x1 x2 x3 z1
>> z=x1&&x2||x3
The following error occurred converting from sdpvar to logical:
Error using logical
Conversion to logical from sdpvar is not possible.

You must mean

z=x1&x2|x3
Nonlinear scalar (real, models 'or', binary, 1 variable, current value : 1)

Johan Löfberg

unread,
Mar 13, 2015, 5:10:23 AM3/13/15
to yal...@googlegroups.com
unless x1,x2,x3 aren't sdpvars of course


李汇熙

unread,
Mar 17, 2015, 8:57:16 AM3/17/15
to yal...@googlegroups.com
no, x_1,x_2,x_3 are not completely sdpars. x_i = X(i)*M(i), in which M(i) are known array and X(i) is the sdpvars(binvar).
So what I attempt to do here is convert z=x_1&x_2|x_3, which sum(z) is my object, into constraints. Hence this could be a standard MILP model as you told me before.

Johan Löfberg

unread,
Mar 17, 2015, 8:59:51 AM3/17/15
to yal...@googlegroups.com
So they are sdpvars, and you should thus not use short-circuit logics

李汇熙

unread,
Mar 17, 2015, 10:17:07 AM3/17/15
to yal...@googlegroups.com
So the reason is that I made a short-circuit logics...BTW, is it feasible to use z1 to describe the relationship between x1 and x2 (x1&x2) as a constraint?

Johan Löfberg

unread,
Mar 17, 2015, 10:22:28 AM3/17/15
to yal...@googlegroups.com
Yes, short-circuit makes no sense when the variables are decision variables, as they don't have any values and there is thus no way to terminate anything early

You are free to write and as z=x1&x2, z=and(x1,x2), or manually z<=x1,z<=x2,z>=x1+x2-1,. it is entirely up to you. They will all generate precisely the same model in the end
Message has been deleted

李汇熙

unread,
Mar 17, 2015, 10:36:55 PM3/17/15
to yal...@googlegroups.com
I tried two pieces of code.
the first one is :
X = binvar(1);
M
=round(rand(400,1));
z11
=X*M;
z_11
= sdpvar(400,1);
C
=round(rand(400,1));
constraint
= [z_11<=z11+C,z_11>=z11,z_11>=C];

It's OK.
Then the 2nd one:
X = binvar(1);
z11
=X*M(:,1);
z_11
= sdpvar(400,1);
constraint
= [z_11<=z11+(~C1(1 ,:)'),z_11>=z11,z_11>=(~C1(1 ,:)')];
matlab showed:
Error using sdpvar/plus (line 35)
Cannot add SDPVAR object and LOGICAL object
Error in exp_test1 (line 4)
constraint = [z_11<=z11+(~C1(1 ,:)'),z_11>=z11,z_11>=(~C1(1 ,:)')];


I've no idea why this happen...
M and C1 are also randomly created.
C1.mat
M.mat

Johan Löfberg

unread,
Mar 18, 2015, 2:27:33 AM3/18/15
to yal...@googlegroups.com
>> x1 + (1~=0)

Error using sdpvar/plus (line 35)
Cannot add SDPVAR object and LOGICAL object

Hence, you have to cast as a double

>> x1 + double(1~=0)


李汇熙

unread,
Mar 18, 2015, 4:55:32 AM3/18/15
to yal...@googlegroups.com
yes, it works.Thx!
But there is another problem.
I changed the scale of my problem, it always said:
Attempted to access internal_sdpvarstate.extVariables(5573); index out of bounds because
numel(internal_sdpvarstate.extVariables)=5572.

Error in yalmip (line 1103)
                logicextvariables = [logicextvariables internal_sdpvarstate.extVariables(i)];

Error in convertlogics (line 6)
    extvariables = yalmip('logicextvariables');

Error in compileinterfacedata (line 71)
[F,changed] = convertlogics(F);

Error in solvesdp (line 251)
[interfacedata,recoverdata,solver,diagnostic,F,Fremoved,ForiginalQuadratics] =
compileinterfacedata(F,[],logdetStruct,h,options,0,solving_parametric);

Error in optimize (line 31)
varargout{:} = solvesdp(varargin{:});

Error in test5 (line 50)
optimize([constraints,vc*X <= pm, vm*X <= pc,sum(X,2)==1], obj);

Johan Löfberg

unread,
Mar 18, 2015, 4:56:44 AM3/18/15
to yal...@googlegroups.com
Reproducible example needed

李汇熙

unread,
Mar 18, 2015, 4:57:14 AM3/18/15
to yal...@googlegroups.com
I was wondering what and why is 5572...

李汇熙

unread,
Mar 18, 2015, 5:04:05 AM3/18/15
to yal...@googlegroups.com
Plz take a look at this, Johan.
Thx!
test5.m
matlab.mat

Johan Löfberg

unread,
Mar 18, 2015, 5:06:48 AM3/18/15
to yal...@googlegroups.com
Runs fine here.

Try yalmip('clear') in case there is some bad internals after crashes etc

李汇熙

unread,
Mar 18, 2015, 5:12:04 AM3/18/15
to yal...@googlegroups.com
oh, it's ok now.
so the error means the cache is full...that's why it keeps saying 5572.
Thank you!

Johan Löfberg

unread,
Mar 18, 2015, 5:16:58 AM3/18/15
to yal...@googlegroups.com
No, it has nothing to do with any cache, and the number 5572 has no particular meaning. The internal database for YALMIP got messed up somehow. It is adviced that you have a yalmip('clear') in the beginning of YALMIP scipts, to setup a clean start.

李汇熙

unread,
Mar 18, 2015, 5:24:40 AM3/18/15
to yal...@googlegroups.com
ok, thanks for your advice!
Reply all
Reply to author
Forward
0 new messages