products of variables as an if condition in a objective function

26 views
Skip to first unread message

Cyan Zhou

unread,
Oct 22, 2019, 7:11:44 AM10/22/19
to YALMIP
I have a binary variable x = binvar(n_files, n_nodes), which determines whether a file is cached in a node or not. There are a set of requesting files and each is allocated with a forwarding path (i.e., a sequence of nodes). If a certain file is not cached in a node, then forward to the next node and add the weight between the two nodes to the cost of that file. Then, the objective function is the maximal cost of all files. 

The mathematical expression of the problem is shown as 

$obj = \max_{f\in F} \{ \sum_{m=1}^{p_f} w_{p_{m+1}p_m} \prod_{m'=1}^{m} (1-x(f,m'))  \}$

With YALMIP, the code is written as follows:

x = binvar(n_files,n_nodes);
delay_files = zeros(n_files,1);
for i = 1:n_files
    path = path_seq{i};
    weights = weights_seq{i};
    for j = 1:length(path)
         delay_files(i) = delay_files(i) + implies(sum(x((files(i),path(1:j)))==0,weights(j));
    end
end

obj = max(delay_files);


Then, there is an error saying that "Error using lmi/double (line 12) Double not applicable on list of constraints". How can I solve this problem?


Johan Löfberg

unread,
Oct 22, 2019, 7:27:16 AM10/22/19
to YALMIP
implies is a constraint, so it makes no sense to add it to the objective

Feels like you want to take a maximum of some scaled product of binaries

minimize max(w1*a1*b1*c1*d1, w2*a2*b2*c2*d2) would be done by introducing new variable t and new binary q1 and q2, minimize t subject to q1*w1 <= t, q2*w2 <= t, and then the binary product would simply be q1 <= a1,q1 <= b1,... (if anyone is 0, the product is 0)

Johan Löfberg

unread,
Oct 22, 2019, 7:42:58 AM10/22/19
to YALMIP
forgot qi >= ai+bi+ci+di-3 (if all are 1, then q is 1)

Cyan Zhou

unread,
Oct 22, 2019, 8:25:47 AM10/22/19
to YALMIP
Thank you. However, in this way, I need to write down all the variables to make the constraints in terms of the slack variables. Moreover, if the set of files are dynamic, then, can we write this in a common way using YALMIP? 

I also try this way :

x = binvar(n_files,n_nodes);
delay_files = zeros(n_files,1);
for i = 1:n_files
    flag = 1;
    path = path_seq{i};
    weights = weights_seq{i};
    for j = 1:length(path)
         flag = flag & (1-x(files(i),path(j));
         delay_files(i) = delay_files(i) + flag * weights(j);
    end
end

Then, an error say "Adding NaN to an SDPVAR makes no sense." happened.

Cyan Zhou

unread,
Oct 22, 2019, 8:29:21 AM10/22/19
to YALMIP
And this new way I tried cannot apply if the set of files are dynamic. I mean there can be set of files can be any subset of a dataset, and actually the objective is the average (expectation) of the cost of subsets of files.

Johan Löfberg

unread,
Oct 22, 2019, 8:39:06 AM10/22/19
to YALMIP
You cannot place an sdpvar inside a previously defined double. You will have to construct it though concatenation

also, as far as I can tell, you can just as well write it as  weights(j)*min(1-x(files(i),:)) or something like that, and optimizing further, it looks like you are doing min(1-x,[],1)*weights(:)

Johan Löfberg

unread,
Oct 22, 2019, 8:42:42 AM10/22/19
to YALMIP
I have no idea what you are talking about

In the end, it's all about not creating polynomials of x, when it is a trivial logic/linear operation q = x*y*z = min([x y z]) = x & y & z or equivalently q <= [x y z], q >= x+y+z-2
Reply all
Reply to author
Forward
0 new messages