-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_ns.cpp
More file actions
63 lines (48 loc) · 817 Bytes
/
model_ns.cpp
File metadata and controls
63 lines (48 loc) · 817 Bytes
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
#include "model_ns.h"
#include "ods_gs.h"
namespace model
{
non_smooth::non_smooth(uint32_t n)
: abstract(n)
, mu(1e-1)
{
}
void
non_smooth::f(point& p)
{
double x_max = p.x[0];
p.f = 0.0;
for (uint32_t i = 0; i < n; ++i)
{
p.f += p.x[i] * p.x[i];
x_max = std::max(x_max, p.x[i]);
}
p.f *= mu;
p.f += x_max;
++fc;
}
void
non_smooth::df(point& p)
{
uint32_t i_max = 0;
double x_max = p.x[i_max];
for (uint32_t i = 0; i < n; ++i)
{
p.g[i] = 2.0 * mu * p.x[i];
if (p.x[i] > x_max)
{
x_max = p.x[i];
i_max = i;
}
}
p.g[i_max] += 1.0;
p.gn = blas::nrm2(p.g);
++gc;
}
ods::abstract&
non_smooth::ods()
{
static ods::golden_section o(*this);
return o;
}
}