@@ -209,9 +209,29 @@ namespace maxsum
209209 /* *
210210 * Sets this function to a constant scalar value.
211211 * @param[in] val the value to assign to this function.
212+ * @post this function will no longer depend on any variables.
212213 */
213214 DiscreteFunction& operator =(ValType val);
214215
216+ /* *
217+ * Sets this function to a constant scalar value, but preserves
218+ * domain.
219+ * @param[in] val the value to assign to this function.
220+ * @post the domain of this function will be unchanged, but all values
221+ * will be set to the specified constant value.
222+ */
223+ DiscreteFunction& assignKeepDomain (ValType val)
224+ {
225+ for (std::vector<ValType>::iterator it=values_i.begin ();
226+ it!=values_i.end (); ++it)
227+ {
228+ (*it) = val;
229+ }
230+
231+ return *this ;
232+
233+ } // assignKeepDomain
234+
215235 /* *
216236 * Sets this function to be equal to another.
217237 * @param[in] val the value to assign to this function.
@@ -241,7 +261,7 @@ namespace maxsum
241261 /* *
242262 * Multiply function by -1
243263 */
244- DiscreteFunction operator -()
264+ DiscreteFunction operator -() const
245265 {
246266 return DiscreteFunction (*this ) *= -1 ;
247267 }
@@ -250,7 +270,16 @@ namespace maxsum
250270 * Identity function.
251271 * @returns a reference to this function.
252272 */
253- DiscreteFunction& operator +()
273+ const DiscreteFunction& operator +() const
274+ {
275+ return *this ;
276+ }
277+
278+ /* *
279+ * Identity function.
280+ * @returns a reference to this function.
281+ */
282+ DiscreteFunction& operator +()
254283 {
255284 return *this ;
256285 }
@@ -800,10 +829,25 @@ namespace maxsum
800829 ValType max () const ;
801830
802831 /* *
803- * Returns the linear index of the maximum value accross entire domain.
832+ * Returns the linear index of the maximum value across entire domain.
804833 */
805834 ValIndex argmax () const ;
806835
836+ /* *
837+ * Returns the linear index of the 2nd largest value.
838+ * Example usage:
839+ * <p>
840+ * <code>
841+ * ValIndex mx1 = fun.argmax();
842+ * ValIndex mx2 = fun.argmax2(mx1);
843+ * </code>
844+ * </p>
845+ * @param mxInd the value returned by DiscreteFunction::argmax()
846+ * This is the maximum of the set of values, excluding the largest one,
847+ * returned by DiscreteFunction::argmax
848+ */
849+ ValIndex argmax2 (ValIndex mxInd) const ;
850+
807851 /* *
808852 * Returns the maxnorm for this function.
809853 * The maxnorm is defined as the maximum absolute value of the function:
@@ -906,6 +950,106 @@ namespace maxsum
906950 {
907951 return !equalWithinTolerance (f1,f2,0.0 );
908952 }
953+
954+ /* *
955+ * Returns true iff function is less than specified value
956+ * across its entire domain.
957+ */
958+ inline bool operator <(const DiscreteFunction& f, const ValType v)
959+ {
960+ for (int k=0 ; k<f.domainSize (); ++k)
961+ {
962+ if (f (k)>=v)
963+ {
964+ return false ;
965+ }
966+ }
967+ return true ;
968+ }
969+
970+ /* *
971+ * Returns true iff function is less than specified value
972+ * across its entire domain.
973+ */
974+ inline bool operator >=(const ValType v, const DiscreteFunction& f)
975+ {
976+ return f < v;
977+ }
978+
979+ /* *
980+ * Returns true iff function is less than or equal to specified value
981+ * across its entire domain.
982+ */
983+ inline bool operator <=(const DiscreteFunction& f, const ValType v)
984+ {
985+ for (int k=0 ; k<f.domainSize (); ++k)
986+ {
987+ if (f (k)>v)
988+ {
989+ return false ;
990+ }
991+ }
992+ return true ;
993+ }
994+
995+ /* *
996+ * Returns true iff function is less than or equal to specified value
997+ * across its entire domain.
998+ */
999+ inline bool operator >(const ValType v, const DiscreteFunction& f)
1000+ {
1001+ return f <= v;
1002+ }
1003+
1004+ /* *
1005+ * Returns true iff function is greater than specified value
1006+ * across its entire domain.
1007+ */
1008+ inline bool operator >(const DiscreteFunction& f, const ValType v)
1009+ {
1010+ for (int k=0 ; k<f.domainSize (); ++k)
1011+ {
1012+ if (f (k)<=v)
1013+ {
1014+ return false ;
1015+ }
1016+ }
1017+ return true ;
1018+ }
1019+
1020+ /* *
1021+ * Returns true iff function is greater than specified value
1022+ * across its entire domain.
1023+ */
1024+ inline bool operator <=(const ValType v, const DiscreteFunction& f)
1025+ {
1026+ return f > v;
1027+ }
1028+
1029+ /* *
1030+ * Returns true iff function is greater than or equal to specified value
1031+ * across its entire domain.
1032+ */
1033+ inline bool operator >=(const DiscreteFunction& f, const ValType v)
1034+ {
1035+ for (int k=0 ; k<f.domainSize (); ++k)
1036+ {
1037+ if (f (k)<v)
1038+ {
1039+ return false ;
1040+ }
1041+ }
1042+ return true ;
1043+ }
1044+
1045+ /* *
1046+ * Returns true iff function is greater than or equal to specified value
1047+ * across its entire domain.
1048+ */
1049+ inline bool operator <(const ValType v, const DiscreteFunction& f)
1050+ {
1051+ return f >= v;
1052+ }
9091053
9101054 /* *
9111055 * Peforms element-wise division of a scalar by a function.
0 commit comments