Line data Source code
1 : /*
2 : * File: IndPos.cpp
3 : * Author: Pantelis Sopasakis
4 : *
5 : * Created on July 26, 2015, 4:36 PM
6 : *
7 : * ForBES is free software: you can redistribute it and/or modify
8 : * it under the terms of the GNU Lesser General Public License as published by
9 : * the Free Software Foundation, either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * ForBES is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU Lesser General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU Lesser General Public License
18 : * along with ForBES. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <math.h>
22 : #include <cmath>
23 :
24 : #include "IndPos.h"
25 :
26 20 : IndPos::~IndPos() {
27 20 : }
28 :
29 3 : IndPos::IndPos(double& uniform_lb) : m_uniform_lb(&uniform_lb) {
30 3 : m_lb = NULL;
31 3 : }
32 :
33 3 : IndPos::IndPos(Matrix& lb) : m_lb(&lb) {
34 3 : m_uniform_lb = NULL;
35 3 : }
36 :
37 4 : IndPos::IndPos() {
38 4 : m_uniform_lb = NULL;
39 4 : m_lb = NULL;
40 4 : }
41 :
42 7 : int IndPos::call(Matrix& x, double& f) {
43 7 : f = 0.0;
44 7 : if (m_uniform_lb != NULL) {
45 28 : for (size_t i = 0; i < x.getNrows(); i++) {
46 26 : if (x[i] < *m_uniform_lb) {
47 1 : f = INFINITY;
48 1 : break;
49 : }
50 : }
51 4 : } else if (m_lb != NULL) {
52 15 : for (size_t i = 0; i < x.getNrows(); i++) {
53 14 : if (x[i] < m_lb->get(i)) {
54 1 : f = INFINITY;
55 1 : break;
56 : }
57 : }
58 : } else {
59 10 : for (size_t i = 0; i < x.getNrows(); i++) {
60 9 : if (x[i] < 0.0) {
61 1 : f = INFINITY;
62 1 : break;
63 : }
64 : }
65 : }
66 7 : return ForBESUtils::STATUS_OK;
67 : }
68 :
69 11 : int IndPos::callConj(Matrix& y, double& f_star) {
70 11 : f_star = 0.0;
71 11 : if (m_uniform_lb != NULL) {
72 406 : for (size_t i = 0; i < y.getNrows(); i++) {
73 404 : if (y[i] > 0) {
74 3 : f_star = INFINITY;
75 3 : break;
76 : }
77 401 : f_star += y[i];
78 : }
79 5 : if (!std::isinf(f_star)) {
80 2 : f_star *= *m_uniform_lb;
81 : }
82 6 : } else if (m_lb != NULL) {
83 203 : for (size_t i = 0; i < y.getNrows(); i++) {
84 201 : if (y[i] > 0) {
85 1 : f_star = INFINITY;
86 1 : break;
87 : }
88 200 : f_star += y[i] * m_lb->get(i);
89 : }
90 : } else { /* this is like m_uniform_lb = 0.0 */
91 407 : for (size_t i = 0; i < y.getNrows(); i++) {
92 405 : if (y[i] > 0) {
93 1 : f_star = INFINITY;
94 1 : break;
95 : }
96 : }
97 : }
98 :
99 :
100 11 : return ForBESUtils::STATUS_OK;
101 : }
102 :
103 4 : int IndPos::callProx(Matrix& x, double gamma, Matrix& prox, double& f_at_prox) {
104 4 : f_at_prox = 0.0;
105 4 : if (m_uniform_lb != NULL) {
106 22 : for (size_t i = 0; i < x.getNrows(); i++) {
107 20 : prox[i] = std::max(x[i], *m_uniform_lb);
108 : }
109 2 : } else if (m_lb != NULL) {
110 51 : for (size_t i = 0; i < x.getNrows(); i++) {
111 50 : prox[i] = std::max(x[i], m_lb->get(i));
112 : }
113 : } else {
114 1 : x.plusop(&prox);
115 : }
116 4 : return ForBESUtils::STATUS_OK;
117 : }
118 :
119 4 : int IndPos::callProx(Matrix& x, double gamma, Matrix& prox) {
120 : double val;
121 4 : return callProx(x, gamma, prox, val);
122 : }
123 :
124 1 : FunctionOntologicalClass IndPos::category() {
125 1 : FunctionOntologicalClass cat = FunctionOntologyRegistry::indicator();
126 1 : cat.set_defines_conjugate(true);
127 1 : return cat;
128 3 : }
129 :
130 :
131 :
132 :
|