Пример #1
0
        /// <summary>
        /// Returns an <see cref="IAlternative{TSource}"/> containing <see cref="Maybe.Just{T}(T)"/> its value, if present, or <see cref="Maybe.Nothing{T}"/> otherwise.
        /// </summary>
        /// <typeparam name="TResult">The type of the value in <paramref name="alt"/>.</typeparam>
        /// <param name="alt">The <see cref="IAlternative{TSource}"/> to check.</param>
        public static IAlternative <Maybe <TResult> > Optional <TResult>(this IAlternative <TResult> alt)
        {
            var altM     = (IAlternative <Maybe <TResult> >)alt.Map(x => Maybe.Just(x));
            var nothingM = (IAlternative <Maybe <TResult> >)Applicative.PureUnsafe(Maybe.Nothing <TResult>(), altM.GetType());

            return(altM.Alt(nothingM));
        }
Пример #2
0
 public static DataBase.Alternative ConvertToDBAlternative(IAlternative alternativeModel)
 {
     return(new DataBase.Alternative
     {
         Name = alternativeModel.Name,
         Description = alternativeModel.Description
     });
 }
 private void WL(int trial, IAlternative alternative)
 {
     if (this._bandit.Diagnostics.LastBest == null)
     {
         Console.WriteLine(
             string.Format("{0}\t{1}",trial, ((ConstantRewardAlternative)alternative).Name)
         );
     }
     else
     {
         Console.WriteLine(
             string.Format("{0}\t{1}\tBest {2} {3}\tWorst {4} {5}",
                 trial, ((ConstantRewardAlternative)alternative).Name,
                 ((ConstantRewardAlternative)this._bandit.Diagnostics.LastBest).Name, Math.Round(this._bandit.Diagnostics.LastBestMean, 4),
                 ((ConstantRewardAlternative)this._bandit.Diagnostics.LastWorst).Name, Math.Round(this._bandit.Diagnostics.LastWorstMean, 4))
             );
     }
 }