Beispiel #1
0
        /// <summary>
        /// <see cref="ICloneable.Clone"/>
        /// </summary>
        public object Clone()
        {
            AlgorithmParams clone = new AlgorithmParams();

            List <IEditableParameter> clonedParams = new List <IEditableParameter>();

            clonedParams.AddRange(this.List.Select(p => (IEditableParameter)p.Clone()));
            clone.List = clonedParams;

            return(clone);
        }
        public Guid CreateTask(AlgorithmParams algorithmParams)
        {
            var newTask = new ApproximationTask {
                TaskGuid        = Guid.NewGuid(),
                AlgorithmParams = algorithmParams,
                TaskProgress    = 1
            };

            _taskRepository.AddTask(newTask);

            return(newTask.TaskGuid);
        }
 public void Approximate(
     OnApproximationProgressUpdateCallback onProgressUpdate,
     OnApproximationFinishedCallback onApproximationFinished,
     Guid taskGuid,
     string datafilePath,
     AlgorithmParams algorithmParams)
 {
     StartApproximation(
         onProgressUpdate,
         onApproximationFinished,
         taskGuid.ToString(),
         datafilePath,
         algorithmParams.PopulationSize,
         algorithmParams.GenerationsNumber,
         algorithmParams.CrossoverProbability,
         algorithmParams.MutationProbability);
 }
Beispiel #4
0
        /// <summary>
        /// Uses reflection to identify the properties of the specified
        /// algorithm, match them to this set of algParams by name, and
        /// apply their values
        /// </summary>
        public static void ApplyTo(this AlgorithmParams algParams, IAlgorithm algInstance)
        {
            foreach (IEditableParameter param in algParams.List)
            {
                PropertyInfo matchingProperty = algInstance.GetMatchingPropertyFor(param);

                if (matchingProperty == null)
                {
                    continue;
                }

                var primaryParamInfo = matchingProperty.GetParameter();

                if (!primaryParamInfo.TryApplyValue(param, algInstance))
                {
                    throw new ArgumentException("Failed to apply IEditableParameter to matching instance property");
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// <see cref="object.Equals(object)"/>
        /// </summary>
        public override bool Equals(object obj)
        {
            AlgorithmParams other = obj as AlgorithmParams;

            if (other == null)
            {
                return(false);
            }
            if (this.List.Count != other.List.Count)
            {
                return(false);
            }
            for (int i = 0; i < this.List.Count; ++i)
            {
                if (!this.List[i].Equals(other.List[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #6
0
        public static AlgorithmParams ParamsPrototype(this IAlgorithm instance)
        {
            AlgorithmParams prototype = new AlgorithmParams()
            {
                List = new List <IEditableParameter>()
            };

            foreach (PropertyInfo currentProperty in instance.GetType().GetProperties())
            {
                var primaryParamInfo = currentProperty.GetParameter();
                if (primaryParamInfo == null)
                {
                    continue;
                }

                if (!primaryParamInfo.Show)
                {
                    continue;
                }
                if (!primaryParamInfo.Supported)
                {
                    continue;
                }

                IEditableParameter newParam = currentProperty.AsEditable();

                // TODO make it so it's system configurable whether to show unsupported params
                if (newParam == null && primaryParamInfo.Supported)
                {
                    throw new Exception("Unable to determine Algorithm Parameter Type. Do you need to apply an AlgorithmParameterInfo tag?");
                }
                // ... and add it to the list of parameters!
                if (newParam != null)
                {
                    prototype.List.Add(newParam);
                }
            }

            return(prototype);
        }
Beispiel #7
0
        /// <summary>
        /// Uses reflection to identify the properties of the specified
        /// algorithm, match them to this set of algParams by name, and
        /// set the values of algParams based on the algorithm's current
        /// state.
        /// </summary>
        public static AlgorithmParams ApplyFrom(this AlgorithmParams algParams, IAlgorithm algorithm)
        {
            foreach (IEditableParameter param in algParams.List)
            {
                PropertyInfo matchingProperty = algorithm.GetMatchingPropertyFor(param);

                if (matchingProperty == null)
                {
                    continue;
                }

                var primaryParamInfo = matchingProperty.GetParameter();

                object currentVal = null;
                if (!primaryParamInfo.TryParseValue(algorithm, matchingProperty, out currentVal))
                {
                    throw new ArgumentException("Failed to apply matching instance property to IEditableParameter.");
                }
                param.Value = currentVal;
            }
            return(algParams);
        }