46 #define max(a,b) ( (a) > (b) ? (a) : (b) )
47 #define min(a,b) ( (a) < (b) ? (a) : (b) )
50 #include "RTOp_obj_null_vtbl.h"
51 #include "RTOp_obj_value_vtbl.h"
52 #include "RTOp_obj_free_free.h"
53 #include "RTOp_get_reduct_op.hpp"
63 static int get_targ_type_num_entries(
77 static int targ_obj_reinit(
79 , RTOp_ReductTarget targ_obj )
91 static int targ_obj_create(
93 ,RTOp_ReductTarget* targ_obj
97 *targ_obj = malloc( mem_size );
98 return targ_obj_reinit(vtbl,obj_data,*targ_obj);
101 static int targ_extract_state(
103 ,
const void * obj_data
106 ,RTOp_value_type value_data[]
108 ,RTOp_index_type index_data[]
110 ,RTOp_char_type char_data[]
114 assert( reduct_obj );
115 assert( num_values == 3 );
116 assert( num_indexes == 3 );
117 assert( num_chars == 0 );
119 value_data[0] = targ->max_viol;
120 value_data[1] = targ->v_i;
121 value_data[2] = targ->vLU_i;
122 index_data[0] = targ->max_viol_i;
123 index_data[1] = targ->bnd_type;
127 static int targ_load_state(
129 ,
const void* obj_data
131 ,
const RTOp_value_type value_data[]
133 ,
const RTOp_index_type index_data[]
135 ,
const RTOp_char_type char_data[]
140 assert( *reduct_obj );
141 assert( num_values == 3 );
142 assert( num_indexes == 2 );
143 assert( num_chars == 0 );
145 targ->max_viol = value_data[0];
146 targ->v_i = value_data[1];
147 targ->vLU_i = value_data[2];
148 targ->max_viol_i = index_data[0];
149 targ->bnd_type = index_data[1];
155 get_targ_type_num_entries
165 static int RTOp_ROp_max_inequ_viol_apply_op(
169 ,RTOp_ReductTarget targ_obj
180 size_t global_offset;
184 const RTOp_value_type *v_val = NULL;
187 const RTOp_value_type *vL_val = NULL;
190 const RTOp_value_type *vU_val = NULL;
195 RTOp_value_type v_scale;
196 RTOp_value_type violL;
197 RTOp_value_type violU;
203 return RTOp_ERR_INVALID_NUM_VECS;
204 if( num_targ_vecs != 0 )
205 return RTOp_ERR_INVALID_NUM_TARG_VECS;
206 if( vecs[0].global_offset != vecs[1].global_offset
207 || vecs[0].sub_dim != vecs[1].sub_dim
208 || vecs[0].global_offset != vecs[2].global_offset
209 || vecs[0].sub_dim != vecs[2].sub_dim )
210 return RTOp_ERR_INCOMPATIBLE_VECS;
219 global_offset = vecs[0].global_offset;
221 sub_dim = vecs[0].sub_dim;
223 v_val = vecs[0].values;
224 v_val_s = vecs[0].values_stride;
226 vL_val = vecs[1].values;
227 vL_val_s = vecs[1].values_stride;
229 vU_val = vecs[2].values;
230 vU_val_s = vecs[2].values_stride;
236 i = global_offset + 1;
237 for( k = 0; k < sub_dim; ++k, ++i, v_val += v_val_s, vL_val += vL_val_s, vU_val += vU_val_s ) {
238 v_scale = 1.0 / (1.0 + fabs(*v_val));
240 violL = (*vL_val - *v_val) * v_scale;
242 violU = (*v_val - *vU_val) * v_scale;
245 ( max(violL,violU) > targ->max_viol )
247 ( max(violL,violU) == targ->max_viol && i < targ->max_viol_i )
250 targ->bnd_type = ( violL > 0.0
251 ? ( *vL_val == *vU_val
257 targ->max_viol = ( targ->bnd_type <= 0 ? violL : violU );
259 targ->vLU_i = ( targ->bnd_type <= 0 ? *vL_val : *vU_val );
260 targ->max_viol_i = i;
267 static int reduce_reduct_objs(
269 , RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj )
277 ( i_targ->max_viol > io_targ->max_viol )
279 ( i_targ->max_viol == io_targ->max_viol && i_targ->max_viol_i < io_targ->max_viol_i )
282 io_targ->max_viol = i_targ->max_viol;
283 io_targ->v_i = i_targ->v_i;
284 io_targ->vLU_i = i_targ->vLU_i;
285 io_targ->max_viol_i = i_targ->max_viol_i;
286 io_targ->bnd_type = i_targ->bnd_type;
291 INSERT_GET_REDUCT_OP_FUNCS(
293 ,targ_load_state,targ_extract_state
294 ,external_reduct_op,get_reduct_op)
300 ,
"ROp_max_inequ_viol"
302 ,RTOp_ROp_max_inequ_viol_apply_op
309 int RTOp_ROp_max_inequ_viol_construct(
struct RTOp_RTOp* op )
311 op->vtbl = &RTOp_ROp_max_inequ_viol_vtbl;
316 int RTOp_ROp_max_inequ_viol_destroy(
struct RTOp_RTOp* op )
324 RTOp_ROp_max_inequ_viol_val(RTOp_ReductTarget targ_obj)