예제 #1
0
        public void CorrectGrayBoxFeaturesAreSelected()
        {
            var gurobiGrayBoxMethods = new GurobiGrayBoxMethods();

            var runtimeFeatures       = new GurobiRuntimeFeatures(DateTime.Now);
            var instanceFeatures      = new GurobiInstanceFeatures();
            var adapterFeatures       = GurobiUtils.ComposeAdapterFeatures(runtimeFeatures, runtimeFeatures, instanceFeatures);
            var adapterFeaturesHeader = GurobiUtils.ComposeAdapterFeaturesHeader(runtimeFeatures, runtimeFeatures, instanceFeatures);
            var result = new GurobiResult(double.NaN, TimeSpan.MaxValue, TargetAlgorithmStatus.CancelledByTimeout, false);

            var adapterDataRecord = new AdapterDataRecord <GurobiResult>(
                "Gurobi901",
                TargetAlgorithmStatus.Running,
                TimeSpan.Zero,
                TimeSpan.Zero,
                DateTime.Now,
                adapterFeaturesHeader,
                adapterFeatures,
                result);

            var tunerDataRecord = new TunerDataRecord <GurobiResult>(
                "Node",
                0,
                0,
                "Instance",
                0.5,
                new[] { "Genome" },
                (GenomeDoubleRepresentation) new[] { 0D },
                result);

            var dataRecord = new DataRecord <GurobiResult>(tunerDataRecord, adapterDataRecord);

            var featureNames = gurobiGrayBoxMethods.GetGrayBoxFeatureNamesFromDataRecord(dataRecord);

            var correctFeatureNames = new[]
            {
                "ExpendedWallClockTime",
                "RuntimeFeature_CuttingPlanesCount_Current",
                "RuntimeFeature_ExploredNodeCount_Current",
                "RuntimeFeature_FeasibleSolutionsCount_Current",
                "RuntimeFeature_MipGap_Current",
                "RuntimeFeature_SimplexIterationsCount_Current",
                "RuntimeFeature_UnexploredNodeCount_Current",
                "RuntimeFeature_CuttingPlanesCount_Last",
                "RuntimeFeature_ExploredNodeCount_Last",
                "RuntimeFeature_FeasibleSolutionsCount_Last",
                "RuntimeFeature_MipGap_Last",
                "RuntimeFeature_SimplexIterationsCount_Last",
                "RuntimeFeature_UnexploredNodeCount_Last",
                "InstanceFeature_NumberOfIntegerVariables",
                "InstanceFeature_NumberOfLinearConstraints",
                "InstanceFeature_NumberOfNonZeroCoefficients",
                "InstanceFeature_NumberOfVariables",
            };

            featureNames.SequenceEqual(correctFeatureNames).ShouldBeTrue();
        }
예제 #2
0
 /// <summary>
 /// Composes the given adapter features to a single array.
 /// </summary>
 /// <param name="currentRuntimeFeatures">The current runtime features.</param>
 /// <param name="lastRuntimeFeatures">The last runtime features.</param>
 /// <param name="instanceFeatures">The instance features.</param>
 /// <returns>The composed array.</returns>
 public static double[] ComposeAdapterFeatures(
     GurobiRuntimeFeatures currentRuntimeFeatures,
     GurobiRuntimeFeatures lastRuntimeFeatures,
     GurobiInstanceFeatures instanceFeatures)
 {
     return(currentRuntimeFeatures.ToArray()
            .Concat(lastRuntimeFeatures.ToArray())
            .Concat(instanceFeatures.ToArray())
            .ToArray());
 }
예제 #3
0
 /// <summary>
 /// Composes the header of the given adapter features to a single array.
 /// </summary>
 /// <param name="currentRuntimeFeatures">The current runtime features.</param>
 /// <param name="lastRuntimeFeatures">The last runtime features.</param>
 /// <param name="instanceFeatures">The instance features.</param>
 /// <returns>The composed array.</returns>
 public static string[] ComposeAdapterFeaturesHeader(
     GurobiRuntimeFeatures currentRuntimeFeatures,
     GurobiRuntimeFeatures lastRuntimeFeatures,
     GurobiInstanceFeatures instanceFeatures)
 {
     return(currentRuntimeFeatures.GetHeader("RuntimeFeature_", "_Current")
            .Concat(lastRuntimeFeatures.GetHeader("RuntimeFeature_", "_Last"))
            .Concat(instanceFeatures.GetHeader("InstanceFeature_"))
            .ToArray());
 }
예제 #4
0
 /// <summary>
 /// Sets the current <see cref="GurobiInstanceFeatures"/>.
 /// </summary>
 /// <param name="model">The <see cref="GRBModel"/>.</param>
 private void SetGurobiInstanceFeatures(GRBModel model)
 {
     this._instanceFeatures = new GurobiInstanceFeatures()
     {
         NumberOfBinaryVariables                = this.GetValueWithTryCatch(() => model.NumBinVars, 0),
         NumberOfGeneralConstraints             = this.GetValueWithTryCatch(() => model.NumGenConstrs, 0),
         NumberOfIntegerVariables               = this.GetValueWithTryCatch(() => model.NumIntVars, 0),
         NumberOfLinearConstraints              = this.GetValueWithTryCatch(() => model.NumConstrs, 0),
         NumberOfNonZeroCoefficients            = this.GetValueWithTryCatch(() => model.NumNZs, 0),
         NumberOfNonZeroQuadraticObjectiveTerms =
             this.GetValueWithTryCatch(() => model.NumQNZs, 0),
         NumberOfNonZeroTermsInQuadraticConstraints =
             this.GetValueWithTryCatch(() => model.NumQCNZs, 0),
         NumberOfQuadraticConstraints = this.GetValueWithTryCatch(() => model.NumQConstrs, 0),
         NumberOfSosConstraints       = this.GetValueWithTryCatch(() => model.NumSOS, 0),
         NumberOfVariables            = this.GetValueWithTryCatch(() => model.NumVars, 0),
         NumberOfVariablesWithPiecewiseLinearObjectiveFunctions = this.GetValueWithTryCatch(
             () => model.NumPWLObjVars,
             0),
     };
 }