Ejemplo n.º 1
0
        /// <inheritdoc />
        public double ComputeEvaluationPriorityOfGenome(ImmutableGenomeStats <InstanceSeedFile, GurobiResult> genomeStats, TimeSpan cpuTimeout)
        {
            if (genomeStats.IsCancelledByRacing)
            {
                return(1000);
            }

            // First decision criterion: The higher the cancelled instance rate, the later the genome will start.
            var cancelledCount        = genomeStats.FinishedInstances.Values.Count(r => r.IsCancelled);
            var cancelledInstanceRate = (double)cancelledCount / genomeStats.TotalInstanceCount;

            // Second decision criterion: The higher the running instance rate, the later the genome will start.
            var runningInstanceRate = (double)genomeStats.RunningInstances.Count / genomeStats.TotalInstanceCount;

            // Third decision criterion: The higher the total runtime rate, the later the genome will start.
            var totalRuntimeRate = genomeStats.RuntimeOfFinishedInstances.TotalMilliseconds
                                   / (genomeStats.TotalInstanceCount * cpuTimeout.TotalMilliseconds);

            RunEvaluatorUtils.CheckIfRateIsOutOfBounds(cancelledInstanceRate, nameof(cancelledInstanceRate));
            RunEvaluatorUtils.CheckIfRateIsOutOfBounds(runningInstanceRate, nameof(runningInstanceRate));
            RunEvaluatorUtils.CheckIfRateIsOutOfBounds(totalRuntimeRate, nameof(totalRuntimeRate));

            var priority = (100 * cancelledInstanceRate) + (10 * runningInstanceRate) + (1 * totalRuntimeRate);

            // The lower the priority, the earlier the genome will start.
            return(priority);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extends the results of the finished instances by the given result for every not finished instance.
        /// </summary>
        /// <param name="genomeStats">The genome stats.</param>
        /// <param name="result">The result.</param>
        /// <returns>The extended genome stats.</returns>
        protected virtual ImmutableGenomeStats <TInstance, TResult> GetExtendedGenomeStats(
            ImmutableGenomeStats <TInstance, TResult> genomeStats,
            TResult result)
        {
            var results = genomeStats.FinishedInstances.Values.Concat(
                Enumerable.Repeat(result, genomeStats.TotalInstanceCount - genomeStats.FinishedInstances.Count));

            var counter          = 0;
            var resultDictionary = results.ToDictionary(x => this._getPlaceholderInstance(counter++));

            return(new ImmutableGenomeStats <TInstance, TResult>(
                       new GenomeStats <TInstance, TResult>(genomeStats.Genome, resultDictionary)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrayBoxSimulationGenomeStatsPair{TInstance, TResult}"/> class.
        /// </summary>
        /// <param name="blackBoxGenomeStats">The black box genome stats.</param>
        /// <param name="grayBoxGenomeStats">The gray box genome stats.</param>
        public GrayBoxSimulationGenomeStatsPair(
            ImmutableGenomeStats <TInstance, TResult> blackBoxGenomeStats,
            ImmutableGenomeStats <TInstance, TResult> grayBoxGenomeStats)
        {
            if (!ImmutableGenome.GenomeComparer.Equals(blackBoxGenomeStats.Genome, grayBoxGenomeStats.Genome))
            {
                throw new ArgumentException(
                          "The genome of the black box genome stats needs to be the same genome than the one of the gray box genome stats.");
            }

            this.Genome = blackBoxGenomeStats.Genome;
            this.BlackBoxGenomeStats = blackBoxGenomeStats;
            this.GrayBoxGenomeStats  = grayBoxGenomeStats;
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public virtual double ComputeEvaluationPriorityOfGenome(ImmutableGenomeStats <TInstance, TResult> genomeStats)
        {
            if (genomeStats.IsCancelledByRacing)
            {
                return(1000);
            }

            // First decision criterion: The higher the cancelled instance rate, the later the genome will start.
            var cancelledCount        = genomeStats.FinishedInstances.Values.Count(r => r.IsCancelled);
            var cancelledInstanceRate = (double)cancelledCount / genomeStats.TotalInstanceCount;

            // Second decision criterion: The higher the running instance rate, the later the genome will start.
            var runningInstanceRate = (double)genomeStats.RunningInstances.Count / genomeStats.TotalInstanceCount;

            // Third decision criterion: The higher the total runtime rate, the later the genome will start.
            var totalRuntimeRate = genomeStats.RuntimeOfFinishedInstances.TotalMilliseconds
                                   / (genomeStats.TotalInstanceCount * this.CpuTimeout.TotalMilliseconds);

            // The lower the priority, the earlier the genome will start.
            return((100 * cancelledInstanceRate) + (10 * runningInstanceRate) + (1 * totalRuntimeRate));
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public double ComputeEvaluationPriorityOfGenome(ImmutableGenomeStats <TInstance, ContinuousResult> genomeStats)
 {
     // Implementing a useful racing strategy is not possible without knowing the global minimum or maximum.
     // Therefore it makes no sense to compute an explicit evaluation priority, and all genomes have the same priority.
     return(42);
 }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public double ComputeEvaluationPriorityOfGenome(ImmutableGenomeStats <TInstance, IntegerResult> genomeStats)
 {
     return(42);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Uses the <paramref name="genomeStats"/>.Genome.Age - OpenInstances.Count as priority.
 /// </summary>
 /// <param name="genomeStats">The genome stats.</param>
 /// <returns><see cref="ImmutableGenomeStats{TInstance,TResult}.Genome"/>.Age.</returns>
 public double ComputeEvaluationPriorityOfGenome(ImmutableGenomeStats <TInstance, TResult> genomeStats)
 {
     return(genomeStats.Genome.Age - genomeStats.OpenInstances.Count);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets an upper bound for the penalized total runtime by adding NumberOfNotFinishedInstances * CpuTimeout * PARK to the current penalized total run time.
 /// </summary>
 /// <param name="genomeStats">The genome stats.</param>
 /// <returns>The upper bound for the penalized total runtime.</returns>
 private double GetUpperBoundForPenalizedTotalRuntime(ImmutableGenomeStats <TInstance, RuntimeResult> genomeStats)
 {
     return(genomeStats.FinishedInstances.Values.Sum(this.GetMetricRepresentation)
            + ((genomeStats.TotalInstanceCount - genomeStats.FinishedInstances.Count)
               * this.CpuTimeout.TotalSeconds * this._factorPar));
 }