-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcp_arcopt.m
74 lines (57 loc) · 1.52 KB
/
hcp_arcopt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%hcp_arcopt attempt to solve hcp with arcopt
function [hcp_slv] = hcp_arcopt(P,x0,name,solve_tol,solver_options)
% handle optional input
if nargin < 3 || isempty(name)
name = 'hcp_problem';
end
if nargin < 4 || isempty(solve_tol)
solve_tol = -.99;
end
if nargin < 5 || isempty(solver_options)
solver_options = arcopt_nm_lc.optset();
solver_options.crash = 'firstm';
solver_options.print_screen = 0;
end
% get number of edges
num_edges = sum(P(:));
% get function handles
func = @(x) usrfun(x,P);
hess = @(x) usrhess(x,P);
% get constraints
[A c] = hcp_con(P);
A = A(1:end-1,:);
c = c(1:end-1);
% set bounds
bl = zeros(num_edges,1);
bu = ones(num_edges,1);
% open print file if requested
if ischar(solver_options.print_file)
solver_options.print_file = fopen(solver_options.print_file,'w');
end
% solve
mysolver = arcopt_nm_lc(func,hess,x0,bl,bu,A,c,c,solver_options);
[xstar fstar solver_info aux] = mysolver.solve();
% prepare output structure
hcp_slv.xstar = xstar;
hcp_slv.fstar = fstar;
hcp_slv.solver_info = solver_info;
hcp_slv.itercnt = aux.phase2cnt;
hcp_slv.fevcnt = aux.fevcnt;
hcp_slv.name = name;
if fstar <= solve_tol
hcp_slv.hc_found = 1;
else
hcp_slv.hc_found = 0;
end
% close file if opened
if solver_options.print_file
fclose(solver_options.print_file);
end
%keyboard
end
function [f g] = usrfun(x,P)
[f g] = hcp_obj(x,P);
end
function H = usrhess(x,P)
H = hcp_hess(x,P);
end