[37] | 1 | function [x,w,x_variables,w_variables,aux_variables,F,failure] = robust_classify_variables(F,h,ops,w); |
---|
| 2 | |
---|
| 3 | failure = 0; |
---|
| 4 | % Variables before expanding nonlinear operators |
---|
| 5 | initial_variables = unique([depends(F) depends(h)]); |
---|
| 6 | |
---|
| 7 | % Uncertain variables |
---|
| 8 | w_variables = getvariables(w); |
---|
| 9 | |
---|
| 10 | % Decision variables |
---|
| 11 | x_variables = 1:yalmip('nvars');%union(depends(F),depends(h)); |
---|
| 12 | x_variables = setdiff(x_variables,w_variables); |
---|
| 13 | |
---|
| 14 | % Any fancy modelling goin on here? If so, we need to expand the model, and |
---|
| 15 | % associate the new lifted variables either to the uncertainty set or to |
---|
| 16 | % the set of general variables. There are some classes of variables |
---|
| 17 | % 1. Uncertain variables |
---|
| 18 | % 2. Original decision variables |
---|
| 19 | % 4. Lifted variables used for uncertain variables in uncertainty description |
---|
| 20 | % 5. Lifted variables used for uncertain variables in uncertain model |
---|
| 21 | % 6. Lifted variables used for mixed variables in uncertain model |
---|
| 22 | % FIX : This code is currently a miserable hack and should be cleaned up |
---|
| 23 | extended = yalmip('extvariables'); |
---|
| 24 | aux_variables = []; |
---|
| 25 | if ~isempty(extended) & any(ismember(initial_variables,extended)) |
---|
| 26 | |
---|
| 27 | % Remove auxilliary variables (defined by YALMIP) |
---|
| 28 | aux_variables = intersect(extended,x_variables); |
---|
| 29 | % These variables are original decision variables |
---|
| 30 | x_variables = setdiff(x_variables,aux_variables); |
---|
| 31 | |
---|
| 32 | % Original constraint index |
---|
| 33 | id = getlmiid(F(find(~lifted(F)))); |
---|
| 34 | |
---|
| 35 | % This is a tweak to allow epxansion of bilinear terms in robust problems, |
---|
| 36 | % is expression such as abs(x*w) < 1 for all -1 < w < 1 |
---|
| 37 | ops.expandbilinear = 1; |
---|
| 38 | |
---|
| 39 | % Expand the model to model norms etc |
---|
| 40 | [F,failure,cause] = expandmodel(F,h,ops); |
---|
| 41 | if failure % Convexity propgation failed |
---|
| 42 | interfacedata = []; |
---|
| 43 | recoverdata = []; |
---|
| 44 | solver = ''; |
---|
| 45 | diagnostic.solvertime = 0; |
---|
| 46 | diagnostic.problem = 14; |
---|
| 47 | diagnostic.info = yalmiperror(14,cause); |
---|
| 48 | x = []; |
---|
| 49 | w = []; |
---|
| 50 | x_variables=[]; |
---|
| 51 | w_variables=[]; |
---|
| 52 | F = []; |
---|
| 53 | return |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | % Auxillary variables (introduced by YALMIP). These variables are lifting |
---|
| 57 | % variables that are used to model advanced constructs suck as norms etc in |
---|
| 58 | % the nonlinear operator framework |
---|
| 59 | new_aux_variables = setdiff(unique([depends(F) depends(h)]),initial_variables); |
---|
| 60 | aux_variables = setdiff(union(aux_variables,new_aux_variables),w_variables); |
---|
| 61 | |
---|
| 62 | % We know try to find the auxillary variables that are used to model |
---|
| 63 | % functions that only depends on w |
---|
| 64 | F_lifted = F(find(~ismember(getlmiid(F),id))); |
---|
| 65 | aux_variables_w = aux_variables; |
---|
| 66 | for i = 1:length(F_lifted) |
---|
| 67 | variables = depends(F_lifted(i)); |
---|
| 68 | with_x = any(ismember(variables,x_variables)); |
---|
| 69 | with_w = any(ismember(variables,w_variables)); |
---|
| 70 | if with_x |
---|
| 71 | aux_variables_w = setdiff(aux_variables_w,intersect(variables,aux_variables)); |
---|
| 72 | x_variables = union(x_variables,intersect(variables,aux_variables)); |
---|
| 73 | end |
---|
| 74 | end |
---|
| 75 | |
---|
| 76 | aux_variables_x = setdiff(aux_variables,aux_variables_w); |
---|
| 77 | x_variables = union(aux_variables_x, x_variables); |
---|
| 78 | w_variables = union(aux_variables_w, w_variables); |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | x_variables = intersect([getvariables(F) getvariables(h)],x_variables); |
---|
| 82 | w_variables = intersect([getvariables(F) getvariables(h)],w_variables); |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | x = recover(x_variables); |
---|
| 86 | x = recover(setdiff(depends(x),w_variables)); |
---|
| 87 | x_variables = getvariables(x); |
---|
| 88 | w = recover(w_variables); |
---|
| 89 | |
---|
| 90 | |
---|