├── GPE_SP1d_Func.m ├── GenQAPLIB.m ├── LICENSE ├── OptManiMulitBallGBB.m ├── OptStiefelGBB.m ├── Print_QAPLIB_orth_table.m ├── Print_QAPLIB_orth_table_fixmu.m ├── QAPORTHALEQQ_QUAD.m ├── README.m ├── TestQAPLIB_orth_fixmu_improve_selected.m ├── Test_maxcut_demo.m ├── check_QAP_solu.m ├── data └── Maxcut │ ├── torusg3-82.mat │ └── toruspm3-8-50.mat ├── maxcut_quad.m ├── maxcut_quad_g.m ├── print_qap_probname.m ├── qapAB.m ├── readme.md └── test_eig_rand_demo.m /GPE_SP1d_Func.m: -------------------------------------------------------------------------------- 1 | function [f, g, mu, rms] = GPE_SP1d_Func(X, data) 2 | 3 | % problem with a single sphere: 4 | % min F(x), s.t. ||X||_F = 1 5 | % 6 | % Example from BEC: 7 | % [X, ~, out] = OptManiMulitBallGBB(X0, @GPE_SP1d_Func, opts, data); 8 | % 9 | % Reference: 10 | % Xinming Wu, Zaiwen Wen, and Weizhu Bao. A regularized Newton method 11 | % for computing ground states of Bose–Einstein condensates. Journal of 12 | % Scientific Computing (2017): 303-329. 13 | % 14 | % 15 | % Author: Xinming Wu, Zaiwen Wen 16 | % Version 0.5 .... 2016/10 17 | 18 | beta = data.beta; 19 | h = data.dx; 20 | V = data.V; 21 | 22 | % Energy Function and Gradient in 1d 23 | % f = E(Phi) 24 | % = (Phi,-Lap/2*Phi) + (Phi,V*Phi) + (|Phi|^4,1)*beta/2 25 | % 26 | % Let Phi = X/sqrt(h), then 27 | % f = E(X) 28 | % = + + <|X|^4,1>*beta/2/h 29 | % = *(N+1)/2 + + <|X|^4,1>*beta/2/h 30 | % g = grad E(X) 31 | % = dst(mu2*Xs) + V*X + |X|^2*X*beta/h 32 | % 33 | Nx = data.Nx-2; 34 | Lx = data.xmax-data.xmin; 35 | 36 | mu2 = ((1:Nx).').^2*(pi/Lx)^2/2; 37 | Xs = idst(X); 38 | 39 | mu2Xs = mu2.*Xs; 40 | VX = V.*X; 41 | 42 | f = Xs'*mu2Xs*(Nx+1)/2 + X'*VX + sum(abs(X).^4)*beta/2/h; 43 | g = 2*(dst(mu2Xs) + VX + abs(X).^2.*X*beta/h); 44 | 45 | if nargout<3, return; end 46 | 47 | % Chemical Potential 48 | % mu = f + (|Phi|^4,1)*beta/2 49 | % = f + <|X|^4,1>*beta/2/h 50 | mu = f + sum(abs(X).^4)*beta/2/h; 51 | 52 | % Root Mean Square 53 | % rms = sqrt(x^2*|Phi|^2,1) 54 | % = sqrt 55 | x = data.x(2:end-1); 56 | rms = sqrt(sum(x.^2.*abs(X).^2)); 57 | -------------------------------------------------------------------------------- /GenQAPLIB.m: -------------------------------------------------------------------------------- 1 | function GenQAPLIB 2 | 3 | clc 4 | close all; 5 | % clear all 6 | 7 | doSeDumi = 0; 8 | doprofile = 1; 9 | 10 | 11 | % data file 12 | 13 | 14 | src = '/home/wenzw/code/ConvexOpt/SDP/QAPLIB/'; 15 | Probname = {'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', 'bur26g', 'bur26h', ... 16 | 'chr12a', 'chr12b', 'chr12c', 'chr15a', 'chr15b', 'chr15c', 'chr18a', 'chr18b', 'chr20a', 'chr20b', 'chr20c', 'chr22a', 'chr22b', 'chr25a', ... 17 | 'els19', 'esc128', 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', ... 18 | 'esc32b', 'esc32c', 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'esc64a', 'had12', 'had14', 'had16', 'had18', 'had20', 'kra30a', ... 19 | 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', 'lipa60a', 'lipa60b', ... 20 | 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', 'lipa90a', 'lipa90b', 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... 21 | 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', 'nug27', 'nug28', 'nug30', 'rou12', 'rou15', 'rou20', 'scr12', 'scr15', ... 22 | 'scr20', 'sko100a', 'sko100b', 'sko100c', 'sko100d', 'sko100e', 'sko100f', 'sko42', 'sko49', 'sko56', 'sko64', 'sko72', ... 23 | 'sko81', 'sko90', 'ste36a', 'ste36b', 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', 'tai12b', 'tai150b', 'tai15a', ... 24 | 'tai15b', 'tai17a', 'tai20a', 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', ... 25 | 'tai50b', 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', 'tho30', 'tho40', 'wil100', 'wil50'}; 26 | 27 | info = {'esc32a',130; 28 | 'esc32b', 168; 29 | 'esc32c', 642; 30 | 'esc32d', 200; 31 | 'esc32h', 438; 32 | 'esc64a', 116; 33 | 'sko42', 15812; 34 | 'sko49', 23386; 35 | 'sko56', 34458; 36 | 'sko64', 48498; 37 | 'sko72', 66256; 38 | 'tai30a', 1818146; 39 | 'tai35a', 2422002; 40 | 'tai40a', 3139370; 41 | 'tho40', 240516; 42 | 'wil50', 48816}; 43 | 44 | % load QAPSDPMATA 45 | % nmax = 40; 46 | % for dn = 1:nmax 47 | % clear n m ACon b L 48 | % n = MATA{dn,1}; m = MATA{dn,2}; ACon = MATA{dn,3}; b = MATA{dn,4}; L = MATA{dn,5}; 49 | % 50 | % save(strcat(src, 'QAPn', num2str(n) ), 'n', 'm', 'ACon', 'b', 'L'); 51 | % 52 | % end 53 | 54 | nprob = length(Probname); 55 | 56 | 57 | Problist = [1:nprob]; 58 | % Problist = [2]; 59 | % Problist = [nprob]; 60 | 61 | for di = 1:length(Problist) 62 | 63 | name = Probname{Problist(di)}; 64 | file = strcat(src, name,'.dat'); 65 | fid = fopen(file, 'r'); 66 | 67 | n = fscanf(fid, '%d', 1); 68 | 69 | A = fscanf(fid, '%f', [n, n]); % It has two rows now. 70 | A = A'; 71 | 72 | B = fscanf(fid, '%f', [n, n]); % It has two rows now. 73 | B = B'; 74 | % A 75 | % B 76 | fclose(fid); 77 | 78 | % read solution 79 | file = strcat(src, name,'.sln'); 80 | fid = fopen(file, 'r'); 81 | if fid > 0 82 | fscanf(fid, '%d', 1); 83 | obj = fscanf(fid, '%f', 1); 84 | [solu, count] = fscanf(fid, '%d', n); % It has two rows now. 85 | 86 | % if count ~= n 87 | % obj = 0; 88 | % end 89 | fclose(fid); 90 | 91 | 92 | fprintf('name: %s, n: %d, obj: %d, count: %d\n', name, n, obj, count); 93 | 94 | else 95 | obj = 0; 96 | fprintf('name: %s, n: %d, obj: %d\n', name, n, obj); 97 | end 98 | 99 | save(strcat(src, name), 'n', 'A', 'B', 'obj'); 100 | 101 | end 102 | 103 | for di = 1:length(info) 104 | name = info{di,1}; 105 | load(strcat(src, name), 'n', 'A', 'B', 'obj'); 106 | obj = info{di,2}; 107 | fprintf('name: %s, n: %d, obj: %d\n', name, n, obj); 108 | save(strcat(src, name), 'n', 'A', 'B', 'obj'); 109 | end 110 | 111 | 112 | fprintf('\n\n'); 113 | for di = 1:length(Problist) 114 | name = Probname{Problist(di)}; 115 | load(strcat(src, name), 'n', 'A', 'B', 'obj'); 116 | fprintf('name: %s, n: %d, obj: %d\n', name, n, obj); 117 | end 118 | 119 | % % print problem whose size is <= 40 120 | % for di = 1:length(Problist) 121 | % 122 | % name = Probname{Problist(di)}; 123 | % file = strcat(src, name,'.dat'); 124 | % fid = fopen(file, 'r'); 125 | % 126 | % n = fscanf(fid, '%d', 1); 127 | % fclose(fid); 128 | % 129 | % if n <= 40 130 | % fprintf('''%s'', ', name); 131 | % end 132 | % 133 | % end 134 | % 135 | 136 | 137 | 138 | 139 | end 140 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /OptManiMulitBallGBB.m: -------------------------------------------------------------------------------- 1 | function [x, g, out]= OptManiMulitBallGBB(x, fun, opts, varargin) 2 | %------------------------------------------------------------------------- 3 | % Line search algorithm for optimization on manifold: 4 | % 5 | % Model 1: 6 | % min f(X), s.t., ||X_i||_2 = radius, where X \in R^{n,p} 7 | % g(X) = grad f(X) 8 | % X = [X_1, X_2, ..., X_p] 9 | % 10 | % each column of X lies on a unit sphere 11 | % 12 | % Model 2: 13 | % min f(X), s.t., ||X||_F = radius, where X \in R^{n,p} 14 | % X is lies on a single sphere 15 | % 16 | % 17 | % Input: 18 | % X --- ||X_i||_2 = radius, each column of X lies on a unit sphere 19 | % fun --- objective function and its gradient: 20 | % [F, G] = fun(X, data1, data2) 21 | % F, G are the objective function value and gradient, repectively 22 | % data1, data2 are addtional data, and can be more 23 | % Calling syntax: 24 | % [X, out]= OptManiMulitBallGBB(X0, @fun, opts, data1, data2); 25 | % 26 | % opts --- option structure with fields: 27 | % record = 0, no print out 28 | % mxitr max number of iterations 29 | % xtol stop control for ||X_k - X_{k-1}|| 30 | % gtol stop control for the projected gradient 31 | % ftol stop control for |F_k - F_{k-1}|/(1+|F_{k-1}|) 32 | % usually, max{xtol, gtol} > ftol 33 | % 34 | % Output: 35 | % x --- solution 36 | % g --- gradient of x 37 | % Out --- output information 38 | % 39 | % ------------------------------------- 40 | % For example, consider the maxcut SDP: 41 | % X is n by n matrix 42 | % max Tr(C*X), s.t., X_ii = 1, X psd 43 | % 44 | % low rank model is: 45 | % X = V'*V, V = [V_1, ..., V_n], V is a p by n matrix 46 | % max Tr(C*V'*V), s.t., ||V_i|| = 1, 47 | % 48 | % function [f, g] = maxcut_quad(V, C) 49 | % g = 2*(V*C); 50 | % f = sum(dot(g,V))/2; 51 | % end 52 | % 53 | % [x, g, out]= OptManiMulitBallGBB(x0, @maxcut_quad, opts, C); 54 | % 55 | % ------------------------------------- 56 | % 57 | % Reference: 58 | % Z. Wen and W. Yin 59 | % A feasible method for optimization with orthogonality constraints 60 | % 61 | % Author: Zaiwen Wen 62 | % Version 0.1 .... 2010/10 63 | % Version 0.5 .... 2013/10 64 | %------------------------------------------------------------------------- 65 | 66 | % termination rule 67 | if ~isfield(opts, 'gtol'); opts.gtol = 1e-5; end % 1e-5 68 | if ~isfield(opts, 'xtol'); opts.xtol = 1e-6; end % 1e-6 69 | if ~isfield(opts, 'ftol'); opts.ftol = 1e-13; end % 1e-13 70 | 71 | % parameters for control the linear approximation in line search, 72 | if ~isfield(opts, 'tau'); opts.tau = 1e-3; end 73 | if ~isfield(opts, 'rhols'); opts.rhols = 1e-4; end 74 | if ~isfield(opts, 'eta'); opts.eta = 0.1; end 75 | if ~isfield(opts, 'gamma'); opts.gamma = 0.85; end 76 | if ~isfield(opts, 'STPEPS'); opts.STPEPS = 1e-10; end 77 | if ~isfield(opts, 'nt'); opts.nt = 3; end % 3 78 | if ~isfield(opts, 'maxit'); opts.maxit = 1000; end 79 | if ~isfield(opts, 'eps'); opts.eps = 1e-14; end 80 | if ~isfield(opts, 'record'); opts.record = 0; end 81 | if ~isfield(opts, 'model'); opts.model = 1; end 82 | if ~isfield(opts, 'radius'); opts.radius = 1; end 83 | 84 | fid = 1; 85 | if isfield(opts, 'recordFile') 86 | fid = fopen(opts.recordFile,'a+'); 87 | end 88 | 89 | %------------------------------------------------------------------------------- 90 | % copy parameters 91 | gtol = opts.gtol; 92 | xtol = opts.xtol; 93 | ftol = opts.ftol; 94 | maxit = opts.maxit; 95 | rhols = opts.rhols; 96 | eta = opts.eta; 97 | eps = opts.eps; 98 | gamma = opts.gamma; 99 | record = opts.record; 100 | model = opts.model; 101 | radius = opts.radius; 102 | nt = opts.nt; 103 | crit = ones(nt,1); 104 | 105 | % normalize x so that ||x||_2 = 1 106 | if model == 1 107 | nrmx = dot(x,x,1); 108 | if norm(nrmx - radius,'fro')> eps; 109 | x = radius*bsxfun(@rdivide, x, sqrt(nrmx)); end; 110 | else 111 | nrmx = norm(x,'fro'); 112 | if abs(nrmx - radius)> eps; x = x*(radius/nrmx); end; 113 | end 114 | 115 | %% Initial function value and gradient 116 | % prepare for iterations 117 | [f,g] = feval(fun, x, varargin{:}); out.nfe = 1; out.fval0 = f; 118 | 119 | if model == 1 120 | xtg = dot(x,g,1); gg = dot(g,g,1); 121 | xx = dot(x,x,1); xxgg = xx.*gg; 122 | dtX = bsxfun(@times, xtg, x) - g; %bsxfun(@times, xx, g); 123 | nrmG = norm(dtX, 'fro'); 124 | else 125 | xtg = iprod(x,g); gg = norm(g,'fro')^2; 126 | xx = norm(x,'fro')^2; xxgg = xx.*gg; 127 | dtX = xtg*x - xx*g; nrmG = norm(dtX, 'fro'); 128 | end 129 | 130 | Q = 1; Cval = f; tau = opts.tau; 131 | 132 | %% Print iteration header if debug == 1 133 | if (record >= 1) 134 | fprintf('----------- OptM For Spherical Constraints ----------- \n'); 135 | fprintf(fid,'%4s \t %10s \t %10s \t %10s \t %10s \t %10s \t %10s \t %10s\n', ... 136 | 'Iter', 'tau', 'f(X)', 'nrmG', 'XDiff', 'FDiff', 'nls', 'feasi'); 137 | end 138 | 139 | if record == 10; out.fvec = f; end 140 | out.msg = 'exceed max iteration'; 141 | 142 | %% main iteration 143 | for iter = 1 : maxit 144 | xp = x; fp = f; gp = g; dtXP = dtX; 145 | 146 | nls = 1; deriv = rhols*nrmG^2; 147 | while 1 148 | % calculate f, g 149 | tau2 = tau/2; beta = (1+(tau2)^2*(-xtg.^2+xxgg)); 150 | a1 = ((1+tau2*xtg).^2 -(tau2)^2*xxgg)./beta; 151 | a2 = -tau*xx./beta; 152 | x = bsxfun(@times, a1, xp) + bsxfun(@times, a2, gp); 153 | 154 | [f,g] = feval(fun, x, varargin{:}); out.nfe = out.nfe + 1; 155 | if f <= Cval - tau*deriv || nls >= 5 156 | break 157 | end 158 | tau = eta*tau; 159 | nls = nls+1; 160 | end 161 | 162 | % % ---- enforce orthogonality ---- 163 | feasi = compute_feasi(); 164 | if feasi > eps 165 | if model == 1; x = radius*bsxfun(@rdivide, x, nrmx); 166 | else x = x*(radius/nrmx); end 167 | 168 | [f,g] = feval(fun, x, varargin{:}); out.nfe = out.nfe + 1; 169 | end 170 | 171 | if record == 10; out.fvec = [out.fvec; f]; end 172 | 173 | if model == 1 174 | xtg = dot(x,g,1); gg = dot(g,g,1); 175 | xx = dot(x,x,1); xxgg = xx.*gg; 176 | dtX = bsxfun(@times, xtg, x) - g; %bsxfun(@times, xx, g); 177 | nrmG = norm(dtX, 'fro'); 178 | else 179 | xtg = iprod(x,g); gg = norm(g,'fro')^2; 180 | xx = norm(x,'fro')^2; xxgg = xx.*gg; 181 | dtX = xtg*x - xx*g; nrmG = norm(dtX, 'fro'); 182 | end 183 | 184 | s = x - xp; 185 | XDiff = norm(s,'fro'); % (relative Xdiff) ~ g 186 | FDiff = abs(f-fp)/(abs(fp)+1); 187 | 188 | % ---- record ---- 189 | if (record >= 1) 190 | fprintf(fid,'%4d \t %3.2e \t %14.13e \t %3.2e \t %3.2e \t %3.2e \t %2d \t feasi: %2.1e\n', ... 191 | iter, tau, f, nrmG, XDiff, FDiff, nls, feasi); 192 | end 193 | 194 | % crit(iter,:) = [nrmG, XDiff, FDiff]; 195 | % mcrit = mean(crit(iter-min(nt,iter)+1:iter, :),1); 196 | % if ( XDiff < xtol && FDiff < ftol ) || nrmG < gtol ... 197 | % % || all(mcrit(2:3) < 10*[xtol, ftol]) 198 | 199 | crit(iter) = FDiff; 200 | mcrit = mean(crit(iter-min(nt,iter)+1:iter)); 201 | 202 | % ---- termination ---- 203 | % if nrmG < gtol || XDiff < xtol || FDiff < ftol 204 | if nrmG < gtol || XDiff < xtol || mcrit < ftol 205 | out.msg = 'converge'; 206 | if nrmG < gtol, out.msg = strcat(out.msg,'_g'); end 207 | if XDiff < xtol, out.msg = strcat(out.msg,'_x'); end 208 | % if FDiff < ftol, out.msg = strcat(out.msg,'_f'); end 209 | if mcrit < ftol, out.msg = strcat(out.msg,'_mf'); end 210 | break; 211 | end 212 | 213 | % y = g - gp; 214 | y = dtX - dtXP; 215 | sy = abs(iprod(s,y)); tau = opts.tau; 216 | if sy > 0; 217 | if mod(iter,2)==0; tau = (norm(s(:),'fro')^2)/sy; 218 | else tau = sy/(norm(y(:),'fro')^2); end 219 | % % safeguarding on tau 220 | % tau1 = (norm(s(:),'fro')^2)/sy; 221 | % tau2 = sy/(norm(y(:),'fro')^2); 222 | % if tau2 < 0.1*tau1; tau = tau2; 223 | % else tau = tau1; end 224 | tau = max(min(tau, 1e20), 1e-20); 225 | end 226 | 227 | % y = dtX - dtXP; 228 | % sy = abs(iprod(s,y)); tau = opts.tau; 229 | % dsnrm = norm(s(:),'fro'); 230 | % dynrm = norm(y(:),'fro'); 231 | % if sy > 1e-8*dsnrm*dynrm 232 | % tau = sy/dynrm^2; 233 | % else 234 | % tau = 0.1*dsnrm/dynrm; 235 | % end 236 | % tau = max(min(tau, 1e20), 1e-20); 237 | 238 | Qp = Q; Q = gamma*Qp + 1; Cval = (gamma*Qp*Cval + f)/Q; 239 | end 240 | 241 | if feasi > eps 242 | if model == 1; x = radius*bsxfun(@rdivide, x, nrmx); 243 | else x = x*(radius/nrmx); end 244 | [f,g] = feval(fun, x, varargin{:}); out.nfe = out.nfe + 1; 245 | if model == 1; xtg = dot(x,g,1); else xtg = iprod(x,g); end 246 | 247 | if model == 1; nrmx = sqrt(dot(x,x,1)); out.feasi = norm(nrmx-radius); 248 | else nrmx = norm(x,'fro'); out.feasi = abs(nrmx-radius); end 249 | end 250 | 251 | out.feasi = feasi; 252 | 253 | xtg = xtg/radius^2; 254 | 255 | out.xtg = xtg; % Lagrangian multipliers of the constraints (=2\mu) 256 | out.XDiff = XDiff; 257 | out.FDiff = FDiff; 258 | out.mcrit = mcrit; 259 | out.nrmG = nrmG; 260 | out.fval = f; 261 | out.iter = iter; 262 | 263 | function feasi = compute_feasi() 264 | nrmx = sqrt(xx); 265 | if model == 1; feasi = norm(nrmx -radius); 266 | else feasi = abs(nrmx-radius); end 267 | end 268 | 269 | end 270 | 271 | function a = iprod(x,y) 272 | a = real(sum(sum(conj(x).*y))); 273 | end 274 | -------------------------------------------------------------------------------- /OptStiefelGBB.m: -------------------------------------------------------------------------------- 1 | function [X, out]= OptStiefelGBB(X, fun, opts, varargin) 2 | %------------------------------------------------------------------------- 3 | % curvilinear search algorithm for optimization on Stiefel manifold 4 | % 5 | % min F(X), S.t., X'*X = I_k, where X \in R^{n,k} 6 | % 7 | % H = [G, X]*[X -G]' 8 | % U = 0.5*tau*[G, X]; V = [X -G] 9 | % X(tau) = X - 2*U * inv( I + V'*U ) * V'*X 10 | % 11 | % ------------------------------------- 12 | % U = -[G,X]; V = [X -G]; VU = V'*U; 13 | % X(tau) = X - tau*U * inv( I + 0.5*tau*VU ) * V'*X 14 | % 15 | % 16 | % Input: 17 | % X --- n by k matrix such that X'*X = I 18 | % fun --- objective function and its gradient: 19 | % [F, G] = fun(X, data1, data2) 20 | % F, G are the objective function value and gradient, repectively 21 | % data1, data2 are addtional data, and can be more 22 | % Calling syntax: 23 | % [X, out]= OptStiefelGBB(X0, @fun, opts, data1, data2); 24 | % 25 | % opts --- option structure with fields: 26 | % record = 0, no print out 27 | % mxitr max number of iterations 28 | % xtol stop control for ||X_k - X_{k-1}|| 29 | % gtol stop control for the projected gradient 30 | % ftol stop control for |F_k - F_{k-1}|/(1+|F_{k-1}|) 31 | % usually, max{xtol, gtol} > ftol 32 | % 33 | % Output: 34 | % X --- solution 35 | % Out --- output information 36 | % 37 | % ------------------------------------- 38 | % For example, consider the eigenvalue problem F(X) = -0.5*Tr(X'*A*X); 39 | % 40 | % function demo 41 | % 42 | % function [F, G] = fun(X, A) 43 | % G = -(A*X); 44 | % F = 0.5*sum(dot(G,X,1)); 45 | % end 46 | % 47 | % n = 1000; k = 6; 48 | % A = randn(n); A = A'*A; 49 | % opts.record = 0; % 50 | % opts.mxitr = 1000; 51 | % opts.xtol = 1e-5; 52 | % opts.gtol = 1e-5; 53 | % opts.ftol = 1e-8; 54 | % 55 | % X0 = randn(n,k); X0 = orth(X0); 56 | % tic; [X, out]= OptStiefelGBB(X0, @fun, opts, A); tsolve = toc; 57 | % out.fval = -2*out.fval; % convert the function value to the sum of eigenvalues 58 | % fprintf('\nOptM: obj: %7.6e, itr: %d, nfe: %d, cpu: %f, norm(XT*X-I): %3.2e \n', ... 59 | % out.fval, out.itr, out.nfe, tsolve, norm(X'*X - eye(k), 'fro') ); 60 | % 61 | % end 62 | % ------------------------------------- 63 | % 64 | % Reference: 65 | % Z. Wen and W. Yin 66 | % A feasible method for optimization with orthogonality constraints 67 | % 68 | % Author: Zaiwen Wen, Wotao Yin 69 | % Version 0.1 .... 2010/10 70 | % Version 0.5 .... 2013/10 71 | %------------------------------------------------------------------------- 72 | 73 | 74 | %% Size information 75 | if isempty(X) 76 | error('input X is an empty matrix'); 77 | else 78 | [n, k] = size(X); 79 | end 80 | 81 | if nargin < 2; error('[X, out]= OptStiefelGBB(X0, @fun, opts)'); end 82 | if nargin < 3; opts = []; end 83 | 84 | if ~isfield(opts, 'X0'); opts.X0 = []; end 85 | if ~isfield(opts, 'xtol'); opts.xtol = 1e-6; end 86 | if ~isfield(opts, 'gtol'); opts.gtol = 1e-6; end 87 | if ~isfield(opts, 'ftol'); opts.ftol = 1e-12; end 88 | 89 | % parameters for control the linear approximation in line search, 90 | if ~isfield(opts, 'tau'); opts.tau = 1e-3; end 91 | if ~isfield(opts, 'rhols'); opts.rhols = 1e-4; end 92 | if ~isfield(opts, 'eta'); opts.eta = 0.1; end 93 | if ~isfield(opts, 'retr'); opts.retr = 0; end 94 | if ~isfield(opts, 'gamma'); opts.gamma = 0.85; end 95 | if ~isfield(opts, 'STPEPS'); opts.STPEPS = 1e-10; end 96 | if ~isfield(opts, 'nt'); opts.nt = 5; end 97 | if ~isfield(opts, 'mxitr'); opts.mxitr = 1000; end 98 | if ~isfield(opts, 'record'); opts.record = 0; end 99 | if ~isfield(opts, 'tiny'); opts.tiny = 1e-13; end 100 | 101 | %------------------------------------------------------------------------------- 102 | % copy parameters 103 | xtol = opts.xtol; 104 | gtol = opts.gtol; 105 | ftol = opts.ftol; 106 | rhols = opts.rhols; 107 | STPEPS = opts.STPEPS; 108 | eta = opts.eta; 109 | gamma = opts.gamma; 110 | retr = opts.retr; 111 | record = opts.record; 112 | nt = opts.nt; 113 | crit = ones(nt, 3); 114 | tiny = opts.tiny; 115 | %------------------------------------------------------------------------------- 116 | 117 | %% Initial function value and gradient 118 | % prepare for iterations 119 | [F, G] = feval(fun, X , varargin{:}); out.nfe = 1; 120 | GX = G'*X; 121 | 122 | if retr == 1 123 | invH = true; if k < n/2; invH = false; eye2k = eye(2*k); end 124 | if invH 125 | GXT = G*X'; H = 0.5*(GXT - GXT'); RX = H*X; 126 | else 127 | U = [G, X]; V = [X, -G]; VU = V'*U; 128 | %U = [G, X]; VU = [GX', X'*X; -(G'*G), -GX]; 129 | %VX = VU(:,k+1:end); %VX = V'*X; 130 | VX = V'*X; 131 | end 132 | end 133 | dtX = G - X*GX; nrmG = norm(dtX, 'fro'); 134 | 135 | Q = 1; Cval = F; tau = opts.tau; 136 | 137 | %% Print iteration header if debug == 1 138 | if (opts.record == 1) 139 | fid = 1; 140 | fprintf(fid, '----------- Gradient Method with Line search ----------- \n'); 141 | fprintf(fid, '%4s %8s %8s %10s %10s\n', 'Iter', 'tau', 'F(X)', 'nrmG', 'XDiff'); 142 | %fprintf(fid, '%4d \t %3.2e \t %3.2e \t %5d \t %5d \t %6d \n', 0, 0, F, 0, 0, 0); 143 | end 144 | 145 | %% main iteration 146 | for itr = 1 : opts.mxitr 147 | XP = X; FP = F; GP = G; dtXP = dtX; 148 | % scale step size 149 | 150 | nls = 1; deriv = rhols*nrmG^2; %deriv 151 | while 1 152 | % calculate G, F, 153 | if retr == 1 154 | if invH 155 | [X, infX] = linsolve(eye(n) + tau*H, XP - tau*RX); 156 | else 157 | [aa, infR] = linsolve(eye2k + (0.5*tau)*VU, VX); 158 | X = XP - U*(tau*aa); 159 | end 160 | else 161 | [X, RR] = myQR(XP - tau*dtX, k); 162 | end 163 | 164 | if norm(X'*X - eye(k),'fro') > tiny; X = myQR(X,k); end 165 | 166 | [F,G] = feval(fun, X, varargin{:}); 167 | out.nfe = out.nfe + 1; 168 | 169 | if F <= Cval - tau*deriv || nls >= 5 170 | break; 171 | end 172 | tau = eta*tau; nls = nls+1; 173 | end 174 | 175 | GX = G'*X; 176 | if retr == 1 177 | if invH 178 | GXT = G*X'; H = 0.5*(GXT - GXT'); RX = H*X; 179 | else 180 | U = [G, X]; V = [X, -G]; VU = V'*U; 181 | %U = [G, X]; VU = [GX', X'*X; -(G'*G), -GX]; 182 | %VX = VU(:,k+1:end); % VX = V'*X; 183 | VX = V'*X; 184 | end 185 | end 186 | dtX = G - X*GX; nrmG = norm(dtX, 'fro'); 187 | S = X - XP; XDiff = norm(S,'fro')/sqrt(n); 188 | tau = opts.tau; FDiff = abs(FP-F)/(abs(FP)+1); 189 | 190 | %Y = G - GP; SY = abs(iprod(S,Y)); 191 | Y = dtX - dtXP; SY = abs(iprod(S,Y)); 192 | if mod(itr,2)==0; tau = (norm(S,'fro')^2)/SY; 193 | else tau = SY/(norm(Y,'fro')^2); end 194 | tau = max(min(tau, 1e20), 1e-20); 195 | 196 | if (record >= 1) 197 | fprintf('%4d %3.2e %4.3e %3.2e %3.2e %3.2e %2d\n', ... 198 | itr, tau, F, nrmG, XDiff, FDiff, nls); 199 | %fprintf('%4d %3.2e %4.3e %3.2e %3.2e (%3.2e, %3.2e)\n', ... 200 | % itr, tau, F, nrmG, XDiff, alpha1, alpha2); 201 | end 202 | 203 | crit(itr,:) = [nrmG, XDiff, FDiff]; 204 | mcrit = mean(crit(itr-min(nt,itr)+1:itr, :),1); 205 | %if (XDiff < xtol && nrmG < gtol ) || FDiff < ftol 206 | %if (XDiff < xtol || nrmG < gtol ) || FDiff < ftol 207 | %if ( XDiff < xtol && FDiff < ftol ) || nrmG < gtol 208 | %if ( XDiff < xtol || FDiff < ftol ) || nrmG < gtol 209 | %if any(mcrit < [gtol, xtol, ftol]) 210 | if ( XDiff < xtol && FDiff < ftol ) || nrmG < gtol || all(mcrit(2:3) < 10*[xtol, ftol]) 211 | out.msg = 'converge'; 212 | break; 213 | end 214 | 215 | Qp = Q; Q = gamma*Qp + 1; Cval = (gamma*Qp*Cval + F)/Q; 216 | end 217 | 218 | if itr >= opts.mxitr 219 | out.msg = 'exceed max iteration'; 220 | end 221 | 222 | out.feasi = norm(X'*X-eye(k),'fro'); 223 | if out.feasi > 1e-13 224 | %X = MGramSchmidt(X); 225 | X = myQR(X,k); 226 | [F,G] = feval(fun, X, varargin{:}); 227 | out.nfe = out.nfe + 1; 228 | out.feasi = norm(X'*X-eye(k),'fro'); 229 | end 230 | 231 | out.nrmG = nrmG; 232 | out.fval = F; 233 | out.itr = itr; 234 | end 235 | 236 | function a = iprod(x,y) 237 | %a = real(sum(sum(x.*y))); 238 | a = real(sum(sum(conj(x).*y))); 239 | end 240 | 241 | 242 | 243 | function [Q, RR] = myQR(XX,k) 244 | [Q, RR] = qr(XX, 0); 245 | diagRR = sign(diag(RR)); ndr = diagRR < 0; 246 | if nnz(ndr) > 0 247 | Q = Q*spdiags(diagRR,0,k,k); 248 | %Q(:,ndr) = Q(:,ndr)*(-1); 249 | end 250 | end 251 | 252 | -------------------------------------------------------------------------------- /Print_QAPLIB_orth_table.m: -------------------------------------------------------------------------------- 1 | function Print_QAPLIB_orth_table 2 | 3 | clc 4 | close all; 5 | % clear all 6 | 7 | % data file 8 | src = '/home/wenzw/code/ConvexOpt/SDP/QAPLIB/'; 9 | Probname = { 'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', ... % 1 -- 6 10 | 'bur26g', 'bur26h', 'chr12a', 'chr12b', 'chr12c', 'chr15a', ... % 7 -- 12 11 | 'chr15b', 'chr15c', 'chr18a', 'chr18b', 'chr20a', 'chr20b', ... % 13 -- 18 12 | 'chr20c', 'chr22a', 'chr22b', 'chr25a', 'els19', 'esc128', ... % 19 -- 24 13 | 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... % 25 -- 30 14 | 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', ... % 31 -- 36 15 | 'esc32c', 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'esc64a', ... % 37 -- 42 16 | 'had12', 'had14', 'had16', 'had18', 'had20', 'kra30a', ... % 43 -- 48 17 | 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... % 49 -- 54 18 | 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', 'lipa60a', 'lipa60b', ... % 55 -- 60 19 | 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', 'lipa90a', 'lipa90b', ... % 61 -- 66 20 | 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... % 67 -- 72 21 | 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', ... % 73 -- 78 22 | 'nug27', 'nug28', 'nug30', 'rou12', 'rou15', 'rou20', ... % 79 -- 84 23 | 'scr12', 'scr15', 'scr20', 'sko100a', 'sko100b', 'sko100c', ... % 85 -- 90 24 | 'sko100d', 'sko100e', 'sko100f', 'sko42', 'sko49', 'sko56', ... % 91 -- 96 25 | 'sko64', 'sko72', 'sko81', 'sko90', 'ste36a', 'ste36b', ... % 97 -- 102 26 | 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', ... % 103 -- 108 27 | 'tai12b', 'tai150b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', ... % 109 -- 114 28 | 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', ... % 115 -- 120 29 | 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', 'tai50b', ... % 121 -- 126 30 | 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', ... % 127 -- 132 31 | 'tho30', 'tho40', 'wil100', 'wil50'}; ... % 133 -- 136 32 | 33 | % % problems whose size is <= 40 34 | % Probname = {'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', 'bur26g', 'bur26h', ... % 1-8 35 | % 'chr12a', 'chr12b', 'chr12c', 'chr15a', 'chr15b', 'chr15c', 'chr18a', 'chr18b', ... %9-16 36 | % 'chr20a', 'chr20b', 'chr20c', 'chr22a', 'chr22b', 'chr25a', ... %17-22 37 | % 'els19', 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... %23-29 38 | % 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', 'esc32c', ... %30-36 39 | % 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'had12', 'had14', 'had16', 'had18', .... %37-44 40 | % 'had20', 'kra30a', 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... %45-52 41 | % 'lipa40a', 'lipa40b', 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... %53-60 42 | % 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', 'nug27', 'nug28', 'nug30', ... %61-69 43 | % 'rou12', 'rou15', 'rou20', 'scr12', 'scr15', 'scr20', 'ste36a', 'ste36b', 'ste36c', ... %70-78 44 | % 'tai10a', 'tai10b', 'tai12a', 'tai12b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', 'tai20b', ... %79-87 45 | % 'tai25a', 'tai25b', 'tai30a', 'tai30b', 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tho30', 'tho40'}; %88-97 46 | 47 | nprob = length(Probname); 48 | 49 | % load('results/res_qap_yind20_1', 'perf', 'mulist'); 50 | % load('results/res_qap_X1SL', 'perf', 'mulist'); 51 | load('results/res_qap_X2SL', 'perf', 'mulist'); 52 | perf1 = perf; mulist1 = mulist; nmu1 = length(mulist); 53 | 54 | % load('results/res_qap_X2SL', 'perf', 'mulist'); 55 | % load('results/res_qap_X1SL', 'perf', 'mulist'); 56 | % load('results/res_qap_X1aa', 'perf', 'mulist'); 57 | % perf2 = perf; mulist2 = mulist; nmu2 = length(mulist); 58 | % nmu = size(perf,1)/nprob; 59 | 60 | 61 | for di = 1:nprob 62 | 63 | load(strcat(src, Probname{di}, '.mat'), 'n','A','B','obj'); 64 | %read from a single solver 65 | [name, stat] = extractInfo(perf1, nmu1, di); 66 | n = stat(1); mu = stat(2); objf = stat(4); fgap = stat(5); 67 | tsolve = stat(6); nfe = stat(8); feasi = stat(9) +stat(10); 68 | tag = ''; if fgap == 0; tag = '$^\dagger$'; end 69 | fprintf('%3d & %8s %8s & %4d & %12d & %2.1e & %12d & %7.3f & %7.2f & %3d & %2.1e \\\\ \\hline\n', ... 70 | di, name, tag, n, obj, mu, objf, fgap, tsolve, nfe, feasi); 71 | 72 | 73 | % [name, stat1] = extractInfo(perf1, nmu1, di); 74 | % [name2, stat2] = extractInfo(perf2, nmu2, di); 75 | % if strcmp(name,name2) ~= 1; error('not the same file'); end 76 | % stat = [stat1; stat2]; 77 | % fidx = stat(:,4) >= 0; idx = (sum(stat(:,9:10),2) < 1e-6) & fidx; 78 | % if all(idx) 79 | % [aa, pp] = min(stat(: ,5)); 80 | % elseif any(idx) 81 | % pp = find(idx); 82 | % else 83 | % pp = 1; 84 | % end 85 | % stat = stat(pp,:); 86 | % 87 | % n = stat(1); mu = stat(2); objf = stat(4); fgap = stat(5); 88 | % tsolve = stat(6); nfe = stat(8); feasi = stat(9) +stat(10); 89 | % tag = sprintf('$^%d$',pp); if fgap == 0; tag = sprintf('$^{%d\\dagger}$',pp); end 90 | % 91 | % fprintf('%3d & %8s %8s & %4d & %12d & %2.1e & %12d & %7.3f & %7.2f & %3d & %2.1e \\\\ \\hline\n', ... 92 | % di, name, tag, n, obj, mu, objf, fgap, tsolve, nfe, feasi); 93 | % 94 | 95 | end 96 | 97 | function [name, stat] = extractInfo(perf, nmu, di) 98 | dp = (di-1)*nmu + 1; name = perf{dp+nmu-1,1}; 99 | for dmu = 1:nmu 100 | stat(dmu,:) = perf{dp+dmu-1,3}; 101 | %if obj == 0 102 | % objf = stat(dmu,4); 103 | % stat(dmu,5) = (abs(objf-obj)/max(1,objf))*100; 104 | %end 105 | %fprintf('name: %8s, n: %4d, mu: %3.2e, opt: %10d, fobj: %10d, fgap: %6.3f, cpu: %7.2f, itr: %3d, nfe: %3d, feasi: (%2.1e, %2.1e)\n', ... 106 | % name, perf{dp,3}); 107 | %dp = dp + 1; 108 | 109 | % perf{dp,1} = name; 110 | % if max(feasi1,feasi2)<1e-3; perf{dp,2} = sparse(X); end 111 | % perf{dp,3} = [n, mu, obj, objf, fgap, tsolve, out.itr, out.nfe, feasi1, feasi2]; 112 | end 113 | fidx = stat(:,4) >= 0; idx = (sum(stat(:,9:10),2) < 1e-6) & fidx; 114 | if any(idx) 115 | stat = stat(idx,:); 116 | else 117 | if ~any(fidx); fidx(1) = 1; end 118 | stat = stat(fidx,:); 119 | end 120 | [aa, pp] = min(stat(: ,5)); 121 | stat = stat(pp,:); 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /Print_QAPLIB_orth_table_fixmu.m: -------------------------------------------------------------------------------- 1 | function Print_QAPLIB_orth_table_fixmu 2 | 3 | clc 4 | close all; 5 | % clear all 6 | 7 | % data file 8 | src = '/home/wenzw/code/ConvexOpt/SDP/QAPLIB/'; 9 | Probname = { 'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', ... % 1 -- 6 10 | 'bur26g', 'bur26h', 'chr12a', 'chr12b', 'chr12c', 'chr15a', ... % 7 -- 12 11 | 'chr15b', 'chr15c', 'chr18a', 'chr18b', 'chr20a', 'chr20b', ... % 13 -- 18 12 | 'chr20c', 'chr22a', 'chr22b', 'chr25a', 'els19', 'esc128', ... % 19 -- 24 13 | 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... % 25 -- 30 14 | 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', ... % 31 -- 36 15 | 'esc32c', 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'esc64a', ... % 37 -- 42 16 | 'had12', 'had14', 'had16', 'had18', 'had20', 'kra30a', ... % 43 -- 48 17 | 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... % 49 -- 54 18 | 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', 'lipa60a', 'lipa60b', ... % 55 -- 60 19 | 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', 'lipa90a', 'lipa90b', ... % 61 -- 66 20 | 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... % 67 -- 72 21 | 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', ... % 73 -- 78 22 | 'nug27', 'nug28', 'nug30', 'rou12', 'rou15', 'rou20', ... % 79 -- 84 23 | 'scr12', 'scr15', 'scr20', 'sko100a', 'sko100b', 'sko100c', ... % 85 -- 90 24 | 'sko100d', 'sko100e', 'sko100f', 'sko42', 'sko49', 'sko56', ... % 91 -- 96 25 | 'sko64', 'sko72', 'sko81', 'sko90', 'ste36a', 'ste36b', ... % 97 -- 102 26 | 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', ... % 103 -- 108 27 | 'tai12b', 'tai150b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', ... % 109 -- 114 28 | 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', ... % 115 -- 120 29 | 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', 'tai50b', ... % 121 -- 126 30 | 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', ... % 127 -- 132 31 | 'tho30', 'tho40', 'wil100', 'wil50'}; ... % 133 -- 136 32 | 33 | % % problems whose size is <= 40 34 | % Probname = {'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', 'bur26g', 'bur26h', ... % 1-8 35 | % 'chr12a', 'chr12b', 'chr12c', 'chr15a', 'chr15b', 'chr15c', 'chr18a', 'chr18b', ... %9-16 36 | % 'chr20a', 'chr20b', 'chr20c', 'chr22a', 'chr22b', 'chr25a', ... %17-22 37 | % 'els19', 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... %23-29 38 | % 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', 'esc32c', ... %30-36 39 | % 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'had12', 'had14', 'had16', 'had18', .... %37-44 40 | % 'had20', 'kra30a', 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... %45-52 41 | % 'lipa40a', 'lipa40b', 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... %53-60 42 | % 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', 'nug27', 'nug28', 'nug30', ... %61-69 43 | % 'rou12', 'rou15', 'rou20', 'scr12', 'scr15', 'scr20', 'ste36a', 'ste36b', 'ste36c', ... %70-78 44 | % 'tai10a', 'tai10b', 'tai12a', 'tai12b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', 'tai20b', ... %79-87 45 | % 'tai25a', 'tai25b', 'tai30a', 'tai30b', 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tho30', 'tho40'}; %88-97 46 | 47 | nprob = length(Probname); 48 | 49 | load('results/fix_res_qap_X2SL20100926T024926', 'perf'); 50 | 51 | 52 | ndp = 120; 53 | 54 | dp = 1; 55 | for di = 1:nprob 56 | 57 | name = Probname{di}; 58 | load(strcat(src, name, '.mat'), 'n','A','B','obj'); 59 | %read from a single solver 60 | [stat, dp] = extractInfo(perf, ndp, dp, name); 61 | if ~isempty(stat) 62 | n = stat(1); mu = stat(2); objf = stat(4); fgap = stat(5); 63 | tsolve = stat(6); nfe = stat(8); feasi = stat(9) +stat(10); 64 | tag = ''; if fgap == 0; tag = '$^\dagger$'; end 65 | fprintf('%3d & %8s %8s & %4d & %12d & %2.1e & %12d & %7.3f & %7.2f & %3d & %2.1e \\\\ \\hline\n', ... 66 | di, name, tag, n, obj, mu, objf, fgap, tsolve, nfe, feasi); 67 | end 68 | end 69 | 70 | function [stat, dp] = extractInfo(perf, ndp, dp, sname) 71 | stat = []; 72 | for dmu = 1:ndp 73 | name = perf{dp,1}; 74 | if strcmp(name, sname) ~= 1 75 | return; 76 | elseif isempty(perf{dp,3}) 77 | dp = dp + 1; 78 | continue; 79 | end 80 | stat(dmu,:) = perf{dp,3}(2:end); 81 | %fprintf('name: %8s, n: %4d, mu: %3.2e, opt: %10d, fobj: %10d, fgap: %6.3f, cpu: %7.2f, itr: %3d, nfe: %3d, feasi: (%2.1e, %2.1e)\n', ... 82 | % name, perf{dp,3}); 83 | dp = dp + 1; 84 | % perf{dp,1} = name; 85 | % if max(feasi1,feasi2)<1e-3; perf{dp,2} = sparse(X); end 86 | % perf{dp,3} = [n, mu, obj, objf, fgap, tsolve, out.itr, out.nfe, feasi1, feasi2]; 87 | end 88 | fidx = stat(:,4) >= 0; idx = (sum(stat(:,9:10),2) < 1e-6) & fidx; 89 | if any(idx) 90 | stat = stat(idx,:); 91 | else 92 | if ~any(fidx); fidx(1) = 1; end 93 | stat = stat(fidx,:); 94 | end 95 | [aa, pp] = min(stat(: ,5)); 96 | stat = stat(pp,:); 97 | end 98 | 99 | end 100 | -------------------------------------------------------------------------------- /QAPORTHALEQQ_QUAD.m: -------------------------------------------------------------------------------- 1 | function [X, out] = QAPORTHALEQQ_QUAD(X, A, B, mu, opts) 2 | 3 | %% ------------------------------------------------------------------------ 4 | % Quadratic Assignment problem: 5 | % min Tr(XAXB), s.t., X'*X = I, X >= 0 6 | % = n 7 | 8 | %% ------------------------------------------------------------------------ 9 | 10 | 11 | if isfield(opts, 'objX') 12 | if opts.objX < 0 || opts.objX > 10 13 | opts.objX = 1; 14 | end 15 | else 16 | opts.objX = 1; 17 | end 18 | objX = opts.objX; 19 | 20 | 21 | %Initialize 22 | tol = opts.tol; tolsub = opts.tolsub; 23 | optsub = opts; 24 | 25 | 26 | %compute f and g 27 | [m,n] = size(A); lmb = zeros(n,n); Axlmb = []; 28 | lmb1 = zeros(n,1); Xen = zeros(n,1); 29 | lmb2 = zeros(n,1); Xtn = zeros(n,1); 30 | lmb3 = zeros(1,1); Xsn = zeros(1,1); 31 | 32 | f = inf; fQAP = inf; 33 | out.itrsub = 0; out.nfe = 0; 34 | for itr = 1:opts.omxitr 35 | fp = f; 36 | [X, outs]= OptStiefelGBB(X, @ObjQAPALEQ_QUAD, optsub); 37 | out.itrsub = out.itrsub + outs.itr; 38 | out.nfe = out.nfe + outs.nfe; 39 | f = outs.fval; fdiff = abs(f-fp)/(abs(fp)+1); 40 | feasi = norm(min(X,0),1); 41 | if opts.record 42 | fprintf('itr: %3d, mu: %3.2e, fdiff: %3.2e, feasi: %3.2e\n\n', ... 43 | itr, mu, fdiff, feasi); 44 | end 45 | 46 | if feasi <= tol 47 | break; 48 | end 49 | 50 | lmb = max(lmb-mu*X,0); 51 | % lmb1 = lmb1 - mu*Xen; 52 | % lmb2 = lmb2 - mu*Xtn; 53 | % lmb3 = lmb3 - mu*Xsn; 54 | if feasi > max(tol,tolsub); 55 | mu = mu*1.2; 56 | % else 57 | % mu = mu*0.8; 58 | end 59 | end 60 | out.itr = itr; 61 | out.fval = fQAP; 62 | 63 | % AXB = (A'*X*B); 64 | % g = AXB + A*X*B'; 65 | % % f = sum(dot(X,AXB)); 66 | % % f = trace(X*AXB); 67 | % f = sum(sum(X.*AXB)); 68 | 69 | function [f, g] = ObjQAPALEQ_QUAD(X) 70 | if objX == 1 71 | AXB = (A'*X*B); %fQAP = sum(dot(X,AXB)); 72 | fQAP = sum(sum(X.*AXB)); 73 | g = AXB + A*X*B'; 74 | elseif objX == 2 75 | X2 = X.^2; 76 | AXB = (A'*X2*B); %fQAP = sum(dot(X2,AXB)); 77 | fQAP = sum(sum(X2.*AXB)); 78 | g = 2*(AXB + (A*X2*B')).*(X); 79 | else 80 | X1 = X.^(objX-1); X2 = X.*X1; 81 | AXB = (A'*X2*B); %fQAP = sum(dot(X2,AXB)); 82 | fQAP = sum(sum(X2.*AXB)); 83 | g = (objX*(AXB + (A*X2*B'))).*(X1); 84 | end 85 | 86 | %Xen = sum(X,2) - n; Xtn = sum(X,1)' - n; %Xsn = sum(sum(X))-n; 87 | Axlmb = X-lmb/mu; Idx = (Axlmb<=0); Axlmb(~Idx) = 0; 88 | 89 | f = fQAP + sum(-lmb(Idx).*X(Idx)+0.5*mu*X(Idx).^2) ... 90 | - 0.5/mu*sum(lmb(~Idx).^2); ... 91 | % - lmb1'*Xen + 0.5*mu*dot(Xen,Xen)... 92 | % - lmb2'*Xtn + 0.5*mu*dot(Xtn,Xtn); ... 93 | % - lmb3*Xsn + 0.5*mu*Xsn^2; 94 | g = g + mu*Axlmb; ... 95 | % -repmat(lmb1,1,n) + mu*repmat(Xen,1,n) ... 96 | % -repmat(lmb2',n,1) + mu*repmat(Xtn',n,1); ... 97 | % -lmb3 + mu*Xsn; 98 | end 99 | 100 | 101 | end 102 | 103 | 104 | -------------------------------------------------------------------------------- /README.m: -------------------------------------------------------------------------------- 1 | % A feasible method for optimization with orthogonality constraints 2 | % 3 | % ------------------------------------------------------------------------- 4 | % 1. Problems and solvers 5 | % 6 | % The package contains codes for the following two problems: 7 | % (1) min F(X), s.t., ||X_i||_2 = 1 8 | % 9 | % Solver: OptManiMulitBallGBB.m 10 | % 11 | % Solver demo: Test_maxcut_demo.m, solving the max-cut problem 12 | % 13 | % The constraints can even be a single sphere: ||X||_F = 1 14 | % 15 | % Solver demo: GPE_SP1d_Func.m, solving the BEC problem 16 | % (the data is not provided). 17 | % 18 | % (2) min F(X), S.t., X'*X = I_k, where X \in R^{n,k} 19 | % 20 | % Solver: OptStiefelGBB.m 21 | % 22 | % Solver demo: test_eig_rand_demo.m, computing leading eigenvalues 23 | % 24 | % 25 | % Applications have been solved by these solvers: 26 | % 27 | % - Homogeneous polynomial optimization problems 28 | % with multiple spherical constraints: 29 | % \max \; \sum_{1\le i\le n_1, 1\le j \le n_2, 1 \le k \le n_3, 30 | % 1\le l \le n_4} a_{ijkl} x_i y_j z_k w_l \; 31 | % s.t., \|x\|_2 = \|y\|_2 = \|z\|_2 = \|w\|_2= 1, 32 | % where A = (a_{ijkl}) is a fourth-order tensor of size 33 | % n\times n \times n\times n. 34 | % 35 | % - Maxcut SDP: \min Tr(CX), s.t., X_{ii}=1, X \succeq 0 36 | % 37 | % - SDP: \min Tr(CX), s.t., Tr(X)=1, X \succeq 0 38 | % 39 | % - Low-Rank Nearest Correlation Estimation: 40 | % \min_{ X \succeq 0} \; \frac{1}{2} \| H \odot (X - C) \|_F^2, 41 | % \; X_{ii} = 1, \; i = 1, \ldots, n, \; rank(X) \le p. 42 | % 43 | % - The Bose–Einstein condensates (BEC) problem 44 | % 45 | % - Linear eigenvalue problems: 46 | % \min Tr(X^{\top}AX), s.t., X^{\top}X =I 47 | % 48 | % - The electronic structure calculation: 49 | % the Kohn-Sham total energy minimization 50 | % the Hartree-Fock total energy minimization 51 | % 52 | % - Quadratic assignment problem 53 | % 54 | % - Harmonic energy minimization 55 | % 56 | % For more general problems and solvers, see: 57 | % Adaptive Regularized Newton Method for Riemannian Optimization 58 | % https://github.com/wenstone/ARNT 59 | % ------------------------------------------------------------------------- 60 | % 2. Reference 61 | % 62 | % (1) Zaiwen Wen and Wotao Yin. A feasible method for optimization with 63 | % orthogonality constraints. Mathematical Programming (2013): 397-434. 64 | % 65 | % (2) Jiang Hu, Andre Milzarek, Zaiwen Wen, Yaxiang Yuan. Adaptive 66 | % Regularized Newton Method for Riemannian Optimization. 67 | % SIAM Journal on Scientific Computing 68 | % 69 | % (3) Zaiwen Wen, Andre Milzarek, Michael Ulbrich and Hongchao Zhang, 70 | % Adaptive regularized self-consistent field iteration with exact 71 | % Hessian for electronic structure calculation. SIAM Journal on 72 | % Scientific Computing (2013), A1299-A1324. 73 | % 74 | % (4) Xinming Wu, Zaiwen Wen, and Weizhu Bao. A regularized Newton method 75 | % for computing ground states of Bose–Einstein condensates. Journal of 76 | % Scientific Computing (2017): 303-329. 77 | % 78 | % (5) X. Zhang, J. Zhu, Z. Wen, A. Zhou, Gradient-type Optimization 79 | % Methods for Electronic Structure Calculation, SIAM Journal on 80 | % Scientific Computing, Vol. 36, No. 3 (2014), pp. C265-C289 81 | % 82 | % (6) R. Lai, Z. Wen, W. Yin, X. Gu, L. Lui, Folding-Free Global Conformal 83 | % Mapping for Genus-0 Surfaces by Harmonic Energy Minimization, 84 | % Journal of Scientfic Computing, 58(2014), 705-725 85 | % 86 | % 87 | % ------------------------------------------------------------------------- 88 | % 3. The Authors 89 | % 90 | % We hope that the package is useful for your application. If you have 91 | % any bug reports or comments, please feel free to email one of the 92 | % toolbox authors: 93 | % 94 | % Zaiwen Wen, wendouble@gmail.com 95 | % Wotao Yin, wotao.yin@gmail.com 96 | % 97 | % Enjoy! 98 | % Zaiwen and Wotao 99 | % 100 | % ------------------------------------------------------------------------- 101 | % Copyright (C) 2018, Zaiwen Wen and Wotao Yin 102 | % Copyright (C) 2010, Zaiwen Wen and Wotao Yin 103 | % 104 | % This program is free software: you can redistribute it and/or modify 105 | % it under the terms of the GNU General Public License as published by 106 | % the Free Software Foundation, either version 3 of the License, or 107 | % (at your option) any later version. 108 | % 109 | % This program is distributed in the hope that it will be useful, 110 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 111 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 112 | % GNU General Public License for more details. 113 | % 114 | % You should have received a copy of the GNU General Public License 115 | % along with this program. If not, see 116 | -------------------------------------------------------------------------------- /TestQAPLIB_orth_fixmu_improve_selected.m: -------------------------------------------------------------------------------- 1 | function TestQAPLIB_orth_fixmu_improve_selected 2 | 3 | 4 | % clc 5 | close all; 6 | % clear all 7 | 8 | 9 | % data file 10 | src = '/Users/wenzw/code/ConvexOpt/SDP/QAPLIB/'; 11 | Probname = { 'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', ... % 1 -- 6 12 | 'bur26g', 'bur26h', 'chr12a', 'chr12b', 'chr12c', 'chr15a', ... % 7 -- 12 13 | 'chr15b', 'chr15c', 'chr18a', 'chr18b', 'chr20a', 'chr20b', ... % 13 -- 18 14 | 'chr20c', 'chr22a', 'chr22b', 'chr25a', 'els19', 'esc128', ... % 19 -- 24 15 | 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... % 25 -- 30 16 | 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', ... % 31 -- 36 17 | 'esc32c', 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'esc64a', ... % 37 -- 42 18 | 'had12', 'had14', 'had16', 'had18', 'had20', 'kra30a', ... % 43 -- 48 19 | 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... % 49 -- 54 20 | 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', 'lipa60a', 'lipa60b', ... % 55 -- 60 21 | 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', 'lipa90a', 'lipa90b', ... % 61 -- 66 22 | 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... % 67 -- 72 23 | 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', ... % 73 -- 78 24 | 'nug27', 'nug28', 'nug30', 'rou12', 'rou15', 'rou20', ... % 79 -- 84 25 | 'scr12', 'scr15', 'scr20', 'sko100a', 'sko100b', 'sko100c', ... % 85 -- 90 26 | 'sko100d', 'sko100e', 'sko100f', 'sko42', 'sko49', 'sko56', ... % 91 -- 96 27 | 'sko64', 'sko72', 'sko81', 'sko90', 'ste36a', 'ste36b', ... % 97 -- 102 28 | 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', ... % 103 -- 108 29 | 'tai12b', 'tai150b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', ... % 109 -- 114 30 | 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', ... % 115 -- 120 31 | 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', 'tai50b', ... % 121 -- 126 32 | 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', ... % 127 -- 132 33 | 'tho30', 'tho40', 'wil100', 'wil50'}; ... % 133 -- 136 34 | 35 | % % problems whose size is <= 40 36 | % Probname = {'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', 'bur26g', 'bur26h', ... % 1-8 37 | % 'chr12a', 'chr12b', 'chr12c', 'chr15a', 'chr15b', 'chr15c', 'chr18a', 'chr18b', ... %9-16 38 | % 'chr20a', 'chr20b', 'chr20c', 'chr22a', 'chr22b', 'chr25a', ... %17-22 39 | % 'els19', 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... %23-29 40 | % 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', 'esc32c', ... %30-36 41 | % 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'had12', 'had14', 'had16', 'had18', .... %37-44 42 | % 'had20', 'kra30a', 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... %45-52 43 | % 'lipa40a', 'lipa40b', 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... %53-60 44 | % 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', 'nug27', 'nug28', 'nug30', ... %61-69 45 | % 'rou12', 'rou15', 'rou20', 'scr12', 'scr15', 'scr20', 'ste36a', 'ste36b', 'ste36c', ... %70-78 46 | % 'tai10a', 'tai10b', 'tai12a', 'tai12b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', 'tai20b', ... %79-87 47 | % 'tai25a', 'tai25b', 'tai30a', 'tai30b', 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tho30', 'tho40'}; %88-97 48 | 49 | nprob = length(Probname); 50 | 51 | 52 | Problist = [1:nprob]; 53 | Problist = [1]; mu = 1e-2; 54 | % Problist = [10]; mu = 1e-2; 55 | 56 | % Problist = [nprob]; 57 | % Problist = [10:22]; 58 | % Problist = [65; 105; 110; 116; 118; 120]; 59 | % Problist = [65]; % mu = 1e2 60 | % Problist = [105]; 61 | % Problist = [118; 120]; 62 | % Problist = [105; 110; 116]; 63 | % Problist = [118; 120; 65; 105; 110]; 64 | % Problist = [1:20]; 65 | % Problist = [1:20]; 66 | % Problist = [1:87]; 67 | 68 | nrand = 12; % number of random trials 69 | 70 | objX = 2; 71 | suffix = 'QQ1'; 72 | perf = cell(nprob*nrand,3); 73 | savename = strcat('results/fix_res_qap_X',num2str(objX), suffix); 74 | 75 | % objX = 2; 76 | % suffix = 'SL_test'; 77 | % perf = cell(nprob*nrand); 78 | % savename = strcat('results/fix_res_qap_X',num2str(objX), suffix); 79 | 80 | dp = 1; 81 | for di = 1:length(Problist) 82 | name = Probname{Problist(di)}; 83 | load(strcat(src, name, '.mat'), 'n','A','B','obj'); 84 | 85 | for dmu = 1:nrand 86 | seed = randi(1e8); rand('state',seed); randn('state',seed); 87 | % seed = 92395570; rand('state',seed); randn('state',seed); 88 | % seed = 43613214; rand('state',seed); randn('state',seed); 89 | % seed = 2010; rand('state',seed); randn('state',seed); 90 | X0 = randn(n); X0 = orth(X0); 91 | 92 | if dmu <= nrand/3; mu = 1; elseif dmu <= 2*nrand/3; mu = 1e1; else mu = 1e-1; end 93 | 94 | %if dmu <= nrand/3; mu = 1; elseif dmu <= 2*nrand/3; mu = 1e1; else mu = 1e2; end 95 | 96 | %if dmu <= nrand/3; mu = 1; elseif dmu <= 2*nrand/3; mu = 1e1; else mu = 1e2; end 97 | 98 | % if dmu <= nrand/6; mu = 1e-1; 99 | % elseif dmu <= 2*nrand/6; mu = 1; 100 | % elseif dmu <= 3*nrand/6; mu = 1e-2; 101 | % elseif dmu <= 4*nrand/6; mu = 1e1; 102 | % elseif dmu <= 5*nrand/6; mu = 1e2; 103 | % else mu = 1e3; end 104 | 105 | % if dmu <= nrand/4; mu = 1e1; 106 | % elseif dmu <= 2*nrand/4; mu = 1; 107 | % elseif dmu <= 3*nrand/4; mu = 1e-1; 108 | % else mu = 1e2; end 109 | 110 | %if dmu <= nrand/3; mu = 1e-1; elseif dmu <= 2*nrand/3; mu = 1e-2; else mu = 1e-3; end 111 | %if dmu <= nrand/3; mu = 1e-4; elseif dmu <= 2*nrand/3; mu = 1e-5; else mu = 1e-6; end 112 | %mu = 1e6; 113 | 114 | %%----------------------------------------------------------------------- 115 | opts.record = 0; 116 | 117 | opts.tol = 1e-3; 118 | opts.tolsub = 1e-3; 119 | opts.omxitr = 100; 120 | 121 | opts.mxitr = 100; 122 | opts.xtol = 1e-5; 123 | opts.gtol = 1e-5; 124 | opts.ftol = 1e-8; 125 | opts.tau = 1e-3; 126 | 127 | opts.objX = objX; 128 | 129 | %mu = 1e-2; 130 | % profile on; 131 | %tic; [X, out] = QAPORTHAL(X0, A, B, mu, opts); tsolve = toc; 132 | %tic; [X, out] = QAPORTHALEQ(X0, A, B, mu, opts); tsolve = toc; 133 | tic; [X, out] = QAPORTHALEQQ_QUAD(X0, A, B, mu, opts); tsolve = toc; 134 | 135 | %tic; [X, out]= OptStiefelGBB_V2010_8_20(X0, @qapAB, opts, A, B); tsolve = toc; 136 | 137 | %mu = 0.1; 138 | %tic; [X, out]= OptStiefelGBB(X0, @qapAB_log, opts, A,B,mu); tsolve = toc; 139 | 140 | % profile viewer; 141 | 142 | X = round(X); 143 | objf = qapAB(X,A,B); 144 | fgap = (abs(objf-obj)/obj)*100; 145 | if obj==0; fgap = (abs(objf-obj)/max(1,objf))*100; end 146 | feasi1 = norm(X'*X - eye(n), 'fro'); 147 | feasi2 = norm(sum(X,1)-1)+norm(sum(X,2)-1); 148 | 149 | fprintf('%3d, sd: %10d, %8s, n: %4d, mu: %3.2e, opt: %10d, fobj: %10d, fgap: %6.3f, cpu: %7.2f, itr: %3d, nfe: %3d, feasi: %2.1e\n', ... 150 | dmu, seed, name, n, mu, obj, objf, fgap, tsolve, out.itr, out.nfe, feasi1+feasi2 ); 151 | 152 | perf{dp,1} = name; 153 | %if max(feasi1,feasi2)<1e-3; perf{dp,2} = sparse(X); end 154 | perf{dp,3} = [seed, n, mu, obj, objf, fgap, tsolve, out.itr, out.nfe, feasi1, feasi2]; 155 | dp = dp + 1; 156 | 157 | if (fgap <= 0.001 || (objf>0 && objf < obj ) ) && objf >= 0 && feasi1+feasi2 <= 1e-7; break; end 158 | end 159 | fprintf('\n\n'); 160 | save(savename, 'perf', 'Problist', 'Probname'); 161 | end 162 | 163 | -------------------------------------------------------------------------------- /Test_maxcut_demo.m: -------------------------------------------------------------------------------- 1 | function Test_maxcut_demo 2 | 3 | %------------------------------------------------------------- 4 | % maxcut SDP: 5 | % X is n by n matrix 6 | % max Tr(C*X), s.t., X_ii = 1, X psd 7 | % 8 | % low rank model: 9 | % X = V'*V, V = [V_1, ..., V_n], V is a p by n matrix 10 | % max Tr(C*V'*V), s.t., ||V_i|| = 1, 11 | % 12 | % ------------------------------------- 13 | % 14 | % Reference: 15 | % Z. Wen and W. Yin 16 | % A feasible method for optimization with orthogonality constraints 17 | % 18 | % Author: Zaiwen Wen 19 | % Version 1.0 .... 2010/10 20 | % Version 0.5 .... 2013/10 21 | %------------------------------------------------------------- 22 | 23 | % clc 24 | clear all 25 | 26 | % seed = 2010; 27 | % fprintf('seed: %d\n', seed); 28 | % if exist('RandStream','file') 29 | % RandStream.setDefaultStream(RandStream('mt19937ar','seed',seed)); 30 | % else 31 | % rand('state',seed); randn('state',seed^2); 32 | % end 33 | 34 | % change the path here 35 | src = [fileparts(mfilename('fullpath')) '/data/Maxcut/']; 36 | 37 | % Probname = {'torusg3-8', 'torusg3-15', 'toruspm3-8-50', 'toruspm3-15-50' }; 38 | Probname = { 'torusg3-82', 'torusg3-152', 'toruspm3-8-50', 'toruspm3-15-50', 'G22', 'G23'}; 39 | nprob = length(Probname); 40 | 41 | % Problist = [1:nprob]; 42 | % Problist = [21:40]; 43 | % Problist = [31]; 44 | Problist = [1]; 45 | nlen = length(Problist); 46 | 47 | perf = zeros(nprob, 14); 48 | 49 | for dprob = Problist; 50 | %clear n m C 51 | name = Probname{dprob}; 52 | file = strcat(src,name,'.mat'); 53 | load(file,'n','m','C'); 54 | 55 | % modify the estimation of rank here 56 | p = max(min(round(sqrt(2*n)/2), 20),1); 57 | 58 | % initial point should be normalized 59 | x0 = randn(p,n); nrmx0 = dot(x0,x0,1); 60 | x0 = bsxfun(@rdivide, x0, sqrt(nrmx0)); 61 | 62 | % profile on 63 | opts.record = 1; 64 | opts.mxitr = 600; 65 | opts.maxit = 600; 66 | opts.gtol = 1e-5; 67 | opts.xtol = 1e-5; 68 | %opts.ftol = 1e-10; 69 | opts.tau = 1e-3; 70 | tic; [x, g, out]= OptManiMulitBallGBB(x0, @maxcut_quad, opts, C); tsolve = toc; 71 | %XSDP = x'*x; % 72 | objf2 = -full(out.fval); 73 | fprintf('name %10s, n %d, p %d, f %6.4e, cpu %4.2f, itr %d, #func eval %d, feasi %3.2e, ||Hx|| %3.2e\n',... 74 | name, n, p, objf2, tsolve, out.iter, out.nfe, out.feasi, out.nrmG); 75 | perf(dprob, 7:14) = [n, p, objf2, tsolve, out.iter, out.nfe, out.feasi, out.nrmG]; 76 | 77 | 78 | 79 | end 80 | 81 | % save('res_maxcut_GLarge_Graph_quad_it600', 'perf'); 82 | % save('res_maxcut_torus_Graph_quad_it600', 'perf'); 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /check_QAP_solu.m: -------------------------------------------------------------------------------- 1 | function check_QAP_solu 2 | 3 | src = '/home/wenzw/code/ConvexOpt/SDP/QAPLIB/'; 4 | Probname = { 'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', ... % 1 -- 6 5 | 'bur26g', 'bur26h', 'chr12a', 'chr12b', 'chr12c', 'chr15a', ... % 7 -- 12 6 | 'chr15b', 'chr15c', 'chr18a', 'chr18b', 'chr20a', 'chr20b', ... % 13 -- 18 7 | 'chr20c', 'chr22a', 'chr22b', 'chr25a', 'els19', 'esc128', ... % 19 -- 24 8 | 'esc16a', 'esc16b', 'esc16c', 'esc16d', 'esc16e', 'esc16f', ... % 25 -- 30 9 | 'esc16g', 'esc16h', 'esc16i', 'esc16j', 'esc32a', 'esc32b', ... % 31 -- 36 10 | 'esc32c', 'esc32d', 'esc32e', 'esc32g', 'esc32h', 'esc64a', ... % 37 -- 42 11 | 'had12', 'had14', 'had16', 'had18', 'had20', 'kra30a', ... % 43 -- 48 12 | 'kra30b', 'kra32', 'lipa20a', 'lipa20b', 'lipa30a', 'lipa30b', ... % 49 -- 54 13 | 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', 'lipa60a', 'lipa60b', ... % 55 -- 60 14 | 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', 'lipa90a', 'lipa90b', ... % 61 -- 66 15 | 'nug12', 'nug14', 'nug15', 'nug16a', 'nug16b', 'nug17', ... % 67 -- 72 16 | 'nug18', 'nug20', 'nug21', 'nug22', 'nug24', 'nug25', ... % 73 -- 78 17 | 'nug27', 'nug28', 'nug30', 'rou12', 'rou15', 'rou20', ... % 79 -- 84 18 | 'scr12', 'scr15', 'scr20', 'sko100a', 'sko100b', 'sko100c', ... % 85 -- 90 19 | 'sko100d', 'sko100e', 'sko100f', 'sko42', 'sko49', 'sko56', ... % 91 -- 96 20 | 'sko64', 'sko72', 'sko81', 'sko90', 'ste36a', 'ste36b', ... % 97 -- 102 21 | 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', ... % 103 -- 108 22 | 'tai12b', 'tai150b', 'tai15a', 'tai15b', 'tai17a', 'tai20a', ... % 109 -- 114 23 | 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', ... % 115 -- 120 24 | 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', 'tai50b', ... % 121 -- 126 25 | 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', ... % 127 -- 132 26 | 'tho30', 'tho40', 'wil100', 'wil50'}; ... % 133 -- 136 27 | 28 | 29 | di = 1; 30 | perm = [26 15 11 7 4 12 13 2 6 18 1 5 9 21 8 14 3 20 19 25 17 10 16 24 23 22]; 31 | 32 | di = 2; 33 | perm = [17 11 26 7 4 14 6 22 23 18 5 9 1 21 8 12 3 19 20 15 10 25 24 16 13 2]; 34 | 35 | name = Probname{di}; 36 | load(strcat(src, name, '.mat'), 'n','A','B','obj'); 37 | 38 | % norm(A-A','fro') 39 | % norm(B-B','fro') 40 | 41 | % return 42 | X = zeros(n); 43 | for di = 1:n 44 | X(di,perm(di)) = 1; 45 | end 46 | 47 | [row, col, v] = find(X'); row'-perm 48 | 49 | norm(X'*X - eye(n)) 50 | trace(A'*X*B*X') 51 | trace(X'*A'*X*B) 52 | % trace(A*X*B*X') 53 | f = 0; 54 | for di = 1:n 55 | for dj = 1:n 56 | f = f + A(di,dj)*B(perm(di),perm(dj)); 57 | end 58 | end 59 | f 60 | 61 | -------------------------------------------------------------------------------- /data/Maxcut/torusg3-82.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optsuite/OptM/f2da8978e92f094e997775fc61f4e49d0742b0a1/data/Maxcut/torusg3-82.mat -------------------------------------------------------------------------------- /data/Maxcut/toruspm3-8-50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/optsuite/OptM/f2da8978e92f094e997775fc61f4e49d0742b0a1/data/Maxcut/toruspm3-8-50.mat -------------------------------------------------------------------------------- /maxcut_quad.m: -------------------------------------------------------------------------------- 1 | function [f, g] = maxcut_quad(V, C) 2 | % maxcut SDP: 3 | % X is n by n matrix 4 | % max Tr(C*X), s.t., X_ii = 1, X psd 5 | % 6 | % low rank model: 7 | % X = V'*V, V = [V_1, ..., V_n], V is a p by n matrix 8 | % max Tr(C*V'*V), s.t., ||V_i|| = 1, 9 | % 10 | % X = V'*V; 11 | % f = sum(sum(C.*X)); 12 | % if nargout >= 2 13 | % g = V*C; 14 | % end 15 | % ------------------------------------- 16 | % 17 | % Reference: 18 | % Z. Wen and W. Yin 19 | % A feasible method for optimization with orthogonality constraints 20 | % 21 | % Author: Zaiwen Wen 22 | % Version 0.1 .... 2010/10 23 | % Version 0.5 .... 2013/10 24 | 25 | % g = V*C; 26 | % f = sum(dot(g,V)); 27 | 28 | g = 2*(V*C); 29 | f = sum(dot(g,V))/2; 30 | 31 | -------------------------------------------------------------------------------- /maxcut_quad_g.m: -------------------------------------------------------------------------------- 1 | function g = maxcut_quad_g(V, C) 2 | % maxcut SDP: 3 | % X is n by n matrix 4 | % max Tr(C*X), s.t., X_ii = 1, X psd 5 | % 6 | % low rank model: 7 | % X = V'*V, V = [V_1, ..., V_n], V is a p by n matrix 8 | % max Tr(C*V'*V), s.t., ||V_i|| = 1, 9 | % 10 | % X = V'*V; 11 | % f = sum(sum(C.*X)); 12 | % if nargout >= 2 13 | % g = V*C; 14 | % end 15 | % ------------------------------------- 16 | % 17 | % Reference: 18 | % Z. Wen and W. Yin 19 | % A feasible method for optimization with orthogonality constraints 20 | % 21 | % Author: Zaiwen Wen 22 | % Version 0.1 .... 2010/10 23 | % Version 0.5 .... 2013/10 24 | 25 | % g = V*C; 26 | % f = sum(dot(g,V)); 27 | 28 | g = 2*(V*C); 29 | 30 | -------------------------------------------------------------------------------- /print_qap_probname.m: -------------------------------------------------------------------------------- 1 | function print_qap_probname 2 | 3 | Probname = {'bur26a', 'bur26b', 'bur26c', 'bur26d', 'bur26e', 'bur26f', 'bur26g', 'bur26h', ... %1- 8 4 | 'chr12a', 'chr12b', 'chr12c', 'chr15a', 'chr15b', 'chr15c', 'chr18a', 'chr18b', ... % 9-16 5 | 'chr20a', 'chr20b', 'chr20c', 'chr22a', 'chr22b', 'chr25a', ... %17-22 6 | 'els19', 'esc128', 'esc16a', 'esc16b', 'esc16c', 'esc16d', ... % 23-28 7 | 'esc16e', 'esc16f', 'esc16g', 'esc16h', 'esc16i', 'esc16j', ... %29-34 8 | 'esc32a', 'esc32b', 'esc32c', 'esc32d', 'esc32e', 'esc32g', ... %35-40 9 | 'esc32h', 'esc64a', 'had12', 'had14', 'had16', 'had18', ... %41-46 10 | 'had20', 'kra30a', 'kra30b', 'kra32', 'lipa20a', 'lipa20b', ... %47-52 11 | 'lipa30a', 'lipa30b', 'lipa40a', 'lipa40b', 'lipa50a', 'lipa50b', ... %53-58 12 | 'lipa60a', 'lipa60b', 'lipa70a', 'lipa70b', 'lipa80a', 'lipa80b', ... %59-64 13 | 'lipa90a', 'lipa90b', 'nug12', 'nug14', 'nug15', 'nug16a', ... %65-70 14 | 'nug16b', 'nug17', 'nug18', 'nug20', 'nug21', 'nug22', ... %71-76 15 | 'nug24', 'nug25', 'nug27', 'nug28', 'nug30', 'rou12', ... %77 -82 16 | 'rou15', 'rou20', 'scr12', 'scr15', 'scr20', 'sko100a', ... %83-88 17 | 'sko100b', 'sko100c', 'sko100d', 'sko100e', 'sko100f', 'sko42', ... %89-94 18 | 'sko49', 'sko56', 'sko64', 'sko72', 'sko81', 'sko90', 'ste36a', 'ste36b', 'ste36c', 'tai100a', 'tai100b', 'tai10a', 'tai10b', 'tai12a', 'tai12b', 'tai150b', 'tai15a', ... 19 | 'tai15b', 'tai17a', 'tai20a', 'tai20b', 'tai256c', 'tai25a', 'tai25b', 'tai30a', 'tai30b', 'tai35a', 'tai35b', 'tai40a', 'tai40b', 'tai50a', ... 20 | 'tai50b', 'tai60a', 'tai60b', 'tai64c', 'tai80a', 'tai80b', 'tho150', 'tho30', 'tho40', 'wil100', 'wil50'}; % 21 | 22 | Probname = {'brock200_1', 'brock200_2', 'brock200_3', 'brock200_4', 'brock400_1', 'brock400_2', 'brock400_3', 'brock400_4', 'brock800_1', 'brock800_2', 'brock800_3', 'brock800_4', 'c-fat200-1', 'c-fat200-2', 'c-fat200-5', 'c-fat500-10', 'c-fat500-1', 'c-fat500-2', 'c-fat500-5', 'hamming10-2', 'hamming10-4', 'hamming6-2', 'hamming6-4', 'hamming8-2', 'hamming8-4', 'johnson16-2-4', 'johnson32-2-4', 'johnson8-2-4', 'johnson8-4-4', 'keller4', 'keller5', 'keller6', 'MANN_a27', 'MANN_a45', 'MANN_a81', 'MANN_a9', 'p_hat1000-1', 'p_hat1000-2', 'p_hat1000-3', 'p_hat1500-1', 'p_hat1500-2', 'p_hat1500-3', 'p_hat300-1', 'p_hat300-2', 'p_hat300-3', 'p_hat500-1', 'p_hat500-2', 'p_hat500-3', 'p_hat700-1', 'p_hat700-2', 'p_hat700-3', 'san1000', 'san200_0.7_1', 'san200_0.7_2', 'san200_0.9_1', 'san200_0.9_2', 'san200_0.9_3', 'san400_0.5_1', 'san400_0.7_1', 'san400_0.7_2', 'san400_0.7_3', 'san400_0.9_1', 'sanr200_0.7', 'sanr200_0.9', 'sanr400_0.5', 'sanr400_0.7'}; 23 | 24 | Probname = { 'MANN_a9', 'MANN_a27', 'MANN_a45', 'MANN_a81', ... 25 | 'brock200_1', 'brock200_2', 'brock200_3', 'brock200_4', 'brock400_1', 'brock400_2', ... % 1 -- 6 26 | 'brock400_3', 'brock400_4', 'brock800_1', 'brock800_2', 'brock800_3', 'brock800_4', ... % 7 -- 12 27 | 'c-fat200-1', 'c-fat200-2', 'c-fat200-5', 'c-fat500-1', 'c-fat500-2', 'c-fat500-5', 'c-fat500-10', ... % 13 -- 18 28 | 'hamming6-2', 'hamming6-4', 'hamming8-2', ... % 19 -- 24 29 | 'hamming8-4','hamming10-2', 'hamming10-4', 'johnson8-2-4', 'johnson8-4-4', 'johnson16-2-4', 'johnson32-2-4', 'keller4', ... % 25 -- 30 30 | 'keller5', 'keller6', ... % 31 -- 36 31 | 'p_hat300-1', 'p_hat300-2', 'p_hat300-3', 'p_hat500-1', 'p_hat500-2', 'p_hat500-3', ... % 43 -- 48 32 | 'p_hat700-1', 'p_hat700-2', 'p_hat700-3', ... 33 | 'p_hat1000-1', 'p_hat1000-2', 'p_hat1000-3', 'p_hat1500-1', 'p_hat1500-2', 'p_hat1500-3', ... % 37 -- 42 34 | 'san200_0.7_1', 'san200_0.7_2', 'san200_0.9_1', 'san200_0.9_2', 'san200_0.9_3', 'san400_0.5_1', 'san400_0.7_1', 'san400_0.7_2', ... % 55 -- 60 35 | 'san400_0.7_3', 'san400_0.9_1', 'san1000', 'sanr200_0.7', 'sanr200_0.9', 'sanr400_0.5', 'sanr400_0.7' }; ... % 61 -- 66 36 | 37 | 38 | % Probname ={'theta4', 'theta42', 'theta6', 'theta62', 'theta8', 'theta82', 'theta83', 'theta10', 'theta102',... %1- 9 39 | % 'theta103', 'theta104', 'theta12', 'theta123','theta32', ... %10-14 40 | % 'MANN-a27', 'johnson8-4-4', 'johnson16-2-4', 'san200-0.7-1', 'sanr200-0.7', 'c-fat200-1', ... %15-20 41 | % 'hamming-6-4', 'hamming-7-5-6', 'hamming-8-3-4', 'hamming-8-4', ... %21-24 42 | % 'hamming-9-5-6', 'hamming-9-8', 'hamming-10-2', 'brock200-1', 'brock200-4', 'brock400-1', ... %25-30 43 | % 'keller4', 'p-hat300-1', 'G43', 'G44', 'G45', 'G46', 'G47', 'G51', 'G52', 'G53', 'G54', ... %31-41 44 | % '1dc.64', '1et.64', '1tc.64', ... % 1-3 45 | % '1dc.128', '1et.128', '1tc.128', '1zc.128', '2dc.128', ... % 4-8 46 | % '1dc.256', '1et.256', '1tc.256', '1zc.256', '2dc.256', ... % 9-13 47 | % '1dc.512', '1et.512', '1tc.512', '1zc.512', '2dc.512', ... % 14-18 48 | % '1dc.1024', '1et.1024', '1tc.1024', '1zc.1024', '2dc.1024', ... %19-23 49 | % '1dc.2048', '1et.2048', '1tc.2048', '1zc.2048', '2dc.2048'}; %24-28 50 | 51 | Probname = {'DSJC1000-1','DSJC1000-5','DSJC1000-9','DSJC125-1','DSJC125-5','DSJC125-9','DSJC250-1','DSJC250-5','DSJC250-9','DSJC500-1','DSJC500-5','DSJC500-9','DSJR500-1c','DSJR500-1','DSJR500-5','flat1000-50-0','flat1000-60-0','flat1000-76-0','flat300-20-0','flat300-26-0','flat300-28-0','fpsol2-i-1','fpsol2-i-2','fpsol2-i-3','inithx-i-1','inithx-i-2','inithx-i-3','latin-square-10','le450-15a','le450-15b','le450-15c','le450-15d','le450-25a','le450-25b','le450-25c','le450-25d','le450-5a','le450-5b','le450-5c','le450-5d','mulsol-i-1','mulsol-i-2','mulsol-i-3','mulsol-i-4','mulsol-i-5','school1','school1-nsh','zeroin-i-1','zeroin-i-2','zeroin-i-3'}; 52 | 53 | Probname = {'band_n200_m100_w0'; 'band_n200_m100_w1'; 'band_n200_m100_w2'; 'band_n200_m100_w4'; 'band_n200_m100_w8'; 'band_n200_m100_w16'; 'band_n200_m100_w32'; 'band_n100_m100_w5'; 'band_n200_m100_w5'; 'band_n400_m100_w5'; 'band_n800_m100_w5'; 'band_n1600_m100_w5'; 'band_n500_m10_w3'; 'band_n500_m50_w3'; 'band_n500_m100_w3'; 'band_n500_m200_w3'; 'band_n500_m400_w3'; 'band_n500_m800_w3'; 'mtxnorm_p90_q10_r100'; 'mtxnorm_p190_q10_r100'; 'mtxnorm_p390_q10_r100'; 'mtxnorm_p790_q10_r100'; 'mtxnorm_p1590_q10_r100'; 'mtxnorm_p400_q10_r200_d1'; 'mtxnorm_p400_q10_r200_d5'; 'mtxnorm_p400_q10_r200_d10'; 'mtxnorm_p400_q10_r200_d20'; 'mtxnorm_p400_q10_r200_d50'; 'mtxnorm_p400_q10_r200_d100'; 'mtxnorm_p400_q10_r200_d250'; 'mtxnorm_p400_q10_r200_d500'; 'mtxnorm_p400_q10_r50'; 'mtxnorm_p400_q10_r100'; 'mtxnorm_p400_q10_r200'; 'mtxnorm_p400_q10_r400'; 'mtxnorm_p400_q10_r800'; 'mtxnorm_p999_q1_r10'; 'mtxnorm_p998_q2_r10'; 'mtxnorm_p995_q5_r10'; 'mtxnorm_p990_q10_r10'; 'mtxnorm_p980_q20_r10'; 'mtxnorm_p950_q50_r10'; 'cliqueoverlap_N16_u0_m100'; 'cliqueoverlap_N16_u1_m100'; 'cliqueoverlap_N16_u2_m100'; 'cliqueoverlap_N16_u4_m100'; 'cliqueoverlap_N16_u8_m100'; 'cliqueoverlap_N16_u15_m100'; 'rs35'; 'rs200'; 'rs228'; 'rs365'; 'rs828'; 'rs1184'; 'rs1288'; 'rs1555'; 'rs1907'}; 54 | 55 | Probname ={'DSJC1000.1', 'DSJC1000.5', 'DSJC1000.9', 'DSJC125.1', 'DSJC125.5', 'DSJC125.9', 'DSJC250.1', 'DSJC250.5', 'DSJC250.9', 'DSJC500.1', 'DSJC500.5', 'DSJC500.9', 'DSJR500.1c', 'DSJR500.1', 'DSJR500.5', 'flat1000_50_0', 'flat1000_60_0', 'flat1000_76_0', 'flat300_20_0', 'flat300_26_0', 'flat300_28_0', 'fpsol2.i.1', 'fpsol2.i.2', 'fpsol2.i.3', 'inithx.i.1', 'inithx.i.2', 'inithx.i.3', 'latin_square_10', 'le450_15a', 'le450_15b', 'le450_15c', 'le450_15d', 'le450_25a', 'le450_25b', 'le450_25c', 'le450_25d', 'le450_5a', 'le450_5b', 'le450_5c', 'le450_5d', 'mulsol.i.1', 'mulsol.i.2', 'mulsol.i.3', 'mulsol.i.4', 'mulsol.i.5', 'school1', 'school1_nsh', 'zeroin.i.1', 'zeroin.i.2', 'zeroin.i.3', 'anna', 'david', 'homer', 'huck', 'jean', 'games120', 'miles1000', 'miles1500', 'miles250', 'miles500', 'miles750', 'queen10_10', 'queen11_11', 'queen12_12', 'queen13_13', 'queen14_14', 'queen15_15', 'queen16_16', 'queen5_5', 'queen6_6', 'queen7_7', 'queen8_12', 'queen8_8', 'queen9_9', 'myciel3', 'myciel4', 'myciel5', 'myciel6', 'myciel7'}; 56 | 57 | Probname ={'Andrews', 'apache1', 'bundle1', 'C60', 'c_65', 'cbuckle', 'cfd1', 'copter1', 'ct20stif', 'F2', 'finan512', 'Ga10As10H30', 'Ga19As19H42', 'Ga3As3H12', 'GaAsH6', 'msc23052', 'nd12k', 'obstclae', 'OPF_3754', 'shallow_water1', 'Si10H16', 'Si34H36', 'Si5H12', 'SiH4', 'SiO', 'torsion1', 'vanbody', 'wathen100'}; 58 | 59 | np = 4; pp = 1; 60 | nlen = length(Probname); 61 | for di = 1:nlen 62 | name = Probname{di}; 63 | fprintf(' ''%s'', ', name); 64 | %fprintf(' ''%s'', ',strrep(strrep(name,'.','-'),'_','-')); 65 | if mod(di, np) == 0 || di == nlen 66 | fprintf(' ... %% %d -- %d\n', pp, di); 67 | pp = pp + np; 68 | end 69 | 70 | end 71 | -------------------------------------------------------------------------------- /qapAB.m: -------------------------------------------------------------------------------- 1 | function [f, g] = qapAB(X,A,B) 2 | % f = trace(A'*X*B*X') 3 | AXB = (A'*X*B); 4 | g = AXB + A*X*B'; 5 | % f = sum(dot(X,AXB)); 6 | % f = trace(X*AXB); 7 | f = sum(sum(X.*AXB)); 8 | 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # OptM beta 1.0 2 | A feasible method for optimization with orthogonality constraints 3 | 4 | # Problems and solvers 5 | The package contains codes for the following three problems: 6 | 7 | - $\min F(X), s.t., ||X_i||_2 = 1$ 8 | 9 | Solver: OptManiMulitBallGBB.m 10 | Solver demo: Test_maxcut_demo.m, solving the max-cut problem 11 | 12 | 13 | 14 | The constraints can even be a single sphere: $||X||_F = 1$ 15 | 16 | Solver demo: GPE_SP1d_Func.m, solving the BEC problem (the data is not provided). 17 | 18 | - $\min F(X), S.t., X^{\top} X = I_k$, where $X \in R^{n,k}$ 19 | 20 | Solver: OptStiefelGBB.m 21 | Solver demo: test_eig_rand_demo.m, computing leading eigenvalues 22 | 23 | QAP: TestQAPLIB_orth_fixmu_improve_selected.m. To run the code, first download qaplib from (https://www.opt.math.tugraz.at/qaplib/), then run GenQAPLIB.m to generate the data matrices in the matlab format. 24 | 25 | Applications have been solved by these solvers: 26 | 27 | - Homogeneous polynomial optimization problems with multiple spherical constraints: 28 | $$\max \; \sum_{1\le i\le n_1, 1\le j \le n_2, 1 \le k \le n_3, 1\le l \le n_4} a_{ijkl} x_i y_j z_k w_l \; s.t., \|x\|_2 = \|y\|_2 = \|z\|_2 = \|w\|_2= 1,$$ 29 | where $A = (a_{ijkl})$ is a fourth-order tensor of size $n\times n \times n\times n$. 30 | - Maxcut SDP: $\min \mathrm{Tr}(CX), s.t., X_{ii}=1, X \succeq 0$ 31 | - SDP: $\min \mathrm{Tr}(CX), s.t., \mathrm{Tr}(X)=1, X \succeq 0 $ 32 | - Low-Rank Nearest Correlation Estimation: $ \min_{ X \succeq 0} \; \frac{1}{2} \| H \odot (X - C) \|_F^2, \; X_{ii} = 1, \; i = 1, \ldots, n, \; \mathrm{rank}(X) \le p.$ 33 | - The Bose–Einstein condensates (BEC) problem 34 | - Linear eigenvalue problems: $\min \mathrm{Tr}(X^{\top}AX), s.t., X^{\top}X =I $ 35 | - The electronic structure calculation: the Kohn-Sham total energy minimization and the Hartree-Fock total energy minimization 36 | - Quadratic assignment problem 37 | - Harmonic energy minimization 38 | 39 | 40 | For more general problems and solvers, see: 41 | Adaptive Regularized Newton Method for Riemannian Optimization 42 | https://github.com/wenstone/ARNT 43 | 44 | 45 | # References 46 | - [Zaiwen Wen and Wotao Yin. A feasible method for optimization with orthogonality constraints. Mathematical Programming (2013): 397-434.](https://link.springer.com/article/10.1007/s10107-012-0584-1) 47 | 48 | - [Jiang Hu, Andre Milzarek, Zaiwen Wen, Yaxiang Yuan. Adaptive Regularized Newton Method for Riemannian Optimization. SIAM Journal on Scientific Computing](https://arxiv.org/abs/1708.02016) 49 | 50 | - [Zaiwen Wen, Andre Milzarek, Michael Ulbrich and Hongchao Zhang, Adaptive regularized self-consistent field iteration with exact Hessian for electronic structure calculation. SIAM Journal on Scientific Computing (2013), A1299-A1324.](https://doi.org/10.1137/120894385) 51 | 52 | - [Xinming Wu, Zaiwen Wen, and Weizhu Bao. A regularized Newton method for computing ground states of Bose–Einstein condensates. Journal of Scientific Computing (2017): 303-329.](https://link.springer.com/article/10.1007/s10915-017-0412-0) 53 | 54 | - X. Zhang, J. Zhu, Z. Wen, A. Zhou, Gradient-type Optimization Methods for Electronic Structure Calculation, SIAM Journal on Scientific Computing, Vol. 36, No. 3 (2014), pp. C265-C289 55 | 56 | - R. Lai, Z. Wen, W. Yin, X. Gu, L. Lui, Folding-Free Global Conformal Mapping for Genus-0 Surfaces by Harmonic Energy Minimization, Journal of Scientfic Computing, 58(2014), 705-725 57 | 58 | 59 | # The Authors 60 | We hope that the package is useful for your application. If you have any bug reports or comments, please feel free to email one of the toolbox authors: 61 | 62 | * Zaiwen Wen, wendouble@gmail.com 63 | * Wotao Yin, wotao.yin@gmail.com 64 | 65 | 66 | 67 | # Copyright 68 | ------------------------------------------------------------------------- 69 | Copyright (C) 2018, Zaiwen Wen and Wotao Yin 70 | Copyright (C) 2010, Zaiwen Wen and Wotao Yin 71 | 72 | This program is free software: you can redistribute it and/or modify 73 | it under the terms of the GNU General Public License as published by 74 | the Free Software Foundation, either version 3 of the License, or 75 | (at your option) any later version. 76 | 77 | This program is distributed in the hope that it will be useful, 78 | but WITHOUT ANY WARRANTY; without even the implied warranty of 79 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 80 | GNU General Public License for more details. 81 | 82 | You should have received a copy of the GNU General Public License 83 | along with this program. If not, see 84 | 85 | -------------------------------------------------------------------------------- /test_eig_rand_demo.m: -------------------------------------------------------------------------------- 1 | function test_eig_rand_demo 2 | 3 | %------------------------------------------------------------- 4 | % A demo of solving 5 | % min f(X), s.t., X'*X = I, where X is an n-by-p matrix 6 | % 7 | % This demo solves the eigenvalue problem by letting 8 | % f(X) = -0.5*Tr(X'*A*X); 9 | % 10 | % The result is compared to the MATLAB function "eigs", 11 | % which call ARPACK (FORTRAN) to find leading eigenvalues. 12 | % 13 | % Our solver can be faster when n is large and p is small 14 | % 15 | % The advantage of our solver is not obvious in this demo 16 | % since our solver is a general MATLAB code while ARPACK implemented 17 | % many tricks for computing the eigenvalues. 18 | % ------------------------------------- 19 | % 20 | % Reference: 21 | % Z. Wen and W. Yin 22 | % A feasible method for optimization with orthogonality constraints 23 | % 24 | % Author: Zaiwen Wen 25 | % Version 0.1 .... 2010/10 26 | % Version 0.5 .... 2013/10 27 | %------------------------------------------------------------- 28 | 29 | clc 30 | 31 | % seed = 2010; 32 | % fprintf('seed: %d\n', seed); 33 | % if exist('RandStream','file') 34 | % RandStream.setDefaultStream(RandStream('mt19937ar','seed',seed)); 35 | % else 36 | % rand('state',seed); randn('state',seed^2); 37 | % end 38 | 39 | % nlist = [500, 1000, 2000, 3000, 4000, 5000]; 40 | nlist = [1000]; 41 | nlen = length(nlist); 42 | 43 | perf = zeros(10,nlen); 44 | 45 | for dn = 1:nlen 46 | n = nlist(dn); 47 | fprintf('matrix size: %d\n', nlist(dn)); 48 | 49 | A = randn(n); A = A'*A; 50 | k = 6; 51 | opteig.issym = 1; 52 | nAx = 0; 53 | 54 | % --- MATLAB eigs --- 55 | tic; [V, D] = eigs(@funAX, n, k, 'la',opteig); teig = toc; D = diag(D); feig = sum(D(1:k)); 56 | 57 | fprintf('\neigs: obj val %7.6e, cpu %f, #func eval %d\n', feig, teig, nAx); 58 | feasi = norm(V'*V - eye(k), 'fro'); 59 | 60 | % --- our solver --- 61 | % X0 = eye(n,k); 62 | X0 = randn(n,k); X0 = orth(X0); 63 | 64 | opts.record = 0; 65 | opts.mxitr = 1000; 66 | opts.xtol = 1e-5; 67 | opts.gtol = 1e-5; 68 | opts.ftol = 1e-8; 69 | out.tau = 1e-3; 70 | %opts.nt = 1; 71 | 72 | %profile on; 73 | tic; [X, out]= OptStiefelGBB(X0, @funeigsym, opts, A); tsolve = toc; 74 | %profile viewer; 75 | 76 | % profile viewer; 77 | out.fval = -2*out.fval; 78 | err = (feig-out.fval)/(abs(feig)+1); 79 | fprintf('ours: obj val %7.6e, cpu %f, #func eval %d, itr %d, |XT*X-I| %3.2e\n', ... 80 | out.fval, tsolve, out.nfe, out.itr, norm(X'*X - eye(k), 'fro')); 81 | fprintf('relative difference between two obj vals: %3.2e\n',... 82 | err); 83 | out.feasi = norm(X'*X - eye(k), 'fro'); 84 | 85 | 86 | perf(:,dn) = [feig; feasi; teig; nAx; out.fval; out.feasi; out.nrmG; out.nfe; tsolve; err]; 87 | 88 | end 89 | % save('results/eig_rand_perf', 'perf', 'nlist'); 90 | 91 | 92 | function AX = funAX(X) 93 | nAx = nAx + 1; 94 | AX = A*X; 95 | %fprintf('iter: %d, size: (%d, %d)\n', nAx, size(X)); 96 | end 97 | 98 | function [F, G] = funeigsym(X, A) 99 | 100 | G = -(A*X); 101 | %F = 0.5*sum(sum( G.*X )); 102 | F = 0.5*sum(dot(G,X,1)); 103 | % F = sum(sum( G.*X )); 104 | % G = 2*G; 105 | 106 | end 107 | 108 | 109 | end 110 | --------------------------------------------------------------------------------