1 | /* _________________________________________________________________________ |
---|
2 | * |
---|
3 | * Acro: A Common Repository for Optimizers |
---|
4 | * Copyright (c) 2008 Sandia Corporation. |
---|
5 | * This software is distributed under the BSD License. |
---|
6 | * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, |
---|
7 | * the U.S. Government retains certain rights in this software. |
---|
8 | * For more information, see the README.txt file in the top Acro directory. |
---|
9 | * _________________________________________________________________________ |
---|
10 | */ |
---|
11 | |
---|
12 | // |
---|
13 | // TCC.cpp |
---|
14 | // |
---|
15 | |
---|
16 | #include <acro_config.h> |
---|
17 | #ifdef USING_TCC |
---|
18 | |
---|
19 | #include <utilib/Uniform.h> |
---|
20 | #include <interfaces/TCC.h> |
---|
21 | |
---|
22 | namespace interfaces { |
---|
23 | |
---|
24 | using colin::real; |
---|
25 | |
---|
26 | extern double (*urandom)(); |
---|
27 | extern void (*cluster_gopt_fn)(BasicArray<double>&, real&, int ,int ); |
---|
28 | extern int cluster_gopt(BasicArray<double>& amin, BasicArray<double>& amax, const int nparm, |
---|
29 | const int m, int n100, int ng0, ostream& ostr, |
---|
30 | const int nsig, const int max_num_clusters, |
---|
31 | DoubleMatrix& x0, |
---|
32 | int& nc, BasicArray<double>& f0, int& nfe, BasicArray<double>& work); |
---|
33 | |
---|
34 | static Uniform urnd; |
---|
35 | double Dummy_urandom() {return urnd();} |
---|
36 | |
---|
37 | // |
---|
38 | // Junk for computing the function |
---|
39 | // |
---|
40 | #ifdef ACRO_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS |
---|
41 | static colin::Problem<BasicArray<double>,BasicArray > *localFn; |
---|
42 | #else |
---|
43 | static colin::Problem<BasicArray<double> >* localFn; |
---|
44 | #endif |
---|
45 | static BasicArray<double> vec; |
---|
46 | |
---|
47 | void DummyFunc(BasicArray<double>& x, real& f, int nparam, int) |
---|
48 | { |
---|
49 | vec.set_data(nparam,&(x[1])); |
---|
50 | localFn->EvalF(vec,f); |
---|
51 | //ucout << "TCC Feval: " << f << ": " << vec << endl; |
---|
52 | } |
---|
53 | |
---|
54 | // |
---|
55 | // Constructor |
---|
56 | // |
---|
57 | TCC::TCC() |
---|
58 | { |
---|
59 | cluster_gopt_fn = &DummyFunc; |
---|
60 | urandom=Dummy_urandom; |
---|
61 | num_samples=300; |
---|
62 | max_nmins=20; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | void TCC::reset() |
---|
67 | { |
---|
68 | urnd.generator(&rng); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | void TCC::minimize() |
---|
73 | { |
---|
74 | //localFn = &problem; |
---|
75 | opt_init(); |
---|
76 | |
---|
77 | if (problem.numConstraints() > 0) |
---|
78 | EXCEPTION_MNGR(runtime_error, "TCCluster::minimize -- no constraints can be handled by this method!"); |
---|
79 | |
---|
80 | int m=1; |
---|
81 | int nfe; |
---|
82 | int nc; |
---|
83 | work.resize(problem.num_real_vars() * (problem.num_real_vars()+1)/2 + 1); |
---|
84 | |
---|
85 | problem.get_real_bounds(lower,upper); |
---|
86 | x0.resize((problem.num_real_vars()+1),max_nmins+1); |
---|
87 | f0.resize(max_nmins+1); |
---|
88 | |
---|
89 | int nparams=problem.num_real_vars(); |
---|
90 | /* |
---|
91 | cluster_gopt(lower,upper,nparams,m,num_samples, |
---|
92 | num_selected,ucout, |
---|
93 | nsig, max_nmins, x0, nc,f0,nfe,work); |
---|
94 | */ |
---|
95 | |
---|
96 | // |
---|
97 | // Setup best value of function |
---|
98 | // |
---|
99 | int ndx=0; |
---|
100 | for (int i=1; i<nc; i++) |
---|
101 | if (f0[i] < f0[ndx]) ndx=i; |
---|
102 | for (unsigned int j=0; j<problem.num_real_vars(); j++) |
---|
103 | best_point[j] = x0[j][ndx]; |
---|
104 | best_val = f0[ndx]; |
---|
105 | } |
---|
106 | |
---|
107 | } // namespace interfaces |
---|
108 | |
---|
109 | #endif |
---|