source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/expandforindex.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.8 KB
Line 
1function [oldvariable,sqrList] = expandforindex(sqrList,candidates,nonconvindex);
2%EXPANDFORINDEX Internal function for organizing nonlinear variables
3
4% Author Johan Löfberg
5% $Id: expandforindex.m,v 1.4 2004/08/06 09:02:52 johanl Exp $
6
7
8% Expand the incoming variables
9
10if 1
11z = sqrList(:,1);
12
13x1_list = find(z==candidates(2));
14if candidates(2)==candidates(1)
15    x2_list = x1_list;
16else
17    x2_list = find(z==candidates(1));
18end
19
20temp = [];
21if isempty(x1_list)
22    temp = candidates(2);
23else
24    temp = sqrList(x1_list,2:end);
25end
26if isempty(x2_list)
27    temp = [temp candidates(1)];
28else
29    temp = [temp sqrList(x2_list,2:end)];
30end
31temp = sort(temp(find(any(temp,1))));
32
33oldsqrList = sqrList;
34if length(temp)>size(sqrList,2)-1
35    % This one cannot already exist
36    index = [];
37   
38    %sqrList = [sqrList zeros(size(sqrList,1),1+size(sqrList,2)-length(temp));nonconvindex temp(end:-1:1)];   
39    sqrList = [sqrList zeros(size(sqrList,1),1+length(temp)-size(sqrList,2));nonconvindex temp(end:-1:1)];   
40else
41%    sqrList = [sqrList;nonconvindex temp(end:-1:1) zeros(1,size(sqrList,2)-length(temp)-1)];
42%    searchfor = sqrList(end,2:end);
43
44    searchfor = [temp(end:-1:1) zeros(1,size(sqrList,2)-length(temp)-1)];
45    searchin = sqrList(:,2:end);
46   
47    % Simple Hash
48    key = sum(searchfor);
49    tbl = sum(searchin,2);
50   
51    possible = find(tbl==key);
52   
53    index = findrows(searchin(possible,:),searchfor);
54    if isempty(index)
55         sqrList = [sqrList;nonconvindex temp(end:-1:1) zeros(1,size(sqrList,2)-length(temp)-1)];
56    else
57         index = possible(index);
58    end
59end
60
61%searchfor = sqrList(end,2:end);
62%index = findrows(sqrList(1:end-1,2:end),searchfor);
63
64if length(index)>1
65    index
66end
67
68if ~isempty(index)
69    oldvariable = sqrList(index,1);
70    sqrList = oldsqrList;
71else
72    oldvariable = [];
73end
74
75
76
77else
78
79
80% Expand the list to begin with
81if isempty(sqrList)
82    sqrList = [nonconvindex candidates];
83else
84    sqrList = [sqrList; nonconvindex candidates(2) candidates(1) zeros(1,size(sqrList,2)-3)];       
85end
86bottom = size(sqrList,1);
87
88%%FIXz = sqrList(1:bottom,1);
89z = sqrList(:,1);
90
91x1_list = find(z==candidates(2));
92if candidates(2)==candidates(1)
93    x2_list = x1_list;
94else
95    x2_list = find(z==candidates(1));
96end
97
98temp = [];
99if isempty(x1_list)
100    temp = sqrList(bottom,2);
101else
102    temp = sqrList(x1_list,2:end);
103end
104if isempty(x2_list)
105    temp = [temp sqrList(bottom,3)];
106else
107    temp = [temp sqrList(x2_list,2:end)];
108end
109temp = sort(temp(find(any(temp,1))));
110sqrList(bottom,2:2+length(temp)-1)=temp(end:-1:1);%fliplr(sort(temp));
111
112bottom = bottom+1;
113
114searchfor = sqrList(end,2:end);
115index = findrows(sqrList(1:end-1,2:end),searchfor);
116
117if ~isempty(index)
118    oldvariable = sqrList(index,1);
119    sqrList = sqrList(1:end-1,:);
120else
121    oldvariable = [];
122end
123
124end
Note: See TracBrowser for help on using the repository browser.