1 /*-------------------------------------------------------------------------------------*/
2 /*  NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2      */
3 /*                                                                                     */
4 /*  Copyright (C) 2001-2015  Mark Abramson        - the Boeing Company, Seattle        */
5 /*                           Charles Audet        - Ecole Polytechnique, Montreal      */
6 /*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
7 /*                           John Dennis          - Rice University, Houston           */
8 /*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
9 /*                           Christophe Tribes    - Ecole Polytechnique, Montreal      */
10 /*                                                                                     */
11 /*  funded in part by AFOSR and Exxon Mobil                                            */
12 /*                                                                                     */
13 /*  Author: Sebastien Le Digabel                                                       */
14 /*                                                                                     */
15 /*  Contact information:                                                               */
16 /*    Ecole Polytechnique de Montreal - GERAD                                          */
17 /*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
18 /*    e-mail: nomad@gerad.ca                                                           */
19 /*    phone : 1-514-340-6053 #6928                                                     */
20 /*    fax   : 1-514-340-5665                                                           */
21 /*                                                                                     */
22 /*  This program is free software: you can redistribute it and/or modify it under the  */
23 /*  terms of the GNU Lesser General Public License as published by the Free Software   */
24 /*  Foundation, either version 3 of the License, or (at your option) any later         */
25 /*  version.                                                                           */
26 /*                                                                                     */
27 /*  This program is distributed in the hope that it will be useful, but WITHOUT ANY    */
28 /*  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A    */
29 /*  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.   */
30 /*                                                                                     */
31 /*  You should have received a copy of the GNU Lesser General Public License along     */
32 /*  with this program. If not, see <http://www.gnu.org/licenses/>.                     */
33 /*                                                                                     */
34 /*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
35 /*-------------------------------------------------------------------------------------*/
36 /**
37   \file   Direction.cpp
38   \brief  Polling direction (implementation)
39   \author Sebastien Le Digabel
40   \date   2010-04-05
41   \see    Direction.hpp
42 */
43 #include "Direction.hpp"
44 
45 /*-----------------------------------*/
46 /*   static members initialization   */
47 /*-----------------------------------*/
48 #ifdef MEMORY_DEBUG
49 int NOMAD::Direction::_cardinality     = 0;
50 int NOMAD::Direction::_max_cardinality = 0;
51 #endif
52 
53 /*---------------------------------------------------------*/
54 /*                       constructor 1                     */
55 /*---------------------------------------------------------*/
Direction(void)56 NOMAD::Direction::Direction ( void )
57   : NOMAD::Point  (                            ) ,
58     _type         ( NOMAD::UNDEFINED_DIRECTION ) ,
59 _index        ( -1                         ),
60 _dir_group_index (-1)
61 {
62 #ifdef MEMORY_DEBUG
63   ++NOMAD::Direction::_cardinality;
64   if ( NOMAD::Direction::_cardinality > NOMAD::Direction::_max_cardinality )
65     ++NOMAD::Direction::_max_cardinality;
66 #endif
67 }
68 
69 /*---------------------------------------------------------*/
70 /*                       constructor 2                     */
71 /*---------------------------------------------------------*/
Direction(int n,const NOMAD::Double & v,NOMAD::direction_type type,int dir_group_index)72 NOMAD::Direction::Direction ( int                     n    ,
73 			      const NOMAD::Double   & v    ,
74 			      NOMAD::direction_type   type ,
75 					int dir_group_index		 )
76   : NOMAD::Point  ( n , v ) ,
77     _type         ( type  ) ,
78     _index        ( -1   ) ,
79     _dir_group_index (dir_group_index)
80 {
81 #ifdef MEMORY_DEBUG
82   ++NOMAD::Direction::_cardinality;
83   if ( NOMAD::Direction::_cardinality > NOMAD::Direction::_max_cardinality )
84     ++NOMAD::Direction::_max_cardinality;
85 #endif
86 }
87 
88 /*---------------------------------------------------------*/
89 /*                       constructor 2b                    */
90 /*---------------------------------------------------------*/
Direction(int n,const NOMAD::Double & v,NOMAD::direction_type type)91 NOMAD::Direction::Direction ( int                     n    ,
92 							 const NOMAD::Double   & v    ,
93 							 NOMAD::direction_type   type   )
94 : NOMAD::Point  ( n , v ) ,
95 _type         ( type  ) ,
96 _index        ( -1    ),
97 _dir_group_index (-1)
98 {
99 #ifdef MEMORY_DEBUG
100   ++NOMAD::Direction::_cardinality;
101   if ( NOMAD::Direction::_cardinality > NOMAD::Direction::_max_cardinality )
102     ++NOMAD::Direction::_max_cardinality;
103 #endif
104 }
105 
106 /*---------------------------------------------------------*/
107 /*                       constructor 3                     */
108 /*---------------------------------------------------------*/
Direction(const NOMAD::Point & x,NOMAD::direction_type type)109 NOMAD::Direction::Direction ( const NOMAD::Point    & x    ,
110 			      NOMAD::direction_type   type   )
111   : NOMAD::Point  ( x    ) ,
112     _type         ( type ) ,
113 _index        ( -1   ),
114 _dir_group_index (-1)
115 {
116 #ifdef MEMORY_DEBUG
117   ++NOMAD::Direction::_cardinality;
118   if ( NOMAD::Direction::_cardinality > NOMAD::Direction::_max_cardinality )
119     ++NOMAD::Direction::_max_cardinality;
120 #endif
121 }
122 
123 /*---------------------------------------------------------*/
124 /*                      copy constructor                   */
125 /*---------------------------------------------------------*/
Direction(const Direction & d)126 NOMAD::Direction::Direction ( const Direction & d )
127   : NOMAD::Point  ( d        ) ,
128     _type         ( d._type  ) ,
129     _index        ( d._index ),
130 _dir_group_index (d._dir_group_index)
131 {
132 #ifdef MEMORY_DEBUG
133   ++NOMAD::Direction::_cardinality;
134   if ( NOMAD::Direction::_cardinality > NOMAD::Direction::_max_cardinality )
135     ++NOMAD::Direction::_max_cardinality;
136 #endif
137 }
138 
139 /*---------------------------------------------------------*/
140 /*                         destructor                      */
141 /*---------------------------------------------------------*/
~Direction(void)142 NOMAD::Direction::~Direction ( void )
143 {
144 #ifdef MEMORY_DEBUG
145   --NOMAD::Direction::_cardinality;
146 #endif
147 }
148 
149 /*---------------------------------------------------------*/
150 /*                  affectation operator                   */
151 /*---------------------------------------------------------*/
operator =(const NOMAD::Direction & d)152 NOMAD::Direction & NOMAD::Direction::operator = ( const NOMAD::Direction & d )
153 {
154   if ( this == &d )
155     return *this;
156 
157   NOMAD::Point::operator = ( d );
158 
159   _type  = d._type;
160   _index = d._index;
161 
162   return *this;
163 }
164 
165 /*---------------------------------------------------------*/
166 /*                            clear                        */
167 /*---------------------------------------------------------*/
clear(void)168 void NOMAD::Direction::clear ( void )
169 {
170   NOMAD::Point::clear();
171   _type  = NOMAD::UNDEFINED_DIRECTION;
172   _index = -1;
173 }
174 
175 /*-----------------------------------------------------------*/
176 /*                           negation                        */
177 /*-----------------------------------------------------------*/
operator -(void) const178 const NOMAD::Direction NOMAD::Direction::operator - ( void ) const
179 {
180   return NOMAD::Direction ( this->NOMAD::Point::operator-() , _type );
181 }
182 
183 /*---------------------------------------------------------*/
184 /*                          display                        */
185 /*---------------------------------------------------------*/
display(const NOMAD::Display & out,const std::string & sep,int w,int lim) const186 void NOMAD::Direction::display ( const NOMAD::Display & out ,
187 				 const std::string    & sep ,
188 				 int                    w   ,
189 				 int                    lim   ) const
190 {
191   if ( is_defined() ) {
192     out << "( ";
193     NOMAD::Point::display ( out , sep , w , lim );
194     out << " ) " << _type;
195   }
196   else
197     out << "undefined";
198 }
199