00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #include <coconut_config.h>
00029 #include <bound_delta.h>
00030
00031 namespace coco {
00032
00033 bool bound_delta::apply(work_node& _x, undelta_base*& _u, const delta_id& _did) const
00034 {
00035 double _gain(1.);
00036 std::vector<interval>::const_iterator _i;
00037 if(indices.empty())
00038 {
00039 std::vector<interval>::const_iterator _e(new_f_bounds.end()),
00040 _xo(_x.node_ranges.begin());
00041 _u = (undelta_base *) new bound_undelta(indices, _x.node_ranges,
00042 _x.gain_factor, _x.log_vol);
00043 _x.node_ranges = new_f_bounds;
00044 for(_i = new_f_bounds.begin(); _i != _e; ++_i, ++_xo)
00045 _gain *= gainfactor(*_xo, *_i);
00046 }
00047 else
00048 {
00049 std::vector<unsigned int>::const_iterator _c,_e;
00050 unsigned int nnds = _x.get_model_ptr()->number_of_nodes();
00051
00052 _e = indices.end();
00053 _u = (undelta_base *) new bound_undelta(indices, _x.gain_factor,
00054 _x.log_vol);
00055 ((bound_undelta*)_u)->old_f_bounds.reserve(indices.size());
00056 _i = new_f_bounds.begin();
00057 for(_c = indices.begin(); _c != _e; ++_c)
00058 {
00059 if(*_c < nnds)
00060 {
00061 const interval& __ix(_x.node_ranges[*_c]);
00062 _gain *= gainfactor(__ix, *_i);
00063 ((bound_undelta*)_u)->old_f_bounds.push_back(__ix);
00064 _x.node_ranges[*_c] = *_i;
00065 }
00066 ++_i;
00067 }
00068 }
00069 _x.log_vol = _x.compute_log_volume(_x.node_ranges);
00070 _x.gain_factor *= _gain;
00071 return true;
00072 }
00073
00074 bool bound_undelta::unapply(work_node& _x, const delta_id& _did) const
00075 {
00076 if(indices.empty())
00077 _x.node_ranges = old_f_bounds;
00078 else
00079 {
00080 std::vector<unsigned int>::const_iterator _c,_e;
00081 std::vector<interval>::const_iterator _i;
00082
00083 _e = indices.end();
00084 _i = old_f_bounds.begin();
00085 for(_c = indices.begin(); _c != _e; ++_c)
00086 _x.node_ranges[*_c] = *_i++;
00087 }
00088 _x.gain_factor = old_gain;
00089 _x.log_vol = old_log_vol;
00090 return true;
00091 }
00092
00093 }