COIN-OR::LEMON - Graph Library

Changeset 1070:6aa1520a0f2f in lemon-0.x


Ignore:
Timestamp:
01/11/05 10:05:24 (20 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1466
Message:

ShiftMap? and ScaleMap? added

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/maps.h

    r1044 r1070  
    213213  }
    214214
     215  ///Shift a maps with a constant.
     216
     217  ///This \ref concept::ReadMap "read only map" returns the sum of the
     218  ///given map and a constant value.
     219  ///Its \c Key and \c Value is inherited from \c M.
     220  ///
     221  ///Actually,
     222  ///\code
     223  ///  ShiftMap<X> sh(x,v);
     224  ///\endcode
     225  ///it is equivalent with
     226  ///\code
     227  ///  ConstMap<X::Key, X::Value> c_tmp(v);
     228  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
     229  ///\endcode
     230  template<class M>
     231  class ShiftMap
     232  {
     233    const M &m;
     234    typename M::Value v;
     235  public:
     236    typedef typename M::Key Key;
     237    typedef typename M::Value Value;
     238
     239    ///Constructor
     240
     241    ///Constructor
     242    ///\param _m is the undelying map
     243    ///\param _v is the shift value
     244    ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
     245    Value operator[](Key k) const {return m[k]+v;}
     246  };
     247 
     248  ///Returns an \ref ShiftMap class
     249
     250  ///This function just returns an \ref ShiftMap class.
     251  ///\relates ShiftMap
     252  ///\todo A better name is required.
     253  template<class M>
     254  inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v)
     255  {
     256    return ShiftMap<M>(m,v);
     257  }
     258
    215259  ///Difference of two maps
    216260
     
    283327  }
    284328 
     329  ///Scale a maps with a constant.
     330
     331  ///This \ref concept::ReadMap "read only map" returns the value of the
     332  ///given map multipied with a constant value.
     333  ///Its \c Key and \c Value is inherited from \c M.
     334  ///
     335  ///Actually,
     336  ///\code
     337  ///  ScaleMap<X> sc(x,v);
     338  ///\endcode
     339  ///it is equivalent with
     340  ///\code
     341  ///  ConstMap<X::Key, X::Value> c_tmp(v);
     342  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
     343  ///\endcode
     344  template<class M>
     345  class ScaleMap
     346  {
     347    const M &m;
     348    typename M::Value v;
     349  public:
     350    typedef typename M::Key Key;
     351    typedef typename M::Value Value;
     352
     353    ///Constructor
     354
     355    ///Constructor
     356    ///\param _m is the undelying map
     357    ///\param _v is the scaling value
     358    ScaleMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
     359    Value operator[](Key k) const {return m[k]*v;}
     360  };
     361 
     362  ///Returns an \ref ScaleMap class
     363
     364  ///This function just returns an \ref ScaleMap class.
     365  ///\relates ScaleMap
     366  ///\todo A better name is required.
     367  template<class M>
     368  inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v)
     369  {
     370    return ScaleMap<M>(m,v);
     371  }
     372
    285373  ///Quotient of two maps
    286374
  • src/test/maps_test.cc

    r1041 r1070  
    2727  checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
    2828  checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
     29  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
     30  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
    2931 
    3032  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
Note: See TracChangeset for help on using the changeset viewer.